drm/sched: Document potential forever-hang
Subsystems (3)
Philipp Stanner
maintainercover drm/sched: Document potential forever-hang
While implementing a similar feature for drm_jobqueue I was looking for inspiration in drm_sched and found this problem here. Now I have two problems instead of one ^^'
Anyways, this is not a huge issue since it's unlikely to occur – but we should document it.
Philipp Stanner (2):
drm/sched: Fix comment in drm_sched_run_job_work() drm/sched: Add FIXME detailing potential hang
drivers/gpu/drm/scheduler/sched_main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.49.0
Philipp Stanner
maintainerPATCH 1/2 drm/sched: Fix comment in drm_sched_run_job_work()
drm_sched_run_job_work() contains a comment which explains that an entity being NULL means that there is no more work to do. It can, however, also mean that there is work, but the scheduler doesn't have enough credits to process the jobs right now.
Provide this detail in the comment.
--- drivers/gpu/drm/scheduler/sched_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +7 -2
@@ -1237,8 +1237,13 @@ static void drm_sched_run_job_work(struct work_struct *w)/* Find entity with a ready job */ entity =drm_sched_select_entity (sched); -if (!entity) -return ;/* No more work */ +if (!entity) { +/* +* Either no more work to do, or the next ready job needs more +* credits than the scheduler has currently available. +*/ +return ; + } sched_job =drm_sched_entity_pop_job (entity);if (!sched_job) {
Signature · 1 line
2.49.0
Philipp Stanner
maintainerPATCH 2/2 drm/sched: Add FIXME detailing potential hang
In reply to Philipp StannerIf a job from a ready entity needs more credits than are currently available, drm_sched_run_job_work() (a work item) simply returns and doesn't reschedule itself. The scheduler is only woken up again when the next job gets pushed with drm_sched_entity_push_job().
If someone submits a job that needs too many credits and doesn't submit more jobs afterwards, this would lead to the scheduler never pulling the too-expensive job, effectively hanging forever.
Document this problem as a FIXME.
--- drivers/gpu/drm/scheduler/sched_main.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/gpu/drm/scheduler/sched_main.c +10 -0
@@ -1237,6 +1237,16 @@ static void drm_sched_run_job_work(struct work_struct *w)/* Find entity with a ready job */ entity =drm_sched_select_entity (sched); +/* +* FIXME: +* The entity can be NULL when the scheduler currently has no capacity +* (credits) for more jobs. If that happens, the work item terminates +* itself here, without rescheduling itself. +* +* It only gets started again in drm_sched_entity_push_job(). IOW, the +* scheduler might hang forever if a job that needs too many credits +* gets submitted to an entity and no other, subsequent jobs are. +*/ if (!entity) {/* * Either no more work to do, or the next ready job needs more
Signature · 1 line
2.49.0
Matthew Brost
maintainerRe: [PATCH 2/2] drm/sched: Add FIXME detailing potential hang
Quoted 24 lines · Philipp Stanner
If a job from a ready entity needs more credits than are currently available,
drm_sched_run_job_work()(a work item) simply returns and doesn't reschedule itself. The scheduler is only woken up again when the next job gets pushed withdrm_sched_entity_push_job().If someone submits a job that needs too many credits and doesn't submit more jobs afterwards, this would lead to the scheduler never pulling the too-expensive job, effectively hanging forever.
Document this problem as a FIXME.
Signed-off-by Philipp Stanner <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -1237,6 +1237,16 @@ static void drm_sched_run_job_work(struct work_struct *w)/* Find entity with a ready job */ entity =drm_sched_select_entity (sched);
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_run_job_work(struct work_struct *w) · line 1249
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+/* +* FIXME: +* The entity can be NULL when the scheduler currently has no capacity +* (credits) for more jobs. If that happens, the work item terminates +* itself here, without rescheduling itself. +* +* It only gets started again in drm_sched_entity_push_job(). IOW, the +* scheduler might hang forever if a job that needs too many credits +* gets submitted to an entity and no other, subsequent jobs are. +*/
drm_sched_job_done frees the credits, which triggers drm_sched_free_job_work, and that in turn triggers drm_sched_run_job_work.
This flow could be refined a bit, but I do believe it works—unless I'm missing something. I'm pretty sure we have tests in Xe that exhaust the credits, though it might be continuous submissions; I'd have to check.
Matt
Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0if (!entity) {/* * Either no more work to do, or the next ready job needs more Signature · 1 line
2.49.0
Re: [PATCH 2/2] drm/sched: Add FIXME detailing potential hang
Quoted 31 lines · Matthew Brost
Quoted 30 lines · Philipp Stanner
If a job from a ready entity needs more credits than are currently available,
drm_sched_run_job_work()(a work item) simply returns and doesn't reschedule itself. The scheduler is only woken up again when the next job gets pushed withdrm_sched_entity_push_job().If someone submits a job that needs too many credits and doesn't submit more jobs afterwards, this would lead to the scheduler never pulling the too-expensive job, effectively hanging forever.
Document this problem as a FIXME.
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c | 10 ++++++++++1 file changed, 10 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -1237,6 +1237,16 @@ static void drm_sched_run_job_work(struct work_struct *w)
/* Find entity with a ready job */
entity =drm_sched_select_entity(sched);drivers/gpu/drm/scheduler/sched_main.c +6
-0+/* +* FIXME: +* The entity can be NULL when the scheduler currently has no capacity +* (credits) for more jobs. If that happens, the work item terminates +* itself here, without rescheduling itself. +*
Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_run_job_work(struct work_struct *w) · line 1249
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-0+* It only gets started again in drm_sched_entity_push_job(). IOW, the +* scheduler might hang forever if a job that needs too many credits +* gets submitted to an entity and no other, subsequent jobs are. +*/
drm_sched_job_donefrees the credits, which triggersdrm_sched_free_job_work, and that in turn triggersdrm_sched_run_job_work.
Sounds correct to me.
We can still merge #1, though, for a bit more clearness.
P.
Re: [PATCH 1/2] drm/sched: Fix comment in drm_sched_run_job_work()
In reply to Philipp StannerQuoted 8 lines · Philipp Stanner
drm_sched_run_job_work()contains a comment which explains that an entity being NULL means that there is no more work to do. It can, however, also mean that there is work, but the scheduler doesn't have enough credits to process the jobs right now.Provide this detail in the comment.
Signed-off-by Philipp Stanner <[email protected]>
Quoted 27 lines
--- drivers/gpu/drm/scheduler/sched_main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +7
-2@@ -1237,8 +1237,13 @@ static void drm_sched_run_job_work(struct work_struct *w)/* Find entity with a ready job */ entity =drm_sched_select_entity (sched); -if (!entity) -return ;/* No more work */ +if (!entity) { +/* +* Either no more work to do, or the next ready job needs more +* credits than the scheduler has currently available. +*/ +return ; + } sched_job =drm_sched_entity_pop_job (entity);if (!sched_job) {Signature · 1 line
2.49.0
Philipp Stanner
AppliedRe: [PATCH 1/2] drm/sched: Fix comment in drm_sched_run_job_work()
Quoted 11 lines · Matthew Brost
Quoted 8 lines · Philipp Stanner
drm_sched_run_job_work()contains a comment which explains that an entity being NULL means that there is no more work to do. It can, however, also mean that there is work, but the scheduler doesn't have enough credits to process the jobs right now.Provide this detail in the comment.
Signed-off-by Philipp Stanner <[email protected]>Reviewed-by Matthew Brost <[email protected]>
Applied to drm-misc-next.
Dropped the other patch.
Thx
P.
Quoted 28 lines
Quoted 28 lines
---
drivers/gpu/drm/scheduler/sched_main.c | 9 +++++++--1 file changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -1237,8 +1237,13 @@ static void drm_sched_run_job_work(struct work_struct *w)
/* Find entity with a ready job */
entity =drm_sched_select_entity(sched);drivers/gpu/drm/scheduler/sched_main.c +7
-2-if (!entity) -return ;/* No more work */ +if (!entity) { +/* +* Either no more work to do, or the next ready job needs more +* credits than the scheduler has currently available. +*/ +return ; + }
sched_job=drm_sched_entity_pop_job(entity); if (!sched_job) {Signature · 1 line
2.49.0