Re: [Intel-gfx] [PATCH 13/26] drm/i915: use the new iterator in i915_gem_busy_ioctl

Tvrtko Ursulin
2021-09-14T13:18:24Z

On 13/09/2021 14:16, Christian König wrote:
> This makes the function much simpler since the complex
> retry logic is now handled else where.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
> drivers/gpu/drm/i915/gem/i915_gem_busy.c | 30 +++++++-----------------
> 1 file changed, 9 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_busy.c b/drivers/gpu/drm/i915/gem/i915_gem_busy.c
> index 6234e17259c1..c6c6d747b33e 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_busy.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_busy.c
> @@ -82,8 +82,8 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
> {
> struct drm_i915_gem_busy *args = data;
> struct drm_i915_gem_object *obj;
> - struct dma_resv_list *list;
> - unsigned int seq;
> + struct dma_resv_cursor cursor;
> + struct dma_fence *fence;
> int err;
>
> err = -ENOENT;
> @@ -109,28 +109,16 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data,
> * to report the overall busyness. This is what the wait-ioctl does.
> *
> */
> -retry:
> - seq = raw_read_seqcount(&obj->base.resv->seq);
> -
> - /* Translate the exclusive fence to the READ *and* WRITE engine */
> - args->busy = busy_check_writer(dma_resv_excl_fence(obj->base.resv));
> -
> - /* Translate shared fences to READ set of engines */
> - list = dma_resv_shared_list(obj->base.resv);
> - if (list) {
> - unsigned int shared_count = list->shared_count, i;
> -
> - for (i = 0; i < shared_count; ++i) {
> - struct dma_fence *fence =
> - rcu_dereference(list->shared[i]);
> -
> + args->busy = false;
> + dma_resv_for_each_fence_unlocked(obj->base.resv, &cursor, true, fence) {

To preserve strictly identical behaviour, I think add before the below
if-else:

if (cursor.is_first)
args->busy = 0;

As mentioned elsewhere in the thread I am not convinced it is hugely
important, all that can happen without it is that stale read activity
gets reported, and this ioctl is not really that sensitive to that.

Regards,

Tvrtko

> + if (cursor.is_exclusive)
> + /* Translate the exclusive fence to the READ *and* WRITE engine */
> + args->busy = busy_check_writer(fence);
> + else
> + /* Translate shared fences to READ set of engines */
> args->busy |= busy_check_reader(fence);
> - }
> }
>
> - if (args->busy && read_seqcount_retry(&obj->base.resv->seq, seq))
> - goto retry;
> -
> err = 0;
> out:
> rcu_read_unlock();
>