Skip to contentSkip to conversation

drm/scheduler: add a current job field to scheduler

PATCH In review Nayan Deshmukh 4 participants 9 messages Sep 18, 2018 – Sep 20, 2018

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

PATCH 1/2 drm/scheduler: add a current job field to scheduler

Which points to the job running on the hardware. This is useful when we need to access the currently executing job from the scheduler.

---
 drivers/gpu/drm/scheduler/sched_main.c | 17 +++++++++++------
 include/drm/gpu_scheduler.h            |  2 ++
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +11 -6
index 9ca741f3a0bc..0e6ccc8243db 100644
@@ -189,6 +189,7 @@ static void drm_sched_job_finish(struct work_struct *work)
 	struct drm_sched_job *s_job = container_of(work, struct drm_sched_job,
 						   finish_work);
 	struct drm_gpu_scheduler *sched = s_job->sched;
+	struct drm_sched_job *next;
 
 	/*
 	 * Canceling the timeout without removing our job from the ring mirror
@@ -201,10 +202,10 @@ static void drm_sched_job_finish(struct work_struct *work)
 
 	spin_lock(&sched->job_list_lock);
 	/* queue TDR for next job */
+	next = list_next_entry(s_job, node);
+	sched->curr_job = next;
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
 	    !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
-		struct drm_sched_job *next = list_next_entry(s_job, node);
-
 		if (!dma_fence_is_signaled(&next->s_fence->finished))
 			schedule_delayed_work(&next->work_tdr, sched->timeout);
 	}
@@ -233,10 +234,12 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 
 	spin_lock(&sched->job_list_lock);
 	list_add_tail(&s_job->node, &sched->ring_mirror_list);
-	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
-	    list_first_entry_or_null(&sched->ring_mirror_list,
-				     struct drm_sched_job, node) == s_job)
-		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+	if (list_first_entry_or_null(&sched->ring_mirror_list,
+				struct drm_sched_job, node) == s_job) {
+		if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
+			schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+		sched->curr_job = s_job;
+	}
 	spin_unlock(&sched->job_list_lock);
 }
 
@@ -316,6 +319,8 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)
 					 struct drm_sched_job, node);
 	if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
 		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+	if (s_job)
+		sched->curr_job = s_job;
 
 	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
 		struct drm_sched_fence *s_fence = s_job->s_fence;
include/drm/gpu_scheduler.h +2 -0
index daec50f887b3..07e776b1ca42 100644
@@ -252,6 +252,7 @@ struct drm_sched_backend_ops {
  * @timeout: the time after which a job is removed from the scheduler.
  * @name: name of the ring for which this scheduler is being used.
  * @sched_rq: priority wise array of run queues.
+ * @curr_job: points to the job currently running on the hardware
  * @wake_up_worker: the wait queue on which the scheduler sleeps until a job
  *                  is ready to be scheduled.
  * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler
@@ -274,6 +275,7 @@ struct drm_gpu_scheduler {
 	long				timeout;
 	const char			*name;
 	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_MAX];
+	struct drm_sched_job            *curr_job;
 	wait_queue_head_t		wake_up_worker;
 	wait_queue_head_t		job_scheduled;
 	atomic_t			hw_rq_count;
Signature · 6 lines
2.14.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/2 drm/scheduler: remove timeout work_struct from drm_sched_job

having a delayed work item per job is redundant as we only need one per scheduler to track the time out the currently executing job.

---
 drivers/gpu/drm/scheduler/sched_main.c | 16 +++++++++-------
 include/drm/gpu_scheduler.h            |  6 +++---
 2 files changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +9 -7
index 0e6ccc8243db..f213b5c7f718 100644
@@ -198,7 +198,7 @@ static void drm_sched_job_finish(struct work_struct *work)
 	 * manages to find this job as the next job in the list, the fence
 	 * signaled check below will prevent the timeout to be restarted.
 	 */
-	cancel_delayed_work_sync(&s_job->work_tdr);
+	cancel_delayed_work_sync(&sched->work_tdr);
 
 	spin_lock(&sched->job_list_lock);
 	/* queue TDR for next job */
@@ -207,7 +207,7 @@ static void drm_sched_job_finish(struct work_struct *work)
 	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
 	    !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
 		if (!dma_fence_is_signaled(&next->s_fence->finished))
-			schedule_delayed_work(&next->work_tdr, sched->timeout);
+			schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	}
 	/* remove job from ring_mirror_list */
 	list_del(&s_job->node);
@@ -237,7 +237,7 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 	if (list_first_entry_or_null(&sched->ring_mirror_list,
 				struct drm_sched_job, node) == s_job) {
 		if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
-			schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+			schedule_delayed_work(&sched->work_tdr, sched->timeout);
 		sched->curr_job = s_job;
 	}
 	spin_unlock(&sched->job_list_lock);
@@ -245,8 +245,10 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 
 static void drm_sched_job_timedout(struct work_struct *work)
 {
-	struct drm_sched_job *job = container_of(work, struct drm_sched_job,
-						 work_tdr.work);
+	struct drm_gpu_scheduler *sched = container_of(work,
+						struct drm_gpu_scheduler,
+						work_tdr.work);
+	struct drm_sched_job *job = sched->curr_job;
 
 	job->sched->ops->timedout_job(job);
 }
@@ -318,7 +320,7 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)
 	s_job = list_first_entry_or_null(&sched->ring_mirror_list,
 					 struct drm_sched_job, node);
 	if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
-		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	if (s_job)
 		sched->curr_job = s_job;
 
@@ -389,7 +391,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
 	INIT_WORK(&job->finish_work, drm_sched_job_finish);
 	INIT_LIST_HEAD(&job->node);
-	INIT_DELAYED_WORK(&job->work_tdr, drm_sched_job_timedout);
 
 	return 0;
 }
@@ -580,6 +581,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
 	INIT_LIST_HEAD(&sched->ring_mirror_list);
 	spin_lock_init(&sched->job_list_lock);
 	atomic_set(&sched->hw_rq_count, 0);
+	INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
 	atomic_set(&sched->num_jobs, 0);
 	atomic64_set(&sched->job_id_count, 0);
 
include/drm/gpu_scheduler.h +3 -3
index 07e776b1ca42..9d50d7f3eaa4 100644
@@ -175,8 +175,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
  *               finished to remove the job from the
  *               @drm_gpu_scheduler.ring_mirror_list.
  * @node: used to append this struct to the @drm_gpu_scheduler.ring_mirror_list.
- * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the timeout
- *            interval is over.
  * @id: a unique id assigned to each job scheduled on the scheduler.
  * @karma: increment on every hang caused by this job. If this exceeds the hang
  *         limit of the scheduler then the job is marked guilty and will not
@@ -195,7 +193,6 @@ struct drm_sched_job {
 	struct dma_fence_cb		finish_cb;
 	struct work_struct		finish_work;
 	struct list_head		node;
-	struct delayed_work		work_tdr;
 	uint64_t			id;
 	atomic_t			karma;
 	enum drm_sched_priority		s_priority;
@@ -260,6 +257,8 @@ struct drm_sched_backend_ops {
  *                 finished.
  * @hw_rq_count: the number of jobs currently in the hardware queue.
  * @job_id_count: used to assign unique id to the each job.
+ * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the
+ *            timeout interval is over.
  * @thread: the kthread on which the scheduler which run.
  * @ring_mirror_list: the list of jobs which are currently in the job queue.
  * @job_list_lock: lock to protect the ring_mirror_list.
@@ -280,6 +279,7 @@ struct drm_gpu_scheduler {
 	wait_queue_head_t		job_scheduled;
 	atomic_t			hw_rq_count;
 	atomic64_t			job_id_count;
+	struct delayed_work		work_tdr;
 	struct task_struct		*thread;
 	struct list_head		ring_mirror_list;
 	spinlock_t			job_list_lock;
Signature · 6 lines
2.14.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Re: [PATCH 2/2] drm/scheduler: remove timeout work_struct from drm_sched_job

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 2 lines

having a delayed work item per job is redundant as we only need one per scheduler to track the time out the currently executing job.

Well that looks simpler than I thought it would be.

But it shows the next problem that the timeout and the completion could race.

As far as I can see that can be fixed by moving the dma_fence_remove_callback()/dma_fence_add_callback() dance from drm_sched_hw_job_reset() to drm_sched_job_timedout().

Anyway, I would say drop patch #1 and fix the one comment below and we can use this.

Quoted 22 lines
---
  drivers/gpu/drm/scheduler/sched_main.c | 16 +++++++++-------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 12 insertions(+), 10 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 0e6ccc8243db..f213b5c7f718 100644
@@ -198,7 +198,7 @@ static void drm_sched_job_finish(struct work_struct *work)
  	 * manages to find this job as the next job in the list, the fence
  	 * signaled check below will prevent the timeout to be restarted.
  	 */
-	cancel_delayed_work_sync(&s_job->work_tdr);
+	cancel_delayed_work_sync(&sched->work_tdr);
 
  	spin_lock(&sched->job_list_lock);
  	/* queue TDR for next job */

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct *work) · line 209

Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -207,7 +207,7 @@ static void drm_sched_job_finish(struct work_struct *work)
  	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
  	    !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
  		if (!dma_fence_is_signaled(&next->s_fence->finished))

Since we now have only one delayed work item we can just drop the test if next is already signaled.

Regards,
Christian.

Quoted 83 lines
drivers/gpu/drm/scheduler/sched_main.c +8 -6
-			schedule_delayed_work(&next->work_tdr, sched->timeout);
+			schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	}
  	/* remove job from ring_mirror_list */
  	list_del(&s_job->node);
@@ -237,7 +237,7 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
  	if (list_first_entry_or_null(&sched->ring_mirror_list,
  				struct drm_sched_job, node) == s_job) {
  		if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
-			schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+			schedule_delayed_work(&sched->work_tdr, sched->timeout);
  		sched->curr_job = s_job;
  	}
  	spin_unlock(&sched->job_list_lock);
@@ -245,8 +245,10 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 
  static void drm_sched_job_timedout(struct work_struct *work)
  {
-	struct drm_sched_job *job = container_of(work, struct drm_sched_job,
-						 work_tdr.work);
+	struct drm_gpu_scheduler *sched = container_of(work,
+						struct drm_gpu_scheduler,
+						work_tdr.work);
+	struct drm_sched_job *job = sched->curr_job;
 
  	job->sched->ops->timedout_job(job);
  }
@@ -318,7 +320,7 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)
  	s_job = list_first_entry_or_null(&sched->ring_mirror_list,
  					 struct drm_sched_job, node);
  	if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
