drm/sched: Add warning for removing hack in drm_sched_fini()
Subsystems (4)
Philipp Stanner
maintainerPATCH v3 1/1 drm/sched: Add warning for removing hack in drm_sched_fini()
The assembled developers agreed at the X.Org Developers Conference 2025 that the hack added for amdgpu in drm_sched_fini() shall be removed. It shouldn't be needed by amdgpu anymore.
As it's unclear whether all drivers really follow the life time rule of entities having to be torn down before their scheduler, it is reasonable to warn for a while before removing the hack.
Add a warning in drm_sched_fini() that fires if an entity is still active.
---
Changes in v3:
- Add a READ_ONCE() + comment to make the warning slightly less horrible.
Changes in v2:
- Fix broken brackets.
--- drivers/gpu/drm/scheduler/sched_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +8 -1
@@ -1419,7 +1419,7 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)struct drm_sched_rq *rq = sched->sched_rq[i];spin_lock (&rq->lock); -list_for_each_entry (s_entity, &rq->entities, list) +list_for_each_entry (s_entity, &rq->entities, list) {/* * Prevents reinsertion and marks job_queue as idle, * it will be removed from the rq in drm_sched_entity_fini()
@@ -1440,8 +1440,15 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)* For now, this remains a potential race in all * drivers that keep entities alive for longer than * the scheduler. +* +* The READ_ONCE() is there to make the lockless read +* (warning about the lockless write below) slightly +* less broken... */ +if (!READ_ONCE (s_entity->stopped)) +dev_warn (sched->dev,"Tearing down scheduler with active entities!\n" ); s_entity->stopped = true; + }spin_unlock (&rq->lock);kfree (sched->sched_rq[i]); }
Signature · 1 line
2.49.0
Quoted 4 lines · Philipp Stanner
The assembled developers agreed at the X.Org Developers Conference 2025 that the hack added for amdgpu in
drm_sched_fini()shall be removed. It shouldn't be needed by amdgpu anymore.
Quoted 8 lines
As it's unclear whether all drivers really follow the life time rule of entities having to be torn down before their scheduler, it is reasonable to warn for a while before removing the hack.
Add a warning in
drm_sched_fini()that fires if an entity is still active.Signed-off-by Philipp Stanner <[email protected]>
Can someone review this?
At XDC we agreed on removing the hack, but wanted to add a warning print first for a few releases, to really catch if there are no users anymore.
Thx
P.
Quoted 40 lines
---
Changes in v3:
- Add aREAD_ONCE()+ comment to make the warning slightly less horrible.Changes in v2:
- Fix broken brackets.
---
drivers/gpu/drm/scheduler/sched_main.c | 9 ++++++++-1 file changed, 8 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -1419,7 +1419,7 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched) struct drm_sched_rq *rq = sched->sched_rq[i];
spin_lock(&rq->lock);drivers/gpu/drm/scheduler/sched_main.c +1
-1-list_for_each_entry (s_entity, &rq->entities, list) +list_for_each_entry (s_entity, &rq->entities, list) {/*
* Prevents reinsertion and marksjob_queueas idle,
* it will be removed from the rq indrm_sched_entity_fini()drivers/gpu/drm/scheduler/sched_main.c +7
-0@@ -1440,8 +1440,15 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)* For now, this remains a potential race in all * drivers that keep entities alive for longer than * the scheduler. +* +* The READ_ONCE() is there to make the lockless read +* (warning about the lockless write below) slightly +* less broken... */ +if (!READ_ONCE (s_entity->stopped)) +dev_warn (sched->dev,"Tearing down scheduler with active entities!\n" ); s_entity->stopped = true; + } spin_unlock(&rq->lock); kfree(sched->sched_rq[i]); }
Hi Philipp,
Le 23/10/2025 à 14:34, Philipp Stanner a écrit :
Quoted 39 lines
The assembled developers agreed at the X.Org Developers Conference 2025 that the hack added for amdgpu in
drm_sched_fini()shall be removed. It shouldn't be needed by amdgpu anymore.As it's unclear whether all drivers really follow the life time rule of entities having to be torn down before their scheduler, it is reasonable to warn for a while before removing the hack.
Add a warning in
drm_sched_fini()that fires if an entity is still active.Signed-off-by Philipp Stanner <[email protected]>---
Changes in v3:
- Add aREAD_ONCE()+ comment to make the warning slightly less horrible.Changes in v2:
- Fix broken brackets.--- drivers/gpu/drm/scheduler/sched_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/gpu/drm/scheduler/sched_main.c +1
-1@@ -1419,7 +1419,7 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)struct drm_sched_rq *rq = sched->sched_rq[i];spin_lock (&rq->lock); -list_for_each_entry (s_entity, &rq->entities, list) +list_for_each_entry (s_entity, &rq->entities, list) {/* * Prevents reinsertion and marks job_queue as idle, * it will be removed from the rq in drm_sched_entity_fini() @@ -1440,8 +1440,15 @@ void drm_sched_fini(struct drm_gpu_scheduler *sched)* For now, this remains a potential race in all * drivers that keep entities alive for longer than
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_fini(struct drm_gpu_scheduler *sched) · line 1451
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +7
-0* the scheduler. +* +* The READ_ONCE() is there to make the lockless read +* (warning about the lockless write below) slightly +* less broken... */ +if (!READ_ONCE (s_entity->stopped)) +dev_warn (sched->dev,"Tearing down scheduler with active entities!\n" ); s_entity->stopped = true; + }
The patch is Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Thanks.
Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +0
-0spin_unlock (&rq->lock);kfree (sched->sched_rq[i]); }
Philipp Stanner
AppliedQuoted 15 lines · Pierre-Eric Pelloux-Prayer
Hi Philipp,
Le 23/10/2025 à 14:34, Philipp Stanner a écrit :
Quoted 12 lines
The assembled developers agreed at the X.Org Developers Conference 2025 that the hack added for amdgpu in
drm_sched_fini()shall be removed. It shouldn't be needed by amdgpu anymore.As it's unclear whether all drivers really follow the life time rule of entities having to be torn down before their scheduler, it is reasonable to warn for a while before removing the hack.
Add a warning in
drm_sched_fini()that fires if an entity is still active.Signed-off-by Philipp Stanner <[email protected]>
[…]
Quoted 3 lines
The patch is Acked-by: Pierre-Eric Pelloux-Prayer
<[email protected]>
Pushed to drm-misc-next, thanks.
For the future: b4 / maintainer-tools wasn't able to automatically harvest your Acked-by. Would be helpful if you have the A-b on a single line without line break and without other content in the future
Have a nice weekend,
P.
Quoted 7 lines
Thanks.
Quoted 3 lines
spin_unlock(&rq->lock);
kfree(sched->sched_rq[i]);
}