Some entity selection streamlining
Subsystems (3)
cover Some entity selection streamlining
Two patches extracted from my deadline scheduler RFC. I think they are making the entity selection logic a bit easier on the eyes but as opinions may vary please have a look and see what you think.
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Tvrtko Ursulin (2):
drm/sched: Clarify locked section in drm_sched_rq_select_entity_fifo drm/sched: Consolidate drm_sched_rq_select_entity_rr
drivers/gpu/drm/scheduler/sched_main.c | 79 ++++++++++++-------------- 1 file changed, 37 insertions(+), 42 deletions(-)
Signature · 1 line
2.47.1
PATCH 1/2 drm/sched: Clarify locked section in drm_sched_rq_select_entity_fifo
Rq->lock only protects the tree walk so lets move the rest out.
Signed-off-by Tvrtko Ursulin <[email protected]>
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
--- drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +17 -14
@@ -325,29 +325,32 @@ static struct drm_sched_entity * drm_sched_rq_select_entity_fifo(struct drm_gpu_scheduler *sched, struct drm_sched_rq *rq) { + struct drm_sched_entity *entity = NULL;struct rb_node *rb;spin_lock (&rq->lock);for (rb =rb_first_cached (&rq->rb_tree_root); rb; rb =rb_next (rb)) { -struct drm_sched_entity *entity; - entity = rb_entry(rb, struct drm_sched_entity, rb_tree_node); -if (drm_sched_entity_is_ready (entity)) { -/* If we can't queue yet, preserve the current entity in -* terms of fairness. -*/ -if (!drm_sched_can_queue (sched, entity)) { -spin_unlock (&rq->lock); -return ERR_PTR (-ENOSPC ); - } - -reinit_completion (&entity->entity_idle); +if (drm_sched_entity_is_ready (entity))break ; - } +else + entity =NULL ; }spin_unlock (&rq->lock); - return rb ? rb_entry(rb, struct drm_sched_entity, rb_tree_node) : NULL; +if (!entity) +return NULL ; + +/* +* If scheduler cannot take more jobs signal the caller to not consider +* lower priority queues. +*/ +if (!drm_sched_can_queue (sched, entity)) +return ERR_PTR (-ENOSPC ); + +reinit_completion (&entity->entity_idle); + +return entity; }/**
Signature · 1 line
2.47.1
PATCH 2/2 drm/sched: Consolidate drm_sched_rq_select_entity_rr
In reply to Tvrtko UrsulinExtract out two copies of the identical code to function epilogue to make it smaller and more readable.
Signed-off-by Tvrtko Ursulin <[email protected]>
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
--- drivers/gpu/drm/scheduler/sched_main.c | 48 +++++++++++--------------- 1 file changed, 20 insertions(+), 28 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +20 -28
@@ -267,38 +267,14 @@ drm_sched_rq_select_entity_rr(struct drm_gpu_scheduler *sched, entity = rq->current_entity;if (entity) {list_for_each_entry_continue (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) { -/* If we can't queue yet, preserve the current -* entity in terms of fairness. -*/ -if (!drm_sched_can_queue (sched, entity)) { -spin_unlock (&rq->lock); -return ERR_PTR (-ENOSPC ); - } - - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); -spin_unlock (&rq->lock); -return entity; - } +if (drm_sched_entity_is_ready (entity)) + goto found; } }list_for_each_entry (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) { -/* If we can't queue yet, preserve the current entity in -* terms of fairness. -*/ -if (!drm_sched_can_queue (sched, entity)) { -spin_unlock (&rq->lock); -return ERR_PTR (-ENOSPC ); - } - - rq->current_entity = entity; -reinit_completion (&entity->entity_idle); -spin_unlock (&rq->lock); -return entity; - } +if (drm_sched_entity_is_ready (entity)) + goto found;if (entity == rq->current_entity)break ;
@@ -307,6 +283,22 @@ drm_sched_rq_select_entity_rr(struct drm_gpu_scheduler *sched,spin_unlock (&rq->lock);return NULL ; + +found: +if (!drm_sched_can_queue (sched, entity)) { +/* +* If scheduler cannot take more jobs signal the caller to not +* consider lower priority queues. +*/ + entity =ERR_PTR (-ENOSPC ); + }else { + rq->current_entity = entity; +reinit_completion (&entity->entity_idle); + } + +spin_unlock (&rq->lock); + +return entity; }/**
Signature · 1 line
2.47.1