Skip to contentSkip to conversation

drm/sched: Declare entity idle only after HW submission

PATCH In review Boris Brezillon 3 participants 4 messages Jun 24, 2021 – Jun 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/sched: Declare entity idle only after HW submission

The panfrost driver tries to kill in-flight jobs on FD close after destroying the FD scheduler entities. For this to work properly, we need to make sure the jobs popped from the scheduler entities have been queued at the HW level before declaring the entity idle, otherwise we might iterate over a list that doesn't contain those jobs.

---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +4 -3
index 81496ae2602e..aa776ebe326a 100644
@@ -811,10 +811,10 @@ static int drm_sched_main(void *param)
 
 		sched_job = drm_sched_entity_pop_job(entity);
 
-		complete(&entity->entity_idle);
-
-		if (!sched_job)
+		if (!sched_job) {
+			complete(&entity->entity_idle);
 			continue;
+		}
 
 		s_fence = sched_job->s_fence;
 
@@ -823,6 +823,7 @@ static int drm_sched_main(void *param)
 
 		trace_drm_run_job(sched_job, entity);
 		fence = sched->ops->run_job(sched_job);
+		complete(&entity->entity_idle);
 		drm_sched_fence_scheduled(s_fence);
 
 		if (!IS_ERR_OR_NULL(fence)) {
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Boris Brezillon

The panfrost driver tries to kill in-flight jobs on FD close after destroying the FD scheduler entities. For this to work properly, we need to make sure the jobs popped from the scheduler entities have been queued at the HW level before declaring the entity idle, otherwise we might iterate over a list that doesn't contain those jobs.

Quoted 31 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +4 -3
index 81496ae2602e..aa776ebe326a 100644
@@ -811,10 +811,10 @@ static int drm_sched_main(void *param)
 
 		sched_job = drm_sched_entity_pop_job(entity);
 
-		complete(&entity->entity_idle);
-
-		if (!sched_job)
+		if (!sched_job) {
+			complete(&entity->entity_idle);
 			continue;
+		}
 
 		s_fence = sched_job->s_fence;
 
@@ -823,6 +823,7 @@ static int drm_sched_main(void *param)
 
 		trace_drm_run_job(sched_job, entity);
 		fence = sched->ops->run_job(sched_job);
+		complete(&entity->entity_idle);
 		drm_sched_fence_scheduled(s_fence);
 
 		if (!IS_ERR_OR_NULL(fence)) {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Boris Brezillon

Am Donnerstag, dem 24.06.2021 um 16:08 +0200 schrieb Boris Brezillon:

Quoted 9 lines

The panfrost driver tries to kill in-flight jobs on FD close after destroying the FD scheduler entities. For this to work properly, we need to make sure the jobs popped from the scheduler entities have been queued at the HW level before declaring the entity idle, otherwise we might iterate over a list that doesn't contain those jobs.

Not sure how much it's worth to review my own suggestion, but the implementation looks correct to me.
I don't see any downsides for the existing drivers and it solves the race window for drivers that want to cancel jobs on the HW submission queue, without introducing yet another synchronization point.

Quoted 30 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +4 -3
index 81496ae2602e..aa776ebe326a 100644
@@ -811,10 +811,10 @@ static int drm_sched_main(void *param)
 
 		sched_job = drm_sched_entity_pop_job(entity);
 
-		complete(&entity->entity_idle);
-
-		if (!sched_job)
+		if (!sched_job) {
+			complete(&entity->entity_idle);
 			continue;
+		}
 
 		s_fence = sched_job->s_fence;
 
@@ -823,6 +823,7 @@ static int drm_sched_main(void *param)
 
 		trace_drm_run_job(sched_job, entity);
 		fence = sched->ops->run_job(sched_job);
+		complete(&entity->entity_idle);
 		drm_sched_fence_scheduled(s_fence);
 
 		if (!IS_ERR_OR_NULL(fence)) {
author Applied
#3 lore raw
Quoted 11 lines · On Mon, 28 Jun 2021 11:46:08 +0200 Lucas Stach <[email protected]> wrote:

Am Donnerstag, dem 24.06.2021 um 16:08 +0200 schrieb Boris Brezillon:

Quoted 9 lines

The panfrost driver tries to kill in-flight jobs on FD close after destroying the FD scheduler entities. For this to work properly, we need to make sure the jobs popped from the scheduler entities have been queued at the HW level before declaring the entity idle, otherwise we might iterate over a list that doesn't contain those jobs.

Quoted 7 lines

Not sure how much it's worth to review my own suggestion, but the implementation looks correct to me.
I don't see any downsides for the existing drivers and it solves the race window for drivers that want to cancel jobs on the HW submission queue, without introducing yet another synchronization point.

Queued to drm-misc-next.

Thanks,

Boris

Quoted 33 lines
Quoted 31 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +4 -3
index 81496ae2602e..aa776ebe326a 100644
@@ -811,10 +811,10 @@ static int drm_sched_main(void *param)
 
 		sched_job = drm_sched_entity_pop_job(entity);
 
-		complete(&entity->entity_idle);
-
-		if (!sched_job)
+		if (!sched_job) {
+			complete(&entity->entity_idle);
 			continue;
+		}
 
 		s_fence = sched_job->s_fence;
 
@@ -823,6 +823,7 @@ static int drm_sched_main(void *param)
 
 		trace_drm_run_job(sched_job, entity);
 		fence = sched->ops->run_job(sched_job);
+		complete(&entity->entity_idle);
 		drm_sched_fence_scheduled(s_fence);
 
 		if (!IS_ERR_OR_NULL(fence)) {