drm/scheduler: Fix hang when sched_entity released
Subsystems (3)
PATCH 1/1 drm/scheduler: Fix hang when sched_entity released
Problem: If scheduler is already stopped by the time sched_entity is released and entity's job_queue not empty I encountred
a hang in drm_sched_entity_flush. This is because drm_sched_entity_is_idle never becomes false.
Fix: In drm_sched_fini detach all sched_entities from the scheduler's run queues. This will satisfy drm_sched_entity_is_idle. Also wakeup all those processes stuck in sched_entity flushing as the scheduler main thread which wakes them up is stopped by now.
--- drivers/gpu/drm/scheduler/sched_main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/gpu/drm/scheduler/sched_main.c +31 -0
@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini (struct drm_gpu_scheduler *sched) { +int i; +struct drm_sched_entity *s_entity;if (sched->thread)kthread_stop (sched->thread); +/* Detach all sched_entites from this scheduler once it's stopped */ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +if (!rq) +continue ; + +/* Loop this way because rq->lock is taken in drm_sched_rq_remove_entity */ +spin_lock (&rq->lock); +while ((s_entity =list_first_entry_or_null (&rq->entities, + struct drm_sched_entity, + list))) { +spin_unlock (&rq->lock); +drm_sched_rq_remove_entity (rq, s_entity); + +/* Mark as stopped to reject adding to any new rq */ +spin_lock (&s_entity->rq_lock); + s_entity->stopped = true; +spin_unlock (&s_entity->rq_lock); + +spin_lock (&rq->lock); + } +spin_unlock (&rq->lock); + + } + +/* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ +wake_up_all (&sched->job_scheduled); +/* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync (&sched->work_tdr);
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Ping
Andrey
Quoted 50 lines · Andrey Grodzovsky
Problem: If scheduler is already stopped by the time
sched_entityis released and entity'sjob_queuenot empty I encountred
a hang indrm_sched_entity_flush. This is becausedrm_sched_entity_is_idlenever becomes false.Fix: In
drm_sched_finidetach allsched_entitiesfrom the scheduler's run queues. This will satisfydrm_sched_entity_is_idle. Also wakeup all those processes stuck insched_entityflushing as the scheduler main thread which wakes them up is stopped by now.Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +24
-0@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini (struct drm_gpu_scheduler *sched) { +int i; +struct drm_sched_entity *s_entity;if (sched->thread)kthread_stop (sched->thread); +/* Detach all sched_entites from this scheduler once it's stopped */ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +if (!rq) +continue ; + +/* Loop this way because rq->lock is taken in drm_sched_rq_remove_entity */ +spin_lock (&rq->lock); +while ((s_entity =list_first_entry_or_null (&rq->entities, + struct drm_sched_entity, + list))) { +spin_unlock (&rq->lock); +drm_sched_rq_remove_entity (rq, s_entity); + +/* Mark as stopped to reject adding to any new rq */ +spin_lock (&s_entity->rq_lock); + s_entity->stopped = true; +spin_unlock (&s_entity->rq_lock); + +spin_lock (&rq->lock); + }
drivers/gpu/drm/scheduler/sched_main.c EXPORT_SYMBOL(drm_sched_init); · line 936
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +7
-0+spin_unlock (&rq->lock); + + } + +/* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ +wake_up_all (&sched->job_scheduled); +/* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync (&sched->work_tdr);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
reviewerAm 16.02.21 um 18:07 schrieb Andrey Grodzovsky:
Quoted 36 lines
Problem: If scheduler is already stopped by the time
sched_entityis released and entity'sjob_queuenot empty I encountred
a hang indrm_sched_entity_flush. This is becausedrm_sched_entity_is_idlenever becomes false.Fix: In
drm_sched_finidetach allsched_entitiesfrom the scheduler's run queues. This will satisfydrm_sched_entity_is_idle. Also wakeup all those processes stuck insched_entityflushing as the scheduler main thread which wakes them up is stopped by now.Signed-off-by Andrey Grodzovsky <[email protected]>--- drivers/gpu/drm/scheduler/sched_main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +10
-0@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini (struct drm_gpu_scheduler *sched) { +int i; +struct drm_sched_entity *s_entity;if (sched->thread)kthread_stop (sched->thread); +/* Detach all sched_entites from this scheduler once it's stopped */ +for (i =DRM_SCHED_PRIORITY_COUNT -1 ; i >=DRM_SCHED_PRIORITY_MIN ; i--) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +if (!rq) +continue ; + +/* Loop this way because rq->lock is taken in drm_sched_rq_remove_entity */
drivers/gpu/drm/scheduler/sched_main.c EXPORT_SYMBOL(drm_sched_init); · line 922
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+spin_lock (&rq->lock); +while ((s_entity =list_first_entry_or_null (&rq->entities, + struct drm_sched_entity, + list))) { +spin_unlock (&rq->lock); +drm_sched_rq_remove_entity (rq, s_entity); + +/* Mark as stopped to reject adding to any new rq */ +spin_lock (&s_entity->rq_lock); + s_entity->stopped = true;
Why not marking it as stopped and then removing it?
Regards,
Christian.
Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +4
-0+spin_unlock (&s_entity->rq_lock); + +spin_lock (&rq->lock); + }
drivers/gpu/drm/scheduler/sched_main.c EXPORT_SYMBOL(drm_sched_init); · line 936
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +7
-0+spin_unlock (&rq->lock); + + } + +/* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ +wake_up_all (&sched->job_scheduled); +/* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync (&sched->work_tdr);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 50 lines · Christian König
Am 16.02.21 um 18:07 schrieb Andrey Grodzovsky:
Quoted 38 lines
Problem: If scheduler is already stopped by the time
sched_entityis released and entity'sjob_queuenot empty I encountred
a hang indrm_sched_entity_flush. This is becausedrm_sched_entity_is_idlenever becomes false.Fix: In
drm_sched_finidetach allsched_entitiesfrom the scheduler's run queues. This will satisfydrm_sched_entity_is_idle. Also wakeup all those processes stuck insched_entityflushing as the scheduler main thread which wakes them up is stopped by now.Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c| 31 +++++++++++++++++++++++++++++++1 file changed, 31 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +2
-0@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini(struct drm_gpu_scheduler *sched) { + int i; + struct drm_sched_entity *s_entity; if (sched->thread) kthread_stop(sched->thread);+ /* Detach all
sched_entitesfrom this scheduler once it's stopped */ + for (i =DRM_SCHED_PRIORITY_COUNT- 1; i >=DRM_SCHED_PRIORITY_MIN; i--) { + structdrm_sched_rq*rq = &sched->sched_rq[i];drivers/gpu/drm/scheduler/sched_main.c +5
-0+ + if (!rq) + continue; + + /* Loop this way because rq->lock is taken in
drm_sched_rq_remove_entity*/
+spin_lock(&rq->lock);
+ while ((s_entity= list_first_entry_or_null(&rq->entities,Quoted 8 lines
+ struct
drm_sched_entity, + list))) {
+spin_unlock(&rq->lock);
+drm_sched_rq_remove_entity(rq, s_entity); +
+ /* Mark as stopped to reject adding to any new rq */ +spin_lock(&s_entity->rq_lock);
+s_entity->stopped= true;Why not marking it as stopped and then removing it?
Quoted 2 lines
Regards,
Christian.
You mean just reverse the order of operations here to prevent a race where someone adding it again to rq before marking it as stopped ?
Andrey
Quoted 15 lines
Quoted 12 lines
+
spin_unlock(&s_entity->rq_lock);drivers/gpu/drm/scheduler/sched_main.c +10
-0+ + spin_lock(&rq->lock); + } + spin_unlock(&rq->lock); + + } + + /* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ + wake_up_all(&sched->job_scheduled); +Quoted 2 lines
/* Confirm no work left behind accessing device structures */
cancel_delayed_work_sync(&sched->work_tdr);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
reviewerAm 17.02.21 um 22:36 schrieb Andrey Grodzovsky:
Quoted 54 lines · Christian König
Quoted 52 lines
Am 16.02.21 um 18:07 schrieb Andrey Grodzovsky:
Quoted 40 lines
Problem: If scheduler is already stopped by the time
sched_entityis released and entity'sjob_queuenot empty I encountred
a hang indrm_sched_entity_flush. This is becausedrm_sched_entity_is_idlenever becomes false.Fix: In
drm_sched_finidetach allsched_entitiesfrom the scheduler's run queues. This will satisfydrm_sched_entity_is_idle. Also wakeup all those processes stuck insched_entityflushing as the scheduler main thread which wakes them up is stopped by now.Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c| 31
+++++++++++++++++++++++++++++++1 file changed, 31 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +2
-0@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini(struct drm_gpu_scheduler *sched) { + int i; + struct drm_sched_entity *s_entity; if (sched->thread) kthread_stop(sched->thread);+ /* Detach all
sched_entitesfrom this scheduler once it's stopped */ + for (i =DRM_SCHED_PRIORITY_COUNT- 1; i >=DRM_SCHED_PRIORITY_MIN; i--) {
+ structdrm_sched_rq*rq = &sched->sched_rq[i];drivers/gpu/drm/scheduler/sched_main.c +5
-0+ + if (!rq) + continue; + + /* Loop this way because rq->lock is taken in
drm_sched_rq_remove_entity*/
+spin_lock(&rq->lock);
+ while ((s_entity= list_first_entry_or_null(&rq->entities,Quoted 8 lines
+ struct
drm_sched_entity, + list))) {
+spin_unlock(&rq->lock);
+drm_sched_rq_remove_entity(rq, s_entity); +
+ /* Mark as stopped to reject adding to any new rq */ +spin_lock(&s_entity->rq_lock);
+s_entity->stopped= true;Why not marking it as stopped and then removing it?
Quoted 5 lines
Quoted 2 lines
Regards,
Christian.You mean just reverse the order of operations here to prevent a race where someone adding it again to rq before marking it as stopped ?
Exactly that, yeah.
Christian.
Quoted 20 lines
Andrey
Quoted 16 lines
Quoted 15 lines
+
spin_unlock(&s_entity->rq_lock);drivers/gpu/drm/scheduler/sched_main.c +8
-0+ + spin_lock(&rq->lock); + } + spin_unlock(&rq->lock); + + } + + /* Wakeup everyone stuck in drm_sched_entity_flush for thisscheduler */
+wake_up_all(&sched->job_scheduled);
+
/* Confirm no work left behind accessing device structures */cancel_delayed_work_sync(&sched->work_tdr);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Will do.
Andrey
Quoted 60 lines · Christian König
Am 17.02.21 um 22:36 schrieb Andrey Grodzovsky:
Quoted 57 lines · Christian König
Quoted 53 lines
Am 16.02.21 um 18:07 schrieb Andrey Grodzovsky:
Quoted 39 lines
Problem: If scheduler is already stopped by the time
sched_entityis released and entity'sjob_queuenot empty I encountred
a hang indrm_sched_entity_flush. This is becausedrm_sched_entity_is_idlenever becomes false.Fix: In
drm_sched_finidetach allsched_entitiesfrom the scheduler's run queues. This will satisfydrm_sched_entity_is_idle. Also wakeup all those processes stuck insched_entityflushing as the scheduler main thread which wakes them up is stopped by now.Signed-off-by Andrey Grodzovsky <[email protected]>---
drivers/gpu/drm/scheduler/sched_main.c| 31 +++++++++++++++++++++++++++++++1 file changed, 31 insertions(+)drivers/gpu/drm/scheduler/sched_main.c +2
-0@@ -897,9 +897,40 @@ EXPORT_SYMBOL(drm_sched_init);*/ void drm_sched_fini(struct drm_gpu_scheduler *sched) { + int i; + struct drm_sched_entity *s_entity; if (sched->thread) kthread_stop(sched->thread);+ /* Detach all
sched_entitesfrom this scheduler once it's stopped */ + for (i =DRM_SCHED_PRIORITY_COUNT- 1; i >=DRM_SCHED_PRIORITY_MIN; i--) {
+ structdrm_sched_rq*rq = &sched->sched_rq[i];drivers/gpu/drm/scheduler/sched_main.c +5
-0+ + if (!rq) + continue; + + /* Loop this way because rq->lock is taken in
drm_sched_rq_remove_entity*/
+spin_lock(&rq->lock);
+ while ((s_entity= list_first_entry_or_null(&rq->entities,Quoted 8 lines
+ struct
drm_sched_entity, + list))) {
+spin_unlock(&rq->lock);
+drm_sched_rq_remove_entity(rq, s_entity); +
+ /* Mark as stopped to reject adding to any new rq */ +spin_lock(&s_entity->rq_lock);
+s_entity->stopped= true;Why not marking it as stopped and then removing it?
Regards,
Christian.
Quoted 26 lines
Quoted 1 line
You mean just reverse the order of operations here to prevent a race where someone adding it again to rq before marking it as stopped ?
Exactly that, yeah.
Christian.
Quoted 19 lines
Andrey
Quoted 15 lines
Quoted 14 lines
+
spin_unlock(&s_entity->rq_lock);drivers/gpu/drm/scheduler/sched_main.c +10
-0+ + spin_lock(&rq->lock); + } + spin_unlock(&rq->lock); + + } + + /* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ + wake_up_all(&sched->job_scheduled); +/* Confirm no work left behind accessing device structures */
cancel_delayed_work_sync(&sched->work_tdr);
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel