Skip to contentSkip to conversation

drm/scheduler: remove timeout work_struct from drm_sched_job

PATCH Superseded Nayan Deshmukh 3 participants 9 messages Sep 21, 2018 – Oct 4, 2018

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

PATCH v2 1/1 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
 drivers/gpu/drm/scheduler/sched_main.c | 28 +++++++++++++++-------------
 include/drm/gpu_scheduler.h            |  6 +++---
 2 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +15 -13
index 9ca741f3a0bc..88f6cff136f2 100644
@@ -197,19 +197,16 @@ 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 */
+	list_del(&s_job->node);
 	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);
+	    !list_empty(&sched->ring_mirror_list)) {
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	}
 	/* remove job from ring_mirror_list */
-	list_del(&s_job->node);
 	spin_unlock(&sched->job_list_lock);
 
 	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +233,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	spin_unlock(&sched->job_list_lock);
 }
 
 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;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);
 }
 
 /**
@@ -315,7 +317,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);
 
 	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
 		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +386,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;
 }
@@ -575,6 +576,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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.
@@ -278,6 +277,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
#1 lore raw

Am 21.09.2018 um 20:57 schrieb Nayan Deshmukh:

Quoted 26 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
  drivers/gpu/drm/scheduler/sched_main.c | 28 +++++++++++++++-------------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 18 insertions(+), 16 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -1
index 9ca741f3a0bc..88f6cff136f2 100644
@@ -197,19 +197,16 @@ 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 208

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +3 -5
+	list_del(&s_job->node);
  	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);
+	    !list_empty(&sched->ring_mirror_list)) {
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	}

You can remove the {} here as well.

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

Quoted 1 line
drivers/gpu/drm/scheduler/sched_main.c +0 -0
  	/* remove job from ring_mirror_list */

That comment should move with the list_del().

Apart from that it looks good to me,
Christian.

Quoted 86 lines
drivers/gpu/drm/scheduler/sched_main.c +11 -7
-	list_del(&s_job->node);
  	spin_unlock(&sched->job_list_lock);
 
  	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +233,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
  	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	spin_unlock(&sched->job_list_lock);
  }
 
  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;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);
  }
 
  /**
@@ -315,7 +317,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);
 
  	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
  		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +386,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;
  }
@@ -575,6 +576,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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 283

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -278,6 +277,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

#2 lore raw

PATCH v2 1/1 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
 drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
 include/drm/gpu_scheduler.h            |  6 +++---
 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +16 -15
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-	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);
-	}
 	/* remove job from ring_mirror_list */
 	list_del(&s_job->node);
+	/* queue TDR for next job */
+	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+	    !list_empty(&sched->ring_mirror_list))
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	spin_unlock(&sched->job_list_lock);
 
 	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	spin_unlock(&sched->job_list_lock);
 }
 
 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;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);
 }
 
 /**
@@ -315,7 +316,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);
 
 	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
 		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
 }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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.
@@ -278,6 +277,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
reviewer Reviewed-by on v2 1/1
#3 lore raw

Am 25.09.2018 um 19:09 schrieb Nayan Deshmukh:

Quoted 8 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

Going to push that into our branch on the next best occasion.

Christian.

Quoted 116 lines
---
  drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +16 -15
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-	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);
-	}
  	/* remove job from ring_mirror_list */
  	list_del(&s_job->node);
+	/* queue TDR for next job */
+	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+	    !list_empty(&sched->ring_mirror_list))
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	spin_unlock(&sched->job_list_lock);
 
  	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
  	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	spin_unlock(&sched->job_list_lock);
  }
 
  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;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);
  }
 
  /**
@@ -315,7 +316,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);
 
  	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
  		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
  }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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 283

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -278,6 +277,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

#4 lore raw
In reply to Nayan Deshmukh

Hi Nayan,

Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:

Quoted 55 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
 drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
 include/drm/gpu_scheduler.h            |  6 +++---
 2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +6 -12
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-	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);
-	}
 	/* remove job from ring_mirror_list */
 	list_del(&s_job->node);
+	/* queue TDR for next job */
+	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+	    !list_empty(&sched->ring_mirror_list))
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	spin_unlock(&sched->job_list_lock);
 
 	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
 	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
 	spin_unlock(&sched->job_list_lock);
 }
 
 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);

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

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8 -1
+	struct drm_gpu_scheduler *sched;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);

I don't think this is fully robust. Jobs are only removed from the ring_mirror_list once the job_finish worker has run. If execution of this worker is delayed for any reason (though it's really unlikely for a delay as long as the job timeout to happen) you are blaming the wrong job here.

So I think what you need to to is find the first job in the ring mirror list with an unsignaled finish fence to robustly find the stuck job.

