<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0078D7;margin:15pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div style="color: rgb(33, 33, 33); background-color: rgb(255, 255, 255); text-align: left;" dir="auto">
Yes I missed <span style="font-family: -apple-system, HelveticaNeue; font-size: 14.6667px; text-align: start; display: inline !important;">gfx_v10_0.c. I will resend a updated one tomorrow. </span></div>
<div id="ms-outlook-mobile-signature" dir="auto" style="text-align: left;">
<div dir="auto" style="text-align: left;"><br>
</div>
<div dir="auto" style="text-align: left;">Regards, </div>
<div dir="auto" style="text-align: left;">Nirmoy </div>
Get <a href="https://aka.ms/ghei36">Outlook for Android</a></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Alex Deucher <alexdeucher@gmail.com><br>
<b>Sent:</b> Thursday, February 27, 2020 10:50:35 PM<br>
<b>To:</b> Nirmoy Das <nirmoy.aiemd@gmail.com><br>
<b>Cc:</b> amd-gfx list <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Das, Nirmoy <Nirmoy.Das@amd.com>; Koenig, Christian <Christian.Koenig@amd.com><br>
<b>Subject:</b> Re: [RFC PATCH 1/4] drm/amdgpu: set compute queue priority at mqd_init</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Thu, Feb 27, 2020 at 4:48 PM Alex Deucher <alexdeucher@gmail.com> wrote:<br>
><br>
> On Thu, Feb 27, 2020 at 4:37 PM Nirmoy Das <nirmoy.aiemd@gmail.com> wrote:<br>
> ><br>
> > We were changing compute ring priority while rings were being used<br>
> > before every job submission which is not recommended. This patch<br>
> > sets compute queue priority at mqd initialization for gfx8 and gfx9.<br>
> ><br>
> > Policy: Enable high priority compute queues only if gpu has >1 MEC, if<br>
> > so PIPE0 and PIPE1 will be in high priority.<br>
><br>
> I think we still want high priority queues on even when there is only<br>
> one MEC.  It might work better on multi-MEC chips, but it should still<br>
> work on single MEC chips.<br>
><br>
> ><br>
> > high/normal priority compute sched list are generated from set of high/normal<br>
> > priority compute queues. At context creation, entity of compute queue<br>
> > get a sched list from high or normal priority depending on ctx->priority<br>
> ><br>
> > Signed-off-by: Nirmoy Das <nirmoy.das@amd.com><br>
> > ---<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   |  4 ----<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c  | 19 +++++++++++++++----<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c  | 14 ++++++++++++++<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h  | 12 ++++++++++++<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  |  6 ------<br>
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +<br>
> >  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 23 ++++++++++++++++++++---<br>
> >  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 20 ++++++++++++++++++++<br>
<br>
Also, can you add a patch for gfx_v10_0.c?<br>
<br>
Alex<br>
<br>
> >  8 files changed, 82 insertions(+), 17 deletions(-)<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
> > index f397ff97b4e4..8304d0c87899 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c<br>
> > @@ -1205,7 +1205,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,<br>
> >         struct amdgpu_fpriv *fpriv = p->filp->driver_priv;<br>
> >         struct drm_sched_entity *entity = p->entity;<br>
> >         enum drm_sched_priority priority;<br>
> > -       struct amdgpu_ring *ring;<br>
> >         struct amdgpu_bo_list_entry *e;<br>
> >         struct amdgpu_job *job;<br>
> >         uint64_t seq;<br>
> > @@ -1258,9 +1257,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,<br>
> >         priority = job->base.s_priority;<br>
> >         drm_sched_entity_push_job(&job->base, entity);<br>
> ><br>
> > -       ring = to_amdgpu_ring(entity->rq->sched);<br>
> > -       amdgpu_ring_priority_get(ring, priority);<br>
> > -<br>
> >         amdgpu_vm_move_to_lru_tail(p->adev, &fpriv->vm);<br>
> ><br>
> >         ttm_eu_fence_buffer_objects(&p->ticket, &p->validated, p->fence);<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> > index 94a6c42f29ea..a1742b1d4f9c 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
> > @@ -85,8 +85,14 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, const u32 hw_ip, const<br>
> >                         num_scheds = 1;<br>
> >                         break;<br>
> >                 case AMDGPU_HW_IP_COMPUTE:<br>
> > -                       scheds = adev->gfx.compute_sched;<br>
> > -                       num_scheds = adev->gfx.num_compute_sched;<br>
> > +                       if (priority > DRM_SCHED_PRIORITY_NORMAL &&<br>
> > +                           adev->gfx.num_compute_sched_high) {<br>
> > +                               scheds = adev->gfx.compute_sched_high;<br>
> > +                               num_scheds = adev->gfx.num_compute_sched_high;<br>
> > +                       } else {<br>
> > +                               scheds = adev->gfx.compute_sched;<br>
> > +                               num_scheds = adev->gfx.num_compute_sched;<br>
> > +                       }<br>
> >                         break;<br>
> >                 case AMDGPU_HW_IP_DMA:<br>
> >                         scheds = adev->sdma.sdma_sched;<br>
> > @@ -638,8 +644,13 @@ void amdgpu_ctx_init_sched(struct amdgpu_device *adev)<br>
> >         }<br>
> ><br>
> >         for (i = 0; i < adev->gfx.num_compute_rings; i++) {<br>
> > -               adev->gfx.compute_sched[i] = &adev->gfx.compute_ring[i].sched;<br>
> > -               adev->gfx.num_compute_sched++;<br>
> > +               if (!adev->gfx.compute_ring[i].high_priority) {<br>
> > +                       adev->gfx.compute_sched[adev->gfx.num_compute_sched++] =<br>
> > +                               &adev->gfx.compute_ring[i].sched;<br>
> > +               } else {<br>
> > +                       adev->gfx.compute_sched_high[adev->gfx.num_compute_sched_high++] =<br>
> > +                               &adev->gfx.compute_ring[i].sched;<br>
> > +               }<br>
> >         }<br>
> ><br>
> >         for (i = 0; i < adev->sdma.num_instances; i++) {<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
> > index 7403588684b3..bdea5d44edf4 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
> > @@ -192,6 +192,20 @@ static bool amdgpu_gfx_is_multipipe_capable(struct amdgpu_device *adev)<br>
> >         return adev->gfx.mec.num_mec > 1;<br>
> >  }<br>
> ><br>
> > +bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,<br>
> > +                                              int queue)<br>
> > +{<br>
> > +       bool multipipe_policy = amdgpu_gfx_is_multipipe_capable(adev);<br>
> > +<br>
> > +       /* only enable high priority queue if more than 1 MEC.<br>
> > +        * When multipipe_policy is true amdgpu gets queue 0,1 from each pipe of<br>
> > +        * 1st MEC. Policy: make queue 0 of each pipe as high priority compute queue */<br>
> > +       if (multipipe_policy && queue == 0)<br>
> > +               return true;<br>
> > +<br>
> > +       return false;<br>
> > +}<br>
> > +<br>
> >  void amdgpu_gfx_compute_queue_acquire(struct amdgpu_device *adev)<br>
> >  {<br>
> >         int i, queue, pipe, mec;<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h<br>
> > index 37ba05b63b2a..13ee0ea66c6f 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h<br>
> > @@ -41,6 +41,14 @@<br>
> >  #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES<br>
> >  #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES<br>
> ><br>
> > +#define AMDGPU_GFX_PIPE_PRIO_LOW    0<br>
> > +#define AMDGPU_GFX_PIPE_PRIO_NORMAL 1<br>
> > +#define AMDGPU_GFX_PIPE_PRIO_HIGH   2<br>
> > +<br>
> > +#define AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM  0<br>
> > +#define AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM  15<br>
> > +<br>
> > +<br>
> >  struct amdgpu_mec {<br>
> >         struct amdgpu_bo        *hpd_eop_obj;<br>
> >         u64                     hpd_eop_gpu_addr;<br>
> > @@ -281,7 +289,9 @@ struct amdgpu_gfx {<br>
> >         unsigned                        num_gfx_rings;<br>
> >         struct amdgpu_ring              compute_ring[AMDGPU_MAX_COMPUTE_RINGS];<br>
> >         struct drm_gpu_scheduler        *compute_sched[AMDGPU_MAX_COMPUTE_RINGS];<br>
> > +       struct drm_gpu_scheduler        *compute_sched_high[AMDGPU_MAX_COMPUTE_RINGS];<br>
> >         uint32_t                        num_compute_sched;<br>
> > +       uint32_t                        num_compute_sched_high;<br>
> >         unsigned                        num_compute_rings;<br>
> >         struct amdgpu_irq_src           eop_irq;<br>
> >         struct amdgpu_irq_src           priv_reg_irq;<br>
> > @@ -363,6 +373,8 @@ void amdgpu_gfx_bit_to_mec_queue(struct amdgpu_device *adev, int bit,<br>
> >                                  int *mec, int *pipe, int *queue);<br>
> >  bool amdgpu_gfx_is_mec_queue_enabled(struct amdgpu_device *adev, int mec,<br>
> >                                      int pipe, int queue);<br>
> > +bool amdgpu_gfx_is_high_priority_compute_queue(struct amdgpu_device *adev,<br>
> > +                                              int queue);<br>
> >  int amdgpu_gfx_me_queue_to_bit(struct amdgpu_device *adev, int me,<br>
> >                                int pipe, int queue);<br>
> >  void amdgpu_gfx_bit_to_me_queue(struct amdgpu_device *adev, int bit,<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
> > index d42be880a236..4981e443a884 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c<br>
> > @@ -117,12 +117,10 @@ void amdgpu_job_free_resources(struct amdgpu_job *job)<br>
> ><br>
> >  static void amdgpu_job_free_cb(struct drm_sched_job *s_job)<br>
> >  {<br>
> > -       struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);<br>
> >         struct amdgpu_job *job = to_amdgpu_job(s_job);<br>
> ><br>
> >         drm_sched_job_cleanup(s_job);<br>
> ><br>
> > -       amdgpu_ring_priority_put(ring, s_job->s_priority);<br>
> >         dma_fence_put(job->fence);<br>
> >         amdgpu_sync_free(&job->sync);<br>
> >         amdgpu_sync_free(&job->sched_sync);<br>
> > @@ -143,7 +141,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,<br>
> >                       void *owner, struct dma_fence **f)<br>
> >  {<br>
> >         enum drm_sched_priority priority;<br>
> > -       struct amdgpu_ring *ring;<br>
> >         int r;<br>
> ><br>
> >         if (!f)<br>
> > @@ -158,9 +155,6 @@ int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,<br>
> >         priority = job->base.s_priority;<br>
> >         drm_sched_entity_push_job(&job->base, entity);<br>
> ><br>
> > -       ring = to_amdgpu_ring(entity->rq->sched);<br>
> > -       amdgpu_ring_priority_get(ring, priority);<br>
> > -<br>
> >         return 0;<br>
> >  }<br>
> ><br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
> > index 24caff085d00..34fcd467f18d 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
> > @@ -222,6 +222,7 @@ struct amdgpu_ring {<br>
> >         struct mutex            priority_mutex;<br>
> >         /* protected by priority_mutex */<br>
> >         int                     priority;<br>
> > +       bool                    high_priority;<br>
> ><br>
> >  #if defined(CONFIG_DEBUG_FS)<br>
> >         struct dentry *ent;<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> > index e63f98b2d389..4260becd569b 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
> > @@ -4426,6 +4426,23 @@ static int gfx_v8_0_deactivate_hqd(struct amdgpu_device *adev, u32 req)<br>
> >         return r;<br>
> >  }<br>
> ><br>
> > +static void gfx_v8_0_mqd_set_priority(struct amdgpu_ring *ring, struct vi_mqd *mqd)<br>
> > +{<br>
> > +       struct amdgpu_device *adev = ring->adev;<br>
> > +<br>
> > +       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {<br>
> > +               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {<br>
> > +                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;<br>
> > +                       ring->high_priority = true;<br>
> > +                       mqd->cp_hqd_queue_priority =<br>
> > +                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;<br>
> > +                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);<br>
><br>
> I think we can move this back to mqd_init().  It needs to be set up<br>
> for both low and high priority queues.<br>
><br>
> > +               }<br>
> > +               else<br>
> > +                       ring->high_priority = false;<br>
> > +       }<br>
> > +}<br>
> > +<br>
> >  static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)<br>
> >  {<br>
> >         struct amdgpu_device *adev = ring->adev;<br>
> > @@ -4549,9 +4566,6 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)<br>
> >         /* defaults */<br>
> >         mqd->cp_hqd_eop_rptr = RREG32(mmCP_HQD_EOP_RPTR);<br>
> >         mqd->cp_hqd_eop_wptr = RREG32(mmCP_HQD_EOP_WPTR);<br>
> > -       mqd->cp_hqd_pipe_priority = RREG32(mmCP_HQD_PIPE_PRIORITY);<br>
> > -       mqd->cp_hqd_queue_priority = RREG32(mmCP_HQD_QUEUE_PRIORITY);<br>
> > -       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);<br>
> >         mqd->cp_hqd_ctx_save_base_addr_lo = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_LO);<br>
> >         mqd->cp_hqd_ctx_save_base_addr_hi = RREG32(mmCP_HQD_CTX_SAVE_BASE_ADDR_HI);<br>
> >         mqd->cp_hqd_cntl_stack_offset = RREG32(mmCP_HQD_CNTL_STACK_OFFSET);<br>
> > @@ -4563,6 +4577,9 @@ static int gfx_v8_0_mqd_init(struct amdgpu_ring *ring)<br>
> >         mqd->cp_hqd_eop_wptr_mem = RREG32(mmCP_HQD_EOP_WPTR_MEM);<br>
> >         mqd->cp_hqd_eop_dones = RREG32(mmCP_HQD_EOP_DONES);<br>
> ><br>
> > +       /* set static priority for a queue/ring */<br>
> > +       gfx_v8_0_mqd_set_priority(ring, mqd);<br>
> > +<br>
> >         /* map_queues packet doesn't need activate the queue,<br>
> >          * so only kiq need set this field.<br>
> >          */<br>
> > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
> > index 4135e4126e82..85a54849abd1 100644<br>
> > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
> > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
> > @@ -3310,6 +3310,23 @@ static void gfx_v9_0_kiq_setting(struct amdgpu_ring *ring)<br>
> >         WREG32_SOC15_RLC(GC, 0, mmRLC_CP_SCHEDULERS, tmp);<br>
> >  }<br>
> ><br>
> > +static void gfx_v9_0_mqd_set_priority(struct amdgpu_ring *ring, struct v9_mqd *mqd)<br>
> > +{<br>
> > +       struct amdgpu_device *adev = ring->adev;<br>
> > +<br>
> > +       if (ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) {<br>
> > +               if (amdgpu_gfx_is_high_priority_compute_queue(adev, ring->queue)) {<br>
> > +                       mqd->cp_hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_HIGH;<br>
> > +                       ring->high_priority = true;<br>
> > +                       mqd->cp_hqd_queue_priority =<br>
> > +                               AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM;<br>
> > +                       mqd->cp_hqd_quantum = RREG32(mmCP_HQD_QUANTUM);<br>
><br>
> Same comment here.<br>
><br>
> Alex<br>
><br>
> > +               }<br>
> > +               else<br>
> > +                       ring->high_priority = false;<br>
> > +       }<br>
> > +}<br>
> > +<br>
> >  static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)<br>
> >  {<br>
> >         struct amdgpu_device *adev = ring->adev;<br>
> > @@ -3446,6 +3463,9 @@ static int gfx_v9_0_mqd_init(struct amdgpu_ring *ring)<br>
> >         tmp = REG_SET_FIELD(tmp, CP_HQD_IB_CONTROL, MIN_IB_AVAIL_SIZE, 3);<br>
> >         mqd->cp_hqd_ib_control = tmp;<br>
> ><br>
> > +       /* set static priority for a queue/ring */<br>
> > +       gfx_v9_0_mqd_set_priority(ring, mqd);<br>
> > +<br>
> >         /* map_queues packet doesn't need activate the queue,<br>
> >          * so only kiq need set this field.<br>
> >          */<br>
> > --<br>
> > 2.25.0<br>
> ><br>
> > _______________________________________________<br>
> > amd-gfx mailing list<br>
> > amd-gfx@lists.freedesktop.org<br>
> > <a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cnirmoy.das%40amd.com%7C9cd63275980e426c420808d7bbcf1b33%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637184370519368178&amp;sdata=qvENGcFENLfXkn3HiA0yeGwo1N0dU2meZm51kD%2FdjsE%3D&amp;reserved=0">
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=02%7C01%7Cnirmoy.das%40amd.com%7C9cd63275980e426c420808d7bbcf1b33%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637184370519368178&amp;sdata=qvENGcFENLfXkn3HiA0yeGwo1N0dU2meZm51kD%2FdjsE%3D&amp;reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>