<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">
      <blockquote type="cite">
        <p>I don't have strong opinion about where the code should be.
          But if we put this code in VM, there will be one extra array
          index operation because the VM bug is ring related. VM manager
          need to maintain an array to manage this information.</p>
      </blockquote>
      Yeah, but array index suck when you access cache cold stuff as
      well.<br>
      <br>
      My concern is not so much where to put the field, but rather where
      to put the code to detect this condition. That is a bug very
      deeply related to how the CP manages VMs and VMIDs and actually
      not specific to the ring.<br>
      <br>
      Just send out a patch which uses the ring type again to check if
      that workaround applies or not. The heavy stuff was calling
      amdgpu_get_ip_block() on every command submission, one additional
      if shouldn't hurt us here.<br>
      <br>
      Regards,<br>
      Christian.<br>
      <br>
      Am 31.05.2017 um 14:53 schrieb Xie, AlexBin:<br>
    </div>
    <blockquote type="cite"
cite="mid:MWHPR1201MB0045FC6C00CA6008273C385BF2F10@MWHPR1201MB0045.namprd12.prod.outlook.com">
      <meta http-equiv="Content-Type" content="text/html;
        charset=windows-1252">
      <style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
      <div id="divtagdefaultwrapper"
style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;"
        dir="ltr">
        <p>HI Christian,</p>
        <p><br>
        </p>
        <p>Too late. The code has been committed.</p>
        <p><br>
        </p>
        <p>I don't have strong opinion about where the code should be.
          But if we put this code in VM, there will be one extra array
          index operation because the VM bug is ring related. VM manager
          need to maintain an array to manage this information.</p>
        <p><br>
        </p>
        <p>In the <span>amdgpu_ring</span> structure, there is already
          information like <span>
            vm_inv_eng</span> and <span>vmhub</span>. Those are VM
          related information too. So this one extra information is not
          new.
          <br>
        </p>
        <p><br>
        </p>
        Thanks,
        <p>Alex Bin<br>
        </p>
        <div style="color: rgb(0, 0, 0);">
          <div>
            <hr tabindex="-1" style="display:inline-block; width:98%">
            <div id="x_divRplyFwdMsg" dir="ltr"><font
                style="font-size:11pt" face="Calibri, sans-serif"
                color="#000000"><b>From:</b> Christian König
                <a class="moz-txt-link-rfc2396E" href="mailto:deathsimple@vodafone.de"><deathsimple@vodafone.de></a><br>
                <b>Sent:</b> Wednesday, May 31, 2017 2:57 AM<br>
                <b>To:</b> Xie, AlexBin; <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
                <b>Subject:</b> Re: [PATCH 1/3] drm/amdgpu: Optimize a
                function called by every IB sheduling</font>
              <div> </div>
            </div>
          </div>
          <font size="2"><span style="font-size:10pt;">
              <div class="PlainText">Am 30.05.2017 um 23:47 schrieb Alex
                Xie:<br>
                >    Move several if statements and a loop statment
                from<br>
                >    run time to initialization time.<br>
                <br>
                Yeah, that's exactly what I've suggested before as well.<br>
                <br>
                Just keep the code inside amdgpu_vm.c (and the variable
                inside <br>
                amdgpu_vm_manager), since this isn't related to ring
                management at all.<br>
                <br>
                Regards,<br>
                Christian.<br>
                <br>
                ><br>
                > Signed-off-by: Alex Xie <a class="moz-txt-link-rfc2396E" href="mailto:AlexBin.Xie@amd.com"><AlexBin.Xie@amd.com></a><br>
                > ---<br>
                >   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 33
                ++++++++++++++++++++++++++++++++<br>
                >   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  6
                ++++++<br>
                >   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   | 28
                +--------------------------<br>
                >   3 files changed, 40 insertions(+), 27
                deletions(-)<br>
                ><br>
                > diff --git
                a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
                b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
                > index 6a85db0..7d95435 100644<br>
                > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
                > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
                > @@ -153,6 +153,36 @@ void amdgpu_ring_undo(struct
                amdgpu_ring *ring)<br>
                >   }<br>
                >   <br>
                >   /**<br>
                > + * amdgpu_ring_check_compute_vm_bug - check
                whether this ring has compute vm bug<br>
                > + *<br>
                > + * @adev: amdgpu_device pointer<br>
                > + * @ring: amdgpu_ring structure holding ring
                information<br>
                > + */<br>
                > +static void
                amdgpu_ring_check_compute_vm_bug(struct amdgpu_device
                *adev,<br>
                > +                                     struct
                amdgpu_ring *ring)<br>
                > +{<br>
                > +     const struct amdgpu_ip_block *ip_block;<br>
                > +<br>
                > +     ring->has_compute_vm_bug = false;<br>
                > +<br>
                > +     if (ring->funcs->type !=
                AMDGPU_RING_TYPE_COMPUTE)<br>
                > +             /* only compute rings */<br>
                > +             return;<br>
                > +<br>
                > +     ip_block = amdgpu_get_ip_block(adev,
                AMD_IP_BLOCK_TYPE_GFX);<br>
                > +     if (!ip_block)<br>
                > +             return;<br>
                > +<br>
                > +     /* Compute ring has a VM bug for GFX version
                < 7.<br>
                > +           And compute ring has a VM bug for GFX 8
                MEC firmware version < 673.*/<br>
                > +     if (ip_block->version->major <= 7) {<br>
                > +             ring->has_compute_vm_bug = true;<br>
                > +     } else if (ip_block->version->major ==
                8)<br>
                > +             if (adev->gfx.mec_fw_version <
                673)<br>
                > +                     ring->has_compute_vm_bug =
                true;<br>
                > +}<br>
                > +<br>
                > +/**<br>
                >    * amdgpu_ring_init - init driver ring struct.<br>
                >    *<br>
                >    * @adev: amdgpu_device pointer<br>
                > @@ -257,6 +287,9 @@ int amdgpu_ring_init(struct
                amdgpu_device *adev, struct amdgpu_ring *ring,<br>
                >        if (amdgpu_debugfs_ring_init(adev, ring)) {<br>
                >                DRM_ERROR("Failed to register
                debugfs file for rings !\n");<br>
                >        }<br>
                > +<br>
                > +     amdgpu_ring_check_compute_vm_bug(adev, ring);<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 a9223a8..334307e 100644<br>
                > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
                > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
                > @@ -185,6 +185,7 @@ struct amdgpu_ring {<br>
                >        u64                     cond_exe_gpu_addr;<br>
                >        volatile u32            *cond_exe_cpu_addr;<br>
                >        unsigned                vm_inv_eng;<br>
                > +     bool                    has_compute_vm_bug;<br>
                >   #if defined(CONFIG_DEBUG_FS)<br>
                >        struct dentry *ent;<br>
                >   #endif<br>
                > @@ -207,4 +208,9 @@ static inline void
                amdgpu_ring_clear_ring(struct amdgpu_ring *ring)<br>
                >   <br>
                >   }<br>
                >   <br>
                > +static inline bool
                amdgpu_ring_has_compute_vm_bug(struct amdgpu_ring *ring)<br>
                > +{<br>
                > +     return ring->has_compute_vm_bug;<br>
                > +}<br>
                > +<br>
                >   #endif<br>
                > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
                b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
                > index b2384b8..7a323f9 100644<br>
                > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
                > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c<br>
                > @@ -656,32 +656,6 @@ static int
                amdgpu_vm_alloc_reserved_vmid(struct amdgpu_device
                *adev,<br>
                >        return r;<br>
                >   }<br>
                >   <br>
                > -static bool
                amdgpu_vm_ring_has_compute_vm_bug(struct amdgpu_ring
                *ring)<br>
                > -{<br>
                > -     struct amdgpu_device *adev = ring->adev;<br>
                > -     const struct amdgpu_ip_block *ip_block;<br>
                > -<br>
                > -     if (ring->funcs->type !=
                AMDGPU_RING_TYPE_COMPUTE)<br>
                > -             /* only compute rings */<br>
                > -             return false;<br>
                > -<br>
                > -     ip_block = amdgpu_get_ip_block(adev,
                AMD_IP_BLOCK_TYPE_GFX);<br>
                > -     if (!ip_block)<br>
                > -             return false;<br>
                > -<br>
                > -     if (ip_block->version->major <= 7) {<br>
                > -             /* gfx7 has no workaround */<br>
                > -             return true;<br>
                > -     } else if (ip_block->version->major ==
                8) {<br>
                > -             if (adev->gfx.mec_fw_version >=
                673)<br>
                > -                     /* gfx8 is fixed in MEC
                firmware 673 */<br>
                > -                     return false;<br>
                > -             else<br>
                > -                     return true;<br>
                > -     }<br>
                > -     return false;<br>
                > -}<br>
                > -<br>
                >   bool amdgpu_vm_need_pipeline_sync(struct
                amdgpu_ring *ring,<br>
                >                                  struct amdgpu_job
                *job)<br>
                >   {<br>
                > @@ -691,7 +665,7 @@ bool
                amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,<br>
                >        struct amdgpu_vm_id *id;<br>
                >        bool gds_switch_needed;<br>
                >        bool vm_flush_needed =
                job->vm_needs_flush ||<br>
                > -            
                amdgpu_vm_ring_has_compute_vm_bug(ring);<br>
                > +             amdgpu_ring_has_compute_vm_bug(ring);<br>
                >   <br>
                >        if (job->vm_id == 0)<br>
                >                return false;<br>
                <br>
                <br>
              </div>
            </span></font></div>
      </div>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>