Regards,
Lucas

Quoted 59 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
 }
 
 /**
@@ -315,7 +316,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);
 
 	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
 		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
 }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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 283

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -278,6 +277,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

#5 lore raw

Am 26.09.2018 um 09:39 schrieb Lucas Stach:

Quoted 74 lines

Hi Nayan,

Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:

Quoted 55 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
  drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +6 -12
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-	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);
-	}
  	/* remove job from ring_mirror_list */
  	list_del(&s_job->node);
+	/* queue TDR for next job */
+	if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+	    !list_empty(&sched->ring_mirror_list))
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	spin_unlock(&sched->job_list_lock);
 
  	dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
  	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);
+		schedule_delayed_work(&sched->work_tdr, sched->timeout);
  	spin_unlock(&sched->job_list_lock);
  }
 
  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);

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

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8 -1
+	struct drm_gpu_scheduler *sched;
+	struct drm_sched_job *job;
+
+	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+	job = list_first_entry_or_null(&sched->ring_mirror_list,
+				       struct drm_sched_job, node);
 
-	job->sched->ops->timedout_job(job);
+	if (job)
+		job->sched->ops->timedout_job(job);

I don't think this is fully robust. Jobs are only removed from the ring_mirror_list once the job_finish worker has run. If execution of this worker is delayed for any reason (though it's really unlikely for a delay as long as the job timeout to happen) you are blaming the wrong job here.

Quoted 2 lines

So I think what you need to to is find the first job in the ring mirror list with an unsignaled finish fence to robustly find the stuck job.

Yeah, that is a known problem I've pointed out as well.

The issue is we have bug reports that this happened before the patch, but I'm not 100% sure how.

My suggestion is to move a good part of the logic from drm_sched_hw_job_reset() and drm_sched_job_recovery() into drm_sched_job_timedout().

E.g. we first call dma_fence_remove_callback() for each job and actually check the return value if the fence was already signaled.

If we find a signaled fence we abort and add the callback back to the ones where we removed it.

Nayan do you want to take care of this or should I take a look?

Regards,
Christian.

Quoted 66 lines

Regards,
Lucas

Quoted 62 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
  }
 
  /**
@@ -315,7 +316,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);
 
  	list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
  		struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
  }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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.
@@ -278,6 +277,7 @@ struct drm_gpu_scheduler {
  	wait_queue_head_t		job_scheduled;
  	atomic_t			hw_rq_count;
  	atomic64_t			job_id_count;
Quoted 8 lines

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

Quoted 4 lines
include/drm/gpu_scheduler.h +1 -0
+	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

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

#6 lore raw

Hi Christian,

Quoted 94 lines · Christian König

Am 26.09.2018 um 09:39 schrieb Lucas Stach:

Quoted 13 lines

Hi Nayan,

Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:

Quoted 10 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
  drivers/gpu/drm/scheduler/sched_main.c | 31

++++++++++++++++---------------

Quoted 4 lines

Review

Quoted 4 lines
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 19 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

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

Quoted 4 lines

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

Quoted 4 lines

index 9ca741f3a0bc..4e8505d51795 100644

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -197,19 +197,15 @@ static void drm_sched_job_finish(struct

work_struct *work)

Quoted 6 lines
Quoted 6 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);
 
Quoted 8 lines

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

Quoted 8 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -7
     spin_lock(&sched->job_list_lock);
-    /* queue TDR for next job */
-    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);

Quoted 11 lines

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

Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +4 -1
-    }
     /* remove job from ring_mirror_list */
     list_del(&s_job->node);
+    /* queue TDR for next job */
+    if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+        !list_empty(&sched->ring_mirror_list))
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
     spin_unlock(&sched->job_list_lock);
 
     dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct

drm_sched_job *s_job)

Quoted 11 lines

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 +1 -2
     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);
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
     spin_unlock(&sched->job_list_lock);
  }
 
  static void drm_sched_job_timedout(struct work_struct *work)
  {
-    struct drm_sched_job *job = container_of(work, struct

drm_sched_job,

Quoted 5 lines

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

Quoted 5 lines
drivers/gpu/drm/scheduler/sched_main.c +4 -1
-                                             work_tdr.work);
+    struct drm_gpu_scheduler *sched;
+    struct drm_sched_job *job;
+
+    sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work

);

Quoted 6 lines

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

Quoted 6 lines
drivers/gpu/drm/scheduler/sched_main.c +4 -1
+    job = list_first_entry_or_null(&sched->ring_mirror_list,
+                                   struct drm_sched_job, node);
 
-    job->sched->ops->timedout_job(job);
+    if (job)
+            job->sched->ops->timedout_job(job);
Quoted 8 lines

