Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/sched: unconditional entity->lock in drm_sched_job_arm()
  regresses hot path
--

commit e186c89420ee185250eb89c11064089f96c74447
Author: Tvrtko Ursulin <[email protected]>

drm/sched: Address the fence_seq fixme

This commit moves entity->lock acquisition from drm_sched_entity_select_rq()
up into drm_sched_job_arm() and converts entity->fence_seq from atomic_t to
unsigned long.

> diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
> b/drivers/gpu/drm/scheduler/sched_main.c
> index 85a49e2198370..9c0d8c1d2395d 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -646,6 +646,9 @@ void drm_sched_job_arm(struct drm_sched_job *job)
>       struct drm_sched_entity *entity = job->entity;
>  
>       BUG_ON(!entity);
> +
> +     spin_lock(&entity->lock);
> +
>       drm_sched_entity_select_rq(entity);
>       sched = entity->rq->sched;
>  
> @@ -653,7 +656,9 @@ void drm_sched_job_arm(struct drm_sched_job *job)
>       job->s_priority = entity->priority;
>       job->entity_stats = drm_sched_entity_stats_get(entity->stats);
>  
> -     drm_sched_fence_init(job->s_fence, job->entity);
> +     drm_sched_fence_init(job->s_fence, entity);
> +
> +     spin_unlock(&entity->lock);
>  }
>  EXPORT_SYMBOL(drm_sched_job_arm);

[Severity: Medium]
Does taking entity->lock unconditionally in drm_sched_job_arm() regress the
submission hot path on busy entities?

Previously, drm_sched_entity_select_rq() returned before acquiring
entity->lock whenever spsc_queue_count(&entity->job_queue) was non-zero,
leaving drm_sched_job_arm() lockless on pipelined workloads with only a
producer-local atomic_inc_return(&entity->fence_seq).

Now every job submission acquires entity->lock here (in addition to
drm_sched_entity_push_job()) and holds it across drm_sched_entity_stats_get()
and both dma_fence_init() calls in drm_sched_fence_init().

Because the scheduler worker acquires entity->lock in
drm_sched_entity_pop_job() and nests rq->lock in drm_sched_rq_pop_entity(),
this trades an uncontended atomic increment for cross-CPU spinlock contention
and stalls submitters behind rq->lock.

Since callers already serialize drm_sched_job_arm() and
drm_sched_entity_push_job() per entity, fence_seq can be converted without
widening entity->lock across the non-empty queue fast path and fence init.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=10

Reply via email to