diff mbox series

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

Message ID 20180918161710.2669-1-nayan26deshmukh@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/2] drm/scheduler: add a current job field to scheduler | expand

Commit Message

Nayan Deshmukh Sept. 18, 2018, 4:17 p.m. UTC
Which points to the job running on the hardware. This is
useful when we need to access the currently executing job
from the scheduler.

Signed-off-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
---
 drivers/gpu/drm/scheduler/sched_main.c | 17 +++++++++++------
 include/drm/gpu_scheduler.h            |  2 ++
 2 files changed, 13 insertions(+), 6 deletions(-)

Comments

Christian König Sept. 18, 2018, 5:09 p.m. UTC | #1
Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:
> 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.

>
> Signed-off-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
> ---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(-)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 9ca741f3a0bc..0e6ccc8243db 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -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;
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index daec50f887b3..07e776b1ca42 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -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;
Nayan Deshmukh Sept. 18, 2018, 11:13 p.m. UTC | #2
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


On Wed, Sep 19, 2018, 2:09 AM Koenig, Christian <Christian.Koenig@amd.com>
wrote:

> Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:
> > 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.
>
> >
> > Signed-off-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
> > ---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(-)
> >
> > diff --git a/drivers/gpu/drm/scheduler/sched_main.c
> b/drivers/gpu/drm/scheduler/sched_main.c
> > index 9ca741f3a0bc..0e6ccc8243db 100644
> > --- a/drivers/gpu/drm/scheduler/sched_main.c
> > +++ b/drivers/gpu/drm/scheduler/sched_main.c
> > @@ -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;
> > diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> > index daec50f887b3..07e776b1ca42 100644
> > --- a/include/drm/gpu_scheduler.h
> > +++ b/include/drm/gpu_scheduler.h
> > @@ -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;
>
>
<div dir="auto"><div><div dir="ltr" style="font-family:sans-serif">Hi Christian,<br></div><div dir="auto" style="font-family:sans-serif"><div dir="auto"><br></div><div dir="auto">Yes you are correct. My bad. </div><div dir="auto"><br></div><div dir="auto">Do you have any comments on the second patch? I will drop this patch and rebase the second one.</div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Nayan</div></div><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 19, 2018, 2:09 AM Koenig, Christian &lt;<a href="mailto:Christian.Koenig@amd.com">Christian.Koenig@amd.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 18.09.2018 um 18:17 schrieb Nayan Deshmukh:<br>
&gt; Which points to the job running on the hardware. This is<br>
&gt; useful when we need to access the currently executing job<br>
&gt; from the scheduler.<br>
<br>
That should be identical to <br>
list_first_entry_or_null(&amp;sched-&gt;ring_mirror_list), doesn&#39;t it?<br>
<br>
Regards,<br>
Christian.<br>
<br>
&gt;<br>
&gt; Signed-off-by: Nayan Deshmukh &lt;<a href="mailto:nayan26deshmukh@gmail.com" target="_blank" rel="noreferrer">nayan26deshmukh@gmail.com</a>&gt;<br>
&gt; ---list_first_entry_or_null(&amp;sched-&gt;ring_mirror_list<br>
&gt;<br>
&gt;   drivers/gpu/drm/scheduler/sched_main.c | 17 +++++++++++------<br>
&gt;   include/drm/gpu_scheduler.h            |  2 ++<br>
&gt;   2 files changed, 13 insertions(+), 6 deletions(-)<br>
&gt;<br>
&gt; diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c<br>
&gt; index 9ca741f3a0bc..0e6ccc8243db 100644<br>
&gt; --- a/drivers/gpu/drm/scheduler/sched_main.c<br>
&gt; +++ b/drivers/gpu/drm/scheduler/sched_main.c<br>
&gt; @@ -189,6 +189,7 @@ static void drm_sched_job_finish(struct work_struct *work)<br>
&gt;       struct drm_sched_job *s_job = container_of(work, struct drm_sched_job,<br>
&gt;                                                  finish_work);<br>
&gt;       struct drm_gpu_scheduler *sched = s_job-&gt;sched;<br>
&gt; +     struct drm_sched_job *next;<br>
&gt;   <br>
&gt;       /*<br>
&gt;        * Canceling the timeout without removing our job from the ring mirror<br>
&gt; @@ -201,10 +202,10 @@ static void drm_sched_job_finish(struct work_struct *work)<br>
&gt;   <br>
&gt;       spin_lock(&amp;sched-&gt;job_list_lock);<br>
&gt;       /* queue TDR for next job */<br>
&gt; +     next = list_next_entry(s_job, node);<br>
&gt; +     sched-&gt;curr_job = next;<br>
&gt;       if (sched-&gt;timeout != MAX_SCHEDULE_TIMEOUT &amp;&amp;<br>
&gt;           !list_is_last(&amp;s_job-&gt;node, &amp;sched-&gt;ring_mirror_list)) {<br>
&gt; -             struct drm_sched_job *next = list_next_entry(s_job, node);<br>
&gt; -<br>
&gt;               if (!dma_fence_is_signaled(&amp;next-&gt;s_fence-&gt;finished))<br>
&gt;                       schedule_delayed_work(&amp;next-&gt;work_tdr, sched-&gt;timeout);<br>
&gt;       }<br>
&gt; @@ -233,10 +234,12 @@ static void drm_sched_job_begin(struct drm_sched_job *s_job)<br>
&gt;   <br>
&gt;       spin_lock(&amp;sched-&gt;job_list_lock);<br>
&gt;       list_add_tail(&amp;s_job-&gt;node, &amp;sched-&gt;ring_mirror_list);<br>
&gt; -     if (sched-&gt;timeout != MAX_SCHEDULE_TIMEOUT &amp;&amp;<br>
&gt; -         list_first_entry_or_null(&amp;sched-&gt;ring_mirror_list,<br>
&gt; -                                  struct drm_sched_job, node) == s_job)<br>
&gt; -             schedule_delayed_work(&amp;s_job-&gt;work_tdr, sched-&gt;timeout);<br>
&gt; +     if (list_first_entry_or_null(&amp;sched-&gt;ring_mirror_list,<br>
&gt; +                             struct drm_sched_job, node) == s_job) {<br>
&gt; +             if (sched-&gt;timeout != MAX_SCHEDULE_TIMEOUT)<br>
&gt; +                     schedule_delayed_work(&amp;s_job-&gt;work_tdr, sched-&gt;timeout);<br>
&gt; +             sched-&gt;curr_job = s_job;<br>
&gt; +     }<br>
&gt;       spin_unlock(&amp;sched-&gt;job_list_lock);<br>
&gt;   }<br>
&gt;   <br>
&gt; @@ -316,6 +319,8 @@ void drm_sched_job_recovery(struct drm_gpu_scheduler *sched)<br>
&gt;                                        struct drm_sched_job, node);<br>
&gt;       if (s_job &amp;&amp; sched-&gt;timeout != MAX_SCHEDULE_TIMEOUT)<br>
&gt;               schedule_delayed_work(&amp;s_job-&gt;work_tdr, sched-&gt;timeout);<br>
&gt; +     if (s_job)<br>
&gt; +             sched-&gt;curr_job = s_job;<br>
&gt;   <br>
&gt;       list_for_each_entry_safe(s_job, tmp, &amp;sched-&gt;ring_mirror_list, node) {<br>
&gt;               struct drm_sched_fence *s_fence = s_job-&gt;s_fence;<br>
&gt; diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h<br>
&gt; index daec50f887b3..07e776b1ca42 100644<br>
&gt; --- a/include/drm/gpu_scheduler.h<br>
&gt; +++ b/include/drm/gpu_scheduler.h<br>
&gt; @@ -252,6 +252,7 @@ struct drm_sched_backend_ops {<br>
&gt;    * @timeout: the time after which a job is removed from the scheduler.<br>
&gt;    * @name: name of the ring for which this scheduler is being used.<br>
&gt;    * @sched_rq: priority wise array of run queues.<br>
&gt; + * @curr_job: points to the job currently running on the hardware<br>
&gt;    * @wake_up_worker: the wait queue on which the scheduler sleeps until a job<br>
&gt;    *                  is ready to be scheduled.<br>
&gt;    * @job_scheduled: once @drm_sched_entity_do_release is called the scheduler<br>
&gt; @@ -274,6 +275,7 @@ struct drm_gpu_scheduler {<br>
&gt;       long                            timeout;<br>
&gt;       const char                      *name;<br>
&gt;       struct drm_sched_rq             sched_rq[DRM_SCHED_PRIORITY_MAX];<br>
&gt; +     struct drm_sched_job            *curr_job;<br>
&gt;       wait_queue_head_t               wake_up_worker;<br>
&gt;       wait_queue_head_t               job_scheduled;<br>
&gt;       atomic_t                        hw_rq_count;<br>
<br>
</blockquote></div></div></div>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index 9ca741f3a0bc..0e6ccc8243db 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -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;
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index daec50f887b3..07e776b1ca42 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -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;