Skip to content

Commit d42a254

Browse files
Tvrtko UrsulinPhilipp Stanner
authored andcommitted
drm/sched: Optimise drm_sched_entity_push_job
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 <[email protected]> Cc: Christian König <[email protected]> Cc: Alex Deucher <[email protected]> Cc: Luben Tuikov <[email protected]> Cc: Matthew Brost <[email protected]> Cc: Philipp Stanner <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Philipp Stanner <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent fd3b2c5 commit d42a254

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

drivers/gpu/drm/scheduler/sched_entity.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,12 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
514514
struct drm_sched_job *next;
515515

516516
next = to_drm_sched_job(spsc_queue_peek(&entity->job_queue));
517-
if (next)
518-
drm_sched_rq_update_fifo(entity, next->submit_ts);
517+
if (next) {
518+
spin_lock(&entity->rq_lock);
519+
drm_sched_rq_update_fifo_locked(entity,
520+
next->submit_ts);
521+
spin_unlock(&entity->rq_lock);
522+
}
519523
}
520524

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

615619
drm_sched_rq_add_entity(rq, entity);
616-
spin_unlock(&entity->rq_lock);
617620

618621
if (drm_sched_policy == DRM_SCHED_POLICY_FIFO)
619-
drm_sched_rq_update_fifo(entity, submit_ts);
622+
drm_sched_rq_update_fifo_locked(entity, submit_ts);
623+
624+
spin_unlock(&entity->rq_lock);
620625

621626
drm_sched_wakeup(sched);
622627
}

drivers/gpu/drm/scheduler/sched_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,15 @@ static inline void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *enti
163163
}
164164
}
165165

166-
void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
166+
void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts)
167167
{
168168
/*
169169
* Both locks need to be grabbed, one to protect from entity->rq change
170170
* for entity from within concurrent drm_sched_entity_select_rq and the
171171
* other to update the rb tree structure.
172172
*/
173-
spin_lock(&entity->rq_lock);
173+
lockdep_assert_held(&entity->rq_lock);
174+
174175
spin_lock(&entity->rq->lock);
175176

176177
drm_sched_rq_remove_fifo_locked(entity);
@@ -181,7 +182,6 @@ void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts)
181182
drm_sched_entity_compare_before);
182183

183184
spin_unlock(&entity->rq->lock);
184-
spin_unlock(&entity->rq_lock);
185185
}
186186

187187
/**

include/drm/gpu_scheduler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ void drm_sched_rq_add_entity(struct drm_sched_rq *rq,
593593
void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
594594
struct drm_sched_entity *entity);
595595

596-
void drm_sched_rq_update_fifo(struct drm_sched_entity *entity, ktime_t ts);
596+
void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts);
597597

598598
int drm_sched_entity_init(struct drm_sched_entity *entity,
599599
enum drm_sched_priority priority,

0 commit comments

Comments
 (0)