I don't think this is fully robust. Jobs are only removed from the ring_mirror_list once the job_finish worker has run. If execution of this worker is delayed for any reason (though it's really unlikely for a delay as long as the job timeout to happen) you are blaming the wrong job here.

So I think what you need to to is find the first job in the ring mirror list with an unsignaled finish fence to robustly find the stuck job.

Yeah, that is a known problem I've pointed out as well.

The issue is we have bug reports that this happened before the patch, but I'm not 100% sure how.

My suggestion is to move a good part of the logic from drm_sched_hw_job_reset() and drm_sched_job_recovery() into drm_sched_job_timedout().

Quoted 8 lines

E.g. we first call dma_fence_remove_callback() for each job and actually check the return value if the fence was already signaled.

If we find a signaled fence we abort and add the callback back to the ones where we removed it.

Nayan do you want to take care of this or should I take a look?

I can take care of it.

Regards,
Nayan

Quoted 70 lines

Regards,
Christian.

Quoted 8 lines

Regards,
Lucas

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

Quoted 4 lines
drivers/gpu/drm/scheduler/sched_main.c +0 -0
  }
 
  /**
@@ -315,7 +316,7 @@ void drm_sched_job_recovery(struct

drm_gpu_scheduler *sched)

Quoted 7 lines

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 +1 -1
     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);
 
     list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list,

node) {

Quoted 17 lines
Quoted 17 lines
drivers/gpu/drm/scheduler/sched_main.c +1 -1
             struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
  }
@@ -575,6 +575,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);
 
Quoted 5 lines

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

Quoted 5 lines
include/drm/gpu_scheduler.h +0 -0
index daec50f887b3..d87b268f1781 100644
@@ -175,8 +175,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct

dma_fence *f);

Quoted 3 lines

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.

Quoted 1 line

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

Quoted 3 lines

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

Quoted 1 line

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

Quoted 5 lines
Quoted 5 lines
include/drm/gpu_scheduler.h +0 -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;
Quoted 8 lines

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

Quoted 8 lines
include/drm/gpu_scheduler.h +1 -0
     uint64_t                        id;
     atomic_t                        karma;
     enum drm_sched_priority         s_priority;
@@ -259,6 +256,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

Quoted 19 lines
Quoted 3 lines

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 13 lines

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

Quoted 9 lines
include/drm/gpu_scheduler.h +1 -0
   * @job_list_lock: lock to protect the ring_mirror_list.
@@ -278,6 +277,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

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

#7 lore raw

Hi Christian,

Quoted 96 lines · Nayan Deshmukh

Hi Christian,

Quoted 91 lines · Christian König

Am 26.09.2018 um 09:39 schrieb Lucas Stach:

Quoted 74 lines

Hi Nayan,

Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:

Quoted 55 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
  drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
  include/drm/gpu_scheduler.h            |  6 +++---
  2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +6 -12
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-    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);
-    }
     /* remove job from ring_mirror_list */
     list_del(&s_job->node);
+    /* queue TDR for next job */
+    if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+        !list_empty(&sched->ring_mirror_list))
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
     spin_unlock(&sched->job_list_lock);
 
     dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
     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);
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
     spin_unlock(&sched->job_list_lock);
  }
 
  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);

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

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8 -1
+    struct drm_gpu_scheduler *sched;
+    struct drm_sched_job *job;
+
+    sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+    job = list_first_entry_or_null(&sched->ring_mirror_list,
+                                   struct drm_sched_job, node);
 
-    job->sched->ops->timedout_job(job);
+    if (job)
+            job->sched->ops->timedout_job(job);

I don't think this is fully robust. Jobs are only removed from the ring_mirror_list once the job_finish worker has run. If execution of this worker is delayed for any reason (though it's really unlikely for a delay as long as the job timeout to happen) you are blaming the wrong job here.

Quoted 2 lines

So I think what you need to to is find the first job in the ring mirror list with an unsignaled finish fence to robustly find the stuck job.

Yeah, that is a known problem I've pointed out as well.

The issue is we have bug reports that this happened before the patch, but I'm not 100% sure how.

My suggestion is to move a good part of the logic from drm_sched_hw_job_reset() and drm_sched_job_recovery() into drm_sched_job_timedout().

E.g. we first call dma_fence_remove_callback() for each job and actually check the return value if the fence was already signaled.

We can move this part to drm_sched_job_timedout().

Quoted 3 lines
Quoted 3 lines

If we find a signaled fence we abort and add the callback back to the ones where we removed it.

I was not able to find the abort part. In drm_sched_hw_job_reset() we don't take a action if the parent fence was already signaled.

