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 <[email protected]>

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/[email protected]?part=4

Reply via email to