-		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	if (s_job)
  		sched->curr_job = s_job;
 
@@ -389,7 +391,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
  	INIT_WORK(&job->finish_work, drm_sched_job_finish);
  	INIT_LIST_HEAD(&job->node);
-	INIT_DELAYED_WORK(&job->work_tdr, drm_sched_job_timedout);
 
  	return 0;
  }
@@ -580,6 +581,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
  	INIT_LIST_HEAD(&sched->ring_mirror_list);
  	spin_lock_init(&sched->job_list_lock);
  	atomic_set(&sched->hw_rq_count, 0);
+	INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
  	atomic_set(&sched->num_jobs, 0);
  	atomic64_set(&sched->job_id_count, 0);
 
include/drm/gpu_scheduler.h +2 -3
index 07e776b1ca42..9d50d7f3eaa4 100644
@@ -175,8 +175,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);
   *               finished to remove the job from the
   *               @drm_gpu_scheduler.ring_mirror_list.
   * @node: used to append this struct to the @drm_gpu_scheduler.ring_mirror_list.
- * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the timeout
- *            interval is over.
   * @id: a unique id assigned to each job scheduled on the scheduler.
   * @karma: increment on every hang caused by this job. If this exceeds the hang
   *         limit of the scheduler then the job is marked guilty and will not
