<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></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> Chengming Gui <Jack.Gui@amd.com><br>
<b>Sent:</b> Tuesday, October 18, 2022 6:12 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Cc:</b> Nie, Tobyn <Tobyn.Nie@amd.com>; Gui, Jack <Jack.Gui@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: fix pstate setting issue</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[WHY]<br>
0, original pstate X<br>
1, ctx_A_create -> ctx_A->stable_pstate = X<br>
2, ctx_A_set_pstate (Y) -> current pstate is Y (PEAK or STANDARD)<br>
3, ctx_B_create -> ctx_B->stable_pstate =  Y<br>
4, ctx_A_destroy -> restore pstate to X<br>
5, ctx_B_destroy -> restore pstate to Y<br>
Above sequence will cause final pstate is wrong (Y), should be original X.<br>
<br>
[HOW]<br>
When ctx_B create,<br>
if  ctx_A touched pstate setting<br>
(not auto, stable_pstate_ctx != NULL),<br>
set ctx_B->stable_pstate the same value as ctx_A saved,<br>
if stable_pstate_ctx == NULL,<br>
fetch current pstate to fill<br>
ctx_B->stable_pstate.<br>
<br>
Signed-off-by: Chengming Gui <Jack.Gui@amd.com><br>
Change-Id: I61cb68b2a5fe2544cd91233fc069b5919fadcb76<br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 5 ++++-<br>
 1 file changed, 4 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
index 5fc3da020a55..331aa191910c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c<br>
@@ -326,7 +326,10 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority,<br>
         if (r)<br>
                 return r;<br>
 <br>
-       ctx->stable_pstate = current_stable_pstate;<br>
+       if (mgr->adev->pm.stable_pstate_ctx)<br>
+               ctx->stable_pstate = mgr->adev->pm.stable_pstate_ctx->stable_pstate;<br>
+       else<br>
+               ctx->stable_pstate = current_stable_pstate;<br>
 <br>
         return 0;<br>
 }<br>
-- <br>
2.37.0<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>