<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body>
<div>Hi James,</div>
<div><br>
</div>
<div>Evan seems to have understood how this all works together.</div>
<div><br>
</div>
<div>See while any begin/end use critical section is active the work should not be active.</div>
<div><br>
</div>
<div>When you handle only one ring you can just call cancel in begin use and schedule in end use. But when you have more than one ring you need a lock or counter to prevent concurrent work items to be started.</div>
<div><br>
</div>
<div>Michelle's idea to use mod_delayed_work is a bad one because it assumes that the delayed work is still running.</div>
<div><br>
</div>
<div>Something similar applies to the first patch I think, so when this makes a difference it is actually a bug.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Christian.</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>Von:</b> Quan, Evan <Evan.Quan@amd.com><br>
<b>Gesendet:</b> Donnerstag, 12. August 2021 04:42<br>
<b>An:</b> Koenig, Christian <Christian.Koenig@amd.com>; Michel Dänzer <michel@daenzer.net>; Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Cc:</b> Liu, Leo <Leo.Liu@amd.com>; Zhu, James <James.Zhu@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org><br>
<b>Betreff:</b> RE: [PATCH 2/2] drm/amdgpu: Use mod_delayed_work in JPEG/UVD/VCE/VCN ring_end_use hooks</font>
<div> </div>
</div>
<style>
<!--
@font-face
{font-family:Wingdings}
@font-face
{font-family:"Cambria Math"}
@font-face
{font-family:DengXian}
@font-face
{font-family:Calibri}
@font-face
{}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
{color:#0563C1;
text-decoration:underline}
p.x_MsoListParagraph, li.x_MsoListParagraph, div.x_MsoListParagraph
{margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
span.x_EmailStyle19
{font-family:"Calibri",sans-serif;
color:windowtext}
p.x_msipheadera4477989, li.x_msipheadera4477989, div.x_msipheadera4477989
{margin-right:0in;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif}
.x_MsoChpDefault
{font-size:10.0pt}
@page WordSection1
{margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
{}
ol
{margin-bottom:0in}
ul
{margin-bottom:0in}
-->
</style>
<div lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_msipheadera4477989" style="margin:0in"><span style="font-size:10.0pt; font-family:"Arial",sans-serif; color:blue">[AMD Official Use Only]</span></p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">Different from the 1<sup>st</sup> patch(for amdgpu_gfx_off_ctrl) of the series, “cancel_delayed_work_sync(&adev->uvd.idle_work)” will be called on like amdgpu_uvd_ring_begin_use(). Under this case, does it make any difference from previous
implementation ”schedule_delayed_work”?</p>
<p class="x_MsoNormal">Suppose the sequence is as below:</p>
<ul type="disc" style="margin-top:0in">
<li class="x_MsoListParagraph" style="margin-left:0in">Ring begin use</li><li class="x_MsoListParagraph" style="margin-left:0in">Ring end use <span style="font-family:Wingdings">
à</span> mod_delayed_work() : queue a new delayed work, right?</li><li class="x_MsoListParagraph" style="margin-left:0in">Ring begin use (within 1s)
<span style="font-family:Wingdings">à</span> cancel_delayed_work_sync() will cancel the work submitted above, right?</li><li class="x_MsoListParagraph" style="margin-left:0in">Ring end use <span style="font-family:Wingdings">
à</span> mod_delayed_work(): queue another new scheduled work, same as previous “schedule_delayed_work”?</li></ul>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">BR</p>
<p class="x_MsoNormal">Evan</p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org>
<b>On Behalf Of </b>Koenig, Christian<br>
<b>Sent:</b> Thursday, August 12, 2021 5:34 AM<br>
<b>To:</b> Michel Dänzer <michel@daenzer.net>; Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Cc:</b> Liu, Leo <Leo.Liu@amd.com>; Zhu, James <James.Zhu@amd.com>; amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org<br>
<b>Subject:</b> AW: [PATCH 2/2] drm/amdgpu: Use mod_delayed_work in JPEG/UVD/VCE/VCN ring_end_use hooks</p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal">NAK to at least this patch.</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">Since activating power management while submitting work is problematic cancel_delayed_work() must have been called during begin use or otherwise we have a serious coding problem in the first place.</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">So this change shouldn't make a difference and I suggest to really stick with schedule_delayed_work().</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">Maybe add a comment how this works?</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">Need to take a closer look at the first patch when I'm back from vacation, but it could be that this applies there as well.</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div>
<p class="x_MsoNormal">Regards,</p>
</div>
<div>
<p class="x_MsoNormal">Christian.</p>
</div>
<div>
<p class="x_MsoNormal"> </p>
</div>
<div class="x_MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="x_divRplyFwdMsg">
<p class="x_MsoNormal"><b><span style="color:black">Von:</span></b><span style="color:black"> Michel Dänzer <<a href="mailto:michel@daenzer.net">michel@daenzer.net</a>><br>
<b>Gesendet:</b> Mittwoch, 11. August 2021 18:52<br>
<b>An:</b> Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com">Alexander.Deucher@amd.com</a>>; Koenig, Christian <<a href="mailto:Christian.Koenig@amd.com">Christian.Koenig@amd.com</a>><br>
<b>Cc:</b> Liu, Leo <<a href="mailto:Leo.Liu@amd.com">Leo.Liu@amd.com</a>>; Zhu, James <<a href="mailto:James.Zhu@amd.com">James.Zhu@amd.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a> <<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>>;
<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a> <<a href="mailto:dri-devel@lists.freedesktop.org">dri-devel@lists.freedesktop.org</a>><br>
<b>Betreff:</b> [PATCH 2/2] drm/amdgpu: Use mod_delayed_work in JPEG/UVD/VCE/VCN ring_end_use hooks</span>
</p>
<div>
<p class="x_MsoNormal"> </p>
</div>
</div>
<div>
<div>
<p class="x_MsoNormal" style="margin-bottom:12.0pt">From: Michel Dänzer <<a href="mailto:mdaenzer@redhat.com">mdaenzer@redhat.com</a>><br>
<br>
In contrast to schedule_delayed_work, this pushes back the work if it<br>
was already scheduled before. Specific behaviour change:<br>
<br>
Before:<br>
<br>
The scheduled work ran ~1 second after the first time ring_end_use was<br>
called, even if the ring was used again during that second.<br>
<br>
After:<br>
<br>
The scheduled work runs ~1 second after the last time ring_end_use is<br>
called.<br>
<br>
Inspired by the corresponding change in amdgpu_gfx_off_ctrl. While I<br>
haven't run into specific issues in this case, the new behaviour makes<br>
more sense to me.<br>
<br>
Signed-off-by: Michel Dänzer <<a href="mailto:mdaenzer@redhat.com">mdaenzer@redhat.com</a>><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 2 +-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 2 +-<br>
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 2 +-<br>
4 files changed, 4 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c<br>
index 8996cb4ed57a..2c0040153f6c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c<br>
@@ -110,7 +110,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)<br>
void amdgpu_jpeg_ring_end_use(struct amdgpu_ring *ring)<br>
{<br>
atomic_dec(&ring->adev->jpeg.total_submission_cnt);<br>
- schedule_delayed_work(&ring->adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);<br>
+ mod_delayed_work(system_wq, &ring->adev->jpeg.idle_work, JPEG_IDLE_TIMEOUT);<br>
}<br>
<br>
int amdgpu_jpeg_dec_ring_test_ring(struct amdgpu_ring *ring)<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
index 0f576f294d8a..b6b1d7eeb8e5 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
@@ -1283,7 +1283,7 @@ void amdgpu_uvd_ring_begin_use(struct amdgpu_ring *ring)<br>
void amdgpu_uvd_ring_end_use(struct amdgpu_ring *ring)<br>
{<br>
if (!amdgpu_sriov_vf(ring->adev))<br>
- schedule_delayed_work(&ring->adev->uvd.idle_work, UVD_IDLE_TIMEOUT);<br>
+ mod_delayed_work(system_wq, &ring->adev->uvd.idle_work, UVD_IDLE_TIMEOUT);<br>
}<br>
<br>
/**<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
index 1ae7f824adc7..2253c18a6688 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
@@ -401,7 +401,7 @@ void amdgpu_vce_ring_begin_use(struct amdgpu_ring *ring)<br>
void amdgpu_vce_ring_end_use(struct amdgpu_ring *ring)<br>
{<br>
if (!amdgpu_sriov_vf(ring->adev))<br>
- schedule_delayed_work(&ring->adev->vce.idle_work, VCE_IDLE_TIMEOUT);<br>
+ mod_delayed_work(system_wq, &ring->adev->vce.idle_work, VCE_IDLE_TIMEOUT);<br>
}<br>
<br>
/**<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c<br>
index 284bb42d6c86..d5937ab5ac80 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c<br>
@@ -1874,7 +1874,7 @@ void vcn_v1_0_set_pg_for_begin_use(struct amdgpu_ring *ring, bool set_clocks)<br>
<br>
void vcn_v1_0_ring_end_use(struct amdgpu_ring *ring)<br>
{<br>
- schedule_delayed_work(&ring->adev->vcn.idle_work, VCN_IDLE_TIMEOUT);<br>
+ mod_delayed_work(system_wq, &ring->adev->vcn.idle_work, VCN_IDLE_TIMEOUT);<br>
mutex_unlock(&ring->adev->vcn.vcn1_jpeg1_workaround);<br>
}<br>
<br>
-- <br>
2.32.0</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>