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 to select a new drm scheduler for better
loadbalance between multiple drm schedulers instead of num_jobs.

Below are test results after running amdgpu_test for ~10 times.

Before this patch:

sched_name num of many times it got schedule
========= ==================================
sdma0 1463
sdma1 198
comp_1.0.1 280

After this patch:

sched_name num of many times it got schedule
========= ==================================
sdma0 925
sdma1 928
comp_1.0.1 177
comp_1.1.1 44
comp_1.2.1 43
comp_1.3.1 44

Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/373000/
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Nirmoy Das and committed by
Christian König
d41a39dd 0dc9b286

+12 -10
+1 -1
drivers/gpu/drm/scheduler/sched_entity.c
··· 486 486 bool first; 487 487 488 488 trace_drm_sched_job(sched_job, entity); 489 - atomic_inc(&entity->rq->sched->num_jobs); 489 + atomic_inc(&entity->rq->sched->score); 490 490 WRITE_ONCE(entity->last_user, current->group_leader); 491 491 first = spsc_queue_push(&entity->job_queue, &sched_job->queue_node); 492 492
+8 -6
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; ··· 649 647 struct drm_gpu_scheduler *sched = s_fence->sched; 650 648 651 649 atomic_dec(&sched->hw_rq_count); 652 - atomic_dec(&sched->num_jobs); 650 + atomic_dec(&sched->score); 653 651 654 652 trace_drm_sched_process_job(s_fence); 655 653 ··· 714 712 { 715 713 struct drm_gpu_scheduler *sched, *picked_sched = NULL; 716 714 int i; 717 - unsigned int min_jobs = UINT_MAX, num_jobs; 715 + unsigned int min_score = UINT_MAX, num_score; 718 716 719 717 for (i = 0; i < num_sched_list; ++i) { 720 718 sched = sched_list[i]; ··· 725 723 continue; 726 724 } 727 725 728 - num_jobs = atomic_read(&sched->num_jobs); 729 - if (num_jobs < min_jobs) { 730 - min_jobs = num_jobs; 726 + num_score = atomic_read(&sched->score); 727 + if (num_score < min_score) { 728 + min_score = num_score; 731 729 picked_sched = sched; 732 730 } 733 731 } ··· 862 860 spin_lock_init(&sched->job_list_lock); 863 861 atomic_set(&sched->hw_rq_count, 0); 864 862 INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout); 865 - atomic_set(&sched->num_jobs, 0); 863 + atomic_set(&sched->score, 0); 866 864 atomic64_set(&sched->job_id_count, 0); 867 865 868 866 /* Each scheduler will run on a seperate kernel thread */
+3 -3
include/drm/gpu_scheduler.h
··· 263 263 * @job_list_lock: lock to protect the ring_mirror_list. 264 264 * @hang_limit: once the hangs by a job crosses this limit then it is marked 265 265 * guilty and it will be considered for scheduling further. 266 - * @num_jobs: the number of jobs in queue in the scheduler 266 + * @score: score to help loadbalancer pick a idle sched 267 267 * @ready: marks if the underlying HW is ready to work 268 268 * @free_guilty: A hit to time out handler to free the guilty job. 269 269 * ··· 284 284 struct list_head ring_mirror_list; 285 285 spinlock_t job_list_lock; 286 286 int hang_limit; 287 - atomic_t num_jobs; 288 - bool ready; 287 + atomic_t score; 288 + bool ready; 289 289 bool free_guilty; 290 290 }; 291 291