Simplify the code and theoretical runtime combinations by disallowing initializing entities with un-initialized schedulers.
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]> --- I do not *think* any of the drivers relies on this inverted initialization order but it needs more eyes for sure. --- drivers/gpu/drm/scheduler/sched_entity.c | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 03e68b4102d5..69bcefdf2c55 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -90,6 +90,19 @@ ktime_t drm_sched_entity_stats_job_add_gpu_time(struct drm_sched_job *job) return duration; } +static bool drm_sched_list_is_initialized(struct drm_gpu_scheduler **sched_list, + unsigned int num_sched_list) +{ + unsigned int i; + + for (i = 0; i < num_sched_list; i++) { + if (!sched_list[i] || !sched_list[i]->sched_rq) + return false; + } + + return true; +} + /** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring. @@ -119,7 +132,10 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { - if (!entity || !sched_list || !num_sched_list || !sched_list[0]) + if (!entity || !sched_list || !num_sched_list) + return -EINVAL; + + if (!drm_sched_list_is_initialized(sched_list, num_sched_list)) return -EINVAL; memset(entity, 0, sizeof(struct drm_sched_entity)); @@ -135,13 +151,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->sched_list = num_sched_list > 1 ? sched_list : NULL; RB_CLEAR_NODE(&entity->rb_tree_node); - if (!sched_list[0]->sched_rq) { - /* Since every entry covered by num_sched_list - * should be non-NULL and therefore we warn drivers - * not to do this and to fix their DRM calling order. - */ - pr_warn("%s: called with uninitialized scheduler\n", __func__); - } else if (priority >= sched_list[0]->num_user_rqs) { + if (priority >= sched_list[0]->num_user_rqs) { /* * The "priority" of an entity cannot exceed the number of * run-queues of a scheduler. Protect against num_rqs being 0, @@ -158,8 +168,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->priority = priority; entity->rq_priority = drm_sched_policy == DRM_SCHED_POLICY_FAIR ? DRM_SCHED_PRIORITY_KERNEL : priority; - if (sched_list[0]->sched_rq) - entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; + entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; init_completion(&entity->entity_idle); @@ -192,7 +201,12 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + if (WARN_ON(!num_sched_list || !sched_list)) + return; + + if (WARN_ON_ONCE(!drm_sched_list_is_initialized(sched_list, + num_sched_list))) + return; spin_lock(&entity->lock); entity->sched_list = sched_list; -- 2.56.0
