Skip to contentSkip to conversation

drm/amdgpu: discard commands of killed processes

PATCH In review Christian König 4 participants 6 messages Aug 21, 2017 – Aug 22, 2017 3 messages not in the archive

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

PATCH 1/1 drm/amdgpu: discard commands of killed processes

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +19 -4
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
 			   struct amd_sched_entity *entity)
 {
 	struct amd_sched_rq *rq = entity->rq;
+	int r;
 
 	if (!amd_sched_entity_is_initialized(sched, entity))
 		return;
-
 	/**
 	 * The client will not queue more IBs during this fini, consume existing
-	 * queued IBs
+	 * queued IBs or discard them on SIGKILL
 	*/
-	wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
-
+	if ((current->flags & PF_SIGNALED) && current->exit_code == SIGKILL)
+		r = -ERESTARTSYS;
+	else
+		r = wait_event_killable(sched->job_scheduled,
+					amd_sched_entity_is_idle(entity));
 	amd_sched_rq_remove_entity(rq, entity);
+	if (r) {
+		struct amd_sched_job *job;
+
+		/* Park the kernel for a moment to make sure it isn't processing
+		 * our enity.
+		 */
+		kthread_park(sched->thread);
+		kthread_unpark(sched->thread);
+		while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+			sched->ops->free_job(job);
+
+	}
 	kfifo_free(&entity->job_queue);
 }
 
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1503320329-2142-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#2 lore raw
Quoted 31 lines · Christian König

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 +++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +3 -4
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
  			   struct amd_sched_entity *entity)
  {
  	struct amd_sched_rq *rq = entity->rq;
+	int r;
 
  	if (!amd_sched_entity_is_initialized(sched, entity))
  		return;
-
  	/**
  	 * The client will not queue more IBs during this fini, consume existing
-	 * queued IBs
+	 * queued IBs or discard them on SIGKILL
  	*/
-	wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
-
+	if ((current->flags & PF_SIGNALED) && current->exit_code == SIGKILL)

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 226

Quoted 10 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +9 -0
+		r = -ERESTARTSYS;
+	else
+		r = wait_event_killable(sched->job_scheduled,
+					amd_sched_entity_is_idle(entity));
  	amd_sched_rq_remove_entity(rq, entity);
+	if (r) {
+		struct amd_sched_job *job;
+
+		/* Park the kernel for a moment to make sure it isn't processing
+		 * our enity.

s/enity/entity/

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 236

Quoted 10 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +7 -0
+		 */
+		kthread_park(sched->thread);
+		kthread_unpark(sched->thread);
+		while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+			sched->ops->free_job(job);
+
+	}
  	kfifo_free(&entity->job_queue);
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#3 lore raw
In reply to a message not in the archive
Quoted 6 lines · Christian König

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

Quoted 48 lines
---
 drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +19 -5
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
                           struct amd_sched_entity *entity)
 {
        struct amd_sched_rq *rq = entity->rq;
+       int r;
 
        if (!amd_sched_entity_is_initialized(sched, entity))
                return;
-
        /**
         * The client will not queue more IBs during this fini, consume existing
-        * queued IBs
+        * queued IBs or discard them on SIGKILL
        */
-       wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
-
+       if ((current->flags & PF_SIGNALED) && current->exit_code == SIGKILL)
+               r = -ERESTARTSYS;
+       else
+               r = wait_event_killable(sched->job_scheduled,
+                                       amd_sched_entity_is_idle(entity));
        amd_sched_rq_remove_entity(rq, entity);
+       if (r) {
+               struct amd_sched_job *job;
+
+               /* Park the kernel for a moment to make sure it isn't processing
+                * our enity.
+                */
+               kthread_park(sched->thread);
+               kthread_unpark(sched->thread);
+               while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+                       sched->ops->free_job(job);
+
+       }
        kfifo_free(&entity->job_queue);
 }
 
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
In reply to a message not in the archive
Quoted 34 lines · Christian König

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 +++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +6 -4
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
  			   struct amd_sched_entity *entity)
  {
  	struct amd_sched_rq *rq = entity->rq;
+	int r;
 
  	if (!amd_sched_entity_is_initialized(sched, entity))
  		return;
-
  	/**
  	 * The client will not queue more IBs during this fini, consume existing
-	 * queued IBs
+	 * queued IBs or discard them on SIGKILL
  	*/
-	wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
-
+	if ((current->flags & PF_SIGNALED) && current->exit_code == SIGKILL)
+		r = -ERESTARTSYS;
+	else
+		r = wait_event_killable(sched->job_scheduled,

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 229

Quoted 10 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +9 -0
+					amd_sched_entity_is_idle(entity));
  	amd_sched_rq_remove_entity(rq, entity);
+	if (r) {
+		struct amd_sched_job *job;
+
+		/* Park the kernel for a moment to make sure it isn't processing
+		 * our enity.
+		 */
+		kthread_park(sched->thread);
+		kthread_unpark(sched->thread);

When entity has been removed, how does sched process entity? seems not need here. otherwise looks good to me.

Regards,
David Zhou

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 236

Quoted 7 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4 -0
+		while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+			sched->ops->free_job(job);
+
+	}
  	kfifo_free(&entity->job_queue);
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 396787e0-89d9-0877-8cf2-5432760ae82e-5C7GfCeVMHo@public.gmane.org

#6 lore raw

Am 22.08.2017 um 04:37 schrieb zhoucm1:

Quoted 45 lines · Christian König
Quoted 42 lines

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 
+++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +1 -1
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct 
 amd_gpu_scheduler *sched,
                 struct amd_sched_entity *entity)
  {
      struct amd_sched_rq *rq = entity->rq;
+    int r;
        if (!amd_sched_entity_is_initialized(sched, entity))
          return;
-
      /**
       * The client will not queue more IBs during this fini, consume 

existing

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +2 -3
-     * queued IBs
+     * queued IBs or discard them on SIGKILL
      */
-    wait_event(sched->job_scheduled, amd_sched_entity_is_idle(entity));
-
+    if ((current->flags & PF_SIGNALED) && current->exit_code == 

SIGKILL)

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +7 -0
+        r = -ERESTARTSYS;
+    else
+        r = wait_event_killable(sched->job_scheduled,
+                    amd_sched_entity_is_idle(entity));
      amd_sched_rq_remove_entity(rq, entity);
+    if (r) {
+        struct amd_sched_job *job;
+
Quoted 8 lines

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 229

Quoted 6 lines

+ /* Park the kernel for a moment to make sure it isn't
processing

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4 -0
+         * our enity.
+         */
+        kthread_park(sched->thread);
+        kthread_unpark(sched->thread);

When entity has been removed, how does sched process entity? seems not need here. otherwise looks good to me.

It's possible that we race here, e.g. we removed the entity but the scheduler is still processing one last job from that entity.

Regards,
Christian.

Quoted 10 lines

Regards,
David Zhou

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 235

Quoted 6 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4 -0
+        while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+            sched->ops->free_job(job);
+
+    }
      kfifo_free(&entity->job_queue);
  }
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 84105d4b-9d01-e4b1-dbdf-f37b01dc6f81-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#8 lore raw
Quoted 56 lines · Christian König

