From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
intel-gfx@lists.freedesktop.org,
"Christian Koenig" <christian.koenig@amd.com>,
intel-xe@lists.freedesktop.org
Subject: [Intel-gfx] [RFC PATCH] drm/ttm: Allow the driver to resolve a WW transaction rollback
Date: Fri, 5 May 2023 16:17:19 +0200 [thread overview]
Message-ID: <20230505141719.332109-1-thomas.hellstrom@linux.intel.com> (raw)
Allow drivers to resolve a WW transaction rollback. This allows for
1) Putting a lower-priority transaction to sleep allowing another to
succeed instead both fighting using trylocks.
2) Letting the driver know whether a received -ENOMEM is the result of
competition with another WW transaction, which can be resolved using
rollback and retry or a real -ENOMEM which should be propagated back
to user-space as a failure.
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 17 +++++++++++++++--
include/drm/ttm/ttm_bo.h | 2 ++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bd5dae4d1624..c3ccbea2be3e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -561,6 +561,10 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!busy_bo || !ticket)
return -EBUSY;
+ /* We want to resolve contention before trying to lock again. */
+ if (ctx->propagate_edeadlk && ctx->contended_bo)
+ return -EDEADLK;
+
if (ctx->interruptible)
r = dma_resv_lock_interruptible(busy_bo->base.resv,
ticket);
@@ -575,7 +579,15 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!r)
dma_resv_unlock(busy_bo->base.resv);
- return r == -EDEADLK ? -EBUSY : r;
+ if (r == -EDEADLK) {
+ if (ctx->propagate_edeadlk) {
+ ttm_bo_get(busy_bo);
+ ctx->contended_bo = busy_bo;
+ }
+ r = -EBUSY;
+ }
+
+ return r;
}
int ttm_mem_evict_first(struct ttm_device *bdev,
@@ -816,7 +828,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
goto error;
}
- ret = -ENOMEM;
+ ret = (ctx->propagate_edeadlk && ctx->contended_bo) ? -EDEADLK : -ENOMEM;
if (!type_found) {
pr_err(TTM_PFX "No compatible memory type found\n");
ret = -EINVAL;
@@ -913,6 +925,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
if (ret)
return ret;
}
+
return 0;
}
EXPORT_SYMBOL(ttm_bo_validate);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 8b113c384236..d8e35a794ce5 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -181,8 +181,10 @@ struct ttm_operation_ctx {
bool gfp_retry_mayfail;
bool allow_res_evict;
bool force_alloc;
+ bool propagate_edeadlk;
struct dma_resv *resv;
uint64_t bytes_moved;
+ struct ttm_buffer_object *contended_bo;
};
/**
--
2.39.2
WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org,
Christian Koenig <christian.koenig@amd.com>,
intel-xe@lists.freedesktop.org
Subject: [Intel-xe] [RFC PATCH] drm/ttm: Allow the driver to resolve a WW transaction rollback
Date: Fri, 5 May 2023 16:17:19 +0200 [thread overview]
Message-ID: <20230505141719.332109-1-thomas.hellstrom@linux.intel.com> (raw)
Allow drivers to resolve a WW transaction rollback. This allows for
1) Putting a lower-priority transaction to sleep allowing another to
succeed instead both fighting using trylocks.
2) Letting the driver know whether a received -ENOMEM is the result of
competition with another WW transaction, which can be resolved using
rollback and retry or a real -ENOMEM which should be propagated back
to user-space as a failure.
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 17 +++++++++++++++--
include/drm/ttm/ttm_bo.h | 2 ++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bd5dae4d1624..c3ccbea2be3e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -561,6 +561,10 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!busy_bo || !ticket)
return -EBUSY;
+ /* We want to resolve contention before trying to lock again. */
+ if (ctx->propagate_edeadlk && ctx->contended_bo)
+ return -EDEADLK;
+
if (ctx->interruptible)
r = dma_resv_lock_interruptible(busy_bo->base.resv,
ticket);
@@ -575,7 +579,15 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!r)
dma_resv_unlock(busy_bo->base.resv);
- return r == -EDEADLK ? -EBUSY : r;
+ if (r == -EDEADLK) {
+ if (ctx->propagate_edeadlk) {
+ ttm_bo_get(busy_bo);
+ ctx->contended_bo = busy_bo;
+ }
+ r = -EBUSY;
+ }
+
+ return r;
}
int ttm_mem_evict_first(struct ttm_device *bdev,
@@ -816,7 +828,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
goto error;
}
- ret = -ENOMEM;
+ ret = (ctx->propagate_edeadlk && ctx->contended_bo) ? -EDEADLK : -ENOMEM;
if (!type_found) {
pr_err(TTM_PFX "No compatible memory type found\n");
ret = -EINVAL;
@@ -913,6 +925,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
if (ret)
return ret;
}
+
return 0;
}
EXPORT_SYMBOL(ttm_bo_validate);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 8b113c384236..d8e35a794ce5 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -181,8 +181,10 @@ struct ttm_operation_ctx {
bool gfp_retry_mayfail;
bool allow_res_evict;
bool force_alloc;
+ bool propagate_edeadlk;
struct dma_resv *resv;
uint64_t bytes_moved;
+ struct ttm_buffer_object *contended_bo;
};
/**
--
2.39.2
WARNING: multiple messages have this Message-ID (diff)
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: dri-devel@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
intel-gfx@lists.freedesktop.org,
"Christian Koenig" <christian.koenig@amd.com>,
intel-xe@lists.freedesktop.org
Subject: [RFC PATCH] drm/ttm: Allow the driver to resolve a WW transaction rollback
Date: Fri, 5 May 2023 16:17:19 +0200 [thread overview]
Message-ID: <20230505141719.332109-1-thomas.hellstrom@linux.intel.com> (raw)
Allow drivers to resolve a WW transaction rollback. This allows for
1) Putting a lower-priority transaction to sleep allowing another to
succeed instead both fighting using trylocks.
2) Letting the driver know whether a received -ENOMEM is the result of
competition with another WW transaction, which can be resolved using
rollback and retry or a real -ENOMEM which should be propagated back
to user-space as a failure.
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
drivers/gpu/drm/ttm/ttm_bo.c | 17 +++++++++++++++--
include/drm/ttm/ttm_bo.h | 2 ++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bd5dae4d1624..c3ccbea2be3e 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -561,6 +561,10 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!busy_bo || !ticket)
return -EBUSY;
+ /* We want to resolve contention before trying to lock again. */
+ if (ctx->propagate_edeadlk && ctx->contended_bo)
+ return -EDEADLK;
+
if (ctx->interruptible)
r = dma_resv_lock_interruptible(busy_bo->base.resv,
ticket);
@@ -575,7 +579,15 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
if (!r)
dma_resv_unlock(busy_bo->base.resv);
- return r == -EDEADLK ? -EBUSY : r;
+ if (r == -EDEADLK) {
+ if (ctx->propagate_edeadlk) {
+ ttm_bo_get(busy_bo);
+ ctx->contended_bo = busy_bo;
+ }
+ r = -EBUSY;
+ }
+
+ return r;
}
int ttm_mem_evict_first(struct ttm_device *bdev,
@@ -816,7 +828,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
goto error;
}
- ret = -ENOMEM;
+ ret = (ctx->propagate_edeadlk && ctx->contended_bo) ? -EDEADLK : -ENOMEM;
if (!type_found) {
pr_err(TTM_PFX "No compatible memory type found\n");
ret = -EINVAL;
@@ -913,6 +925,7 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
if (ret)
return ret;
}
+
return 0;
}
EXPORT_SYMBOL(ttm_bo_validate);
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 8b113c384236..d8e35a794ce5 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -181,8 +181,10 @@ struct ttm_operation_ctx {
bool gfp_retry_mayfail;
bool allow_res_evict;
bool force_alloc;
+ bool propagate_edeadlk;
struct dma_resv *resv;
uint64_t bytes_moved;
+ struct ttm_buffer_object *contended_bo;
};
/**
--
2.39.2
next reply other threads:[~2023-05-05 14:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-05 14:17 Thomas Hellström [this message]
2023-05-05 14:17 ` [RFC PATCH] drm/ttm: Allow the driver to resolve a WW transaction rollback Thomas Hellström
2023-05-05 14:17 ` [Intel-xe] " Thomas Hellström
2023-05-05 14:20 ` [Intel-xe] ✓ CI.Patch_applied: success for " Patchwork
2023-05-05 14:21 ` [Intel-xe] ✓ CI.KUnit: " Patchwork
2023-05-05 14:25 ` [Intel-xe] ✓ CI.Build: " Patchwork
2023-05-05 14:50 ` [Intel-xe] ○ CI.BAT: info " Patchwork
2023-05-05 20:19 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning " Patchwork
2023-05-05 20:33 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2023-05-25 12:59 ` [Intel-gfx] [RFC PATCH] " Thomas Hellström
2023-05-25 12:59 ` Thomas Hellström
2023-05-25 12:59 ` [Intel-xe] " Thomas Hellström
2023-05-25 13:59 ` [Intel-gfx] " Christian König
2023-05-25 13:59 ` Christian König
2023-05-25 13:59 ` [Intel-xe] " Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230505141719.332109-1-thomas.hellstrom@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.