Deadline DRM scheduler
Subsystems (4)
v3 cover Deadline DRM scheduler
This is similar to v2 but I dropped some patches (for now) and added some new ones. Most notably deadline scaling based on queue depth appears to be able to add a little bit of fairness with spammy clients (deep submission queue).
As such, on the high level main advantages of the series:
1. Code simplification - no more multiple run queues.
2. Scheduling quality - schedules better than FIFO.
3. No more RR is even more code simplification but this one needs to be tested and approved by someone who actually uses RR.
In the future futher simplifactions and improvements should be possible on top of this work. But for now I keep it simple.
First patch adds some unit tests which allow for easy evaluation of scheduling behaviour against different client submission patterns. From there onwards it is a hopefully natural progression of patches (or close) to the end result which is a slightly more fair scheduler than FIFO.
Regarding the submission patterns tested, it is always two parallel clients and they broadly cover these categories:
* Deep queue clients
* Hogs versus interactive
* Priority handling
Lets look at the results:
1. Two normal priority deep queue clients.
These ones submit one second worth of 8ms jobs. As fast as they can, no dependencies etc. There is no difference in runtime between FIFO and qddl but the latter allows both clients to progress with work more evenly:
https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers separately.)
2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO completely starves the low priority client until the normal priority is fully done. Only then the low priority client gets any GPU time.
In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de-prioritised relative to high, than low was against normal.
https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a 2.5ms wait.
Interactive client emites a 10% GPU load in the format of 1x 1ms job followed by a 9ms wait.
This simulates an interactive graphical client used on top of a relatively heavy background load but no GPU oversubscription.
Graphs show the interactive client only and from now on, instead of looking at the client's queue depth, we look at its "fps".
https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client which is good.
5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients with a 50% "duty cycle" GPU time usage.
Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.png
Both schedulers favour the higher frequency duty cycle with qddl giving it a little bit more which should be good for interactivity.
b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.png
Qddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.png
Again, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness, especially avoiding priority starvation. There do not appear to be any regressions with the tested workloads.
As before, I am looking for feedback, ideas for what kind of submission scenarios to test. Testers on different GPUs would be very welcome too.
And I should probably test round-robin at some point, to see if we are maybe okay to drop unconditionally, it or further work improving qddl would be needed.
v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.
v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.
Tvrtko Ursulin (14):
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidate drm_sched_job_timedout
drm/sched: Clarify locked section in drm_sched_rq_select_entity_fifo drm/sched: Consolidate drm_sched_rq_select_entity_rr drm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutter drm_sched_init
drm/sched: Scale deadlines depending on queue depth
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++-------------- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +- 15 files changed, 962 insertions(+), 579 deletions(-) create mode 100644 drivers/gpu/drm/scheduler/sched_rq.c create mode 100644 drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Signature · 1 line
2.48.0
RFC v3 1/14 drm/sched: Add some scheduling quality unit tests
--- drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 ++++++++++++++++++ 2 files changed, 550 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/scheduler/tests/tests_scheduler.c
drivers/gpu/drm/scheduler/tests/Makefile +2 -1
@@ -2,6 +2,7 @@ drm-sched-tests-y := \ mock_scheduler.o \ - tests_basic.o + tests_basic.o \ + tests_scheduler.o obj-$(CONFIG_DRM_SCHED_KUNIT_TEST) += drm-sched-tests.o
drivers/gpu/drm/scheduler/tests/tests_scheduler.c new file +548 -0
548 lines not on this page · raw message
Signature · 1 line
2.48.0
RFC v3 2/14 drm/sched: Avoid double re-lock on the job free path
In reply to Tvrtko UrsulinCurrently the job free work item will lock sched->job_list_lock first time to see if there are any jobs, free a single job, and then lock again to decide whether to re-queue itself if there are more finished jobs.
Since drm_sched_get_finished_job() already looks at the second job in the queue we can simply extend the timestamp check with the full signaled check and have it return the presence of more jobs to free to the caller. That way the work item does not have to lock the list again and repeat the very similar check.
v2:
* Consolidate to single dma_fence_is_signaled check.
--- drivers/gpu/drm/scheduler/sched_main.c | 40 ++++++++++---------------- 1 file changed, 15 insertions(+), 25 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +15 -25
@@ -371,22 +371,6 @@ static void __drm_sched_run_free_queue(struct drm_gpu_scheduler *sched)queue_work (sched->submit_wq, &sched->work_free_job); } -/** -* drm_sched_run_free_queue - enqueue free-job work if ready -* @sched: scheduler instance -*/ -static void drm_sched_run_free_queue (struct drm_gpu_scheduler *sched) -{ -struct drm_sched_job *job; - -spin_lock (&sched->job_list_lock); - job =list_first_entry_or_null (&sched->pending_list, - struct drm_sched_job, list); -if (job &&dma_fence_is_signaled (&job->s_fence->finished)) -__drm_sched_run_free_queue (sched); -spin_unlock (&sched->job_list_lock); -} -/** * drm_sched_job_done - complete a job * @s_job: pointer to the job which is done
@@ -1103,12 +1087,13 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)* drm_sched_get_finished_job - fetch the next finished job to be destroyed * * @sched: scheduler instance +* @have_more: are there more finished jobs on the list * * Returns the next finished job from the pending list (if there is one) * ready for it to be destroyed. */ static struct drm_sched_job * -drm_sched_get_finished_job (struct drm_gpu_scheduler *sched) +drm_sched_get_finished_job (struct drm_gpu_scheduler *sched,bool *have_more) {struct drm_sched_job *job, *next;
@@ -1116,22 +1101,24 @@ drm_sched_get_finished_job(struct drm_gpu_scheduler *sched) job =list_first_entry_or_null (&sched->pending_list, struct drm_sched_job, list); -if (job &&dma_fence_is_signaled (&job->s_fence->finished)) {/* remove job from pending_list */ list_del_init (&job->list);/* cancel this job's TO timer */ cancel_delayed_work (&sched->work_tdr); -/* make the scheduled timestamp more accurate */ + + *have_more = false; next =list_first_entry_or_null (&sched->pending_list,typeof (*next), list); -if (next) { -if (test_bit (DMA_FENCE_FLAG_TIMESTAMP_BIT , - &next->s_fence->scheduled.flags)) +if (dma_fence_is_signaled (&next->s_fence->finished)) { + *have_more = true; +/* make the scheduled timestamp more accurate */ next->s_fence->scheduled.timestamp =dma_fence_timestamp (&job->s_fence->finished); + } +/* start TO timer for next job */ drm_sched_start_timeout (sched); }
@@ -1190,12 +1177,15 @@ static void drm_sched_free_job_work(struct work_struct *w)struct drm_gpu_scheduler *sched = container_of(w, struct drm_gpu_scheduler, work_free_job);struct drm_sched_job *job; +bool have_more; - job =drm_sched_get_finished_job (sched); -if (job) + job =drm_sched_get_finished_job (sched, &have_more); +if (job) { sched->ops->free_job (job); +if (have_more) +__drm_sched_run_free_queue (sched); + } -drm_sched_run_free_queue (sched);drm_sched_run_job_queue (sched); }
Signature · 1 line
2.48.0
RFC v3 3/14 drm/sched: Consolidate drm_sched_job_timedout
In reply to Tvrtko UrsulinReduce to one spin_unlock for hopefully a little bit clearer flow in the function. It may appear that there is a behavioural change with the drm_sched_start_timeout_unlocked() now not being called if there were initially no jobs on the pending list, and then some appeared after unlock, however if the code would rely on the TDR handler restarting itself then it would fail to do that if the job arrived on the pending list after the check.
Also fix one stale comment while touching the function.
--- drivers/gpu/drm/scheduler/sched_main.c | 37 +++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +18 -19
@@ -522,38 +522,37 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)static void drm_sched_job_timedout (struct work_struct *work) { -struct drm_gpu_scheduler *sched; +struct drm_gpu_scheduler *sched = + container_of(work, struct drm_gpu_scheduler, work_tdr.work); +enum drm_gpu_sched_stat status;struct drm_sched_job *job; -enum drm_gpu_sched_stat status =DRM_GPU_SCHED_STAT_NOMINAL ; - - sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);/* Protects against concurrent deletion in drm_sched_get_finished_job */ spin_lock (&sched->job_list_lock); job =list_first_entry_or_null (&sched->pending_list, struct drm_sched_job, list); -if (job) {/* * Remove the bad job so it cannot be freed by concurrent -* drm_sched_cleanup_jobs. It will be reinserted back after sched->thread -* is parked at which point it's safe. +* drm_sched_get_finished_job. It will be reinserted back after +* scheduler worker is stopped at which point it's safe. */ list_del_init (&job->list); -spin_unlock (&sched->job_list_lock); + } +spin_unlock (&sched->job_list_lock); - status = job->sched->ops->timedout_job (job); +if (!job) +return ; -/* -* Guilty job did complete and hence needs to be manually removed -* See drm_sched_stop doc. -*/ -if (sched->free_guilty) { - job->sched->ops->free_job (job); - sched->free_guilty = false; - } - }else { -spin_unlock (&sched->job_list_lock); + status = job->sched->ops->timedout_job (job); + +/* +* Guilty job did complete and hence needs to be manually removed. See +* documentation for drm_sched_stop. +*/ +if (sched->free_guilty) { + job->sched->ops->free_job (job); + sched->free_guilty = false; }if (status !=DRM_GPU_SCHED_STAT_ENODEV )
Signature · 1 line
2.48.0
RFC v3 4/14 drm/sched: Clarify locked section in drm_sched_rq_select_entity_fifo
In reply to Tvrtko UrsulinRq->lock only protects the tree walk so lets move the rest out.
--- drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +17 -14
@@ -326,29 +326,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.48.0
Re: [RFC v3 04/14] drm/sched: Clarify locked section in drm_sched_rq_select_entity_fifo
Quoted 1 line · Tvrtko Ursulin
Rq->lockonly protects the tree walk so lets move the rest out.
I retract this one, reinit_completion has to be in the locked section too. Next posting will be rebased accordingly but I will hold off sending it out until more comments are received.
Regards,
Tvrtko
Quoted 60 lines
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@@ -326,29 +326,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; }/**
RFC v3 5/14 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.
--- drivers/gpu/drm/scheduler/sched_main.c | 48 +++++++++++--------------- 1 file changed, 20 insertions(+), 28 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +20 -28
@@ -268,38 +268,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 ;
@@ -308,6 +284,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.48.0
RFC v3 6/14 drm/sched: Implement RR via FIFO
In reply to Tvrtko UrsulinRound-robin being the non-default policy and unclear how much it is used, we can notice that it can be implemented using the FIFO data structures if we only invent a fake submit timestamp which is monotonically increasing inside drm_sched_rq instances.
So instead of remembering which was the last entity the scheduler worker picked, we can bump the picked one to the bottom of the tree, achieving the same round-robin behaviour.
Advantage is that we can consolidate to a single code path and remove a bunch of code. Downside is round-robin mode now needs to lock on the job pop path but that should not be visible.
--- drivers/gpu/drm/scheduler/sched_entity.c | 45 ++++++++------ drivers/gpu/drm/scheduler/sched_main.c | 76 ++---------------------- include/drm/gpu_scheduler.h | 5 +- 3 files changed, 36 insertions(+), 90 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +28 -17
@@ -469,9 +469,19 @@ drm_sched_job_dependency(struct drm_sched_job *job,return NULL ; } +static ktime_t +drm_sched_rq_get_rr_deadline (struct drm_sched_rq *rq) +{ +lockdep_assert_held (&rq->lock); + + rq->rr_deadline =ktime_add_ns (rq->rr_deadline,1 ); + +return rq->rr_deadline; +} +struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity) { -struct drm_sched_job *sched_job; +struct drm_sched_job *sched_job, *next_job; sched_job =drm_sched_entity_queue_peek (entity);if (!sched_job)
@@ -506,21 +516,22 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)* Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; + next_job =drm_sched_entity_queue_peek (entity); +if (next_job) { +struct drm_sched_rq *rq; +ktime_t ts; - next =drm_sched_entity_queue_peek (entity); -if (next) { -struct drm_sched_rq *rq; +if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) + ts = next_job->submit_ts; +else + ts =drm_sched_rq_get_rr_deadline (rq); -spin_lock (&entity->lock); - 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); - } +spin_lock (&entity->lock); + rq = entity->rq; +spin_lock (&rq->lock); +drm_sched_rq_update_fifo_locked (entity, rq, ts); +spin_unlock (&rq->lock); +spin_unlock (&entity->lock); }/* Jobs and entities might have different lifecycles. Since we're
@@ -619,9 +630,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)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, rq, submit_ts); +if (drm_sched_policy ==DRM_SCHED_POLICY_RR ) + submit_ts =drm_sched_rq_get_rr_deadline (rq); +drm_sched_rq_update_fifo_locked (entity, rq, submit_ts);spin_unlock (&rq->lock);spin_unlock (&entity->lock);
drivers/gpu/drm/scheduler/sched_main.c +6 -70
110 lines not on this page · raw message
include/drm/gpu_scheduler.h +2 -3
@@ -239,8 +239,7 @@ struct drm_sched_entity {* struct drm_sched_rq - queue of entities to be scheduled. * * @sched: the scheduler to which this rq belongs to. -* @lock: protects @entities, @rb_tree_root and @current_entity. -* @current_entity: the entity which is to be scheduled. +* @lock: protects @entities, @rb_tree_root and @rr_deadline. * @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities for FIFO scheduling *
@@ -253,7 +252,7 @@ struct drm_sched_rq {spinlock_t lock;/* Following members are protected by the @lock: */ -struct drm_sched_entity *current_entity; +ktime_t rr_deadline;struct list_head entities;struct rb_root_cached rb_tree_root; };
Signature · 1 line
2.48.0
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Quoted 14 lines · Tvrtko Ursulin
Round-robin being the non-default policy and unclear how much it is used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.
Quoted 5 lines
Advantage is that we can consolidate to a single code path and remove a
bunch of code. Downside is round-robin mode now needs to lock on the job
pop path but that should not be visible.
Why did you decide to do it that way and then later remove RR & FIFO alltogether in patch 10, basically?
I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new, deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it would be easy to revert.
I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
Quoted 6 lines
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]>
+Cc Michel here, too
P.
Quoted 239 lines
---
drivers/gpu/drm/scheduler/sched_entity.c | 45 ++++++++------ drivers/gpu/drm/scheduler/sched_main.c | 76 ++-------------------- --
include/drm/gpu_scheduler.h | 5 +-3 files changed, 36 insertions(+), 90 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -469,9 +469,19 @@ drm_sched_job_dependency(struct drm_sched_job *job, return NULL; }drivers/gpu/drm/scheduler/sched_entity.c +10
-0+static ktime_t +drm_sched_rq_get_rr_deadline (struct drm_sched_rq *rq) +{ +lockdep_assert_held (&rq->lock); + + rq->rr_deadline =ktime_add_ns (rq->rr_deadline,1 ); + +return rq->rr_deadline; +} +struct
drm_sched_job*drm_sched_entity_pop_job(structdrm_sched_entity*entity)
{
- structdrm_sched_job*sched_job;
+ structdrm_sched_job*sched_job,*next_job;
sched_job=drm_sched_entity_queue_peek(entity); if (!sched_job)drivers/gpu/drm/scheduler/sched_entity.c +4
-2@@ -506,21 +516,22 @@ struct drm_sched_job*drm_sched_entity_pop_job(struct drm_sched_entity *entity) * Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; + next_job =drm_sched_entity_queue_peek (entity); +if (next_job) { +struct drm_sched_rq *rq; +ktime_t ts;
- next =drm_sched_entity_queue_peek(entity);
- if (next) {
- structdrm_sched_rq*rq;
+ if (drm_sched_policy==DRM_SCHED_POLICY_FIFO)
+ ts =next_job->submit_ts;
+ else
+ ts =drm_sched_rq_get_rr_deadline(rq);
-spin_lock(&entity->lock);
- 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);
- }
+spin_lock(&entity->lock);
+ rq =entity->rq;
+spin_lock(&rq->lock);
+drm_sched_rq_update_fifo_locked(entity, rq, ts);
+spin_unlock(&rq->lock);
+spin_unlock(&entity->lock);
}
/* Jobs and entities might have different lifecycles. Since we'redrivers/gpu/drm/scheduler/sched_entity.c +0
-0@@ -619,9 +630,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
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, rq, submit_ts);
+ if (drm_sched_policy==DRM_SCHED_POLICY_RR)
+submit_ts=drm_sched_rq_get_rr_deadline(rq);
+drm_sched_rq_update_fifo_locked(entity, rq, submit_ts);
spin_unlock(&rq->lock);spin_unlock(&entity->lock);drivers/gpu/drm/scheduler/sched_main.c +0
-1@@ -190,7 +190,6 @@ static void drm_sched_rq_init(structdrm_gpu_scheduler *sched, spin_lock_init(&rq->lock); INIT_LIST_HEAD(&rq->entities); rq->rb_tree_root = RB_ROOT_CACHED; - rq->current_entity =NULL ; rq->sched = sched; }drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -236,74 +235,13 @@ void drm_sched_rq_remove_entity(structdrm_sched_rq *rq, atomic_dec(rq->sched->score); list_del_init(&entity->list);
- if (rq->current_entity== entity)
-rq->current_entity= NULL;
-
- if (drm_sched_policy==DRM_SCHED_POLICY_FIFO)
-drm_sched_rq_remove_fifo_locked(entity, rq);
+drm_sched_rq_remove_fifo_locked(entity, rq);
spin_unlock(&rq->lock);
}
/**
- *drm_sched_rq_select_entity_rr- Select an entity which could provide a job to run
- *
- * @sched: the gpu scheduler
- * @rq: scheduler run queue to check.
- *
- * Try to find the next ready entity.
- *
- * Return an entity if one is found; return an error-pointer (!NULL) if an
- * entity was ready, but the scheduler had insufficient credits to accommodate
- * its job; return NULL, if no ready entity was found.
- */drivers/gpu/drm/scheduler/sched_main.c +0
-47-static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_gpu_scheduler *sched, - struct drm_sched_rq *rq) -{ -struct drm_sched_entity *entity; - -spin_lock (&rq->lock); - - entity = rq->current_entity; -if (entity) { -list_for_each_entry_continue (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) - goto found; - } - } - -list_for_each_entry (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) - goto found; - -if (entity == rq->current_entity) -break ; - } - -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; -} - -/** -* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run
+ *drm_sched_rq_select_entity- Select an entity which provides a job to run
*
* @sched: the gpu scheduler
* @rq: scheduler run queue to check.drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -315,8 +253,8 @@ drm_sched_rq_select_entity_rr(structdrm_gpu_scheduler *sched, * its job; return NULL, if no ready entity was found. */ static struct
drm_sched_entity*drivers/gpu/drm/scheduler/sched_main.c +2
-2-drm_sched_rq_select_entity_fifo(struct drm_gpu_scheduler *sched, - struct drm_sched_rq *rq) +drm_sched_rq_select_entity(struct drm_gpu_scheduler *sched, + struct drm_sched_rq *rq){
structdrm_sched_entity*entity = NULL;
structrb_node*rb;drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -1061,15 +999,13 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched)static struct
drm_sched_entity*drm_sched_select_entity(struct drm_gpu_scheduler *sched){
- structdrm_sched_entity*entity;
+ structdrm_sched_entity*entity = NULL;
int i;
/* Start with the highest priority.
*/
for (i =DRM_SCHED_PRIORITY_KERNEL; i <sched->num_rqs; i++) {
- entity =drm_sched_policy==DRM_SCHED_POLICY_FIFO?
-drm_sched_rq_select_entity_fifo(sched, sched->sched_rq[i]):
-drm_sched_rq_select_entity_rr(sched, sched->sched_rq[i]);
+ entity =drm_sched_rq_select_entity(sched, sched->sched_rq[i]); if (entity)
break;
}include/drm/gpu_scheduler.h +1
-2@@ -239,8 +239,7 @@ struct drm_sched_entity { * struct drm_sched_rq - queue of entities to be scheduled. * * @sched: the scheduler to which this rq belongs to. - * @lock: protects @entities, @rb_tree_root and @current_entity. - * @current_entity: the entity which is to be scheduled. + * @lock: protects @entities, @rb_tree_root and @rr_deadline. * @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities forFIFO scheduling
*include/drm/gpu_scheduler.h +0
-0@@ -253,7 +252,7 @@ struct drm_sched_rq {
spinlock_tlock;
/* Following members are protected by the @lock: */
- structdrm_sched_entity*current_entity;
+ktime_trr_deadline;
structlist_headentities;
structrb_root_cachedrb_tree_root;
};
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Quoted 38 lines · Philipp Stanner
Quoted 14 lines · Tvrtko Ursulin
Round-robin being the non-default policy and unclear how much it is used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.Quoted 5 lines
Advantage is that we can consolidate to a single code path and remove a
bunch of code. Downside is round-robin mode now needs to lock on the job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO alltogether in patch 10, basically?
I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new, deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it would be easy to revert.
Quoted 2 lines
I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
https://gitlab.freedesktop.org/drm/amd/-/issues/2516 has a bunch of RR users...
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Quoted 48 lines · Michel Dänzer
Quoted 47 lines · Philipp Stanner
Quoted 15 lines · Tvrtko Ursulin
Round-robin being the non-default policy and unclear how much it is
used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.Quoted 7 lines
Advantage is that we can consolidate to a single code path and remove
a
bunch of code. Downside is round-robin mode now needs to lock on the
job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO
alltogether in patch 10, basically?I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what
happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new,
deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it
would be easy to revert.
Quoted 6 lines
Quoted 3 lines
I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
https://gitlab.freedesktop.org/drm/amd/-/issues/2516 has a bunch of RR users...
Right, there's a number of people complaining about the regression. But what I'm interested in is: how did it evolve since then. Are there distributions who set the module parameter? Does Steam do it? Or is it individual users who work around the problem that way?
https://gitlab.freedesktop.org/drm/amd/-/issues/2516#note_2679509
^ this comment for example seems to indicate that on newer Wayland versions part of the problem has vanished?
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Quoted 53 lines · Philipp Stanner
Quoted 52 lines · Michel Dänzer
Quoted 50 lines · Philipp Stanner
Quoted 15 lines · Tvrtko Ursulin
Round-robin being the non-default policy and unclear how much it is
used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.Quoted 7 lines
Advantage is that we can consolidate to a single code path and remove
a
bunch of code. Downside is round-robin mode now needs to lock on the
job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO
alltogether in patch 10, basically?I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what
happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new,
deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it
would be easy to revert.I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
Quoted 7 lines
Quoted 2 lines
https://gitlab.freedesktop.org/drm/amd/-/issues/2516 has a bunch of RR users...
Right, there's a number of people complaining about the regression. But what I'm interested in is: how did it evolve since then. Are there distributions who set the module parameter? Does Steam do it? Or is it individual users who work around the problem that way?
I know only of the latter.
Quoted 4 lines
https://gitlab.freedesktop.org/drm/amd/-/issues/2516#note_2679509
^ this comment for example seems to indicate that on newer Wayland versions part of the problem has vanished?
That's about using the Wine wayland driver (which uses the Wayland protocol directly) instead of the x11 driver (which uses the X11 protocol via Xwayland). Xwayland not being involved can avoid at least some of the issues (in particular, the scenario I described in https://gitlab.freedesktop.org/drm/amd/-/issues/2516#note_2119750 can't happen then). That doesn't solve the issues when Xwayland is involved though, just avoids them.
Signature · 2 lines
Earthling Michel Dänzer \ GNOME / Xwayland / Mesa developer https://redhat.com \ Libre software enthusiast
Christian König
maintainerRe: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Am 02.04.25 um 15:22 schrieb Michel Dänzer:
Quoted 52 lines · Philipp Stanner
Quoted 51 lines · Michel Dänzer
Quoted 50 lines · Philipp Stanner
Quoted 49 lines · Tvrtko Ursulin
Quoted 15 lines
Round-robin being the non-default policy and unclear how much it is
used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.Quoted 7 lines
Advantage is that we can consolidate to a single code path and remove
a
bunch of code. Downside is round-robin mode now needs to lock on the
job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO
alltogether in patch 10, basically?I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what
happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new,
deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it
would be easy to revert.I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
https://gitlab.freedesktop.org/drm/amd/-/issues/2516 has a bunch of RR users...
Right, there's a number of people complaining about the regression. But what I'm interested in is: how did it evolve since then. Are there distributions who set the module parameter? Does Steam do it? Or is it individual users who work around the problem that way?
I know only of the latter.
Tvrtko, you should probably prepare a branch on fdo and let the people on that bug report test it.
Quoted 5 lines
Quoted 3 lines
^ this comment for example seems to indicate that on newer Wayland versions part of the problem has vanished?
That's about using the Wine wayland driver (which uses the Wayland protocol directly) instead of the x11 driver (which uses the X11 protocol via Xwayland). Xwayland not being involved can avoid at least some of the issues (in particular, the scenario I described in https://gitlab.freedesktop.org/drm/amd/-/issues/2516#note_2119750 can't happen then). That doesn't solve the issues when Xwayland is involved though, just avoids them.
From what I remember the bug condition is that the display server submits works after the client has started rendering the next frame. With RR that resulted in the display servers work to be picked first while with FIFO the clients works would be picked first.
Arguable that RR picked the display server was just coincident while with Tvrtko's work the fair queuing should make that perfectly intentional.
So this patch set here should (in theory) help a lot with that bug report and finally make RR superfluous.
Christian.
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
Quoted 55 lines · Christian König
Am 02.04.25 um 15:22 schrieb Michel Dänzer:
Quoted 54 lines · Philipp Stanner
Quoted 53 lines · Michel Dänzer
Quoted 52 lines · Philipp Stanner
Quoted 46 lines · Tvrtko Ursulin
Quoted 15 lines
Round-robin being the non-default policy and unclear how much it is
used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.Quoted 7 lines
Advantage is that we can consolidate to a single code path and remove
a
bunch of code. Downside is round-robin mode now needs to lock on the
job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO
alltogether in patch 10, basically?I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of
what
happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely
new,
deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common
ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on
RR, it
would be easy to revert.Quoted 3 lines
I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
https://gitlab.freedesktop.org/drm/amd/-/issues/2516 has a bunch of RR users...
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Right, there's a number of people complaining about the regression. But what I'm interested in is: how did it evolve since then. Are there distributions who set the module parameter? Does Steam do it? Or is it individual users who work around the problem that way?
I know only of the latter.
Tvrtko, you should probably prepare a branch on fdo and let the people on that bug report test it.
If people are interested to test I have two branches. This qddl approach:
https://gitlab.freedesktop.org/tursulin/kernel/-/commits/drm-sched-deadline?ref_type=heads
And a very early CFS-like experiment:
https://gitlab.freedesktop.org/tursulin/kernel/-/commits/drm-sched-cfs?ref_type=heads
I would certainly be very interested to get feedback.
Quoted 11 lines
Quoted 4 lines
Quoted 2 lines
^ this comment for example seems to indicate that on newer Wayland versions part of the problem has vanished?
That's about using the Wine wayland driver (which uses the Wayland protocol directly) instead of the x11 driver (which uses the X11 protocol via Xwayland). Xwayland not being involved can avoid at least some of the issues (in particular, the scenario I described inhttps://gitlab.freedesktop.org/drm/amd/-/issues/2516#note_2119750 can't happen then). That doesn't solve the issues when Xwayland is involved though, just avoids them.
From what I remember the bug condition is that the display server
submits works after the client has started rendering the next frame. With RR that resulted in the display servers work to be picked first while with FIFO the clients works would be picked first.Arguable that RR picked the display server was just coincident while with Tvrtko's work the fair queuing should make that perfectly intentional.
So this patch set here should (in theory) help a lot with that bug report and finally make RR superfluous.
Disclaimer that it is way too generous to call what I made fair. It may help with the above described case *if* the client has queue depth > 1, which would then push out its deadline a bit further out so display server could beat it even if submitted later. But it also may need refining to account for currently executing jobs as the queue-depth too (currently it does not). And also to perhaps base the deadline buckets on some dynamically adjusting runtime measure rather than hardcoding them.
Regards,
Tvrtko
Re: [RFC v3 06/14] drm/sched: Implement RR via FIFO
In reply to Philipp StannerQuoted 15 lines · Philipp Stanner
Quoted 14 lines · Tvrtko Ursulin
Round-robin being the non-default policy and unclear how much it is used,
we can notice that it can be implemented using the FIFO data structures if
we only invent a fake submit timestamp which is monotonically increasing
insidedrm_sched_rqinstances.So instead of remembering which was the last entity the scheduler worker
picked, we can bump the picked one to the bottom of the tree, achieving
the same round-robin behaviour.
Quoted 8 lines
Quoted 5 lines
Advantage is that we can consolidate to a single code path and remove a
bunch of code. Downside is round-robin mode now needs to lock on the job
pop path but that should not be visible.Why did you decide to do it that way and then later remove RR & FIFO alltogether in patch 10, basically?
Idea is that you can take the series up to here and still gain something. I this case it is code consolidation. Still the same FIFO and RR policies just in less lines of code. Ie. you can take it up to here for no regressions. (If we ignore FIFO does some more locking than RR does, which I think we can.)
Quoted 14 lines
I think the far cleaner way for our development-process would be a separate patch(-series) that *removes* RR completely. Advantages are:
1. It should be relatively easy to do
2. It would simplify the existing code base independently of what happens with your RFC series here
3. Before changing everyone's scheduling policy to a completely new, deadline-based one, we could first be sure for a few release cycles that everyone is now on FIFO, establishing common ground.
4. We could CC every- and anyone who might use RR or might know someone who does
5. If it turns out we screwed up and someone really relies on RR, it would be easy to revert.
Quoted 2 lines
I am not aware of any RR users and have, in past discussions, never heard of any. So removing it is more tempting for the above reasons.
Yes that could be an option. I however did not simply want to remove RR, I wanted to improve FIFO so it is better in the edge cases where people switch to RR, or to at least not regress against FIFO, and at the same time end up with a smaller code base.
Regards,
Tvrtko
Quoted 251 lines
Quoted 5 lines
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]>+Cc Michel here, too
P.
Quoted 239 lines
--- drivers/gpu/drm/scheduler/sched_entity.c | 45 ++++++++------ drivers/gpu/drm/scheduler/sched_main.c | 76 ++-------------------- -- include/drm/gpu_scheduler.h | 5 +- 3 files changed, 36 insertions(+), 90 deletions(-)drivers/gpu/drm/scheduler/sched_entity.c +11
-1@@ -469,9 +469,19 @@ drm_sched_job_dependency(struct drm_sched_job *job, return NULL; } +static ktime_t +drm_sched_rq_get_rr_deadline (struct drm_sched_rq *rq) +{ +lockdep_assert_held (&rq->lock); + + rq->rr_deadline =ktime_add_ns (rq->rr_deadline,1 ); + +return rq->rr_deadline; +} + struct drm_sched_job *drm_sched_entity_pop_job(structdrm_sched_entity *entity) { -struct drm_sched_job *sched_job; +struct drm_sched_job *sched_job, *next_job;
sched_job=drm_sched_entity_queue_peek(entity); if (!sched_job)drivers/gpu/drm/scheduler/sched_entity.c +14
-13@@ -506,21 +516,22 @@ struct drm_sched_job*drm_sched_entity_pop_job(struct drm_sched_entity *entity) * Update the entity's location in the min heap according to * the timestamp of the next job, if any. */ -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) { -struct drm_sched_job *next; + next_job =drm_sched_entity_queue_peek (entity); +if (next_job) { +struct drm_sched_rq *rq; +ktime_t ts; - next =drm_sched_entity_queue_peek (entity); -if (next) { -struct drm_sched_rq *rq; +if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) + ts = next_job->submit_ts; +else + ts =drm_sched_rq_get_rr_deadline (rq); -spin_lock (&entity->lock); - 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); - } +spin_lock (&entity->lock); + rq = entity->rq; +spin_lock (&rq->lock); +drm_sched_rq_update_fifo_locked (entity, rq, ts); +spin_unlock (&rq->lock); +spin_unlock (&entity->lock); }/* Jobs and entities might have different lifecycles. Since we're
drivers/gpu/drm/scheduler/sched_entity.c +3
-3@@ -619,9 +630,9 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) 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, rq, submit_ts); +if (drm_sched_policy ==DRM_SCHED_POLICY_RR ) + submit_ts =drm_sched_rq_get_rr_deadline (rq); +drm_sched_rq_update_fifo_locked (entity, rq, submit_ts); spin_unlock(&rq->lock);
spin_unlock(&entity->lock);drivers/gpu/drm/scheduler/sched_main.c +1
-7@@ -190,7 +190,6 @@ static void drm_sched_rq_init(structdrm_gpu_scheduler *sched, spin_lock_init(&rq->lock); INIT_LIST_HEAD(&rq->entities); rq->rb_tree_root = RB_ROOT_CACHED; - rq->current_entity =NULL ; rq->sched = sched; }@@ -236,74 +235,13 @@ void drm_sched_rq_remove_entity(structdrm_sched_rq *rq, atomic_dec(rq->sched->score); list_del_init(&entity->list); -if (rq->current_entity == entity) - rq->current_entity =NULL ; - -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) -drm_sched_rq_remove_fifo_locked (entity, rq); +drm_sched_rq_remove_fifo_locked (entity, rq); spin_unlock(&rq->lock); } /** -* drm_sched_rq_select_entity_rr - Select an entity which could provide a job to run
- *
- * @sched: the gpu scheduler
- * @rq: scheduler run queue to check.
- *
- * Try to find the next ready entity.
- *
- * Return an entity if one is found; return an error-pointer (!NULL) if an
- * entity was ready, but the scheduler had insufficient credits to accommodate
- * its job; return NULL, if no ready entity was found.
- */drivers/gpu/drm/scheduler/sched_main.c +0
-47-static struct drm_sched_entity * -drm_sched_rq_select_entity_rr (struct drm_gpu_scheduler *sched, - struct drm_sched_rq *rq) -{ -struct drm_sched_entity *entity; - -spin_lock (&rq->lock); - - entity = rq->current_entity; -if (entity) { -list_for_each_entry_continue (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) - goto found; - } - } - -list_for_each_entry (entity, &rq->entities, list) { -if (drm_sched_entity_is_ready (entity)) - goto found; - -if (entity == rq->current_entity) -break ; - } - -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; -} - -/** -* drm_sched_rq_select_entity_fifo - Select an entity which provides a job to run
+ *drm_sched_rq_select_entity- Select an entity which provides a job to run
*
* @sched: the gpu scheduler
* @rq: scheduler run queue to check.drivers/gpu/drm/scheduler/sched_main.c +2
-2@@ -315,8 +253,8 @@ drm_sched_rq_select_entity_rr(structdrm_gpu_scheduler *sched, * its job; return NULL, if no ready entity was found. */ static struct drm_sched_entity * -drm_sched_rq_select_entity_fifo (struct drm_gpu_scheduler *sched, -struct drm_sched_rq *rq) +drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched, + struct drm_sched_rq *rq) { struct drm_sched_entity *entity = NULL;struct
rb_node*rb;drivers/gpu/drm/scheduler/sched_main.c +2
-4@@ -1061,15 +999,13 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched) static struct drm_sched_entity * drm_sched_select_entity(struct drm_gpu_scheduler *sched) { -struct drm_sched_entity *entity; +struct drm_sched_entity *entity =NULL ; int i; /* Start with the highest priority. */ for (i = DRM_SCHED_PRIORITY_KERNEL; i < sched->num_rqs; i++) { - entity = drm_sched_policy ==DRM_SCHED_POLICY_FIFO ? -drm_sched_rq_select_entity_fifo (sched, sched->sched_rq[i]) : -drm_sched_rq_select_entity_rr (sched, sched->sched_rq[i]); + entity =drm_sched_rq_select_entity (sched, sched->sched_rq[i]); if (entity) break;}
include/drm/gpu_scheduler.h +1
-2@@ -239,8 +239,7 @@ struct drm_sched_entity { * struct drm_sched_rq - queue of entities to be scheduled. * * @sched: the scheduler to which this rq belongs to. - * @lock: protects @entities, @rb_tree_root and @current_entity. - * @current_entity: the entity which is to be scheduled. + * @lock: protects @entities, @rb_tree_root and @rr_deadline. * @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities forFIFO scheduling
*include/drm/gpu_scheduler.h +1
-1@@ -253,7 +252,7 @@ struct drm_sched_rq { spinlock_t lock; /* Following members are protected by the @lock: */ -struct drm_sched_entity *current_entity; +ktime_t rr_deadline; struct list_head entities; struct rb_root_cached rb_tree_root; };
RFC v3 7/14 drm/sched: Consolidate entity run queue management
In reply to Tvrtko UrsulinMove the code dealing with entities entering and exiting run queues to helpers to logically separate it from jobs entering and exiting entities.
--- drivers/gpu/drm/scheduler/sched_entity.c | 60 ++------------- drivers/gpu/drm/scheduler/sched_internal.h | 8 +- drivers/gpu/drm/scheduler/sched_main.c | 87 +++++++++++++++++++--- 3 files changed, 83 insertions(+), 72 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +5 -55
@@ -469,19 +469,9 @@ drm_sched_job_dependency(struct drm_sched_job *job,return NULL ; } -static ktime_t -drm_sched_rq_get_rr_deadline (struct drm_sched_rq *rq) -{ -lockdep_assert_held (&rq->lock); - - rq->rr_deadline =ktime_add_ns (rq->rr_deadline,1 ); - -return rq->rr_deadline; -} -struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity) { -struct drm_sched_job *sched_job, *next_job; +struct drm_sched_job *sched_job; sched_job =drm_sched_entity_queue_peek (entity);if (!sched_job)
@@ -512,27 +502,7 @@ struct drm_sched_job *drm_sched_entity_pop_job(struct drm_sched_entity *entity)spsc_queue_pop (&entity->job_queue); -/* -* Update the entity's location in the min heap according to -* the timestamp of the next job, if any. -*/ - next_job =drm_sched_entity_queue_peek (entity); -if (next_job) { -struct drm_sched_rq *rq; -ktime_t ts; - -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) - ts = next_job->submit_ts; -else - ts =drm_sched_rq_get_rr_deadline (rq); - -spin_lock (&entity->lock); - rq = entity->rq; -spin_lock (&rq->lock); -drm_sched_rq_update_fifo_locked (entity, rq, ts); -spin_unlock (&rq->lock); -spin_unlock (&entity->lock); - } +drm_sched_rq_pop_entity (entity);/* Jobs and entities might have different lifecycles. Since we're * removing the job from the entities queue, set the jobs entity pointer
@@ -614,30 +584,10 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* first job wakes up scheduler */ if (first) {struct drm_gpu_scheduler *sched; -struct drm_sched_rq *rq; -/* Add the entity to the run queue */ -spin_lock (&entity->lock); -if (entity->stopped) { -spin_unlock (&entity->lock); - -DRM_ERROR ("Trying to push to a killed entity\n" ); -return ; - } - - rq = entity->rq; - sched = rq->sched; - -spin_lock (&rq->lock); -drm_sched_rq_add_entity (rq, entity); -if (drm_sched_policy ==DRM_SCHED_POLICY_RR ) - submit_ts =drm_sched_rq_get_rr_deadline (rq); -drm_sched_rq_update_fifo_locked (entity, rq, submit_ts); - -spin_unlock (&rq->lock); -spin_unlock (&entity->lock); - -drm_sched_wakeup (sched); + sched =drm_sched_rq_add_entity (entity, submit_ts); +if (sched) +drm_sched_wakeup (sched); } }EXPORT_SYMBOL (drm_sched_entity_push_job);
drivers/gpu/drm/scheduler/sched_internal.h +3 -5
@@ -12,13 +12,11 @@ extern int drm_sched_policy;void drm_sched_wakeup (struct drm_gpu_scheduler *sched); -void drm_sched_rq_add_entity (struct drm_sched_rq *rq, -struct drm_sched_entity *entity); +struct drm_gpu_scheduler * +drm_sched_rq_add_entity (struct drm_sched_entity *entity,ktime_t ts);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, -struct drm_sched_rq *rq,ktime_t ts); +void drm_sched_rq_pop_entity (struct drm_sched_entity *entity);void drm_sched_entity_select_rq (struct drm_sched_entity *entity);struct drm_sched_job *drm_sched_entity_pop_job (struct drm_sched_entity *entity);
drivers/gpu/drm/scheduler/sched_main.c +75 -12
121 lines not on this page · raw message
Signature · 1 line
2.48.0
RFC v3 8/14 drm/sched: Move run queue related code into a separate file
In reply to Tvrtko UrsulinLets move all the code dealing with struct drm_sched_rq into a separate compilation unit. Advantage being sched_main.c is left with a clearer set of responsibilities.
--- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 7 + drivers/gpu/drm/scheduler/sched_main.c | 213 +------------------- drivers/gpu/drm/scheduler/sched_rq.c | 217 +++++++++++++++++++++ 4 files changed, 227 insertions(+), 212 deletions(-) create mode 100644 drivers/gpu/drm/scheduler/sched_rq.c
drivers/gpu/drm/scheduler/Makefile +1 -1
@@ -20,7 +20,7 @@ # OTHER DEALINGS IN THE SOFTWARE. # # -gpu-sched-y := sched_main.o sched_fence.o sched_entity.o +gpu-sched-y := sched_main.o sched_fence.o sched_entity.o sched_rq.o obj-$(CONFIG_DRM_SCHED) += gpu-sched.o
drivers/gpu/drm/scheduler/sched_internal.h +7 -0
@@ -10,8 +10,15 @@ extern int drm_sched_policy;#define DRM_SCHED_POLICY_RR 0#define DRM_SCHED_POLICY_FIFO 1 +bool drm_sched_can_queue (struct drm_gpu_scheduler *sched, +struct drm_sched_entity *entity);void drm_sched_wakeup (struct drm_gpu_scheduler *sched); +void drm_sched_rq_init (struct drm_gpu_scheduler *sched, +struct drm_sched_rq *rq); +struct drm_sched_entity * +drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched, +struct drm_sched_rq *rq);struct drm_gpu_scheduler *drm_sched_rq_add_entity (struct drm_sched_entity *entity,ktime_t ts); void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
drivers/gpu/drm/scheduler/sched_main.c +2 -211
225 lines not on this page · raw message
drivers/gpu/drm/scheduler/sched_rq.c new file +217 -0
217 lines not on this page · raw message
Signature · 1 line
2.48.0
RFC v3 9/14 drm/sched: Add deadline policy
In reply to Tvrtko UrsulinDeadline scheduling policy should be a fairer flavour of FIFO with two main advantages being that it can naturally connect with the dma-fence deadlines, and secondly that it can get away with multiple run queues per scheduler.
From the latter comes the fairness advantage. Where the current FIFO policy will always starve low priority entities by normal, and normal by high etc, deadline tracks all runnable entities in a single run queue and assigns them deadlines based on priority. Instead of being ordered strictly by priority, jobs and entities become ordered by deadlines.
This means that a later higher priority submission can still overtake an earlier lower priority one, but eventually the lower priority will get its turn even if high priority is constantly feeding new work.
Current mapping of priority to deadlines is somewhat arbitrary and looks like this (submit timestamp plus constant offset in micro-seconds):
static const unsigned int d_us[] = {
[DRM_SCHED_PRIORITY_KERNEL] = 100,
[DRM_SCHED_PRIORITY_HIGH] = 1000,
[DRM_SCHED_PRIORITY_NORMAL] = 5000,
[DRM_SCHED_PRIORITY_LOW] = 100000,
};Assuming simultaneous submission of one normal and one low prioriy job at a time of "t", they will get respective deadlines of t+5ms and t+100ms. Hence normal will run first and low will run after it, or at the latest 100ms after it was submitted in case other higher priority submissions overtake it in the meantime.
Because deadline policy does not need run queues, if the FIFO and RR polices are later removed, that would allow for a significant simplification of the code base by reducing the 1:N to 1:1 scheduler to run queue relationship.
--- drivers/gpu/drm/scheduler/sched_entity.c | 53 ++++++++++++++++++---- drivers/gpu/drm/scheduler/sched_internal.h | 9 +++- drivers/gpu/drm/scheduler/sched_main.c | 14 ++++-- drivers/gpu/drm/scheduler/sched_rq.c | 4 +- include/drm/gpu_scheduler.h | 3 ++ 5 files changed, 65 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +43 -10
@@ -70,6 +70,8 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; + entity->rq_priority = drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ? +DRM_SCHED_PRIORITY_KERNEL : priority;/* * It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it
@@ -86,17 +88,23 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,*/ pr_warn ("%s: called with uninitialized scheduler\n" , __func__); }else if (num_sched_list) { -/* The "priority" of an entity cannot exceed the number of run-queues of a -* scheduler. Protect against num_rqs being 0, by converting to signed. Choose -* the lowest priority available. +enum drm_sched_priority p = entity->priority; + +/* +* The "priority" of an entity cannot exceed the number of +* run-queues of a scheduler. Protect against num_rqs being 0, +* by converting to signed. Choose the lowest priority +* available. */ -if (entity->priority >= sched_list[0 ]->num_rqs) { -dev_err (sched_list[0 ]->dev,"entity has out-of-bounds priority: %u. num_rqs: %u\n" , - entity->priority, sched_list[0 ]->num_rqs); - entity->priority =max_t (s32, (s32 ) sched_list[0 ]->num_rqs -1 , - (s32 )DRM_SCHED_PRIORITY_KERNEL ); +if (p >= sched_list[0 ]->num_user_rqs) { +dev_err (sched_list[0 ]->dev,"entity with out-of-bounds priority:%u num_user_rqs:%u\n" , + p, sched_list[0 ]->num_user_rqs); + p =max_t (s32, + (s32 )sched_list[0 ]->num_user_rqs -1 , + (s32 )DRM_SCHED_PRIORITY_KERNEL ); + entity->priority = p; } - entity->rq = sched_list[0 ]->sched_rq[entity->priority]; + entity->rq = sched_list[0 ]->sched_rq[entity->rq_priority]; }init_completion (&entity->entity_idle);
@@ -398,6 +406,27 @@ void drm_sched_entity_set_priority(struct drm_sched_entity *entity, }EXPORT_SYMBOL (drm_sched_entity_set_priority); +static ktime_t +__drm_sched_entity_get_job_deadline (struct drm_sched_entity *entity, +ktime_t submit_ts) +{ +static const unsigned int d_us[] = { + [DRM_SCHED_PRIORITY_KERNEL ] =100 , + [DRM_SCHED_PRIORITY_HIGH ] =1000 , + [DRM_SCHED_PRIORITY_NORMAL ] =5000 , + [DRM_SCHED_PRIORITY_LOW ] =100000 , + }; + +return ktime_add_us (submit_ts, d_us[entity->priority]); +} + +ktime_t +drm_sched_entity_get_job_deadline (struct drm_sched_entity *entity, +struct drm_sched_job *job) +{ +return __drm_sched_entity_get_job_deadline (entity, job->submit_ts); +} +/* * Add a callback to the current dependency of the entity to wake up the * scheduler when the entity becomes available.
@@ -543,7 +572,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)spin_lock (&entity->lock); sched =drm_sched_pick_best (entity->sched_list, entity->num_sched_list); - rq = sched ? sched->sched_rq[entity->priority] :NULL ; + rq = sched ? sched->sched_rq[entity->rq_priority] :NULL ;if (rq != entity->rq) {drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq;
@@ -585,6 +614,10 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)if (first) {struct drm_gpu_scheduler *sched; +if (drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ) + submit_ts =__drm_sched_entity_get_job_deadline (entity, + submit_ts); + sched =drm_sched_rq_add_entity (entity, submit_ts);if (sched)drm_sched_wakeup (sched);
drivers/gpu/drm/scheduler/sched_internal.h +7 -2
@@ -7,8 +7,9 @@/* Used to choose between FIFO and RR job-scheduling */ extern int drm_sched_policy; -#define DRM_SCHED_POLICY_RR 0 -#define DRM_SCHED_POLICY_FIFO 1 +#define DRM_SCHED_POLICY_RR 0 +#define DRM_SCHED_POLICY_FIFO 1 +#define DRM_SCHED_POLICY_DEADLINE 2bool drm_sched_can_queue (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);
@@ -38,6 +39,10 @@ void drm_sched_fence_scheduled(struct drm_sched_fence *fence, struct dma_fence *parent);void drm_sched_fence_finished (struct drm_sched_fence *fence,int result); + +ktime_t drm_sched_entity_get_job_deadline (struct drm_sched_entity *entity, +struct drm_sched_job *job); +/** * drm_sched_entity_queue_pop - Low level helper for popping queued jobs *
drivers/gpu/drm/scheduler/sched_main.c +9 -5
@@ -89,13 +89,13 @@ static struct lockdep_map drm_sched_lockdep_map = { };#endif -int drm_sched_policy =DRM_SCHED_POLICY_FIFO ; +int drm_sched_policy =DRM_SCHED_POLICY_DEADLINE ;/** * DOC: sched_policy (int) * Used to override default entities scheduling policy in a run queue. */ -MODULE_PARM_DESC(sched_policy, "Specify the scheduling policy for entities on a run-queue, " __stringify(DRM_SCHED_POLICY_RR) " = Round Robin, " __stringify(DRM_SCHED_POLICY_FIFO) " = FIFO (default)."); +MODULE_PARM_DESC(sched_policy, "Specify the scheduling policy for entities on a run-queue, " __stringify(DRM_SCHED_POLICY_RR) " = Round Robin, " __stringify(DRM_SCHED_POLICY_FIFO) " = FIFO, " __stringify(DRM_SCHED_POLICY_DEADLINE) " = Virtual deadline (default).");module_param_named (sched_policy, drm_sched_policy, int,0444 );static u32 drm_sched_available_credits (struct drm_gpu_scheduler *sched)
@@ -1085,11 +1085,15 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_ sched->own_submit_wq = true; } - sched->sched_rq =kmalloc_array (args->num_rqs,sizeof (*sched->sched_rq), + sched->num_user_rqs = args->num_rqs; + sched->num_rqs = drm_sched_policy !=DRM_SCHED_POLICY_DEADLINE ? + args->num_rqs :1 ; + sched->sched_rq =kmalloc_array (sched->num_rqs, +sizeof (*sched->sched_rq),GFP_KERNEL | __GFP_ZERO);if (!sched->sched_rq) goto Out_check_own; - sched->num_rqs = args->num_rqs; +for (i =DRM_SCHED_PRIORITY_KERNEL ; i < sched->num_rqs; i++) { sched->sched_rq[i] =kzalloc (sizeof (*sched->sched_rq[i]),GFP_KERNEL );if (!sched->sched_rq[i])
@@ -1204,7 +1208,7 @@ void drm_sched_increase_karma(struct drm_sched_job *bad)if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) {atomic_inc (&bad->karma); -for (i =DRM_SCHED_PRIORITY_HIGH ; i < sched->num_rqs; i++) { +for (i =DRM_SCHED_PRIORITY_KERNEL ; i < sched->num_rqs; i++) {struct drm_sched_rq *rq = sched->sched_rq[i];spin_lock (&rq->lock);
drivers/gpu/drm/scheduler/sched_rq.c +3 -1
@@ -159,7 +159,9 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)if (!next_job)return ; -if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) +if (drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ) + ts =drm_sched_entity_get_job_deadline (entity, next_job); +else if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) ts = next_job->submit_ts;else ts =drm_sched_rq_get_rr_deadline (rq);
include/drm/gpu_scheduler.h +3 -0
@@ -147,6 +147,8 @@ struct drm_sched_entity {*/ struct spsc_queue job_queue; +enum drm_sched_priority rq_priority; +/** * @fence_seq: *
@@ -551,6 +553,7 @@ struct drm_gpu_scheduler {long timeout;const char *name;u32 num_rqs; +u32 num_user_rqs;struct drm_sched_rq **sched_rq;wait_queue_head_t job_scheduled;atomic64_t job_id_count;
Signature · 1 line
2.48.0
RFC v3 10/14 drm/sched: Remove FIFO and RR and simplify to a single run queue
In reply to Tvrtko UrsulinIf the new deadline policy is at least as good as FIFO and we can afford to remove round-robin, we can simplify the scheduler code by making the scheduler to run queue relationship always 1:1 and remove some code.
Also, now that the FIFO policy is gone the tree of entities is not a FIFO tree any more so rename it to just the tree.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 23 ++-- drivers/gpu/drm/scheduler/sched_entity.c | 30 +---- drivers/gpu/drm/scheduler/sched_internal.h | 7 -- drivers/gpu/drm/scheduler/sched_main.c | 133 +++++---------------- drivers/gpu/drm/scheduler/sched_rq.c | 32 ++--- include/drm/gpu_scheduler.h | 6 +- 6 files changed, 54 insertions(+), 177 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +10 -13
@@ -459,25 +459,22 @@ drm_sched_entity_queue_pop(struct drm_sched_entity *entity)void amdgpu_job_stop_all_jobs_on_sched (struct drm_gpu_scheduler *sched) { +struct drm_sched_rq *rq = sched->rq; +struct drm_sched_entity *s_entity;struct drm_sched_job *s_job; -struct drm_sched_entity *s_entity =NULL ; -int i;/* Signal all jobs not yet scheduled */ -for (i =DRM_SCHED_PRIORITY_KERNEL ; i < sched->num_rqs; i++) { -struct drm_sched_rq *rq = sched->sched_rq[i]; -spin_lock (&rq->lock); -list_for_each_entry (s_entity, &rq->entities, list) { -while ((s_job =drm_sched_entity_queue_pop (s_entity))) { -struct drm_sched_fence *s_fence = s_job->s_fence; +spin_lock (&rq->lock); +list_for_each_entry (s_entity, &rq->entities, list) { +while ((s_job =drm_sched_entity_queue_pop (s_entity))) { +struct drm_sched_fence *s_fence = s_job->s_fence; -dma_fence_signal (&s_fence->scheduled); -dma_fence_set_error (&s_fence->finished, -EHWPOISON ); -dma_fence_signal (&s_fence->finished); - } +dma_fence_signal (&s_fence->scheduled); +dma_fence_set_error (&s_fence->finished, -EHWPOISON ); +dma_fence_signal (&s_fence->finished); } -spin_unlock (&rq->lock); } +spin_unlock (&rq->lock);/* Signal all jobs already scheduled to HW */ list_for_each_entry (s_job, &sched->pending_list, list) {
drivers/gpu/drm/scheduler/sched_entity.c +5 -25
@@ -70,8 +70,6 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->guilty = guilty; entity->num_sched_list = num_sched_list; entity->priority = priority; - entity->rq_priority = drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ? -DRM_SCHED_PRIORITY_KERNEL : priority;/* * It's perfectly valid to initialize an entity without having a valid * scheduler attached. It's just not valid to use the scheduler before it
@@ -81,30 +79,14 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,RCU_INIT_POINTER (entity->last_scheduled,NULL );RB_CLEAR_NODE (&entity->rb_tree_node); -if (num_sched_list && !sched_list[0 ]->sched_rq) { +if (num_sched_list && !sched_list[0 ]->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 (num_sched_list) { -enum drm_sched_priority p = entity->priority; - -/* -* The "priority" of an entity cannot exceed the number of -* run-queues of a scheduler. Protect against num_rqs being 0, -* by converting to signed. Choose the lowest priority -* available. -*/ -if (p >= sched_list[0 ]->num_user_rqs) { -dev_err (sched_list[0 ]->dev,"entity with out-of-bounds priority:%u num_user_rqs:%u\n" , - p, sched_list[0 ]->num_user_rqs); - p =max_t (s32, - (s32 )sched_list[0 ]->num_user_rqs -1 , - (s32 )DRM_SCHED_PRIORITY_KERNEL ); - entity->priority = p; - } - entity->rq = sched_list[0 ]->sched_rq[entity->rq_priority]; + entity->rq = sched_list[0 ]->rq; }init_completion (&entity->entity_idle);
@@ -572,7 +554,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)spin_lock (&entity->lock); sched =drm_sched_pick_best (entity->sched_list, entity->num_sched_list); - rq = sched ? sched->sched_rq[entity->rq_priority] :NULL ; + rq = sched ? sched->rq :NULL ;if (rq != entity->rq) {drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq;
@@ -614,10 +596,8 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)if (first) {struct drm_gpu_scheduler *sched; -if (drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ) - submit_ts =__drm_sched_entity_get_job_deadline (entity, - submit_ts); - + submit_ts =__drm_sched_entity_get_job_deadline (entity, + submit_ts); sched =drm_sched_rq_add_entity (entity, submit_ts);if (sched)drm_sched_wakeup (sched);
drivers/gpu/drm/scheduler/sched_internal.h +0 -7
@@ -4,13 +4,6 @@#define _DRM_GPU_SCHEDULER_INTERNAL_H_ -/* Used to choose between FIFO and RR job-scheduling */ -extern int drm_sched_policy; - -#define DRM_SCHED_POLICY_RR 0 -#define DRM_SCHED_POLICY_FIFO 1 -#define DRM_SCHED_POLICY_DEADLINE 2 -bool drm_sched_can_queue (struct drm_gpu_scheduler *sched,struct drm_sched_entity *entity);void drm_sched_wakeup (struct drm_gpu_scheduler *sched);
drivers/gpu/drm/scheduler/sched_main.c +31 -102
210 lines not on this page · raw message
drivers/gpu/drm/scheduler/sched_rq.c +7 -25
@@ -16,7 +16,7 @@ drm_sched_entity_compare_before(struct rb_node *a, const struct rb_node *b)return ktime_before (ea->oldest_job_waiting, eb->oldest_job_waiting); } -static void drm_sched_rq_remove_fifo_locked (struct drm_sched_entity *entity, +static void drm_sched_rq_remove_tree_locked (struct drm_sched_entity *entity,struct drm_sched_rq *rq) {lockdep_assert_held (&entity->lock);
@@ -28,7 +28,7 @@ static void drm_sched_rq_remove_fifo_locked(struct drm_sched_entity *entity, } } -static void drm_sched_rq_update_fifo_locked (struct drm_sched_entity *entity, +static void drm_sched_rq_update_tree_locked (struct drm_sched_entity *entity,struct drm_sched_rq *rq,ktime_t ts) {
@@ -40,7 +40,7 @@ static void drm_sched_rq_update_fifo_locked(struct drm_sched_entity *entity,lockdep_assert_held (&entity->lock);lockdep_assert_held (&rq->lock); -drm_sched_rq_remove_fifo_locked (entity, rq); +drm_sched_rq_remove_tree_locked (entity, rq); entity->oldest_job_waiting = ts;
@@ -65,16 +65,6 @@ void drm_sched_rq_init(struct drm_gpu_scheduler *sched, rq->sched = sched; } -static ktime_t -drm_sched_rq_get_rr_deadline (struct drm_sched_rq *rq) -{ -lockdep_assert_held (&rq->lock); - - rq->rr_deadline =ktime_add_ns (rq->rr_deadline,1 ); - -return rq->rr_deadline; -} -/** * drm_sched_rq_add_entity - add an entity *
@@ -109,9 +99,7 @@ drm_sched_rq_add_entity(struct drm_sched_entity *entity, ktime_t ts)list_add_tail (&entity->list, &rq->entities); } -if (drm_sched_policy ==DRM_SCHED_POLICY_RR ) - ts =drm_sched_rq_get_rr_deadline (rq); -drm_sched_rq_update_fifo_locked (entity, rq, ts); +drm_sched_rq_update_tree_locked (entity, rq, ts);spin_unlock (&rq->lock);spin_unlock (&entity->lock);
@@ -140,7 +128,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,atomic_dec (rq->sched->score);list_del_init (&entity->list); -drm_sched_rq_remove_fifo_locked (entity, rq); +drm_sched_rq_remove_tree_locked (entity, rq);spin_unlock (&rq->lock); }
@@ -159,17 +147,11 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)if (!next_job)return ; -if (drm_sched_policy ==DRM_SCHED_POLICY_DEADLINE ) - ts =drm_sched_entity_get_job_deadline (entity, next_job); -else if (drm_sched_policy ==DRM_SCHED_POLICY_FIFO ) - ts = next_job->submit_ts; -else - ts =drm_sched_rq_get_rr_deadline (rq); - + ts =drm_sched_entity_get_job_deadline (entity, next_job);spin_lock (&entity->lock); rq = entity->rq;spin_lock (&rq->lock); -drm_sched_rq_update_fifo_locked (entity, rq, ts); +drm_sched_rq_update_tree_locked (entity, rq, ts);spin_unlock (&rq->lock);spin_unlock (&entity->lock); }
include/drm/gpu_scheduler.h +1 -5
@@ -147,8 +147,6 @@ struct drm_sched_entity {*/ struct spsc_queue job_queue; -enum drm_sched_priority rq_priority; -/** * @fence_seq: *
@@ -552,9 +550,7 @@ struct drm_gpu_scheduler {atomic_t credit_count;long timeout;const char *name; -u32 num_rqs; -u32 num_user_rqs; -struct drm_sched_rq **sched_rq; +struct drm_sched_rq *rq;wait_queue_head_t job_scheduled;atomic64_t job_id_count;struct workqueue_struct *submit_wq;
Signature · 1 line
2.48.0
RFC v3 11/14 drm/sched: Queue all free credits in one worker invocation
In reply to Tvrtko UrsulinThere is no reason to queue just a single job if scheduler can take more and re-queue the worker to queue more. We can simply feed the hardware with as much as it can take in one go and hopefully win some latency.
--- drivers/gpu/drm/scheduler/sched_internal.h | 2 - drivers/gpu/drm/scheduler/sched_main.c | 127 ++++++++++----------- drivers/gpu/drm/scheduler/sched_rq.c | 17 +-- 3 files changed, 61 insertions(+), 85 deletions(-)
drivers/gpu/drm/scheduler/sched_internal.h +0 -2
@@ -4,8 +4,6 @@#define _DRM_GPU_SCHEDULER_INTERNAL_H_ -bool drm_sched_can_queue (struct drm_gpu_scheduler *sched, -struct drm_sched_entity *entity);void drm_sched_wakeup (struct drm_gpu_scheduler *sched); void drm_sched_rq_init(struct drm_gpu_scheduler *sched,
drivers/gpu/drm/scheduler/sched_main.c +58 -69
147 lines not on this page · raw message
drivers/gpu/drm/scheduler/sched_rq.c +3 -14
@@ -164,9 +164,7 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)* * Find oldest waiting ready entity. * -* Return an entity if one is found; return an error-pointer (!NULL) if an -* entity was ready, but the scheduler had insufficient credits to accommodate -* its job; return NULL, if no ready entity was found. +* Return an entity if one is found or NULL if no ready entity was found. */ struct drm_sched_entity * drm_sched_rq_select_entity(struct drm_gpu_scheduler *sched,
@@ -185,17 +183,8 @@ drm_sched_rq_select_entity(struct drm_gpu_scheduler *sched, }spin_unlock (&rq->lock); -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); +if (entity) +reinit_completion (&entity->entity_idle);return entity; }
Signature · 1 line
2.48.0
RFC v3 12/14 drm/sched: Embed run queue singleton into the scheduler
In reply to Tvrtko UrsulinNow that the run queue to scheduler relationship is always 1:1 we can embed it (the run queue) directly in the scheduler struct and save on some allocation error handling code and such.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 6 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 ++--- drivers/gpu/drm/scheduler/sched_entity.c | 34 +++++++++------------ drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 6 ++-- drivers/gpu/drm/scheduler/sched_main.c | 31 +++---------------- drivers/gpu/drm/scheduler/sched_rq.c | 18 +++++------ include/drm/gpu_scheduler.h | 5 +-- 12 files changed, 59 insertions(+), 78 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -2
@@ -1108,7 +1108,8 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)if (p->gang_size >1 && !adev->vm_manager.concurrent_flush) {for (i =0 ; i < p->gang_size; ++i) {struct drm_sched_entity *entity = p->entities[i]; -struct drm_gpu_scheduler *sched = entity->rq->sched; +struct drm_gpu_scheduler *sched = +container_of (entity->rq,typeof (*sched), rq);struct amdgpu_ring *ring =to_amdgpu_ring (sched);if (amdgpu_vmid_uses_reserved (vm, ring->vm_hub))
@@ -1236,7 +1237,8 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)return r; } - sched = p->gang_leader->base.entity->rq->sched; + sched =container_of (p->gang_leader->base.entity->rq,typeof (*sched), + rq);while ((fence =amdgpu_sync_get_fence (&p->sync))) {struct drm_sched_fence *s_fence =to_drm_sched_fence (fence);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +4 -2
@@ -359,7 +359,9 @@ static struct dma_fence * amdgpu_job_prepare_job(struct drm_sched_job *sched_job, struct drm_sched_entity *s_entity) { - struct amdgpu_ring *ring = to_amdgpu_ring(s_entity->rq->sched); + struct drm_gpu_scheduler *sched = +container_of (s_entity->rq,typeof (*sched), rq); +struct amdgpu_ring *ring =to_amdgpu_ring (sched);struct amdgpu_job *job =to_amdgpu_job (sched_job);struct dma_fence *fence;int r;
@@ -459,7 +461,7 @@ drm_sched_entity_queue_pop(struct drm_sched_entity *entity)void amdgpu_job_stop_all_jobs_on_sched (struct drm_gpu_scheduler *sched) { -struct drm_sched_rq *rq = sched->rq; +struct drm_sched_rq *rq = &sched->rq;struct drm_sched_entity *s_entity;struct drm_sched_job *s_job;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +4 -1
@@ -85,7 +85,10 @@ struct amdgpu_job {static inline struct amdgpu_ring *amdgpu_job_ring (struct amdgpu_job *job) { -return to_amdgpu_ring (job->base.entity->rq->sched); +struct drm_gpu_scheduler *sched = +container_of (job->base.entity->rq,typeof (*sched), rq); + +return to_amdgpu_ring (sched); } int amdgpu_job_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h +6 -2
@@ -145,6 +145,7 @@ TRACE_EVENT(amdgpu_cs, struct amdgpu_ib *ib),TP_ARGS (p ,job ,ib ),TP_STRUCT__entry ( + __field(struct drm_gpu_scheduler *, sched)__field (struct amdgpu_bo_list *,bo_list )__field (u32, ring) __field(u32, dw)
@@ -152,11 +153,14 @@ TRACE_EVENT(amdgpu_cs, ),TP_fast_assign ( + __entry->sched =container_of (job->base.entity->rq, +typeof (*__entry->sched), + rq); __entry->bo_list = p->bo_list; - __entry->ring =to_amdgpu_ring (job->base.entity->rq->sched)->idx; + __entry->ring =to_amdgpu_ring (__entry->sched)->idx; __entry->dw = ib->length_dw; __entry->fences =amdgpu_fence_count_emitted ( -to_amdgpu_ring (job->base.entity->rq->sched)); +to_amdgpu_ring (__entry->sched)); ), TP_printk("bo_list=%p, ring=%u, dw=%u, fences=%u", __entry->bo_list, __entry->ring, __entry->dw,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +4 -4
@@ -105,13 +105,13 @@ static int amdgpu_vm_sdma_prepare(struct amdgpu_vm_update_params *p,static int amdgpu_vm_sdma_commit (struct amdgpu_vm_update_params *p,struct dma_fence **fence) { +struct drm_gpu_scheduler *sched = +container_of (p->vm->delayed.rq,typeof (*sched), rq); +struct amdgpu_ring *ring = + container_of(sched, struct amdgpu_ring, sched);struct amdgpu_ib *ib = p->job->ibs; -struct amdgpu_ring *ring;struct dma_fence *f; - ring = container_of(p->vm->delayed.rq->sched, struct amdgpu_ring, - sched); -WARN_ON (ib->length_dw ==0 );amdgpu_ring_pad_ib (ring, ib);
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +4 -4
@@ -420,15 +420,15 @@ int amdgpu_xcp_open_device(struct amdgpu_device *adev,void amdgpu_xcp_release_sched (struct amdgpu_device *adev,struct amdgpu_ctx_entity *entity) { -struct drm_gpu_scheduler *sched; -struct amdgpu_ring *ring; +struct drm_gpu_scheduler *sched = +container_of (entity->entity.rq,typeof (*sched), rq);if (!adev->xcp_mgr)return ; - sched = entity->entity.rq->sched;if (drm_sched_wqueue_ready (sched)) { - ring =to_amdgpu_ring (entity->entity.rq->sched); +struct amdgpu_ring *ring =to_amdgpu_ring (sched); +atomic_dec (&adev->xcp_mgr->xcp[ring->xcp_id].ref_cnt); } }
drivers/gpu/drm/scheduler/sched_entity.c +15 -19
@@ -76,19 +76,12 @@ int drm_sched_entity_init(struct drm_sched_entity *entity,* is initialized itself. */ entity->sched_list = num_sched_list >1 ? sched_list :NULL ; +if (num_sched_list) { + entity->sched_list = num_sched_list >1 ? sched_list :NULL ; + entity->rq = &sched_list[0 ]->rq; + }RCU_INIT_POINTER (entity->last_scheduled,NULL );RB_CLEAR_NODE (&entity->rb_tree_node); - -if (num_sched_list && !sched_list[0 ]->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 (num_sched_list) { - entity->rq = sched_list[0 ]->rq; - } -init_completion (&entity->entity_idle);/* We start in an idle state. */
@@ -275,7 +268,7 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout)if (!entity->rq)return 0 ; - sched = entity->rq->sched; + sched =container_of (entity->rq,typeof (*sched), rq);/** * The client will not queue more IBs during this fini, consume existing * queued IBs or discard them on SIGKILL
@@ -366,9 +359,11 @@ static void drm_sched_entity_wakeup(struct dma_fence *f, {struct drm_sched_entity *entity = container_of(cb, struct drm_sched_entity, cb); +struct drm_gpu_scheduler *sched = +container_of (entity->rq,typeof (*sched), rq);drm_sched_entity_clear_dep (f, cb); -drm_sched_wakeup (entity->rq->sched); +drm_sched_wakeup (sched); }/**
@@ -415,7 +410,8 @@ drm_sched_entity_get_job_deadline(struct drm_sched_entity *entity,*/ static bool drm_sched_entity_add_dependency_cb (struct drm_sched_entity *entity) { -struct drm_gpu_scheduler *sched = entity->rq->sched; +struct drm_gpu_scheduler *sched = +container_of (entity->rq,typeof (*sched), rq);struct dma_fence *fence = entity->dependency;struct drm_sched_fence *s_fence;
@@ -554,7 +550,7 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)spin_lock (&entity->lock); sched =drm_sched_pick_best (entity->sched_list, entity->num_sched_list); - rq = sched ? sched->rq :NULL ; + rq = sched ? &sched->rq :NULL ;if (rq != entity->rq) {drm_sched_rq_remove_entity (entity->rq, entity); entity->rq = rq;
@@ -577,11 +573,13 @@ void drm_sched_entity_select_rq(struct drm_sched_entity *entity)void drm_sched_entity_push_job (struct drm_sched_job *sched_job) {struct drm_sched_entity *entity = sched_job->entity; -bool first; +struct drm_gpu_scheduler *sched = +container_of (entity->rq,typeof (*sched), rq);ktime_t submit_ts; +bool first;trace_drm_sched_job (sched_job, entity); -atomic_inc (entity->rq->sched->score); +atomic_inc (sched->score);WRITE_ONCE (entity->last_user, current->group_leader);/*
@@ -594,8 +592,6 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* first job wakes up scheduler */ if (first) { -struct drm_gpu_scheduler *sched; - submit_ts =__drm_sched_entity_get_job_deadline (entity, submit_ts); sched =drm_sched_rq_add_entity (entity, submit_ts);
drivers/gpu/drm/scheduler/sched_fence.c +1 -1
@@ -225,7 +225,7 @@ void drm_sched_fence_init(struct drm_sched_fence *fence, {unsigned seq; - fence->sched = entity->rq->sched; + fence->sched =container_of (entity->rq,typeof (*fence->sched), rq); seq =atomic_inc_return (&entity->fence_seq);dma_fence_init (&fence->scheduled, &drm_sched_fence_ops_scheduled, &fence->lock, entity->fence_context, seq);
drivers/gpu/drm/scheduler/sched_internal.h +2 -4
@@ -6,11 +6,9 @@void drm_sched_wakeup (struct drm_gpu_scheduler *sched); -void drm_sched_rq_init (struct drm_gpu_scheduler *sched, -struct drm_sched_rq *rq); +void drm_sched_rq_init (struct drm_gpu_scheduler *sched);struct drm_sched_entity * -drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched, -struct drm_sched_rq *rq); +drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched);struct drm_gpu_scheduler *drm_sched_rq_add_entity (struct drm_sched_entity *entity,ktime_t ts); void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,
drivers/gpu/drm/scheduler/sched_main.c +5 -26
@@ -578,7 +578,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)BUG_ON (!entity);drm_sched_entity_select_rq (entity); - sched = entity->rq->sched; + sched =container_of (entity->rq,typeof (*sched), rq); job->sched = sched; job->s_priority = entity->priority;
@@ -924,7 +924,7 @@ static void drm_sched_run_job_work(struct work_struct *w)while (!READ_ONCE (sched->pause_submit)) {/* Find entity with a ready job */ - entity =drm_sched_rq_select_entity (sched, sched->rq); + entity =drm_sched_rq_select_entity (sched);if (!entity)break ;/* No more work */
@@ -1003,15 +1003,6 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_ sched->score = args->score ? args->score : &sched->_score; sched->dev = args->dev; -if (sched->rq) { -/* Not an error, but warn anyway so drivers can -* fine-tune their DRM calling order, and return all -* is good. -*/ -dev_warn (sched->dev,"%s: scheduler already initialized!\n" , __func__); -return 0 ; - } -if (args->submit_wq) { sched->submit_wq = args->submit_wq; sched->own_submit_wq = false;
@@ -1029,11 +1020,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_ sched->own_submit_wq = true; } - sched->rq =kmalloc (sizeof (*sched->rq),GFP_KERNEL | __GFP_ZERO); -if (!sched->rq) - goto Out_check_own; - -drm_sched_rq_init (sched, sched->rq); +drm_sched_rq_init (sched);init_waitqueue_head (&sched->job_scheduled);INIT_LIST_HEAD (&sched->pending_list);
@@ -1048,12 +1035,6 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_ sched->ready = true;return 0 ; - -Out_check_own: -if (sched->own_submit_wq) -destroy_workqueue (sched->submit_wq); -dev_err (sched->dev,"%s: Failed to setup GPU scheduler--out of memory\n" , __func__); -return -ENOMEM ; }EXPORT_SYMBOL (drm_sched_init);
@@ -1081,7 +1062,7 @@ EXPORT_SYMBOL(drm_sched_init);void drm_sched_fini (struct drm_gpu_scheduler *sched) { -struct drm_sched_rq *rq = sched->rq; +struct drm_sched_rq *rq = &sched->rq;struct drm_sched_entity *s_entity;drm_sched_wqueue_stop (sched);
@@ -1105,8 +1086,6 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)if (sched->own_submit_wq)destroy_workqueue (sched->submit_wq); sched->ready = false; -kfree (sched->rq); - sched->rq =NULL ; }EXPORT_SYMBOL (drm_sched_fini);
@@ -1123,7 +1102,7 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) {struct drm_gpu_scheduler *sched = bad->sched;struct drm_sched_entity *entity, *tmp; -struct drm_sched_rq *rq = sched->rq; +struct drm_sched_rq *rq = &sched->rq;/* don't change @bad's karma if it's from KERNEL RQ, * because sometimes GPU hang would cause kernel jobs (like VM updating jobs)
drivers/gpu/drm/scheduler/sched_rq.c +9 -9
@@ -52,17 +52,16 @@ static void drm_sched_rq_update_tree_locked(struct drm_sched_entity *entity,* drm_sched_rq_init - initialize a given run queue struct * * @sched: scheduler instance to associate with this run queue -* @rq: scheduler run queue * * Initializes a scheduler runqueue. */ -void drm_sched_rq_init (struct drm_gpu_scheduler *sched, -struct drm_sched_rq *rq) +void drm_sched_rq_init (struct drm_gpu_scheduler *sched) { +struct drm_sched_rq *rq = &sched->rq; +spin_lock_init (&rq->lock);INIT_LIST_HEAD (&rq->entities); rq->rb_tree_root =RB_ROOT_CACHED ; - rq->sched = sched; }/**
@@ -91,8 +90,8 @@ drm_sched_rq_add_entity(struct drm_sched_entity *entity, ktime_t ts) } rq = entity->rq; + sched =container_of (rq,typeof (*sched), rq);spin_lock (&rq->lock); - sched = rq->sched;if (list_empty (&entity->list)) {atomic_inc (sched->score);
@@ -118,6 +117,8 @@ drm_sched_rq_add_entity(struct drm_sched_entity *entity, ktime_t ts)void drm_sched_rq_remove_entity (struct drm_sched_rq *rq,struct drm_sched_entity *entity) { +struct drm_gpu_scheduler *sched =container_of (rq,typeof (*sched), rq); +lockdep_assert_held (&entity->lock);if (list_empty (&entity->list))
@@ -125,7 +126,7 @@ void drm_sched_rq_remove_entity(struct drm_sched_rq *rq,spin_lock (&rq->lock); -atomic_dec (rq->sched->score); +atomic_dec (sched->score);list_del_init (&entity->list);drm_sched_rq_remove_tree_locked (entity, rq);
@@ -160,17 +161,16 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)* drm_sched_rq_select_entity - Select an entity which provides a job to run * * @sched: the gpu scheduler -* @rq: scheduler run queue to check. * * Find oldest waiting ready entity. * * Return an entity if one is found or NULL if no ready entity was found. */ struct drm_sched_entity * -drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched, -struct drm_sched_rq *rq) +drm_sched_rq_select_entity (struct drm_gpu_scheduler *sched) {struct drm_sched_entity *entity =NULL ; +struct drm_sched_rq *rq = &sched->rq;struct rb_node *rb;spin_lock (&rq->lock);
include/drm/gpu_scheduler.h +1 -4
@@ -238,7 +238,6 @@ struct drm_sched_entity {/** * struct drm_sched_rq - queue of entities to be scheduled. * -* @sched: the scheduler to which this rq belongs to. * @lock: protects @entities, @rb_tree_root and @rr_deadline. * @entities: list of the entities to be scheduled. * @rb_tree_root: root of time based priority queue of entities for FIFO scheduling
@@ -248,8 +247,6 @@ struct drm_sched_entity {* the next entity to emit commands from. */ struct drm_sched_rq { -struct drm_gpu_scheduler *sched; -spinlock_t lock;/* Following members are protected by the @lock: */ ktime_t rr_deadline;
@@ -550,7 +547,7 @@ struct drm_gpu_scheduler {atomic_t credit_count;long timeout;const char *name; -struct drm_sched_rq *rq; +struct drm_sched_rq rq;wait_queue_head_t job_scheduled;atomic64_t job_id_count;struct workqueue_struct *submit_wq;
Signature · 1 line
2.48.0
RFC v3 13/14 drm/sched: De-clutter drm_sched_init
In reply to Tvrtko UrsulinMove work queue allocation into a helper for a more streamlined function body.
--- drivers/gpu/drm/scheduler/sched_main.c | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +14 -14
@@ -83,12 +83,6 @@#define CREATE_TRACE_POINTS #include "gpu_scheduler_trace.h" -#ifdef CONFIG_LOCKDEP -static struct lockdep_map drm_sched_lockdep_map = { - .name ="drm_sched_lockdep_map" -}; -#endif -static u32 drm_sched_available_credits (struct drm_gpu_scheduler *sched) {u32 credits;
@@ -984,6 +978,19 @@ static void drm_sched_run_job_work(struct work_struct *w)wake_up (&sched->job_scheduled); } +static struct workqueue_struct *drm_sched_alloc_wq (const char *name) +{ +#if (IS_ENABLED (CONFIG_LOCKDEP )) +static struct lockdep_map map = { + .name ="drm_sched_lockdep_map" + }; + +return alloc_ordered_workqueue_lockdep_map (name,WQ_MEM_RECLAIM , &map); +#else +return alloc_ordered_workqueue (name,WQ_MEM_RECLAIM ); +#endif +} +/** * drm_sched_init - Init a gpu scheduler instance *
@@ -1007,16 +1014,9 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_ sched->submit_wq = args->submit_wq; sched->own_submit_wq = false; }else { -#ifdef CONFIG_LOCKDEP - sched->submit_wq =alloc_ordered_workqueue_lockdep_map (args->name, -WQ_MEM_RECLAIM , - &drm_sched_lockdep_map); -#else - sched->submit_wq =alloc_ordered_workqueue (args->name,WQ_MEM_RECLAIM ); -#endif + sched->submit_wq =drm_sched_alloc_wq (args->name);if (!sched->submit_wq)return -ENOMEM ; - sched->own_submit_wq = true; }
Signature · 1 line
2.48.0
RFC v3 14/14 drm/sched: Scale deadlines depending on queue depth
In reply to Tvrtko UrsulinSo far deadline based scheduling was able to remove the need for separate run queues (per priority) and alleviate the starvation issues hampering FIFO when somewhat reasonable clients are concerned.
Because the deadline implementation is however still based on the submission time as its baseline criteria, since the current DRM scheduler design makes it difficult to perhaps consider job (or entity) "runnable" timestamp as an alternative, it shares the same weakness as FIFO with clients which rapidly submit deep job queues. In those cases deadline scheduler will be similarly unfair as FIFO is.
One simple approach to somewhat alleviate that and apply some fairness is to scale the relative deadlines by client queue depth.
Apart from queue depth scaling is based on client priority, where kernel submissions are aggresively pulled in, while userspace priority levels are pushed out proportionately to the decrease in priority.
--- drivers/gpu/drm/scheduler/sched_entity.c | 39 ++++++++++++---------- drivers/gpu/drm/scheduler/sched_internal.h | 4 --- drivers/gpu/drm/scheduler/sched_rq.c | 4 +-- include/drm/gpu_scheduler.h | 6 ++-- 4 files changed, 25 insertions(+), 28 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +21 -18
@@ -387,21 +387,25 @@ static ktime_t __drm_sched_entity_get_job_deadline(struct drm_sched_entity *entity, ktime_t submit_ts) { -static const unsigned int d_us[] = { - [DRM_SCHED_PRIORITY_KERNEL ] =100 , - [DRM_SCHED_PRIORITY_HIGH ] =1000 , - [DRM_SCHED_PRIORITY_NORMAL ] =5000 , - [DRM_SCHED_PRIORITY_LOW ] =100000 , +static const long d_us[] = { + [DRM_SCHED_PRIORITY_KERNEL ] =-1000 , + [DRM_SCHED_PRIORITY_HIGH ] =1000 , + [DRM_SCHED_PRIORITY_NORMAL ] =2500 , + [DRM_SCHED_PRIORITY_LOW ] =10000 , }; +static const unsigned int shift[] = { + [DRM_SCHED_PRIORITY_KERNEL ] =4 , + [DRM_SCHED_PRIORITY_HIGH ] =0 , + [DRM_SCHED_PRIORITY_NORMAL ] =1 , + [DRM_SCHED_PRIORITY_LOW ] =2 , + }; +const unsigned int prio = entity->priority; +long d; -return ktime_add_us (submit_ts, d_us[entity->priority]); -} + d = d_us[prio] * + ((spsc_queue_count (&entity->job_queue) +1 ) << shift[prio]); -ktime_t -drm_sched_entity_get_job_deadline (struct drm_sched_entity *entity, -struct drm_sched_job *job) -{ -return __drm_sched_entity_get_job_deadline (entity, job->submit_ts); +return ktime_add_us (submit_ts, d); }/*
@@ -575,7 +579,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)struct drm_sched_entity *entity = sched_job->entity;struct drm_gpu_scheduler *sched =container_of (entity->rq,typeof (*sched), rq); -ktime_t submit_ts; +ktime_t deadline_ts;bool first;trace_drm_sched_job (sched_job, entity);
@@ -585,16 +589,15 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)/* * After the sched_job is pushed into the entity queue, it may be * completed and freed up at any time. We can no longer access it. -* Make sure to set the submit_ts first, to avoid a race. +* Make sure to set the deadline_ts first, to avoid a race. */ - sched_job->submit_ts = submit_ts =ktime_get (); + sched_job->deadline_ts = deadline_ts = +__drm_sched_entity_get_job_deadline (entity,ktime_get ()); first =spsc_queue_push (&entity->job_queue, &sched_job->queue_node);/* first job wakes up scheduler */ if (first) { - submit_ts =__drm_sched_entity_get_job_deadline (entity, - submit_ts); - sched =drm_sched_rq_add_entity (entity, submit_ts); + sched =drm_sched_rq_add_entity (entity, deadline_ts);if (sched)drm_sched_wakeup (sched); }
drivers/gpu/drm/scheduler/sched_internal.h +0 -4
@@ -28,10 +28,6 @@ void drm_sched_fence_scheduled(struct drm_sched_fence *fence, struct dma_fence *parent);void drm_sched_fence_finished (struct drm_sched_fence *fence,int result); - -ktime_t drm_sched_entity_get_job_deadline (struct drm_sched_entity *entity, -struct drm_sched_job *job); -/** * drm_sched_entity_queue_pop - Low level helper for popping queued jobs *
drivers/gpu/drm/scheduler/sched_rq.c +1 -3
@@ -138,7 +138,6 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity) {struct drm_sched_job *next_job;struct drm_sched_rq *rq; -ktime_t ts;/* * Update the entity's location in the min heap according to
@@ -148,11 +147,10 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity)if (!next_job)return ; - ts =drm_sched_entity_get_job_deadline (entity, next_job);spin_lock (&entity->lock); rq = entity->rq;spin_lock (&rq->lock); -drm_sched_rq_update_tree_locked (entity, rq, ts); +drm_sched_rq_update_tree_locked (entity, rq, next_job->deadline_ts);spin_unlock (&rq->lock);spin_unlock (&entity->lock); }
include/drm/gpu_scheduler.h +3 -3
@@ -331,11 +331,11 @@ struct drm_sched_job {u64 id;/** -* @submit_ts: +* @deadline_ts: * -* When the job was pushed into the entity queue. +* Job deadline set at push time. */ -ktime_t submit_ts; +ktime_t deadline_ts;/** * @sched:
Signature · 1 line
2.48.0
Christian König
maintainerAdding Leo since that is especially interesting for our multimedia engines.
@Leo could you spare someone to test and maybe review this?
Am 31.03.25 um 22:16 schrieb Tvrtko Ursulin:
Quoted 19 lines
This is similar to v2 but I dropped some patches (for now) and added some new ones. Most notably deadline scaling based on queue depth appears to be able to add a little bit of fairness with spammy clients (deep submission queue).
As such, on the high level main advantages of the series:
1. Code simplification - no more multiple run queues.
2. Scheduling quality - schedules better than FIFO.
3. No more RR is even more code simplification but this one needs to be tested and approved by someone who actually uses RR.In the future futher simplifactions and improvements should be possible on top of this work. But for now I keep it simple.
First patch adds some unit tests which allow for easy evaluation of scheduling behaviour against different client submission patterns. From there onwards it is a hopefully natural progression of patches (or close) to the end result which is a slightly more fair scheduler than FIFO.
Quoted 6 lines
Regarding the submission patterns tested, it is always two parallel clients and they broadly cover these categories:
* Deep queue clients
* Hogs versus interactive
* Priority handling
First of all, impressive piece of work.
Quoted 5 lines
Lets look at the results:
1. Two normal priority deep queue clients.
Quoted 8 lines
These ones submit one second worth of 8ms jobs. As fast as they can, no dependencies etc. There is no difference in runtime between FIFO and qddl but the latter allows both clients to progress with work more evenly:
https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers separately.)
This was basically the killer argument why we implemented FIFO in the first place. RR completely sucked on fairness when you have many clients submitting many small jobs.
Looks like that the deadline scheduler is even better than FIFO in that regard, but I would also add a test with (for example) 100 clients doing submissions at the same time.
Quoted 29 lines
2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO completely starves the low priority client until the normal priority is fully done. Only then the low priority client gets any GPU time.
In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de-prioritised relative to high, than low was against normal.
https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a 2.5ms wait.
Interactive client emites a 10% GPU load in the format of 1x 1ms job followed by a 9ms wait.
This simulates an interactive graphical client used on top of a relatively heavy background load but no GPU oversubscription.
Quoted 7 lines
Graphs show the interactive client only and from now on, instead of looking at the client's queue depth, we look at its "fps".
https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client which is good.
The most interesting question for this is what is the maximum frame time?
E.g. how long needs the user to wait for a response from the interactive client at maximum?
Thanks,
Christian.
Quoted 101 lines
5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients with a 50% "duty cycle" GPU time usage.
Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a little bit more which should be good for interactivity.
b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.pngAgain, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness, especially avoiding priority starvation. There do not appear to be any regressions with the tested workloads.
As before, I am looking for feedback, ideas for what kind of submission scenarios to test. Testers on different GPUs would be very welcome too.
And I should probably test round-robin at some point, to see if we are maybe okay to drop unconditionally, it or further work improving qddl would be needed.
v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>Tvrtko Ursulin (14):
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidatedrm_sched_job_timedout
drm/sched: Clarify locked section indrm_sched_rq_select_entity_fifodrm/sched: Consolidatedrm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init
drm/sched: Scale deadlines depending on queue depthdrivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++-------------- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +- 15 files changed, 962 insertions(+), 579 deletions(-) create mode 100644 drivers/gpu/drm/scheduler/sched_rq.c create mode 100644 drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Quoted 24 lines · Christian König
Adding Leo since that is especially interesting for our multimedia engines.
@Leo could you spare someone to test and maybe review this?
Am 31.03.25 um 22:16 schrieb Tvrtko Ursulin:
Quoted 19 lines
This is similar to v2 but I dropped some patches (for now) and added some new ones. Most notably deadline scaling based on queue depth appears to be able to add a little bit of fairness with spammy clients (deep submission queue).
As such, on the high level main advantages of the series:
1. Code simplification - no more multiple run queues.
2. Scheduling quality - schedules better than FIFO.
3. No more RR is even more code simplification but this one needs to be tested and approved by someone who actually uses RR.In the future futher simplifactions and improvements should be possible on top of this work. But for now I keep it simple.
First patch adds some unit tests which allow for easy evaluation of scheduling behaviour against different client submission patterns. From there onwards it is a hopefully natural progression of patches (or close) to the end result which is a slightly more fair scheduler than FIFO.
Quoted 8 lines
Quoted 6 lines
Regarding the submission patterns tested, it is always two parallel clients and they broadly cover these categories:
* Deep queue clients
* Hogs versus interactive
* Priority handlingFirst of all, impressive piece of work.
Thank you!
I am not super happy though, since what would be much better is some sort of a CFS. But to do that would require to crack the entity GPU time tracking problem. That I tried two times so far and failed to find a generic, elegant and not too intrusive solution.
Quoted 8 lines
Quoted 8 lines
Lets look at the results:
1. Two normal priority deep queue clients.
These ones submit one second worth of 8ms jobs. As fast as they can, no dependencies etc. There is no difference in runtime between FIFO and qddl but the latter allows both clients to progress with work more evenly:
Quoted 8 lines
Quoted 4 lines
https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers separately.)This was basically the killer argument why we implemented FIFO in the first place. RR completely sucked on fairness when you have many clients submitting many small jobs.
Looks like that the deadline scheduler is even better than FIFO in that regard, but I would also add a test with (for example) 100 clients doing submissions at the same time.
I can try that. So 100 clients with very deep submission queues? How deep? Fully async? Or some synchronicity and what kind?
Quoted 31 lines
Quoted 31 lines
2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO completely starves the low priority client until the normal priority is fully done. Only then the low priority client gets any GPU time.
In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de-prioritised relative to high, than low was against normal.
https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a 2.5ms wait.
Interactive client emites a 10% GPU load in the format of 1x 1ms job followed by a 9ms wait.
This simulates an interactive graphical client used on top of a relatively heavy background load but no GPU oversubscription.
Graphs show the interactive client only and from now on, instead of looking at the client's queue depth, we look at its "fps".
Quoted 8 lines
Quoted 4 lines
https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client which is good.
The most interesting question for this is what is the maximum frame time?
E.g. how long needs the user to wait for a response from the interactive client at maximum?
I did a quick measure of those metrics, for this workload only.
Measured time from submit of the first job in the group (so frame), to time last job in a group finished, and then subtracted the expected jobs duration to get just the wait plus overheads latency.
Five averaged runs:
min avg max [ms]
FIFO 2.5 13.14 18.3
qddl 3.2 9.9 16.6
So it is a bit better in max, more so in max latencies. Question is how representative is this synthetic workload of the real world.
Regards,
Tvrtko
Quoted 102 lines
Quoted 101 lines
5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients with a 50% "duty cycle" GPU time usage.
Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a little bit more which should be good for interactivity.
b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.pngAgain, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness, especially avoiding priority starvation. There do not appear to be any regressions with the tested workloads.
As before, I am looking for feedback, ideas for what kind of submission scenarios to test. Testers on different GPUs would be very welcome too.
And I should probably test round-robin at some point, to see if we are maybe okay to drop unconditionally, it or further work improving qddl would be needed.
v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>Tvrtko Ursulin (14):
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidatedrm_sched_job_timedout
drm/sched: Clarify locked section indrm_sched_rq_select_entity_fifodrm/sched: Consolidatedrm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init
drm/sched: Scale deadlines depending on queue depthdrivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++-------------- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +- 15 files changed, 962 insertions(+), 579 deletions(-)create mode 100644
drivers/gpu/drm/scheduler/sched_rq.ccreate mode 100644drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Christian König
maintainerAm 02.04.25 um 10:26 schrieb Tvrtko Ursulin:
Quoted 7 lines · Christian König
Quoted 2 lines
First of all, impressive piece of work.
Thank you!
I am not super happy though, since what would be much better is some sort of a CFS. But to do that would require to crack the entity GPU time tracking problem. That I tried two times so far and failed to find a generic, elegant and not too intrusive solution.
When the numbers you posted hold true I think this solution here is perfectly sufficient. Keep in mind that GPU submission scheduling is a bit more complicated then classic I/O scheduling.
E.g. you have no idea how much work a GPU submission was until it is completed, for an other I/O transfer you know pre-hand how many bytes are transferred. That makes tracking things far more complicated.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Lets look at the results:
1. Two normal priority deep queue clients.
These ones submit one second worth of 8ms jobs. As fast as they can, no dependencies etc. There is no difference in runtime between FIFO and qddl but the latter allows both clients to progress with work more evenly:
https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds with work progress for both clients, tested with both schedulers separately.)
This was basically the killer argument why we implemented FIFO in the first place. RR completely sucked on fairness when you have many clients submitting many small jobs.
Looks like that the deadline scheduler is even better than FIFO in that regard, but I would also add a test with (for example) 100 clients doing submissions at the same time.
I can try that. So 100 clients with very deep submission queues? How deep? Fully async? Or some synchronicity and what kind?
Not deep queues, more like 4-8 jobs maximum for each. Send all submissions roughly at the same time and with the same priority.
When you have 100 entities each submission from each entity should have ~99 other submissions in between them.
Record the minimum and maximum of that value and you should have a good indicator how well the algorithm performs.
You can then of course start to make it more complicated, e.g. 50 entities who have 8 submissions, each taking 4ms and 50 other entities who have 4 submissions, each taking 8ms.
Quoted 45 lines
Quoted 32 lines
Quoted 32 lines
2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO completely starves the low priority client until the normal priority is fully done. Only then the low priority client gets any GPU time.
In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de-prioritised relative to high, than low was against normal.
https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a 2.5ms wait.
Interactive client emites a 10% GPU load in the format of 1x 1ms job followed by a 9ms wait.
This simulates an interactive graphical client used on top of a relatively heavy background load but no GPU oversubscription.
Graphs show the interactive client only and from now on, instead of looking at the client's queue depth, we look at its "fps".
Quoted 8 lines
Quoted 4 lines
https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client which is good.
The most interesting question for this is what is the maximum frame time?
E.g. how long needs the user to wait for a response from the interactive client at maximum?
I did a quick measure of those metrics, for this workload only.
Measured time from submit of the first job in the group (so frame), to time last job in a group finished, and then subtracted the expected jobs duration to get just the wait plus overheads latency.
Quoted 7 lines
Five averaged runs:
min avg max [ms]
FIFO 2.5 13.14 18.3
qddl 3.2 9.9 16.6So it is a bit better in max, more so in max latencies. Question is how representative is this synthetic workload of the real world.
Well if I'm not completely mistaken that is 9,2% better on max and nearly 24,6% better on average, the min time is negligible as far as I can see.
That is more than a bit better. Keep in mind that we usually deal with interactive GUIs and background worker use cases which benefits a lot of that stuff.
Regards,
Christian.
Quoted 108 lines
Regards,
Tvrtko
Quoted 102 lines
Quoted 101 lines
5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients with a 50% "duty cycle" GPU time usage.
Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a little bit more which should be good for interactivity.
b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.pngAgain, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness, especially avoiding priority starvation. There do not appear to be any regressions with the tested workloads.
As before, I am looking for feedback, ideas for what kind of submission scenarios to test. Testers on different GPUs would be very welcome too.
And I should probably test round-robin at some point, to see if we are maybe okay to drop unconditionally, it or further work improving qddl would be needed.
v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>Tvrtko Ursulin (14):
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidatedrm_sched_job_timedout
drm/sched: Clarify locked section indrm_sched_rq_select_entity_fifodrm/sched: Consolidatedrm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init
drm/sched: Scale deadlines depending on queue depthdrivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++-------------- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +-
.../gpu/drm/scheduler/tests/tests_scheduler.c| 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +-15 files changed, 962 insertions(+), 579 deletions(-)create mode 100644
drivers/gpu/drm/scheduler/sched_rq.ccreate mode 100644drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Quoted 33 lines · Christian König
Am 02.04.25 um 10:26 schrieb Tvrtko Ursulin:
Quoted 7 lines · Christian König
Quoted 2 lines
First of all, impressive piece of work.
Thank you!
I am not super happy though, since what would be much better is some sort of a CFS. But to do that would require to crack the entity GPU time tracking problem. That I tried two times so far and failed to find a generic, elegant and not too intrusive solution.
When the numbers you posted hold true I think this solution here is perfectly sufficient. Keep in mind that GPU submission scheduling is a bit more complicated then classic I/O scheduling.
E.g. you have no idea how much work a GPU submission was until it is completed, for an other I/O transfer you know pre-hand how many bytes are transferred. That makes tracking things far more complicated.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Lets look at the results:
1. Two normal priority deep queue clients.
These ones submit one second worth of 8ms jobs. As fast as they can, no dependencies etc. There is no difference in runtime between FIFO and qddl but the latter allows both clients to progress with work more evenly:
https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers separately.)This was basically the killer argument why we implemented FIFO in the first place. RR completely sucked on fairness when you have many clients submitting many small jobs.
Looks like that the deadline scheduler is even better than FIFO in that regard, but I would also add a test with (for example) 100 clients doing submissions at the same time.
I can try that. So 100 clients with very deep submission queues? How deep? Fully async? Or some synchronicity and what kind?
Quoted 7 lines
Not deep queues, more like 4-8 jobs maximum for each. Send all submissions roughly at the same time and with the same priority.
When you have 100 entities each submission from each entity should have ~99 other submissions in between them.
Record the minimum and maximum of that value and you should have a good indicator how well the algorithm performs.
You can then of course start to make it more complicated, e.g. 50 entities who have 8 submissions, each taking 4ms and 50 other entities who have 4 submissions, each taking 8ms.
I started working on this "many clients test" and so far did not find a definitive pattern to show a significant difference between different schedulers.
Quoted 50 lines
Quoted 50 lines
Quoted 31 lines
Quoted 31 lines
2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO completely starves the low priority client until the normal priority is fully done. Only then the low priority client gets any GPU time.
In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de-prioritised relative to high, than low was against normal.
https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a 2.5ms wait.
Interactive client emites a 10% GPU load in the format of 1x 1ms job followed by a 9ms wait.
This simulates an interactive graphical client used on top of a relatively heavy background load but no GPU oversubscription.
Graphs show the interactive client only and from now on, instead of looking at the client's queue depth, we look at its "fps".
Quoted 8 lines
Quoted 4 lines
https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client which is good.
The most interesting question for this is what is the maximum frame time?
E.g. how long needs the user to wait for a response from the interactive client at maximum?
I did a quick measure of those metrics, for this workload only.
Measured time from submit of the first job in the group (so frame), to time last job in a group finished, and then subtracted the expected jobs duration to get just the wait plus overheads latency.
Five averaged runs:
min avg max [ms]
FIFO 2.5 13.14 18.3
qddl 3.2 9.9 16.6
Quoted 5 lines
Quoted 1 line
So it is a bit better in max, more so in max latencies. Question is how representative is this synthetic workload of the real world.
Well if I'm not completely mistaken that is 9,2% better on max and nearly 24,6% better on average, the min time is negligible as far as I can see.
That is more than a bit better. Keep in mind that we usually deal with interactive GUIs and background worker use cases which benefits a lot of that stuff.
The improvement on that one and some other ones is nice indeed. I still haven't found a regressing workload myself but Pierre-Eric has something involving viewperf. We tried to simulate that via unit test but so far did not get it to behave as bad with qddl as the real thing.
I am parking this work for a week or so now but will come back to it.
If in the meantime people want to experiment, my latest code is here:
https://gitlab.freedesktop.org/tursulin/kernel/-/commits/drm-sched-deadline?ref_type=heads
There is also a CFS like very early experiment at:
https://gitlab.freedesktop.org/tursulin/kernel/-/commits/drm-sched-cfs?ref_type=heads
If that one works out it could perhaps be even better but it is far from finished.
Regards,
Tvrtko
Quoted 104 lines
Quoted 103 lines
Quoted 102 lines
Quoted 101 lines
5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients with a 50% "duty cycle" GPU time usage.
Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a little bit more which should be good for interactivity.
b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.pngAgain, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness, especially avoiding priority starvation. There do not appear to be any regressions with the tested workloads.
As before, I am looking for feedback, ideas for what kind of submission scenarios to test. Testers on different GPUs would be very welcome too.
And I should probably test round-robin at some point, to see if we are maybe okay to drop unconditionally, it or further work improving qddl would be needed.
v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>Tvrtko Ursulin (14):
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidatedrm_sched_job_timedout
drm/sched: Clarify locked section indrm_sched_rq_select_entity_fifodrm/sched: Consolidatedrm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init
drm/sched: Scale deadlines depending on queue depthdrivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +- drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++-------------- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +- 15 files changed, 962 insertions(+), 579 deletions(-)create mode 100644
drivers/gpu/drm/scheduler/sched_rq.ccreate mode 100644drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Alright alright, uff, so this will be a lot to discuss…
(btw. my chaotic email filters had me search the cover-letter for a while, which seems to have gone to my RH addr, with the others going to kernel.org – I need a better mail client)
Quoted 39 lines · Tvrtko Ursulin
This is similar to v2 but I dropped some patches (for now) and added some new
ones. Most notably deadline scaling based on queue depth appears to be able to
add a little bit of fairness with spammy clients (deep submission queue).As such, on the high level main advantages of the series:
1. Code simplification - no more multiple run queues.
2. Scheduling quality - schedules better than FIFO.
3. No more RR is even more code simplification but this one needs to be tested
and approved by someone who actually uses RR.In the future futher simplifactions and improvements should be possible on top
of this work. But for now I keep it simple.First patch adds some unit tests which allow for easy evaluation of scheduling
behaviour against different client submission patterns. From there onwards it is
a hopefully natural progression of patches (or close) to the end result which is
a slightly more fair scheduler than FIFO.Regarding the submission patterns tested, it is always two parallel clients
and they broadly cover these categories:* Deep queue clients
* Hogs versus interactive
* Priority handlingLets look at the results:
1. Two normal priority deep queue clients.
Quoted 7 lines
These ones submit one second worth of 8ms jobs. As fast as they can, no
dependencies etc. There is no difference in runtime between FIFO and qddl but
the latter allows both clients to progress with work more evenly:https://people.igalia.com/tursulin/drm-sched-qddl/normal-normal.png
I read qd surprisingly long as dp and was confused :)
And the title reads "Normal vs Normal"
Quoted 89 lines
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers separately.)2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO
completely starves the low priority client until the normal priority is fully
done. Only then the low priority client gets any GPU time.In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de- prioritised
relative to high, than low was against normal.https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a
2.5ms wait.Interactive client emites a 10% GPU load in the format of 1x 1ms job followed
by a 9ms wait.This simulates an interactive graphical client used on top of a relatively heavy
background load but no GPU oversubscription.Graphs show the interactive client only and from now on, instead of looking at
the client's queue depth, we look at its "fps".https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client
which is good.5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients
with a 50% "duty cycle" GPU time usage.Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a
little bit more which should be good for interactivity.b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.png
Quoted 7 lines
Again, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness,
especially avoiding priority starvation. There do not appear to be any
regressions with the tested workloads.
OK, so the above seems to be the measurements serving as a justification for the major rework.
I suppose this was tested on a workstation with AMD card?
Quoted 21 lines
As before, I am looking for feedback, ideas for what kind of submission
scenarios to test. Testers on different GPUs would be very welcome too.And I should probably test round-robin at some point, to see if we are maybe
okay to drop unconditionally, it or further work improving qddl would be needed.v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.
Quoted 8 lines
Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>Tvrtko Ursulin (14):
There appear to be, again, some candidates which should be branched out since they're independent from the scheduling policy. Suspicious ones are:
Quoted 3 lines
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidate
drm_sched_job_timedout
this one
Quoted 2 lines
drm/sched: Clarify locked section in
drm_sched_rq_select_entity_fifo
^
Quoted 9 lines
drm/sched: Consolidate
drm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init
^
Quoted 8 lines
drm/sched: Scale deadlines depending on queue depth
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +-
Alright, so here we have our lovely AMD cards :)
Here's a thing:
Back in the day, we did a seemingly harmless change of the scheduler's default scheduling policy, from RR to FIFO. From all the arguments I have seen in the git log and the archives, this was one of the typical changes where the developer is tempted to think "This *cannot* break anything, it makes everything _better_ and has only advantages". But it turned out that it did break things and resulted in lengthy and interesting discussions here:
https://gitlab.freedesktop.org/drm/amd/-/issues/2516
Now, from time to time it is worth breaking things for progress. So the possibility that things *could* break even with the best improvements is not really an argument.
It becomes an argument, however, when we consider the following:
AMD cards are the major profiteer of this change, generating X percent of performance and fairness gain.
Reason being that AMD seems to be the most important party that has hardware scheduling. For Nouveau and Xe, that deadline policy won't do anything.
And, if I understood correctly, new AMD generations will move to firmware schedeuling, too.
So that raises the question: is it worth it?
If I am not mistaken, the firmware scheduler stakeholders largely shouldn't feel an impact when drm_sched changes its scheduling behavior, since the firmware does what it wants anyways.
But there are some other drivers that use hardware scheduling, and this (and remaining bad feelings in the guts about firmware schedulers) makes me nervous about touching the global scheduling behavior.
It appears to me that if AMD cards are the major profiteer, and it is deemed that the performance gain is really worth it for the older and current generations, then we should at least explore / consider paths toward changing scheduling behavior for AMD only.
But, as you, I am also interested in hearing from the other drivers. And correct me on any wrong assumptions above.
P.
Quoted 15 lines
drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++------------ --
drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +-.../gpu/drm/scheduler/tests/tests_scheduler.c| 548
+++++++++++++++++
include/drm/gpu_scheduler.h | 17 +-15 files changed, 962 insertions(+), 579 deletions(-)create mode 100644
drivers/gpu/drm/scheduler/sched_rq.ccreate mode 100644drivers/gpu/drm/scheduler/tests/tests_scheduler.c
Quoted 5 lines · Philipp Stanner
Alright alright, uff, so this will be a lot to discuss…
(btw. my chaotic email filters had me search the cover-letter for a while, which seems to have gone to my RH addr, with the others going to kernel.org – I need a better mail client)
My bad.
Quoted 46 lines · Tvrtko Ursulin
Quoted 45 lines
This is similar to v2 but I dropped some patches (for now) and added some new
ones. Most notably deadline scaling based on queue depth appears to be able to
add a little bit of fairness with spammy clients (deep submission queue).As such, on the high level main advantages of the series:
1. Code simplification - no more multiple run queues.
2. Scheduling quality - schedules better than FIFO.
3. No more RR is even more code simplification but this one needs to
be tested
and approved by someone who actually uses RR.In the future futher simplifactions and improvements should be possible on top
of this work. But for now I keep it simple.First patch adds some unit tests which allow for easy evaluation of scheduling
behaviour against different client submission patterns. From there onwards it is
a hopefully natural progression of patches (or close) to the end result which is
a slightly more fair scheduler than FIFO.Regarding the submission patterns tested, it is always two parallel clients
and they broadly cover these categories:* Deep queue clients
* Hogs versus interactive
* Priority handlingLets look at the results:
1. Two normal priority deep queue clients.
These ones submit one second worth of 8ms jobs. As fast as they can, no
dependencies etc. There is no difference in runtime between FIFO and qddl but
the latter allows both clients to progress with work more evenly:
Quoted 5 lines
I read qd surprisingly long as dp and was confused :)
And the title reads "Normal vs Normal"
Yes, two identical DRM_SCHED_PRIORITY_NORMAL clients.
Quoted 96 lines
Quoted 88 lines
(X axis is time, Y is submitted queue-depth, hence lowering of qd corresponds
with work progress for both clients, tested with both schedulers
separately.)2. Same two clients but one is now low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/normal-low.png
Normal priority client is a solid line, low priority dotted. We can see how FIFO
completely starves the low priority client until the normal priority is fully
done. Only then the low priority client gets any GPU time.In constrast, qddl allows some GPU time to the low priority client.
3. Same clients but now high versus normal priority.
Similar behaviour as in the previous one with normal a bit less de- prioritised
relative to high, than low was against normal.https://people.igalia.com/tursulin/drm-sched-qddl/high-normal.png
4. Heavy load vs interactive client.
Heavy client emits a 75% GPU load in the format of 3x 2.5ms jobs followed by a
2.5ms wait.Interactive client emites a 10% GPU load in the format of 1x 1ms job followed
by a 9ms wait.This simulates an interactive graphical client used on top of a relatively heavy
background load but no GPU oversubscription.Graphs show the interactive client only and from now on, instead of looking at
the client's queue depth, we look at its "fps".https://people.igalia.com/tursulin/drm-sched-qddl/heavy-interactive.png
We can see that qddl allows a slighty higher fps for the interactive client
which is good.5. Low priority GPU hog versus heavy-interactive.
Low priority client: 3x 2.5ms jobs client followed by a 0.5ms wait. Interactive client: 1x 0.5ms job followed by a 10ms wait.
https://people.igalia.com/tursulin/drm-sched-qddl/lowhog-interactive.png
No difference between the schedulers.
6. Last set of test scenarios will have three subgroups.
In all cases we have two interactive (synchronous, single job at a time) clients
with a 50% "duty cycle" GPU time usage.Client 1: 1.5ms job + 1.5ms wait (aka short bursty) Client 2: 2.5ms job + 2.5ms wait (aka long bursty)
a) Both normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-short.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-long.pngBoth schedulers favour the higher frequency duty cycle with qddl giving it a
little bit more which should be good for interactivity.b) Normal vs low priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-normal.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-normal-low-low.pngQddl gives a bit more to the normal than low.
c) High vs normal priority.
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-high.png
https://people.igalia.com/tursulin/drm-sched-qddl/5050-high-normal-normal.pngQuoted 7 lines
Again, qddl gives a bit more share to the higher priority client.
On the overall qddl looks like a potential improvement in terms of fairness,
especially avoiding priority starvation. There do not appear to be any
regressions with the tested workloads.
Quoted 4 lines
OK, so the above seems to be the measurements serving as a justification for the major rework.
I suppose this was tested on a workstation with AMD card?
No, using the mock scheduler unit tests. ;)
Quoted 27 lines
Quoted 27 lines
As before, I am looking for feedback, ideas for what kind of submission
scenarios to test. Testers on different GPUs would be very welcome too.And I should probably test round-robin at some point, to see if we are maybe
okay to drop unconditionally, it or further work improving qddl would be needed.v2:
* Fixed many rebase errors.
* Added some new patches.
* Dropped single shot dependecy handling.v3:
* Added scheduling quality unit tests.
* Refined a tiny bit by adding some fairness.
* Dropped a few patches for now.Cc Christian König <[email protected]>Cc Danilo Krummrich <[email protected]>Cc Matthew Brost <[email protected]>Cc Philipp Stanner <[email protected]>Cc Pierre-Eric Pelloux-Prayer <[email protected]>Cc Michel Dänzer <[email protected]>
Quoted 9 lines
Quoted 1 line
Tvrtko Ursulin (14):
There appear to be, again, some candidates which should be branched out since they're independent from the scheduling policy. Suspicious ones are:
Quoted 3 lines
drm/sched: Add some scheduling quality unit tests drm/sched: Avoid double re-lock on the job free path drm/sched: Consolidate
drm_sched_job_timedout
Tests are WIP but the other two are indeed independent.
Quoted 6 lines
this one
Quoted 2 lines
drm/sched: Clarify locked section in
drm_sched_rq_select_entity_fifo^
This one I retracted, its wrong.
Quoted 11 lines
Quoted 9 lines
drm/sched: Consolidate
drm_sched_rq_select_entity_rrdrm/sched: Implement RR via FIFO
drm/sched: Consolidate entity run queue management drm/sched: Move run queue related code into a separate file drm/sched: Add deadline policy
drm/sched: Remove FIFO and RR and simplify to a single run queue drm/sched: Queue all free credits in one worker invocation drm/sched: Embed run queue singleton into the scheduler drm/sched: De-clutterdrm_sched_init^
Yep. I will pull in this one at some point.
Quoted 10 lines
Quoted 8 lines
drm/sched: Scale deadlines depending on queue depth
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 27 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_trace.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 8 +-Alright, so here we have our lovely AMD cards :)
Those diffs are just a consequence of "drm/sched: Embed run queue singleton into the scheduler" since deadline does not need per priority run queues is is code simplification.
Quoted 37 lines
Here's a thing:
Back in the day, we did a seemingly harmless change of the scheduler's default scheduling policy, from RR to FIFO. From all the arguments I have seen in the git log and the archives, this was one of the typical changes where the developer is tempted to think "This *cannot* break anything, it makes everything _better_ and has only advantages". But it turned out that it did break things and resulted in lengthy and interesting discussions here:
https://gitlab.freedesktop.org/drm/amd/-/issues/2516
Now, from time to time it is worth breaking things for progress. So the possibility that things *could* break even with the best improvements is not really an argument.
It becomes an argument, however, when we consider the following:
AMD cards are the major profiteer of this change, generating X percent of performance and fairness gain.Reason being that AMD seems to be the most important party that has hardware scheduling. For Nouveau and Xe, that deadline policy won't do anything.
And, if I understood correctly, new AMD generations will move to firmware schedeuling, too.
So that raises the question: is it worth it?
If I am not mistaken, the firmware scheduler stakeholders largely shouldn't feel an impact when
drm_schedchanges its scheduling behavior, since the firmware does what it wants anyways.But there are some other drivers that use hardware scheduling, and this (and remaining bad feelings in the guts about firmware schedulers) makes me nervous about touching the global scheduling behavior.
Quoted 7 lines
It appears to me that if AMD cards are the major profiteer, and it is deemed that the performance gain is really worth it for the older and current generations, then we should at least explore / consider paths toward changing scheduling behavior for AMD only.
But, as you, I am also interested in hearing from the other drivers. And correct me on any wrong assumptions above.
You are correct that there is no benefit in the scheduling algorithm for drivers with 1:1 entity to scheduler.
But it is not just about AMD. There are other drivers which are not 1:1, like simple GPUs which process one job at a time. They would benefit if we come up with scheduling improvements.
Then there is a secondary benefit that the code is simplified. If you look at the series diffstat and subtract the unit tests you will see the code on the overall shrinks. Partly due RR removal, and partly due removal of per priority run queues.
I would say it could conditionally be worth it. Conditional on building confidence that there are no regressing workloads. As I say in the cover letter I am looking for ideas, suggestions, testing.
So far my synthetic workloads did not find a weakness relative to FIFO. But Pierre-Eric apparently did find a regression with viewperf+glxgears. I am trying to model that in the unit tests.
Also, both him and I experiment with CFS like scheduler in parallel to this. That would be even better but it is not easy to do in a nice way.
Regards,
Tvrtko
Quoted 16 lines
Quoted 15 lines
drivers/gpu/drm/scheduler/Makefile | 2 +- drivers/gpu/drm/scheduler/sched_entity.c | 121 ++-- drivers/gpu/drm/scheduler/sched_fence.c | 2 +- drivers/gpu/drm/scheduler/sched_internal.h | 17 +- drivers/gpu/drm/scheduler/sched_main.c | 581 ++++------------ -- drivers/gpu/drm/scheduler/sched_rq.c | 188 ++++++ drivers/gpu/drm/scheduler/tests/Makefile | 3 +- .../gpu/drm/scheduler/tests/tests_scheduler.c | 548 +++++++++++++++++ include/drm/gpu_scheduler.h | 17 +- 15 files changed, 962 insertions(+), 579 deletions(-)create mode 100644
drivers/gpu/drm/scheduler/sched_rq.ccreate mode 100644drivers/gpu/drm/scheduler/tests/tests_scheduler.c