From: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org
Cc: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>, christian.koenig@amd.com
Subject: [PATCH v2 3/4] drm/amdgpu: Add option to disable implicit sync for a context.
Date: Mon, 21 Aug 2023 15:20:04 +0900 [thread overview]
Message-ID: <20230821062005.109771-4-ishitatsuyuki@gmail.com> (raw)
In-Reply-To: <20230821062005.109771-1-ishitatsuyuki@gmail.com>
From: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
This changes all BO usages in a submit to BOOKKEEP instead of READ,
which effectively disables implicit sync for these submits.
This is configured at a context level using the existing IOCTL.
Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Co-developed-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 16 +++++++++----
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 30 +++++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 +
include/uapi/drm/amdgpu_drm.h | 4 ++++
4 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 2cb814de0149..008547f97fd1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1200,8 +1200,11 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)
struct dma_resv *resv = bo->tbo.base.resv;
enum amdgpu_sync_mode sync_mode;
- sync_mode = amdgpu_bo_explicit_sync(bo) ?
- AMDGPU_SYNC_EXPLICIT : AMDGPU_SYNC_NE_OWNER;
+ if (amdgpu_bo_explicit_sync(bo) || p->ctx->disable_implicit_sync)
+ sync_mode = AMDGPU_SYNC_EXPLICIT;
+ else
+ sync_mode = AMDGPU_SYNC_NE_OWNER;
+
r = amdgpu_sync_resv(p->adev, &p->sync, resv, sync_mode,
AMDGPU_SYNC_EXPLICIT, &fpriv->vm);
if (r)
@@ -1322,11 +1325,16 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
dma_resv_add_fence(gobj->resv,
&p->jobs[i]->base.s_fence->finished,
- DMA_RESV_USAGE_READ);
+ p->ctx->disable_implicit_sync ?
+ DMA_RESV_USAGE_BOOKKEEP :
+ DMA_RESV_USAGE_READ);
}
/* The gang leader as remembered as writer */
- dma_resv_add_fence(gobj->resv, p->fence, DMA_RESV_USAGE_WRITE);
+ dma_resv_add_fence(gobj->resv, p->fence,
+ p->ctx->disable_implicit_sync ?
+ DMA_RESV_USAGE_BOOKKEEP :
+ DMA_RESV_USAGE_WRITE);
}
seq = amdgpu_ctx_add_fence(p->ctx, p->entities[p->gang_leader_idx],
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 0dc9c655c4fb..fe6f30d8fd70 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -661,6 +661,30 @@ static int amdgpu_ctx_stable_pstate(struct amdgpu_device *adev,
return r;
}
+static int amdgpu_ctx_set_implicit_sync(struct amdgpu_device *adev,
+ struct amdgpu_fpriv *fpriv, uint32_t id,
+ bool enable)
+{
+ struct amdgpu_ctx *ctx;
+ struct amdgpu_ctx_mgr *mgr;
+
+ if (!fpriv)
+ return -EINVAL;
+
+ mgr = &fpriv->ctx_mgr;
+ mutex_lock(&mgr->lock);
+ ctx = idr_find(&mgr->ctx_handles, id);
+ if (!ctx) {
+ mutex_unlock(&mgr->lock);
+ return -EINVAL;
+ }
+
+ ctx->disable_implicit_sync = !enable;
+
+ mutex_unlock(&mgr->lock);
+ return 0;
+}
+
int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
struct drm_file *filp)
{
@@ -709,6 +733,12 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
return -EINVAL;
r = amdgpu_ctx_stable_pstate(adev, fpriv, id, true, &stable_pstate);
break;
+ case AMDGPU_CTX_OP_SET_IMPLICIT_SYNC:
+ if ((args->in.flags & ~AMDGPU_CTX_IMPLICIT_SYNC_ENABLED) || args->in.priority)
+ return -EINVAL;
+ r = amdgpu_ctx_set_implicit_sync(adev, fpriv, id,
+ args->in.flags & ~AMDGPU_CTX_IMPLICIT_SYNC_ENABLED);
+ break;
default:
return -EINVAL;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
index 85376baaa92f..a330e5b65d30 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h
@@ -58,6 +58,7 @@ struct amdgpu_ctx {
unsigned long ras_counter_ue;
uint32_t stable_pstate;
struct amdgpu_ctx_mgr *ctx_mgr;
+ bool disable_implicit_sync;
};
struct amdgpu_ctx_mgr {
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 79b14828d542..6a0168436c31 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -226,6 +226,7 @@ union drm_amdgpu_bo_list {
#define AMDGPU_CTX_OP_QUERY_STATE2 4
#define AMDGPU_CTX_OP_GET_STABLE_PSTATE 5
#define AMDGPU_CTX_OP_SET_STABLE_PSTATE 6
+#define AMDGPU_CTX_OP_SET_IMPLICIT_SYNC 7
/* GPU reset status */
#define AMDGPU_CTX_NO_RESET 0
@@ -268,6 +269,9 @@ union drm_amdgpu_bo_list {
#define AMDGPU_CTX_STABLE_PSTATE_MIN_MCLK 3
#define AMDGPU_CTX_STABLE_PSTATE_PEAK 4
+/* opt-out of implicit sync */
+#define AMDGPU_CTX_IMPLICIT_SYNC_ENABLED 1
+
struct drm_amdgpu_ctx_in {
/** AMDGPU_CTX_OP_* */
__u32 op;
--
2.41.0
next prev parent reply other threads:[~2023-08-21 6:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-21 6:20 [PATCH v2 0/4] amdgpu: Allow explicitly synchronized submissions Tatsuyuki Ishi
2023-08-21 6:20 ` [PATCH v2 1/4] drm/amdgpu: Add separate mode for syncing DMA_RESV_USAGE_BOOKKEEP Tatsuyuki Ishi
2023-08-21 6:20 ` [PATCH v2 2/4] drm/amdgpu: Allow explicit sync for VM ops Tatsuyuki Ishi
2023-08-21 9:47 ` Christian König
2023-08-21 6:20 ` Tatsuyuki Ishi [this message]
2023-08-21 6:20 ` [PATCH v2 4/4] drm/amdgpu: Bump amdgpu driver version Tatsuyuki Ishi
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=20230821062005.109771-4-ishitatsuyuki@gmail.com \
--to=ishitatsuyuki@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox