Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Philipp Stanner" <phasta@kernel.org>
Cc: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org, media-ci@linuxtv.org
Subject: Re: [RFC PATCH 4/8] dma-buf: dma-fence: Improve dma_fence_timestamp()
Date: Fri, 27 Nov 2026 10:42:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-237161@kernel.org> (raw)
In-Reply-To: <20261127101812.2706432-6-phasta@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dma-buf: redundant ktime_get() on signaled fences in
  __dma_fence_unwrap_merge()
--

commit e022bd65ff0c3c874a861f648d1911f74f6646f1
Author: Philipp Stanner <phasta@kernel.org>

dma-buf: dma-fence: Improve dma_fence_timestamp()

This commit changes dma_fence_timestamp() to write the completion
timestamp through an output pointer and return an integer status code,
updating callers across dma-buf and drm/sched.

> diff --git a/drivers/dma-buf/dma-fence-unwrap.c b/drivers/dma-buf/dma-fence-unwrap.c
> index 120fe0c2a75af..a1e9b1ee2c325 100644
> --- a/drivers/dma-buf/dma-fence-unwrap.c
> +++ b/drivers/dma-buf/dma-fence-unwrap.c
> @@ -136,10 +136,14 @@ struct dma_fence *__dma_fence_unwrap_merge(size_t num_fences,
>  				unsignaled = dma_fence_get(tmp);
>  				++count;
>  			} else {
> -				ktime_t t = dma_fence_timestamp(tmp);
> -
> -				if (ktime_after(t, timestamp))
> -					timestamp = t;
> +				ktime_t fence_ts = ktime_get();
> +				/* Leaves fence_ts unchanged if fence is not yet
> +				 * signaled.
> +				 */
> +				dma_fence_timestamp(tmp, &fence_ts);
> +
> +				if (ktime_after(fence_ts, timestamp))
> +					timestamp = fence_ts;
>  			}
>  		}
>  	}
> @@ -168,10 +172,14 @@ struct dma_fence *__dma_fence_unwrap_merge(size_t num_fences,
>  			if (!dma_fence_is_signaled(tmp)) {
>  				array[count++] = dma_fence_get(tmp);
>  			} else {
> -				ktime_t t = dma_fence_timestamp(tmp);
> -
> -				if (ktime_after(t, timestamp))
> -					timestamp = t;
> +				ktime_t fence_ts = ktime_get();
> +				/* Leaves fence_ts unchanged if fence is not yet
> +				 * signaled.
> +				 */
> +				dma_fence_timestamp(tmp, &fence_ts);
> +
> +				if (ktime_after(fence_ts, timestamp))
> +					timestamp = fence_ts;
>  			}
>  		}
>  	}

[Severity: Medium]
Does initializing fence_ts with ktime_get() in both else branches perform
an unnecessary clocksource read for every signaled fence?

Both branches only run after dma_fence_is_signaled(tmp) returns true, so
DMA_FENCE_FLAG_SIGNALED_BIT is already set on tmp->flags and
dma_fence_timestamp(tmp, &fence_ts) will always overwrite fence_ts with
tmp->timestamp.  Before this change, ktime_get() was only called on the
unsignaled fallback path inside dma_fence_timestamp().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127101812.2706432-2-phasta@kernel.org?part=4

  reply	other threads:[~2026-11-27 10:43 UTC|newest]

Thread overview: 14+ 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 [this message]
2026-11-27 10:18 ` [RFC PATCH 5/8] drm/amdgpu: Stop using dma_fence internals Philipp Stanner
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

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=sashiko-outbox-237161@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=media-ci@linuxtv.org \
    --cc=phasta@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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