Small DRM scheduler improvements
Subsystems (3)
v2 cover Small DRM scheduler improvements
From: Tvrtko Ursulin <[email protected]>
Leftovers from the earlier "DRM scheduler fixes and improvements" series.
It looks the fixes have now propagated back to drm-misc-next so this should now be mergeable.
It also needed a small rebase to account for one revert and one spelling fix which landed in the meantime.
As a reminder, what remains are kerneldoc improvements, struct layout tweaks for clarity, one trivial cleanup for the FIFO mode, and most importantly two spin lock-unlock cycles are removed from the push job path by pulling taking of the locks one level up.
I smoke tested it on the Steam Deck and lockdep seems happy.
v2:
* Tweaks to commit messages and rename of some leftover rq_lock naming inside kerneldoc.
Tvrtko Ursulin (5):
drm/sched: Optimise drm_sched_entity_push_job drm/sched: Stop setting current entity in FIFO mode drm/sched: Re-order struct drm_sched_rq members for clarity drm/sched: Re-group and rename the entity run-queue lock drm/sched: Further optimise drm_sched_entity_push_job
drivers/gpu/drm/scheduler/sched_entity.c | 42 +++++++++++++++--------- drivers/gpu/drm/scheduler/sched_main.c | 32 +++++++++--------- include/drm/gpu_scheduler.h | 34 ++++++++++--------- 3 files changed, 61 insertions(+), 47 deletions(-)
Signature · 1 line
2.46.0
PATCH v2 1/5 drm/sched: Optimise drm_sched_entity_push_job
From: Tvrtko Ursulin <[email protected]>
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)
--- drivers/gpu/drm/scheduler/sched_entity.c | 13 +++++++++---- drivers/gpu/drm/scheduler/sched_main.c | 6 +++--- include/drm/gpu_scheduler.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +9 -4
@@ -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
@@ -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); }
drivers/gpu/drm/scheduler/sched_main.c +3 -3
@@ -169,14 +169,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);
@@ -187,7 +188,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); }/**
include/drm/gpu_scheduler.h +1 -1
@@ -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,
Signature · 1 line
2.46.0
PATCH v2 2/5 drm/sched: Stop setting current entity in FIFO mode
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
It does not seem there is a need to set the current entity in FIFO mode since ot only serves as being a "cursor" in round-robin mode. Even if scheduling mode is changed at runtime the change in behaviour is simply to restart from the first entity, instead of continuing in RR mode from where FIFO left it, and that sounds completely fine.
--- drivers/gpu/drm/scheduler/sched_main.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -1
@@ -355,7 +355,6 @@ drm_sched_rq_select_entity_fifo(struct drm_gpu_scheduler *sched,return ERR_PTR (-ENOSPC ); } - rq->current_entity = entity;reinit_completion (&entity->entity_idle);break ; }
Signature · 1 line
2.46.0
PATCH v2 3/5 drm/sched: Re-order struct drm_sched_rq members for clarity
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Current kerneldoc for struct drm_sched_rq incompletely documents what fields are protected by the lock.
This is not good because it is misleading.
Lets fix it by listing all the elements which are protected by the lock.
While at it, lets also re-order the members so all protected by the lock are in a single group.
v2:
* Refer variables by kerneldoc syntax, more verbose commit text. (Philipp)
--- include/drm/gpu_scheduler.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
include/drm/gpu_scheduler.h +6 -4
@@ -243,10 +243,10 @@ struct drm_sched_entity {/** * struct drm_sched_rq - queue of entities to be scheduled. * -* @lock: to modify the entities list. * @sched: the scheduler to which this rq belongs to. -* @entities: list of the entities to be scheduled. +* @lock: protects @entities, @rb_tree_root and @current_entity. * @current_entity: the entity which is to be scheduled. +* @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities for FIFO scheduling * * Run queue is a set of entities scheduling command submissions for
@@ -254,10 +254,12 @@ struct drm_sched_entity {* the next entity to emit commands from. */ struct drm_sched_rq { -spinlock_t lock;struct drm_gpu_scheduler *sched; -struct list_head entities; + +spinlock_t lock; +/* Following members are protected by the @lock: */ struct drm_sched_entity *current_entity; +struct list_head entities;struct rb_root_cached rb_tree_root; };
Signature · 1 line
2.46.0
PATCH v2 4/5 drm/sched: Re-group and rename the entity run-queue lock
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
When writing to a drm_sched_entity's run-queue, writers are protected through the lock drm_sched_entity.rq_lock. This naming, however, frequently collides with the separate internal lock of struct drm_sched_rq, resulting in uses like this:
spin_lock(&entity->rq_lock); spin_lock(&entity->rq->lock);
Rename drm_sched_entity.rq_lock to improve readability. While at it, re-order that struct's members to make it more obvious what the lock protects.
v2:
* Rename some rq_lock straddlers in kerneldoc, improve commit text. (Philipp)
--- drivers/gpu/drm/scheduler/sched_entity.c | 28 ++++++++++++------------ drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 21 +++++++++--------- 3 files changed, 26 insertions(+), 25 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +14 -14
@@ -105,7 +105,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,/* We start in an idle state. */ complete_all (&entity->entity_idle); -spin_lock_init (&entity->rq_lock); +spin_lock_init (&entity->lock);spsc_queue_init (&entity->job_queue);atomic_set (&entity->fence_seq,0 );
@@ -133,10 +133,10 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, {WARN_ON (!num_sched_list || !sched_list); -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->sched_list = sched_list; entity->num_sched_list = num_sched_list; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); }EXPORT_SYMBOL (drm_sched_entity_modify_sched);
@@ -244,10 +244,10 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity)if (!entity->rq)return ; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->stopped = true;drm_sched_rq_remove_entity (entity->rq, entity); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);/* Make sure this entity is not used by the scheduler at the moment */ wait_for_completion (&entity->entity_idle);
@@ -396,9 +396,9 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,void drm_sched_entity_set_priority (struct drm_sched_entity *entity,enum drm_sched_priority priority) { -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); entity->priority = priority; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); }EXPORT_SYMBOL (drm_sched_entity_set_priority);
@@ -515,10 +515,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));if (next) { -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);drm_sched_rq_update_fifo_locked (entity, next->submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } }
@@ -559,14 +559,14 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)if (fence && !dma_fence_is_signaled (fence))return ; -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock); sched =drm_sched_pick_best (entity->sched_list, entity->num_sched_list); rq = sched ? sched->sched_rq[entity->priority] :NULL ;if (rq != entity->rq) {drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq; } -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);if (entity->num_sched_list ==1 ) entity->sched_list =NULL ;
@@ -605,9 +605,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)struct drm_sched_rq *rq;/* Add the entity to the run queue */ -spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);if (entity->stopped) { -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);DRM_ERROR ("Trying to push to a killed entity\n" );return ;
@@ -621,7 +621,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO )drm_sched_rq_update_fifo_locked (entity, submit_ts); -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);drm_sched_wakeup (sched); }
drivers/gpu/drm/scheduler/sched_main.c +1 -1
@@ -176,7 +176,7 @@ void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts* for entity from within concurrent drm_sched_entity_select_rq and the * other to update the rb tree structure. */ -lockdep_assert_held (&entity->rq_lock); +lockdep_assert_held (&entity->lock);spin_lock (&entity->rq->lock);
include/drm/gpu_scheduler.h +11 -10
@@ -96,14 +96,22 @@ struct drm_sched_entity {*/ struct list_head list; +/** +* @lock: +* +* Lock protecting the run-queue (@rq) to which this entity belongs, +* @priority and the list of schedulers (@sched_list, @num_sched_list). +*/ +spinlock_t lock; +/** * @rq: * * Runqueue on which this entity is currently scheduled. * * FIXME: Locking is very unclear for this. Writers are protected by -* @rq_lock, but readers are generally lockless and seem to just race -* with not even a READ_ONCE. +* @lock, but readers are generally lockless and seem to just race with +* not even a READ_ONCE. */ struct drm_sched_rq *rq;
@@ -136,17 +144,10 @@ struct drm_sched_entity {* @priority: * * Priority of the entity. This can be modified by calling -* drm_sched_entity_set_priority(). Protected by &rq_lock. +* drm_sched_entity_set_priority(). Protected by &lock. */ enum drm_sched_priority priority; -/** -* @rq_lock: -* -* Lock to modify the runqueue to which this entity belongs. -*/ -spinlock_t rq_lock; -/** * @job_queue: the list of jobs of this entity. */
Signature · 1 line
2.46.0
Re: [PATCH 4/5] drm/sched: Re-group and rename the entity run-queue lock
Quoted 201 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
When writing to a drm_sched_entity's run-queue, writers are protected through the lock drm_sched_entity.rq_lock. This naming, however, frequently collides with the separate internal lock of struct
drm_sched_rq, resulting in uses like this:spin_lock(&entity->rq_lock); spin_lock(&entity->rq->lock);Rename drm_sched_entity.rq_lock to improve readability. While at it, re-order that struct's members to make it more obvious what the lock protects.
v2:
* Rename somerq_lockstraddlers in kerneldoc, improve commit text. (Philipp)Signed-off-by Tvrtko Ursulin <[email protected]>Suggested-by 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]>---
drivers/gpu/drm/scheduler/sched_entity.c | 28 ++++++++++++---------- --
drivers/gpu/drm/scheduler/sched_main.c | 2 +- include/drm/gpu_scheduler.h | 21 +++++++++---------3 files changed, 26 insertions(+), 25 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -105,7 +105,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, /* We start in an idle state. */ complete_all(&entity->entity_idle);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock_init (&entity->rq_lock); +spin_lock_init (&entity->lock);
spsc_queue_init(&entity->job_queue);
atomic_set(&entity->fence_seq, 0);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -133,10 +133,10 @@ void drm_sched_entity_modify_sched(structdrm_sched_entity *entity, { WARN_ON(!num_sched_list || !sched_list);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);
entity->sched_list=sched_list;
entity->num_sched_list=num_sched_list;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);}
EXPORT_SYMBOL(drm_sched_entity_modify_sched);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -244,10 +244,10 @@ static void drm_sched_entity_kill(struct drm_sched_entity *entity) if (!entity->rq) return;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);
entity->stopped= true;drm_sched_rq_remove_entity(entity->rq, entity);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
/* Make sure this entity is not used by the scheduler at the moment */
wait_for_completion(&entity->entity_idle);drivers/gpu/drm/scheduler/sched_entity.c +2
-2@@ -396,9 +396,9 @@ static void drm_sched_entity_wakeup(structdma_fence *f, void drm_sched_entity_set_priority(struct drm_sched_entity *entity, enum drm_sched_priority priority) { - spin_lock(&entity->rq_lock); + spin_lock(&entity->lock); entity->priority = priority; -spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock); } EXPORT_SYMBOL(drm_sched_entity_set_priority);drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -515,10 +515,10 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)
next = to_drm_sched_job(spsc_queue_peek(&entity-Quoted 1 line
job_queue));if (next) {
drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);drm_sched_rq_update_fifo_locked(entity, next-
Quoted 1 line
submit_ts);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);}
}drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -559,14 +559,14 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity) if (fence && !dma_fence_is_signaled(fence)) return;drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);sched = drm_sched_pick_best(entity->sched_list, entity-
Quoted 1 line
num_sched_list);rq = sched ? sched->sched_rq[entity->priority] : NULL; if (rq !=
entity->rq) {drm_sched_rq_remove_entity(entity->rq, entity);entity->rq= rq;
}drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
if (entity->num_sched_list== 1)
entity->sched_list= NULL;drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -605,9 +605,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) struct drm_sched_rq *rq;
/* Add the entity to the run queue */drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_lock (&entity->rq_lock); +spin_lock (&entity->lock);if (
entity->stopped) {drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
DRM_ERROR("Trying to push to a killed entity\n");
return;drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -621,7 +621,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) if (drm_sched_policy == DRM_SCHED_POLICY_FIFO) drm_sched_rq_update_fifo_locked(entity, submit_ts);drivers/gpu/drm/scheduler/sched_entity.c +1
-1-spin_unlock (&entity->rq_lock); +spin_unlock (&entity->lock);
drm_sched_wakeup(sched);
}drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -176,7 +176,7 @@ void drm_sched_rq_update_fifo_locked(struct
drm_sched_entity*entity,ktime_tts
* for entity from within concurrentdrm_sched_entity_select_rqand the
* other to update the rb tree structure.
*/drivers/gpu/drm/scheduler/sched_main.c +1
-1-lockdep_assert_held (&entity->rq_lock); +lockdep_assert_held (&entity->lock);
spin_lock(&entity->rq->lock);include/drm/gpu_scheduler.h +0
-0@@ -96,14 +96,22 @@ struct drm_sched_entity {*/ struct list_head list;include/drm/gpu_scheduler.h +4
-0+/** +* @lock: +* +* Lock protecting the run-queue (@rq) to which this entity belongs,
include/drm/gpu_scheduler.h +1
-0+* @priority and the list of schedulers (@sched_list, @num_sched_list).
include/drm/gpu_scheduler.h +3
-0+*/ +spinlock_t lock; +/**
* @rq:
*
* Runqueue on which this entity is currently scheduled. *
* FIXME: Locking is very unclear for this. Writers are protected byinclude/drm/gpu_scheduler.h +0
-1-* @rq_lock, but readers are generally lockless and seem to just race
include/drm/gpu_scheduler.h +1
-1-* with not even a READ_ONCE. +* @lock, but readers are generally lockless and seem to just race with
include/drm/gpu_scheduler.h +1
-0+* not even a READ_ONCE. */
structdrm_sched_rq*rq;
include/drm/gpu_scheduler.h struct drm_sched_entity { · line 147
Quoted 5 lines
include/drm/gpu_scheduler.h +1
-1@@ -136,17 +144,10 @@ struct drm_sched_entity { * @priority: * * Priority of the entity. This can be modified by calling - * drm_sched_entity_set_priority(). Protected by &rq_lock. + * drm_sched_entity_set_priority(). Protected by &lock.
Should be '@lock'.
I fixed it on my branch.
P.
Quoted 13 lines
include/drm/gpu_scheduler.h +0
-0*/ enum drm_sched_priority priority;include/drm/gpu_scheduler.h +0
-7-/** -* @rq_lock: -* -* Lock to modify the runqueue to which this entity belongs. -*/ -spinlock_t rq_lock; -/**
* @job_queue: the list of jobs of this entity. */
PATCH v2 5/5 drm/sched: Further optimise drm_sched_entity_push_job
In reply to Tvrtko UrsulinFrom: Tvrtko Ursulin <[email protected]>
Having removed one re-lock cycle on the entity->lock in a patch titled "drm/sched: Optimise drm_sched_entity_push_job", with only a tiny bit larger refactoring we can do the same optimisation on the rq->lock. (Currently both drm_sched_rq_add_entity() and drm_sched_rq_update_fifo_locked() take and release the same lock.)
To achieve this we make drm_sched_rq_update_fifo_locked() and drm_sched_rq_add_entity() expect the rq->lock to be held.
We also align drm_sched_rq_update_fifo_locked(), drm_sched_rq_add_entity() and drm_sched_rq_remove_fifo_locked() function signatures, by adding rq as a parameter to the latter.
v2:
* Fix after rebase of the series.
* Avoid naming inconsistency between drm_sched_rq_add/remove. (Christian)
--- drivers/gpu/drm/scheduler/sched_entity.c | 11 +++++++-- drivers/gpu/drm/scheduler/sched_main.c | 29 ++++++++++++------------ include/drm/gpu_scheduler.h | 3 ++- 3 files changed, 25 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +9 -2
@@ -515,9 +515,14 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity) next =to_drm_sched_job (spsc_queue_peek (&entity->job_queue));if (next) { +struct drm_sched_rq *rq; +spin_lock (&entity->lock); -drm_sched_rq_update_fifo_locked (entity, + rq = entity->rq; +spin_lock (&rq->lock); +drm_sched_rq_update_fifo_locked (entity, rq, next->submit_ts); +spin_unlock (&rq->lock);spin_unlock (&entity->lock); } }
@@ -616,11 +621,13 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) rq = entity->rq; sched = rq->sched; +spin_lock (&rq->lock);drm_sched_rq_add_entity (rq, entity);if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_update_fifo_locked (entity, submit_ts); +drm_sched_rq_update_fifo_locked (entity, rq, submit_ts); +spin_unlock (&rq->lock);spin_unlock (&entity->lock);drm_sched_wakeup (sched);
drivers/gpu/drm/scheduler/sched_main.c +14 -15
@@ -159,17 +159,18 @@ static __always_inline bool drm_sched_entity_compare_before(struct rb_node *a,return ktime_before (ent_a->oldest_job_waiting, ent_b->oldest_job_waiting); } -static inline void drm_sched_rq_remove_fifo_locked (struct drm_sched_entity *entity) +static void drm_sched_rq_remove_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq) { -struct drm_sched_rq *rq = entity->rq; -if (!RB_EMPTY_NODE (&entity->rb_tree_node)) {rb_erase_cached (&entity->rb_tree_node, &rq->rb_tree_root);RB_CLEAR_NODE (&entity->rb_tree_node); } } -void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity,ktime_t ts) +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq, +ktime_t ts) {/* * Both locks need to be grabbed, one to protect from entity->rq change
@@ -177,17 +178,14 @@ void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity, ktime_t ts* other to update the rb tree structure. */ lockdep_assert_held (&entity->lock); +lockdep_assert_held (&rq->lock); -spin_lock (&entity->rq->lock); - -drm_sched_rq_remove_fifo_locked (entity); +drm_sched_rq_remove_fifo_locked (entity, rq); entity->oldest_job_waiting = ts; -rb_add_cached (&entity->rb_tree_node, &entity->rq->rb_tree_root, +rb_add_cached (&entity->rb_tree_node, &rq->rb_tree_root, drm_sched_entity_compare_before); - -spin_unlock (&entity->rq->lock); }/**
@@ -219,15 +217,14 @@ static void drm_sched_rq_init(struct drm_gpu_scheduler *sched,void drm_sched_rq_add_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +lockdep_assert_held (&entity->lock); +lockdep_assert_held (&rq->lock); +if (!list_empty (&entity->list))return ; -spin_lock (&rq->lock); -atomic_inc (rq->sched->score);list_add_tail (&entity->list, &rq->entities); - -spin_unlock (&rq->lock); }/**
@@ -241,6 +238,8 @@ 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) { +lockdep_assert_held (&entity->lock); +if (list_empty (&entity->list))return ;
@@ -253,7 +252,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq, rq->current_entity =NULL ;if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_remove_fifo_locked (entity); +drm_sched_rq_remove_fifo_locked (entity, rq);spin_unlock (&rq->lock); }
include/drm/gpu_scheduler.h +2 -1
@@ -596,7 +596,8 @@ 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_locked (struct drm_sched_entity *entity,ktime_t ts); +void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity, +struct drm_sched_rq *rq,ktime_t ts); int drm_sched_entity_init(struct drm_sched_entity *entity, enum drm_sched_priority priority,
Signature · 1 line
2.46.0
Philipp Stanner
AppliedQuoted 38 lines · Tvrtko Ursulin
From: Tvrtko Ursulin <[email protected]>
Leftovers from the earlier "DRM scheduler fixes and improvements" series.
It looks the fixes have now propagated back to drm-misc-next so this should now
be mergeable.It also needed a small rebase to account for one revert and one spelling fix
which landed in the meantime.As a reminder, what remains are kerneldoc improvements, struct layout tweaks for
clarity, one trivial cleanup for the FIFO mode, and most importantly two spin
lock-unlock cycles are removed from the push job path by pulling taking of the
locks one level up.I smoke tested it on the Steam Deck and lockdep seems happy.
v2:
* Tweaks to commit messages and rename of some leftoverrq_locknaming inside
kerneldoc.Cc Christian König <[email protected]>Cc Philipp Stanner <[email protected]>Tvrtko Ursulin (5):
drm/sched: Optimisedrm_sched_entity_push_jobdrm/sched: Stop setting current entity in FIFO mode drm/sched: Re-order structdrm_sched_rqmembers for clarity drm/sched: Re-group and rename the entity run-queue lock drm/sched: Further optimisedrm_sched_entity_push_job
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_entity.c | 42 +++++++++++++++------- --
drivers/gpu/drm/scheduler/sched_main.c | 32 +++++++++--------- include/drm/gpu_scheduler.h | 34 ++++++++++---------3 files changed, 61 insertions(+), 47 deletions(-)
Applied to drm-misc-next
Thank you,
P.