Skip to contentSkip to conversation

drm/sched: Document potential forever-hang

PATCH Applied Philipp Stanner 3 participants 7 messages Oct 28, 2025 – Oct 31, 2025

Subsystems (3)
lore
Share & tools
lore

Philipp Stanner

author maintainer
#0 lore raw

cover 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
author maintainer
#1 lore raw

PATCH 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
index c39f0245e3a9..492e8af639db 100644
@@ -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
author maintainer
#4 lore raw

PATCH 2/2 drm/sched: Add FIXME detailing potential hang

In reply to 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 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
index 492e8af639db..eaf8d17b2a66 100644
@@ -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
maintainer
#5 lore raw

Re: [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 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 +0 -0
index 492e8af639db..eaf8d17b2a66 100644
@@ -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 -0
 	if (!entity) {
 		/*
 		 * Either no more work to do, or the next ready job needs more
Signature · 1 line
2.49.0
#6 lore raw

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 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 +0 -0
index 492e8af639db..eaf8d17b2a66 100644
@@ -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_done frees the credits, which triggers drm_sched_free_job_work, and that in turn triggers drm_sched_run_job_work.

Sounds correct to me.

We can still merge #1, though, for a bit more clearness.

P.

maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] drm/sched: Fix comment in drm_sched_run_job_work()

In reply to Philipp Stanner
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.

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
index c39f0245e3a9..492e8af639db 100644
@@ -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
#3 lore raw

Re: [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.

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
index c39f0245e3a9..492e8af639db 100644
@@ -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