<html>
<head>
<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>
</head>
<body>
<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><font size="2"><span style="font-size:10pt">>First question why do we want to limit the dw per submit to 256? Some
<br>
>limitation for SRIOV?</span></font></p>
<p><font size="2"><span style="font-size:10pt"><br>
</span></font></p>
<p><font size="2"><span style="font-size:10pt">[ML] <br>
</span></font></p>
<p><font size="2">suppose hw_submit_count in gpu_scheduler is 2 (by default), and without suppress frame size under 256, we may sometime submit 256dw, and sometime submit 512 dw, and that could lead to CPU override ring buffer content which is under processing
by GPU, e.g. :</font></p>
<p><font size="2"><br>
</font></p>
<p><font size="2">we assume ring buffer size = 512 dw (so ring buffer can hold 2 hw submit) for easy understanding.<br>
</font></p>
<p><br>
<font size="2"></font></p>
<p><font size="2">hw_count =2;</font></p>
<p><font size="2">submit job-1 (take 256 dw)</font></p>
<p><font size="2">hw_count = 1;</font></p>
<p><font size="2">submit job-2 (take 256 dw) //now ring buffer is full</font></p>
<p><font size="2">hw_count =0; <br>
</font></p>
<p><font size="2">gpu_scheduler waiting</font></p>
<p><font size="2">...</font></p>
<p><font size="2">job-1 signaled, then hw_count => 1</font></p>
<p><font size="2">submit job3, and the job3 is filled in the head of RB (wrapped)<br>
</font></p>
<p><font size="2">but job3 take 512 dw (e.g. it takes 259 dw, but we aligned it to 512)</font></p>
<p><font size="2"><br>
</font></p>
<p><font size="2">job-2 still under processing, but the package belongs to job-2 is override by job3, disaster ...</font></p>
<p><font size="2"><br>
</font></p>
<p><font size="2">another reason is we keep each DMAframe to 256dw is for better performance.<br>
</font></p>
<p><font size="2"><br>
</font></p>
<p><font size="2">BR Monk<br>
</font></p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>发件人:</b> Christian König <deathsimple@vodafone.de><br>
<b>发送时间:</b> 2017年1月18日 17:28:15<br>
<b>收件人:</b> Liu, Monk; amd-gfx@lists.freedesktop.org<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">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 <Monk.Liu@amd.com><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 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 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 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 << 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 simd, uint32_t wave, uint32_t address)<br>
> @@ -6489,6 +6491,8 @@ static void 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 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 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 amdgpu_ring *ring,<br>
> /* GFX8 emits 128 dw nop to prevent CE access VM 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 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 : ring->adev->virt.csa_vmid0_addr);<br>
> + ring->dws_between_vm_ib += 8;<br>
> + }<br>
> <br>
> dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */<br>
> if (flags & AMDGPU_HAVE_CTX_SWITCH) {<br>
> @@ -6739,10 +6750,19 @@ static void gfx_v8_ring_emit_cntxcntl(struct 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 : 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 emi_ib,<br>
> + * and we need to pad some NOPs before emit_ib to prevent CE 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, uint32_t reg)<br>
<br>
<br>
</div>
</span></font>
</body>
</html>