@@ -195,7 +193,6 @@ struct drm_sched_job {
  	struct dma_fence_cb		finish_cb;
  	struct work_struct		finish_work;
  	struct list_head		node;
-	struct delayed_work		work_tdr;
  	uint64_t			id;
  	atomic_t			karma;
  	enum drm_sched_priority		s_priority;
@@ -260,6 +257,8 @@ struct drm_sched_backend_ops {
   *                 finished.
   * @hw_rq_count: the number of jobs currently in the hardware queue.
   * @job_id_count: used to assign unique id to the each job.
+ * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after the
+ *            timeout interval is over.
   * @thread: the kthread on which the scheduler which run.
   * @ring_mirror_list: the list of jobs which are currently in the job queue.
   * @job_list_lock: lock to protect the ring_mirror_list.

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 285

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -280,6 +279,7 @@ struct drm_gpu_scheduler {
  	wait_queue_head_t		job_scheduled;
  	atomic_t			hw_rq_count;
  	atomic64_t			job_id_count;
+	struct delayed_work		work_tdr;
  	struct task_struct		*thread;
  	struct list_head		ring_mirror_list;
  	spinlock_t			job_list_lock;

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

#3 lore raw

Re: [PATCH 2/2] drm/scheduler: remove timeout work_struct from drm_sched_job

Quoted 4 lines · Christian König

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 2 lines

having a delayed work item per job is redundant as we only need one per scheduler to track the time out the currently executing job.

Quoted 8 lines

Well that looks simpler than I thought it would be.

But it shows the next problem that the timeout and the completion could race.

As far as I can see that can be fixed by moving the dma_fence_remove_callback()/dma_fence_add_callback() dance from drm_sched_hw_job_reset() to drm_sched_job_timedout().

BTW, while you guys are looking into this code, please keep an eye open for things that could explain https://bugs.freedesktop.org/107762 .

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [PATCH 2/2] drm/scheduler: remove timeout work_struct from drm_sched_job

Am 19.09.2018 um 17:39 schrieb Michel Dänzer:

Quoted 6 lines · Christian König
Quoted 5 lines

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 2 lines

having a delayed work item per job is redundant as we only need one per scheduler to track the time out the currently executing job.

Well that looks simpler than I thought it would be.

Quoted 8 lines
Quoted 6 lines

But it shows the next problem that the timeout and the completion could race.

As far as I can see that can be fixed by moving the dma_fence_remove_callback()/dma_fence_add_callback() dance from drm_sched_hw_job_reset() to drm_sched_job_timedout().

BTW, while you guys are looking into this code, please keep an eye open for things that could explain https://bugs.freedesktop.org/107762 .

Yeah, since we now have only one timer that should be fixed by this as well.

Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH 2/2] drm/scheduler: remove timeout work_struct from drm_sched_job

In reply to Christian König
Quoted 41 lines · Christian König

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 2 lines

having a delayed work item per job is redundant as we only need one per scheduler to track the time out the currently executing job.

Well that looks simpler than I thought it would be.

But it shows the next problem that the timeout and the completion could race.

As far as I can see that can be fixed by moving the dma_fence_remove_callback()/dma_fence_add_callback() dance from drm_sched_hw_job_reset() to drm_sched_job_timedout().

Anyway, I would say drop patch #1 and fix the one comment below and we can use this.

Review

Quoted 9 lines
---
  drivers/gpu/drm/scheduler/sched_main.c | 16 +++++++++-------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 12 insertions(+), 10 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/scheduler/sched_main.c

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct

Quoted 4 lines

index 0e6ccc8243db..f213b5c7f718 100644

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -198,7 +198,7 @@ static void drm_sched_job_finish(struct work_struct

*work)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct

Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +1 -1
       * manages to find this job as the next job in the list, the fence
       * signaled check below will prevent the timeout to be restarted.
       */
-     cancel_delayed_work_sync(&s_job->work_tdr);
+     cancel_delayed_work_sync(&sched->work_tdr);
 
      spin_lock(&sched->job_list_lock);
      /* queue TDR for next job */
@@ -207,7 +207,7 @@ static void drm_sched_job_finish(struct work_struct

*work)

Quoted 7 lines

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct *work) · line 209

Quoted 3 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
      if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
          !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
              if (!dma_fence_is_signaled(&next->s_fence->finished))

Since we now have only one delayed work item we can just drop the test if next is already signaled.

Can you elaborate more on this. Which test are you talking about?

Regards,
Nayan

Quoted 101 lines

Regards,
Christian.

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct · line 210

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0 -1
-                     schedule_delayed_work(&next->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct · line 210

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1 -0
+                     schedule_delayed_work(&sched->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct drm_sched_job

Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
      }
      /* remove job from ring_mirror_list */
      list_del(&s_job->node);
@@ -237,7 +237,7 @@ static void drm_sched_job_begin(struct drm_sched_job

*s_job)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct drm_sched_job *s_job)

Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -1
      if (list_first_entry_or_null(&sched->ring_mirror_list,
                              struct drm_sched_job, node) == s_job) {
              if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
-                     schedule_delayed_work(&s_job->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct drm_sched_job · line 240

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +1 -0
+                     schedule_delayed_work(&sched->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct

Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
              sched->curr_job = s_job;
      }
      spin_unlock(&sched->job_list_lock);
@@ -245,8 +245,10 @@ static void drm_sched_job_begin(struct

drm_sched_job *s_job)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct drm_sched_job *s_job)

Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -1
  static void drm_sched_job_timedout(struct work_struct *work)
  {
-     struct drm_sched_job *job = container_of(work, struct

drm_sched_job,

drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_recovery(struct drm_gpu_scheduler

Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +4 -1
-                                              work_tdr.work);
+     struct drm_gpu_scheduler *sched = container_of(work,
+                                             struct drm_gpu_scheduler,
+                                             work_tdr.work);
+     struct drm_sched_job *job = sched->curr_job;
 
      job->sched->ops->timedout_job(job);
  }
@@ -318,7 +320,7 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler

*sched)

include/drm/gpu_scheduler.h struct drm_sched_fence *to_drm_sched_fence(struct

Quoted 29 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
      s_job = list_first_entry_or_null(&sched->ring_mirror_list,
                                       struct drm_sched_job, node);
      if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
-             schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+             schedule_delayed_work(&sched->work_tdr, sched->timeout);
      if (s_job)
              sched->curr_job = s_job;
 
@@ -389,7 +391,6 @@ int drm_sched_job_init(struct drm_sched_job *job,
 
      INIT_WORK(&job->finish_work, drm_sched_job_finish);
      INIT_LIST_HEAD(&job->node);
-     INIT_DELAYED_WORK(&job->work_tdr, drm_sched_job_timedout);
 
      return 0;
  }
@@ -580,6 +581,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched,
      INIT_LIST_HEAD(&sched->ring_mirror_list);
      spin_lock_init(&sched->job_list_lock);
      atomic_set(&sched->hw_rq_count, 0);
+     INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
      atomic_set(&sched->num_jobs, 0);
      atomic64_set(&sched->job_id_count, 0);
 
include/drm/gpu_scheduler.h +0 -0
index 07e776b1ca42..9d50d7f3eaa4 100644
@@ -175,8 +175,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct

dma_fence *f);

include/drm/gpu_scheduler.h struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);

Quoted 3 lines
include/drm/gpu_scheduler.h +0 -0
   *               finished to remove the job from the
   *               @drm_gpu_scheduler.ring_mirror_list.
   * @node: used to append this struct to the

@drm_gpu_scheduler.ring_mirror_list.

include/drm/gpu_scheduler.h struct drm_sched_fence *to_drm_sched_fence(struct · line 178

Quoted 1 line
include/drm/gpu_scheduler.h +0 -1
- * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after

the timeout

include/drm/gpu_scheduler.h struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);

Quoted 3 lines
include/drm/gpu_scheduler.h +0 -1
- *            interval is over.
   * @id: a unique id assigned to each job scheduled on the scheduler.
   * @karma: increment on every hang caused by this job. If this exceeds

the hang

include/drm/gpu_scheduler.h struct drm_sched_fence *to_drm_sched_fence(struct · line 180

Quoted 1 line
include/drm/gpu_scheduler.h +0 -0
   *         limit of the scheduler then the job is marked guilty and

will not

include/drm/gpu_scheduler.h struct drm_sched_backend_ops { · line 260

Quoted 13 lines
include/drm/gpu_scheduler.h +1 -1
@@ -195,7 +193,6 @@ struct drm_sched_job {
      struct dma_fence_cb             finish_cb;
      struct work_struct              finish_work;
      struct list_head                node;
-     struct delayed_work             work_tdr;
      uint64_t                        id;
      atomic_t                        karma;
      enum drm_sched_priority         s_priority;
@@ -260,6 +257,8 @@ struct drm_sched_backend_ops {
   *                 finished.
   * @hw_rq_count: the number of jobs currently in the hardware queue.
   * @job_id_count: used to assign unique id to the each job.
+ * @work_tdr: schedules a delayed call to @drm_sched_job_timedout after

the

include/drm/gpu_scheduler.h struct drm_sched_backend_ops {

Quoted 3 lines
include/drm/gpu_scheduler.h +1 -0
+ *            timeout interval is over.
   * @thread: the kthread on which the scheduler which run.
   * @ring_mirror_list: the list of jobs which are currently in the job

queue.

Quoted 11 lines

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 285

Quoted 9 lines
include/drm/gpu_scheduler.h +1 -0
   * @job_list_lock: lock to protect the ring_mirror_list.
@@ -280,6 +279,7 @@ struct drm_gpu_scheduler {
      wait_queue_head_t               job_scheduled;
      atomic_t                        hw_rq_count;
      atomic64_t                      job_id_count;
+     struct delayed_work             work_tdr;
      struct task_struct              *thread;
      struct list_head                ring_mirror_list;
      spinlock_t                      job_list_lock;

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

#6 lore raw

Re: [PATCH 2/2] drm/scheduler: remove timeout work_struct from drm_sched_job

Am 20.09.2018 um 13:25 schrieb Nayan Deshmukh:

Quoted 55 lines · On Wed, Sep 19, 2018, 9:31 PM Christian König <[email protected]…

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:
> having a delayed work item per job is redundant as we only need one > per scheduler to track the time out the currently executing job.

Well that looks simpler than I thought it would be.

But it shows the next problem that the timeout and the completion could
race.

As far as I can see that can be fixed by moving the dma_fence_remove_callback()/dma_fence_add_callback() dance from drm_sched_hw_job_reset() to drm_sched_job_timedout().

Anyway, I would say drop patch #1 and fix the one comment below and we
can use this.

>
> Signed-off-by: Nayan Deshmukh <[email protected] <mailto:[email protected]>>
> Suggested-by: Christian König <[email protected] <mailto:[email protected]>>
> ---
>   drivers/gpu/drm/scheduler/sched_main.c | 16 +++++++++------- >   include/drm/gpu_scheduler.h            |  6 +++---
>   2 files changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 0e6ccc8243db..f213b5c7f718 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -198,7 +198,7 @@ static void drm_sched_job_finish(struct work_struct *work)
>        * manages to find this job as the next job in the list, the fence
>        * signaled check below will prevent the timeout to be restarted.
>        */
> -  cancel_delayed_work_sync(&s_job->work_tdr);
> +  cancel_delayed_work_sync(&sched->work_tdr);
>
>       spin_lock(&sched->job_list_lock);
>       /* queue TDR for next job */
> @@ -207,7 +207,7 @@ static void drm_sched_job_finish(struct work_struct *work)
>       if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
>           !list_is_last(&s_job->node, &sched->ring_mirror_list)) { >               if (!dma_fence_is_signaled(&next->s_fence->finished))

Quoted 5 lines

Since we now have only one delayed work item we can just drop the test
if next is already signaled.

Can you elaborate more on this. Which test are you talking about?

I was talking about the "!dma_fence_is_signaled()" test here.

Quoted 6 lines

Regards,
Nayan

Quoted 9 lines
    Regards,
    Christian.

    > -  schedule_delayed_work(&next->work_tdr, sched->timeout);
    > +  schedule_delayed_work(&sched->work_tdr, sched->timeout);
    >       }
    >       /* remove job from ring_mirror_list */
    >       list_del(&s_job->node);

Basically you could do this first and then you need to only test if sched->ring_mirror_list is empty.

Regards,
Christian.

Quoted 95 lines

Review static void drm_sched_job_begin(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -237,7 +237,7 @@ static void drm_sched_job_begin(struct
    drm_sched_job *s_job)
    >       if (list_first_entry_or_null(&sched->ring_mirror_list,
    >                               struct drm_sched_job, node) ==
    s_job) {
    >               if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
    > -  schedule_delayed_work(&s_job->work_tdr, sched->timeout);
    > +  schedule_delayed_work(&sched->work_tdr, sched->timeout);
    >               sched->curr_job = s_job;
    >       }
    >       spin_unlock(&sched->job_list_lock);
    > @@ -245,8 +245,10 @@ static void drm_sched_job_begin(struct
    drm_sched_job *s_job)
    >
    >   static void drm_sched_job_timedout(struct work_struct *work)
    >   {
    > -     struct drm_sched_job *job = container_of(work, struct
    drm_sched_job,
    > - work_tdr.work <http://work_tdr.work>);
    > +     struct drm_gpu_scheduler *sched = container_of(work,
    > +                                             struct
    drm_gpu_scheduler,
    > + work_tdr.work <http://work_tdr.work>);
    > +     struct drm_sched_job *job = sched->curr_job;
    >
    >       job->sched->ops->timedout_job(job);
    >   }
    > @@ -318,7 +320,7 @@ void drm_sched_job_recovery(struct
    drm_gpu_scheduler *sched)
    >       s_job = list_first_entry_or_null(&sched->ring_mirror_list,
    >                                        struct drm_sched_job, node);
    >       if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
    > -  schedule_delayed_work(&s_job->work_tdr, sched->timeout);
    > +  schedule_delayed_work(&sched->work_tdr, sched->timeout);
    >       if (s_job)
    >               sched->curr_job = s_job;
    >
    > @@ -389,7 +391,6 @@ int drm_sched_job_init(struct drm_sched_job
    *job,
    >
    >       INIT_WORK(&job->finish_work, drm_sched_job_finish);
    >       INIT_LIST_HEAD(&job->node);
    > -     INIT_DELAYED_WORK(&job->work_tdr, drm_sched_job_timedout);
    >
    >       return 0;
    >   }
    > @@ -580,6 +581,7 @@ int drm_sched_init(struct drm_gpu_scheduler
    *sched,
    >  INIT_LIST_HEAD(&sched->ring_mirror_list);
    >       spin_lock_init(&sched->job_list_lock);
    >       atomic_set(&sched->hw_rq_count, 0);
    > +     INIT_DELAYED_WORK(&sched->work_tdr, drm_sched_job_timedout);
    >       atomic_set(&sched->num_jobs, 0);
    >       atomic64_set(&sched->job_id_count, 0);
    >
    > diff --git a/include/drm/gpu_scheduler.h
    b/include/drm/gpu_scheduler.h
    > index 07e776b1ca42..9d50d7f3eaa4 100644
    > --- a/include/drm/gpu_scheduler.h
    > +++ b/include/drm/gpu_scheduler.h
    > @@ -175,8 +175,6 @@ struct drm_sched_fence
    *to_drm_sched_fence(struct dma_fence *f);
    >    *               finished to remove the job from the
    >    *  @drm_gpu_scheduler.ring_mirror_list.
    >    * @node: used to append this struct to the
    @drm_gpu_scheduler.ring_mirror_list.
    > - * @work_tdr: schedules a delayed call to
    @drm_sched_job_timedout after the timeout
    > - *            interval is over.
    >    * @id: a unique id assigned to each job scheduled on the
    scheduler.
    >    * @karma: increment on every hang caused by this job. If this
    exceeds the hang
    >    *         limit of the scheduler then the job is marked
    guilty and will not
    > @@ -195,7 +193,6 @@ struct drm_sched_job {
    >       struct dma_fence_cb             finish_cb;
    >       struct work_struct              finish_work;
    >       struct list_head                node;
    > -     struct delayed_work             work_tdr;
    >       uint64_t                        id;
    >       atomic_t                        karma;
    >       enum drm_sched_priority         s_priority;
    > @@ -260,6 +257,8 @@ struct drm_sched_backend_ops {
    >    *                 finished.
    >    * @hw_rq_count: the number of jobs currently in the hardware
    queue.
    >    * @job_id_count: used to assign unique id to the each job.
    > + * @work_tdr: schedules a delayed call to
    @drm_sched_job_timedout after the
    > + *            timeout interval is over.
    >    * @thread: the kthread on which the scheduler which run.
    >    * @ring_mirror_list: the list of jobs which are currently in
    the job queue.
    >    * @job_list_lock: lock to protect the ring_mirror_list.
Quoted 9 lines
    > @@ -280,6 +279,7 @@ struct drm_gpu_scheduler {
    >       wait_queue_head_t               job_scheduled;
    >       atomic_t                        hw_rq_count;
    >       atomic64_t                      job_id_count;
    > +     struct delayed_work             work_tdr;
    >       struct task_struct              *thread;
    >       struct list_head ring_mirror_list;
    >       spinlock_t                      job_list_lock;

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

#7 lore raw
In reply to Nayan Deshmukh

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 3 lines

Which points to the job running on the hardware. This is useful when we need to access the currently executing job from the scheduler.

That should be identical to list_first_entry_or_null(&sched->ring_mirror_list), doesn't it?

Regards,
Christian.

Quoted 72 lines

---list_first_entry_or_null(&sched->ring_mirror_list

  drivers/gpu/drm/scheduler/sched_main.c | 17 +++++++++++------
  include/drm/gpu_scheduler.h            |  2 ++
  2 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +11 -6
index 9ca741f3a0bc..0e6ccc8243db 100644
@@ -189,6 +189,7 @@ static void drm_sched_job_finish(struct work_struct *work)
  	struct drm_sched_job *s_job = container_of(work, struct drm_sched_job,
  						   finish_work);
  	struct drm_gpu_scheduler *sched = s_job->sched;
+	struct drm_sched_job *next;
 
  	/*
  	 * Canceling the timeout without removing our job from the ring mirror
@@ -201,10 +202,10 @@ static void drm_sched_job_finish(struct work_struct *work)
 
  	spin_lock(&sched->job_list_lock);
  	/* queue TDR for next job */
+	next = list_next_entry(s_job, node);
+	sched->curr_job = next;
  	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
  	    !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
-		struct drm_sched_job *next = list_next_entry(s_job, node);
-
  		if (!dma_fence_is_signaled(&next->s_fence->finished))
  			schedule_delayed_work(&next->work_tdr, sched->timeout);
  	}
@@ -233,10 +234,12 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 
  	spin_lock(&sched->job_list_lock);
  	list_add_tail(&s_job->node, &sched->ring_mirror_list);
-	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
-	    list_first_entry_or_null(&sched->ring_mirror_list,
-				     struct drm_sched_job, node) == s_job)
-		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+	if (list_first_entry_or_null(&sched->ring_mirror_list,
+				struct drm_sched_job, node) == s_job) {
+		if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
+			schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+		sched->curr_job = s_job;
+	}
  	spin_unlock(&sched->job_list_lock);
  }
 
@@ -316,6 +319,8 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)
  					 struct drm_sched_job, node);
  	if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
  		schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+	if (s_job)
+		sched->curr_job = s_job;
 
  	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
  		struct drm_sched_fence *s_fence = s_job->s_fence;
include/drm/gpu_scheduler.h +1 -0
index daec50f887b3..07e776b1ca42 100644
@@ -252,6 +252,7 @@ struct drm_sched_backend_ops {
   * @timeout: the time after which a job is removed from the scheduler.
   * @name: name of the ring for which this scheduler is being used.
   * @sched_rq: priority wise array of run queues.
+ * @curr_job: points to the job currently running on the hardware
   * @wake_up_worker: the wait queue on which the scheduler sleeps until a job
   *                  is ready to be scheduled.
   * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 281

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -274,6 +275,7 @@ struct drm_gpu_scheduler {
  	long				timeout;
  	const char			*name;
  	struct drm_sched_rq		sched_rq[DRM_SCHED_PRIORITY_MAX];
+	struct drm_sched_job            *curr_job;
  	wait_queue_head_t		wake_up_worker;
  	wait_queue_head_t		job_scheduled;
  	atomic_t			hw_rq_count;

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

#8 lore raw

Hi Christian,

Yes you are correct. My bad.

Do you have any comments on the second patch? I will drop this patch and rebase the second one.

Regards,
Nayan

Quoted 94 lines · Christian

Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:

Quoted 3 lines

Which points to the job running on the hardware. This is useful when we need to access the currently executing job from the scheduler.

That should be identical to list_first_entry_or_null(&sched->ring_mirror_list), doesn't it?

Regards,
Christian.

Review

Quoted 9 lines

---list_first_entry_or_null(&sched->ring_mirror_list

  drivers/gpu/drm/scheduler/sched_main.c | 17 +++++++++++------
  include/drm/gpu_scheduler.h            |  2 ++
  2 files changed, 13 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/scheduler/sched_main.c

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct

Quoted 4 lines

index 9ca741f3a0bc..0e6ccc8243db 100644

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -189,6 +189,7 @@ static void drm_sched_job_finish(struct work_struct

*work)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct · line 189

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0 -0
      struct drm_sched_job *s_job = container_of(work, struct

drm_sched_job,

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct *work)

Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +1 -0
                                                 finish_work);
      struct drm_gpu_scheduler *sched = s_job->sched;
+     struct drm_sched_job *next;
 
      /*
       * Canceling the timeout without removing our job from the ring

mirror

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -201,10 +202,10 @@ static void drm_sched_job_finish(struct

work_struct *work)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_finish(struct work_struct *work)

Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
      spin_lock(&sched->job_list_lock);
      /* queue TDR for next job */
+     next = list_next_entry(s_job, node);
+     sched->curr_job = next;
      if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
          !list_is_last(&s_job->node, &sched->ring_mirror_list)) {
-             struct drm_sched_job *next = list_next_entry(s_job, node);
-
              if (!dma_fence_is_signaled(&next->s_fence->finished))
                      schedule_delayed_work(&next->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct

Quoted 2 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
      }
@@ -233,10 +234,12 @@ static void drm_sched_job_begin(struct

drm_sched_job *s_job)

drivers/gpu/drm/scheduler/sched_main.c static void drm_sched_job_begin(struct drm_sched_job *s_job)

Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +4 -4
      spin_lock(&sched->job_list_lock);
      list_add_tail(&s_job->node, &sched->ring_mirror_list);
-     if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
-         list_first_entry_or_null(&sched->ring_mirror_list,
-                                  struct drm_sched_job, node) == s_job)
-             schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+     if (list_first_entry_or_null(&sched->ring_mirror_list,
+                             struct drm_sched_job, node) == s_job) {
+             if (sched->timeout != MAX_SCHEDULE_TIMEOUT)
+                     schedule_delayed_work(&s_job->work_tdr,

sched->timeout);

drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_recovery(struct drm_gpu_scheduler

Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -0
+             sched->curr_job = s_job;
+     }
      spin_unlock(&sched->job_list_lock);
  }
 
@@ -316,6 +319,8 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler

*sched)

drivers/gpu/drm/scheduler/sched_main.c void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)

Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -0
                                       struct drm_sched_job, node);
      if (s_job && sched->timeout != MAX_SCHEDULE_TIMEOUT)
              schedule_delayed_work(&s_job->work_tdr, sched->timeout);
+     if (s_job)
+             sched->curr_job = s_job;
 
      list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list,

node) {

include/drm/gpu_scheduler.h struct drm_sched_backend_ops { · line 256

Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
              struct drm_sched_fence *s_fence = s_job->s_fence;
include/drm/gpu_scheduler.h +1 -0
index daec50f887b3..07e776b1ca42 100644
@@ -252,6 +252,7 @@ struct drm_sched_backend_ops {
   * @timeout: the time after which a job is removed from the scheduler.
   * @name: name of the ring for which this scheduler is being used.
   * @sched_rq: priority wise array of run queues.
+ * @curr_job: points to the job currently running on the hardware
   * @wake_up_worker: the wait queue on which the scheduler sleeps until

a job

include/drm/gpu_scheduler.h struct drm_sched_backend_ops { · line 258

Quoted 2 lines
include/drm/gpu_scheduler.h +0 -0
   *                  is ready to be scheduled.
   * @job_scheduled: once @drm_sched_entity_do_release is called the

scheduler

Quoted 10 lines

include/drm/gpu_scheduler.h struct drm_gpu_scheduler { · line 281

Quoted 8 lines
include/drm/gpu_scheduler.h +1 -0
@@ -274,6 +275,7 @@ struct drm_gpu_scheduler {
      long                            timeout;
      const char                      *name;
      struct drm_sched_rq             sched_rq[DRM_SCHED_PRIORITY_MAX];
+     struct drm_sched_job            *curr_job;
      wait_queue_head_t               wake_up_worker;
      wait_queue_head_t               job_scheduled;
      atomic_t                        hw_rq_count;

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