Am 22.08.2017 um 04:37 schrieb zhoucm1:

Quoted 46 lines · Christian König
Quoted 43 lines

From: Christian König <[email protected]>

When a process is killed we shouldn't submit all waiting jobs, but instead clean up as fast as possible.

---
  drivers/gpu/drm/amd/scheduler/gpu_scheduler.c | 23 
+++++++++++++++++++----
  1 file changed, 19 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +1 -1
index 38cea6f..97c94f9 100644
@@ -205,17 +205,32 @@ void amd_sched_entity_fini(struct 
 amd_gpu_scheduler *sched,
                 struct amd_sched_entity *entity)
  {
      struct amd_sched_rq *rq = entity->rq;
+    int r;
        if (!amd_sched_entity_is_initialized(sched, entity))
          return;
-
      /**
       * The client will not queue more IBs during this fini, 

consume existing

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +1 -2
-     * queued IBs
+     * queued IBs or discard them on SIGKILL
      */
-    wait_event(sched->job_scheduled, 

amd_sched_entity_is_idle(entity));

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +1 -1
-
+    if ((current->flags & PF_SIGNALED) && current->exit_code == 

SIGKILL)

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +7 -0
+        r = -ERESTARTSYS;
+    else
+        r = wait_event_killable(sched->job_scheduled,
+                    amd_sched_entity_is_idle(entity));
      amd_sched_rq_remove_entity(rq, entity);
+    if (r) {
+        struct amd_sched_job *job;
+
Quoted 8 lines

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 229

Quoted 6 lines

+ /* Park the kernel for a moment to make sure it isn't
processing

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4 -0
+         * our enity.
+         */
+        kthread_park(sched->thread);
+        kthread_unpark(sched->thread);

When entity has been removed, how does sched process entity? seems not need here. otherwise looks good to me.

Quoted 1 line

It's possible that we race here, e.g. we removed the entity but the scheduler is still processing one last job from that entity.

Fair, feel free to add my RB.

Regards,
David Zhou

Quoted 20 lines

Regards,
Christian.

Quoted 14 lines

Regards,
David Zhou

drivers/gpu/drm/amd/scheduler/gpu_scheduler.c void amd_sched_entity_fini(struct amd_gpu_scheduler *sched, · line 235

Quoted 6 lines
drivers/gpu/drm/amd/scheduler/gpu_scheduler.c +4 -0
+        while (kfifo_out(&entity->job_queue, &job, sizeof(job)))
+            sched->ops->free_job(job);
+
+    }
      kfifo_free(&entity->job_queue);
  }

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx