[PATCH 4/8] drm/sched: Optimise drm_sched_entity_push_job

Christian König ckoenig.leichtzumerken at gmail.com
Tue Sep 10 08:36:47 UTC 2024



Am 09.09.24 um 19:19 schrieb Tvrtko Ursulin:
> From: Tvrtko Ursulin <tvrtko.ursulin at igalia.com>
>
> In FIFO mode We can avoid dropping the lock only to immediately re-acquire
> by adding a new drm_sched_rq_update_fifo_locked() helper.
>
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at igalia.com>
> Cc: Christian König <christian.koenig at amd.com>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: Luben Tuikov <ltuikov89 at gmail.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
> Cc: Philipp Stanner <pstanner at redhat.com>
> ---
>   drivers/gpu/drm/scheduler/sched_entity.c |  5 +++--
>   drivers/gpu/drm/scheduler/sched_main.c   | 21 ++++++++++++++-------
>   include/drm/gpu_scheduler.h              |  1 +
>   3 files changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
> index 6645a8524699..2da677681291 100644
> --- a/drivers/gpu/drm/scheduler/sched_entity.c
> +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> @@ -615,10 +615,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
>   
>   		atomic_inc(sched->score);
>   		drm_sched_rq_add_entity(rq, entity);
> -		spin_unlock(&entity->rq_lock);
>   
>   		if (drm_sched_policy == DRM_SCHED_POLICY_FIFO)
> -			drm_sched_rq_update_fifo(entity, submit_ts);
> +			drm_sched_rq_update_fifo_locked(entity, submit_ts);
> +
> +		spin_unlock(&entity->rq_lock);
>   
>   		drm_sched_wakeup(sched, entity);
>   	}
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index ab53ab486fe6..10abbcefe9d8 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -163,14 +163,10 @@ static inline void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *enti
>   	}
>   }
>   
> -void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
> +void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts)
>   {
> -	/*
> -	 * Both locks need to be grabbed, one to protect from entity->rq change
> -	 * for entity from within concurrent drm_sched_entity_select_rq and the
> -	 * other to update the rb tree structure.
> -	 */
> -	spin_lock(&entity->rq_lock);
> +	lockdep_assert_held(&entity->rq_lock);
> +
>   	spin_lock(&entity->rq->lock);
>   
>   	drm_sched_rq_remove_fifo_locked(entity);
> @@ -181,6 +177,17 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
>   		      drm_sched_entity_compare_before);
>   
>   	spin_unlock(&entity->rq->lock);
> +}
> +
> +void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
> +{
> +	/*
> +	 * Both locks need to be grabbed, one to protect from entity->rq change
> +	 * for entity from within concurrent drm_sched_entity_select_rq and the
> +	 * other to update the rb tree structure.
> +	 */
> +	spin_lock(&entity->rq_lock);
> +	drm_sched_rq_update_fifo_locked(entity, ts);
>   	spin_unlock(&entity->rq_lock);
>   }

I wonder if we shouldn't change the only other occasion calling this to 
grab the lock manually as well.

Christian.

>   
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index fe8edb917360..a06753987d93 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -594,6 +594,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
>   				struct drm_sched_entity *entity);
>   
>   void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts);
> +void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts);
>   
>   int drm_sched_entity_init(struct drm_sched_entity *entity,
>   			  enum drm_sched_priority priority,



More information about the dri-devel mailing list