From: Philipp Stanner <phasta@kernel.org>
To: "Sumit Semwal" <sumit.semwal@linaro.org>,
"Christian König" <christian.koenig@amd.com>,
"Philipp Stanner" <phasta@kernel.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Tvrtko Ursulin" <tursulin@ursulin.net>,
"Matthew Brost" <matthew.brost@intel.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Mario Limonciello (AMD)" <superm1@kernel.org>,
"Ruslan Vagner" <rusya92266@gmail.com>,
"Gustavo Padovan" <gustavo.padovan@collabora.com>,
"Chris Wilson" <chris@chris-wilson.co.uk>
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org,
intel-gfx@lists.freedesktop.org
Subject: [RFC PATCH 5/8] drm/amdgpu: Stop using dma_fence internals
Date: Fri, 27 Nov 2026 11:18:10 +0100 [thread overview]
Message-ID: <20261127101812.2706432-7-phasta@kernel.org> (raw)
In-Reply-To: <20261127101812.2706432-2-phasta@kernel.org>
amdgpu_ctx_fence_time() directly accesses a fence's internal timestamp,
not ensuring memory ordering.
Make the code more robust and readable by using the (now improved)
dma_fence_timestamp() function.
Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
I think this should, contrary to my previous statements, be fine since
the lock taken is the s_fence lock, whereas this function's caller holds
a distinct fctx lock.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
index 2f0349233695..9d6d92cb9734 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c
@@ -170,6 +170,7 @@ static unsigned int amdgpu_ctx_get_hw_prio(struct amdgpu_ctx *ctx, u32 hw_ip)
/* Calculate the time spend on the hw */
static ktime_t amdgpu_ctx_fence_time(struct dma_fence *fence)
{
+ ktime_t scheduled_ts, finished_ts;
struct drm_sched_fence *s_fence;
if (!fence)
@@ -177,15 +178,15 @@ static ktime_t amdgpu_ctx_fence_time(struct dma_fence *fence)
/* When the fence is not even scheduled it can't have spend time */
s_fence = to_drm_sched_fence(fence);
- if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->scheduled.flags))
+
+ if (dma_fence_timestamp(&s_fence->scheduled, &scheduled_ts) != 0)
return ns_to_ktime(0);
/* When it is still running account how much already spend */
- if (!test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT, &s_fence->finished.flags))
- return ktime_sub(ktime_get(), s_fence->scheduled.timestamp);
+ if (dma_fence_timestamp(&s_fence->finished, &finished_ts) != 0)
+ return ktime_sub(ktime_get(), scheduled_ts);
- return ktime_sub(s_fence->finished.timestamp,
- s_fence->scheduled.timestamp);
+ return ktime_sub(finished_ts, scheduled_ts);
}
static ktime_t amdgpu_ctx_entity_time(struct amdgpu_ctx *ctx,
--
2.56.0
next prev parent reply other threads:[~2026-11-27 10:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:18 [RFC PATCH 0/8] dma-fence: Remove TIMESTAMP bit Philipp Stanner
2026-11-27 10:18 ` [RFC PATCH 1/8] dma-buf: dma-fence: Hot-fix timestamp misordering Philipp Stanner
2026-11-27 10:18 ` [RFC PATCH 2/8] drm/sched: " Philipp Stanner
2026-11-27 10:18 ` [RFC PATCH 3/8] dma-buf: dma-fence: Ensure ordering with locks for timestamps Philipp Stanner
2026-11-27 10:48 ` sashiko-bot
2026-11-27 10:18 ` [RFC PATCH 4/8] dma-buf: dma-fence: Improve dma_fence_timestamp() Philipp Stanner
2026-11-27 10:42 ` sashiko-bot
2026-11-27 10:18 ` Philipp Stanner [this message]
2026-11-27 10:18 ` [RFC PATCH 6/8] dma-buf: sync_debug: don't use TIMESTAMP bit Philipp Stanner
2026-11-27 10:26 ` sashiko-bot
2026-11-27 10:18 ` [RFC PATCH 7/8] drm/i915: Remove " Philipp Stanner
2026-11-27 10:35 ` sashiko-bot
2026-11-27 10:18 ` [RFC PATCH 8/8] dma-buf: dma-fence: " Philipp Stanner
2026-11-27 10:36 ` sashiko-bot
2026-11-27 12:27 ` ✓ i915.CI.BAT: success for " Patchwork
2026-11-28 17:57 ` ✓ i915.CI.Full: " Patchwork
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=20261127101812.2706432-7-phasta@kernel.org \
--to=phasta@kernel.org \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=chris@chris-wilson.co.uk \
--cc=christian.koenig@amd.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo.padovan@collabora.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=matthew.brost@intel.com \
--cc=mripard@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=rusya92266@gmail.com \
--cc=simona@ffwll.ch \
--cc=sumit.semwal@linaro.org \
--cc=superm1@kernel.org \
--cc=tursulin@ursulin.net \
--cc=tzimmermann@suse.de \
/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.