We cannot shift a lot from drm_sched_job_recovery() to drm_sched_job_timedout(). The only part that seems shiftable is the one where we cancel the guilty job.

Regards,
Nayan

Quoted 86 lines
Quoted 1 line

Nayan do you want to take care of this or should I take a look?

I can take care of it.

Regards,
Nayan

Quoted 80 lines

Regards,
Christian.

Quoted 74 lines

Regards,
Lucas

Quoted 59 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
  }
 
  /**
@@ -315,7 +316,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);
 
     list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
             struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
  }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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 283

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -278,6 +277,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

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

#8 lore raw

Am 04.10.2018 um 18:32 schrieb Nayan Deshmukh:

Quoted 97 lines

Hi Christian,

Quoted 93 lines · Nayan Deshmukh

Hi Christian,

Quoted 89 lines · Christian König

Am 26.09.2018 um 09:39 schrieb Lucas Stach:

Quoted 74 lines

Hi Nayan,

Am Mittwoch, den 26.09.2018, 02:09 +0900 schrieb Nayan Deshmukh:

Quoted 55 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.

v2: the first element of the ring mirror list is the currently executing job so we don't need a additional variable for it

---
   drivers/gpu/drm/scheduler/sched_main.c | 31 ++++++++++++++++---------------
   include/drm/gpu_scheduler.h            |  6 +++---
   2 files changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +6 -12
index 9ca741f3a0bc..4e8505d51795 100644
@@ -197,19 +197,15 @@ 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 */
-    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);
-    }
      /* remove job from ring_mirror_list */
      list_del(&s_job->node);
+    /* queue TDR for next job */
+    if (sched->timeout != MAX_SCHEDULE_TIMEOUT &&
+        !list_empty(&sched->ring_mirror_list))
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
      spin_unlock(&sched->job_list_lock);
 
      dma_fence_put(&s_job->s_fence->finished);
@@ -236,16 +232,21 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)
      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);
+            schedule_delayed_work(&sched->work_tdr, sched->timeout);
      spin_unlock(&sched->job_list_lock);
   }
 
   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);

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

Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +8 -1
+    struct drm_gpu_scheduler *sched;
+    struct drm_sched_job *job;
+
+    sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
+    job = list_first_entry_or_null(&sched->ring_mirror_list,
+                                   struct drm_sched_job, node);
 
-    job->sched->ops->timedout_job(job);
+    if (job)
+            job->sched->ops->timedout_job(job);

I don't think this is fully robust. Jobs are only removed from the ring_mirror_list once the job_finish worker has run. If execution of this worker is delayed for any reason (though it's really unlikely for a delay as long as the job timeout to happen) you are blaming the wrong job here.

Quoted 2 lines

So I think what you need to to is find the first job in the ring mirror list with an unsignaled finish fence to robustly find the stuck job.

Yeah, that is a known problem I've pointed out as well.

The issue is we have bug reports that this happened before the patch, but I'm not 100% sure how.

My suggestion is to move a good part of the logic from drm_sched_hw_job_reset() and drm_sched_job_recovery() into drm_sched_job_timedout().

E.g. we first call dma_fence_remove_callback() for each job and actually check the return value if the fence was already signaled.

Quoted 7 lines

We can move this part to drm_sched_job_timedout().

Quoted 3 lines
Quoted 3 lines

If we find a signaled fence we abort and add the callback back to the ones where we removed it.

I was not able to find the abort part. In drm_sched_hw_job_reset() we don't take a action if the parent fence was already signaled.

That is a bug a swell.

Quoted 3 lines

We cannot shift a lot from drm_sched_job_recovery() to drm_sched_job_timedout(). The only part that seems shiftable is the one where we cancel the guilty job.

Actually I wanted to completely rework that part since it is rather unreliable as well.

Considering how buggy all of that is and how important it is to get it right I think I will rather do it myself.

Regards,
Christian.

Quoted 85 lines

Regards,
Nayan

Quoted 82 lines
Quoted 1 line

Nayan do you want to take care of this or should I take a look?

I can take care of it.

Regards,
Nayan

Quoted 77 lines

Regards,
Christian.

Quoted 73 lines

Regards,
Lucas

Quoted 59 lines
drivers/gpu/drm/scheduler/sched_main.c +2 -2
   }
 
   /**
@@ -315,7 +316,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);
 
      list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
              struct drm_sched_fence *s_fence = s_job->s_fence;
@@ -384,7 +385,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;
   }
@@ -575,6 +575,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 daec50f887b3..d87b268f1781 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;
@@ -259,6 +256,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 283

Quoted 7 lines
include/drm/gpu_scheduler.h +1 -0
@@ -278,6 +277,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

Quoted 4 lines

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

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