Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/scheduler: improve job distribution with multiple queues

This patch uses score based logic to select a new rq for better
loadbalance between multiple rq/scheds instead of num_jobs.

Below are test results after running amdgpu_test from mesa drm

Before this patch:

sched_name num of many times it got scheduled
========= ==================================
sdma0 314
sdma1 32
comp_1.0.0 56
comp_1.0.1 0
comp_1.1.0 0
comp_1.1.1 0
comp_1.2.0 0
comp_1.2.1 0
comp_1.3.0 0
comp_1.3.1 0
After this patch:

sched_name num of many times it got scheduled
========= ==================================
sdma0 216
sdma1 185
comp_1.0.0 39
comp_1.0.1 9
comp_1.1.0 12
comp_1.1.1 0
comp_1.2.0 12
comp_1.2.1 0
comp_1.3.0 12
comp_1.3.1 0

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Nirmoy Das and committed by
Alex Deucher
56822db1 0c0dab86

+12 -10
+5 -5
drivers/gpu/drm/scheduler/sched_entity.c
··· 130 130 drm_sched_entity_get_free_sched(struct drm_sched_entity *entity) 131 131 { 132 132 struct drm_sched_rq *rq = NULL; 133 - unsigned int min_jobs = UINT_MAX, num_jobs; 133 + unsigned int min_score = UINT_MAX, num_score; 134 134 int i; 135 135 136 136 for (i = 0; i < entity->num_sched_list; ++i) { ··· 141 141 continue; 142 142 } 143 143 144 - num_jobs = atomic_read(&sched->num_jobs); 145 - if (num_jobs < min_jobs) { 146 - min_jobs = num_jobs; 144 + num_score = atomic_read(&sched->score); 145 + if (num_score < min_score) { 146 + min_score = num_score; 147 147 rq = &entity->sched_list[i]->sched_rq[entity->priority]; 148 148 } 149 149 } ··· 498 498 bool first; 499 499 500 500 trace_drm_sched_job(sched_job, entity); 501 - atomic_inc(&entity->rq->sched->num_jobs); 501 + atomic_inc(&entity->rq->sched->score); 502 502 WRITE_ONCE(entity->last_user, current->group_leader); 503 503 first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node); 504 504
+4 -2
drivers/gpu/drm/scheduler/sched_main.c
··· 92 92 if (!list_empty(&entity->list)) 93 93 return; 94 94 spin_lock(&rq->lock); 95 + atomic_inc(&rq->sched->score); 95 96 list_add_tail(&entity->list, &rq->entities); 96 97 spin_unlock(&rq->lock); 97 98 } ··· 111 110 if (list_empty(&entity->list)) 112 111 return; 113 112 spin_lock(&rq->lock); 113 + atomic_dec(&rq->sched->score); 114 114 list_del_init(&entity->list); 115 115 if (rq->current_entity == entity) 116 116 rq->current_entity = NULL; ··· 657 655 struct drm_gpu_scheduler *sched = s_fence->sched; 658 656 659 657 atomic_dec(&sched->hw_rq_count); 660 - atomic_dec(&sched->num_jobs); 658 + atomic_dec(&sched->score); 661 659 662 660 trace_drm_sched_process_job(s_fence); 663 661 ··· 832 830 spin_lock_init(&sched->job_list_lock); 833 831 atomic_set(&sched->hw_rq_count, 0); 834 832 INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout); 835 - atomic_set(&sched->num_jobs, 0); 833 + atomic_set(&sched->score, 0); 836 834 atomic64_set(&sched->job_id_count, 0); 837 835 838 836 /* Each scheduler will run on a seperate kernel thread */
+3 -3
include/drm/gpu_scheduler.h
··· 261 261 * @job_list_lock: lock to protect the ring_mirror_list. 262 262 * @hang_limit: once the hangs by a job crosses this limit then it is marked 263 263 * guilty and it will be considered for scheduling further. 264 - * @num_jobs: the number of jobs in queue in the scheduler 264 + * @score: score to help loadbalancer pick a idle sched 265 265 * @ready: marks if the underlying HW is ready to work 266 266 * @free_guilty: A hit to time out handler to free the guilty job. 267 267 * ··· 282 282 struct list_head ring_mirror_list; 283 283 spinlock_t job_list_lock; 284 284 int hang_limit; 285 - atomic_t num_jobs; 286 - bool ready; 285 + atomic_t score; 286 + bool ready; 287 287 bool free_guilty; 288 288 }; 289 289