<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">
      <blockquote type="cite">
        <p>so the conclusion is if we have vm-flush, we make sure 128dw
          between vm flush and CE ib, if we don't insert vm flush we
          stil make sure 128 DW between SWITCH_BUFFER and CE ib.</p>
      </blockquote>
      Good point.<br>
      <br>
      <blockquote type="cite">
        <p>if you reject this patch, please give me a solution to fix
          above VM fault <br>
        </p>
      </blockquote>
      Well, we could follow the windows approach, e.g. increase padding
      to 256dw and separate the VM flush in it's own submission.<br>
      <br>
      But that's more a long term fix, for now I'm ok with that patch
      and just reviewed your v4 of it.<br>
      <br>
      Regards,<br>
      Christian.<br>
      <br>
      Am 19.01.2017 um 04:19 schrieb Liu, Monk:<br>
    </div>
    <blockquote
cite="mid:BY2PR1201MB11109CD4EC58A7C8F9C180CA847E0@BY2PR1201MB1110.namprd12.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="Generator" content="Microsoft Exchange Server">
      <!-- converted from text -->
      <style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
      <meta content="text/html; charset=UTF-8">
      <style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
      <div dir="ltr">
        <div id="x_divtagdefaultwrapper" dir="ltr"
          style="font-size:12pt; color:#000000;
          font-family:Calibri,Arial,Helvetica,sans-serif">
          <p>current code missed the 128 DW after SWITCH_BUFFER, even
            without vm flush, we still need those 128 DW betwen previous
            frame's SWITCH_BUFFER and current frame's CE ib,
          </p>
          <p>and this patch fixed this issue as well otherwise in SRIOV
            case (Unigeen HEAVEN) CE will meet vm fault, and in  steam
            OS case (DOTA2) will meet VM fault as well.</p>
          <p><br>
          </p>
          <p>so the conclusion is if we have vm-flush, we make sure
            128dw between vm flush and CE ib, if we don't insert vm
            flush we stil make sure 128 DW between SWITCH_BUFFER and CE
            ib.</p>
          <p><br>
          </p>
          <p>if you reject this patch, please give me a solution to fix
            above VM fault <br>
          </p>
          <p><br>
          </p>
          <p>BR Monk<br>
          </p>
        </div>
        <hr tabindex="-1" style="display:inline-block; width:98%">
        <div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt"
            color="#000000" face="Calibri, sans-serif"><b>发件人:</b>
            amd-gfx <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx-bounces@lists.freedesktop.org"><amd-gfx-bounces@lists.freedesktop.org></a> 代表
            Christian König <a class="moz-txt-link-rfc2396E" href="mailto:deathsimple@vodafone.de"><deathsimple@vodafone.de></a><br>
            <b>发送时间:</b> 2017年1月18日 20:52:14<br>
            <b>收件人:</b> Liu, Monk; <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
            <b>主题:</b> Re: 答复: [PATCH] drm/amdgpu:guarantee 128dws
            between vm flush and IB</font>
          <div> </div>
        </div>
      </div>
      <font size="2"><span style="font-size:10pt;">
          <div class="PlainText">> suppose hw_submit_count in
            gpu_scheduler is 2 (by default), and
            <br>
            > without suppress frame size under 256, we may sometime
            submit 256dw, <br>
            > and sometime submit 512 dw, and that could lead to CPU
            override ring <br>
            > buffer content which is under processing by GPU, e.g. :<br>
            ><br>
            The max_dw parameter for amdgpu_ring_init() is multiplied by
            <br>
            amdgpu_sched_hw_submission. See amdgpu_ring_init():<br>
            <br>
                     ring->ring_size = roundup_pow_of_two(max_dw * 4
            *<br>
            amdgpu_sched_hw_submission);<br>
            <br>
            Since we use 1024 for max_dw for the GFX, Compute and SDMA
            rings using <br>
            512 dw is perfectly ok.<br>
            <br>
            Even if we ever try to submit more than 1024 including
            padding we will <br>
            get a nice warning in the logs. See amdgpu_ring_alloc():<br>
            <br>
                     if (WARN_ON_ONCE(ndw > ring->max_dw))<br>
                             return -ENOMEM;<br>
            <br>
            > another reason is we keep each DMAframe to 256dw is for
            better <br>
            > performance.<br>
            ><br>
            Well considering what else we have in those command buffers
            I would <br>
            strongly say that this is negligible.<br>
            <br>
            So NAK on that patch as long as we don't have a good reason
            for it.<br>
            <br>
            Regards,<br>
            Christian.<br>
            <br>
            Am 18.01.2017 um 11:11 schrieb Liu, Monk:<br>
            ><br>
            > >First question why do we want to limit the dw per
            submit to 256? Some<br>
            > >limitation for SRIOV?<br>
            ><br>
            ><br>
            > [ML]<br>
            ><br>
            > suppose hw_submit_count in gpu_scheduler is 2 (by
            default), and <br>
            > without suppress frame size under 256, we may sometime
            submit 256dw, <br>
            > and sometime submit 512 dw, and that could lead to CPU
            override ring <br>
            > buffer content which is under processing by GPU, e.g. :<br>
            ><br>
            ><br>
            > we assume ring buffer size = 512 dw (so ring buffer can
            hold 2 hw <br>
            > submit) for easy understanding.<br>
            ><br>
            ><br>
            > hw_count =2;<br>
            ><br>
            > submit job-1 (take 256 dw)<br>
            ><br>
            > hw_count = 1;<br>
            ><br>
            > submit job-2 (take 256 dw) //now ring buffer is full<br>
            ><br>
            > hw_count =0;<br>
            ><br>
            > gpu_scheduler waiting<br>
            ><br>
            > ...<br>
            ><br>
            > job-1 signaled, then hw_count => 1<br>
            ><br>
            > submit job3, and the job3 is filled in the head of RB
            (wrapped)<br>
            ><br>
            > but job3 take 512 dw (e.g. it takes 259 dw, but we
            aligned it to 512)<br>
            ><br>
            ><br>
            > job-2 still under processing, but the package belongs
            to job-2 is <br>
            > override by job3, disaster ...<br>
            ><br>
            ><br>
            > another reason is we keep each DMAframe to 256dw is for
            better <br>
            > performance.<br>
            ><br>
            ><br>
            > BR Monk<br>
            ><br>
            >
            ------------------------------------------------------------------------<br>
            > *发件人:* Christian König <a class="moz-txt-link-rfc2396E" href="mailto:deathsimple@vodafone.de"><deathsimple@vodafone.de></a><br>
            > *发送时间:* 2017年1月18日 17:28:15<br>
            > *收件人:* Liu, Monk; <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
            > *主题:* Re: [PATCH] drm/amdgpu:guarantee 128dws between
            vm flush and IB<br>
            > Am 18.01.2017 um 06:55 schrieb Monk Liu:<br>
            > > previously we always insert 128nops behind
            vm_flush, which<br>
            > > may lead to DAMframe size above 256 dw and
            automatially aligned<br>
            > > to 512 dw.<br>
            > ><br>
            > > now we calculate how many DWs already inserted
            after vm_flush<br>
            > > and make up for the reset to pad up to 128dws
            before emit_ib.<br>
            > ><br>
            > > that way we only take 256 dw per submit.<br>
            ><br>
            > First question why do we want to limit the dw per
            submit to 256? Some<br>
            > limitation for SRIOV?<br>
            ><br>
            > Then for the implementation, please don't add all that
            counting to the<br>
            > different functions. Instead save the current position
            in the ring in<br>
            > emit_vm_flush and then calculate in emit_cntxcntl() how
            many dw we still<br>
            > need to add to have at least 128. E.g. call the
            variable something like<br>
            > last_vm_flush_pos.<br>
            ><br>
            > That makes the code way more robust towards any
            changes.<br>
            ><br>
            > Regards,<br>
            > Christian.<br>
            ><br>
            > ><br>
            > > Change-Id:
            Iac198e16f35b071476ba7bd48ab338223f6fe650<br>
            > > Signed-off-by: Monk Liu <a class="moz-txt-link-rfc2396E" href="mailto:Monk.Liu@amd.com"><Monk.Liu@amd.com></a><br>
            > > ---<br>
            > >   drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  1 +<br>
            > >   drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 24
            ++++++++++++++++++++++--<br>
            > >   2 files changed, 23 insertions(+), 2
            deletions(-)<br>
            > ><br>
            > > diff --git
            a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h <br>
            > b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
            > > index c813cbe..1dbe600 100644<br>
            > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
            > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h<br>
            > > @@ -173,6 +173,7 @@ struct amdgpu_ring {<br>
            > >   #if defined(CONFIG_DEBUG_FS)<br>
            > >        struct dentry *ent;<br>
            > >   #endif<br>
            > > +     u32 dws_between_vm_ib;<br>
            > >   };<br>
            > ><br>
            > >   int amdgpu_ring_alloc(struct amdgpu_ring *ring,
            unsigned ndw);<br>
            > > diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
            <br>
            > b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
            > > index 5f37313..76b1315 100644<br>
            > > --- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
            > > +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
            > > @@ -5670,6 +5670,8 @@ static void <br>
            > gfx_v8_0_ring_emit_gds_switch(struct amdgpu_ring *ring,<br>
            > >        amdgpu_ring_write(ring,
            amdgpu_gds_reg_offset[vmid].oa);<br>
            > >        amdgpu_ring_write(ring, 0);<br>
            > >        amdgpu_ring_write(ring, (1 <<
            (oa_size + oa_base)) - (1 << <br>
            > oa_base));<br>
            > > +<br>
            > > +     ring->dws_between_vm_ib += 20;<br>
            > >   }<br>
            > ><br>
            > >   static uint32_t wave_read_ind(struct
            amdgpu_device *adev, uint32_t <br>
            > simd, uint32_t wave, uint32_t address)<br>
            > > @@ -6489,6 +6491,8 @@ static void <br>
            > gfx_v8_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)<br>
            > >        amdgpu_ring_write(ring, ref_and_mask);<br>
            > >        amdgpu_ring_write(ring, ref_and_mask);<br>
            > >        amdgpu_ring_write(ring, 0x20); /* poll
            interval */<br>
            > > +<br>
            > > +     ring->dws_between_vm_ib += 7;<br>
            > >   }<br>
            > ><br>
            > >   static void gfx_v8_0_ring_emit_vgt_flush(struct
            amdgpu_ring *ring)<br>
            > > @@ -6500,6 +6504,8 @@ static void <br>
            > gfx_v8_0_ring_emit_vgt_flush(struct amdgpu_ring *ring)<br>
            > >        amdgpu_ring_write(ring,
            PACKET3(PACKET3_EVENT_WRITE, 0));<br>
            > >        amdgpu_ring_write(ring,
            EVENT_TYPE(VGT_FLUSH) |<br>
            > >                EVENT_INDEX(0));<br>
            > > +<br>
            > > +     ring->dws_between_vm_ib += 4;<br>
            > >   }<br>
            > ><br>
            > ><br>
            > > @@ -6573,6 +6579,7 @@ static void <br>
            > gfx_v8_0_ring_emit_fence_gfx(struct amdgpu_ring *ring,
            u64 addr,<br>
            > >        amdgpu_ring_write(ring,
            lower_32_bits(seq));<br>
            > >        amdgpu_ring_write(ring,
            upper_32_bits(seq));<br>
            > ><br>
            > > +     ring->dws_between_vm_ib += 6;<br>
            > >   }<br>
            > ><br>
            > >   static void
            gfx_v8_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)<br>
            > > @@ -6639,6 +6646,8 @@ static void
            gfx_v8_0_ring_emit_vm_flush(struct <br>
            > amdgpu_ring *ring,<br>
            > >                /* GFX8 emits 128 dw nop to prevent
            CE access VM <br>
            > before vm_flush finish */<br>
            > >                amdgpu_ring_insert_nop(ring, 128);<br>
            > >        }<br>
            > > +<br>
            > > +     ring->dws_between_vm_ib = 0; /* clear
            before recalculate */<br>
            > >   }<br>
            > ><br>
            > >   static u32 gfx_v8_0_ring_get_wptr_compute(struct
            amdgpu_ring *ring)<br>
            > > @@ -6711,9 +6720,11 @@ static void
            gfx_v8_ring_emit_cntxcntl(struct <br>
            > amdgpu_ring *ring, uint32_t flags)<br>
            > >   {<br>
            > >        uint32_t dw2 = 0;<br>
            > ><br>
            > > -     if (amdgpu_sriov_vf(ring->adev))<br>
            > > +     if (amdgpu_sriov_vf(ring->adev)) {<br>
            > >               
            gfx_v8_0_ring_emit_ce_meta_init(ring,<br>
            > >                        (flags &
            AMDGPU_VM_DOMAIN) ? AMDGPU_CSA_VADDR <br>
            > : ring->adev->virt.csa_vmid0_addr);<br>
            > > +             ring->dws_between_vm_ib += 8;<br>
            > > +     }<br>
            > ><br>
            > >        dw2 |= 0x80000000; /* set load_enable
            otherwise this package <br>
            > is just NOPs */<br>
            > >        if (flags & AMDGPU_HAVE_CTX_SWITCH) {<br>
            > > @@ -6739,10 +6750,19 @@ static void
            gfx_v8_ring_emit_cntxcntl(struct <br>
            > amdgpu_ring *ring, uint32_t flags)<br>
            > >        amdgpu_ring_write(ring,
            PACKET3(PACKET3_CONTEXT_CONTROL, 1));<br>
            > >        amdgpu_ring_write(ring, dw2);<br>
            > >        amdgpu_ring_write(ring, 0);<br>
            > > +     ring->dws_between_vm_ib += 3;<br>
            > ><br>
            > > -     if (amdgpu_sriov_vf(ring->adev))<br>
            > > +     if (amdgpu_sriov_vf(ring->adev)) {<br>
            > >               
            gfx_v8_0_ring_emit_de_meta_init(ring,<br>
            > >                        (flags &
            AMDGPU_VM_DOMAIN) ? AMDGPU_CSA_VADDR <br>
            > : ring->adev->virt.csa_vmid0_addr);<br>
            > > +             ring->dws_between_vm_ib += 21;<br>
            > > +     }<br>
            > > +<br>
            > > +     /* emit_de_meta_init should be the last
            package right before <br>
            > emi_ib,<br>
            > > +      * and we need to pad some NOPs before
            emit_ib to prevent CE <br>
            > run ahead of<br>
            > > +      * vm_flush, which may trigger VM fault.<br>
            > > +      */<br>
            > > +     amdgpu_ring_insert_nop(ring, 128 -
            ring->dws_between_vm_ib);<br>
            > >   }<br>
            > ><br>
            > >   static void gfx_v8_0_ring_emit_rreg(struct
            amdgpu_ring *ring, <br>
            > uint32_t reg)<br>
            ><br>
            ><br>
            <br>
            _______________________________________________<br>
            amd-gfx mailing list<br>
            <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
            <a moz-do-not-send="true"
              href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
          </div>
        </span></font>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
amd-gfx mailing list
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>