Skip to content

Commit

Permalink
drm/sched: Optimise drm_sched_entity_push_job
Browse files Browse the repository at this point in the history
In FIFO mode (which is the default), both drm_sched_entity_push_job() and
drm_sched_rq_update_fifo(), where the latter calls the former, are
currently taking and releasing the same entity->rq_lock.

We can avoid that design inelegance, and also have a miniscule
efficiency improvement on the submit from idle path, by introducing a new
drm_sched_rq_update_fifo_locked() helper and pulling up the lock taking to
its callers.

v2:
 * Remove drm_sched_rq_update_fifo() altogether. (Christian)

v3:
 * Improved commit message. (Philipp)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Luben Tuikov <ltuikov89@gmail.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Philipp Stanner <pstanner@redhat.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241016122013.7857-2-tursulin@igalia.com
  • Loading branch information
Tvrtko Ursulin authored and Philipp Stanner committed Oct 17, 2024
1 parent fd3b2c5 commit d42a254
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions drivers/gpu/drm/scheduler/sched_entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
struct drm_sched_job *next;

next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
if (next)
drm_sched_rq_update_fifo(entity, next->submit_ts);
if (next) {
spin_lock(&entity->rq_lock);
drm_sched_rq_update_fifo_locked(entity,
next->submit_ts);
spin_unlock(&entity->rq_lock);
}
}

/* Jobs and entities might have different lifecycles. Since we're
Expand Down Expand Up @@ -613,10 +617,11 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
sched = rq->sched;

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);
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/scheduler/sched_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ 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);
Expand All @@ -181,7 +182,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
drm_sched_entity_compare_before);

spin_unlock(&entity->rq->lock);
spin_unlock(&entity->rq_lock);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/drm/gpu_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,
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,
Expand Down

0 comments on commit d42a254

Please sign in to comment.