<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<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>
<div>
<div>
<div>
<div style="direction:ltr">reviewed-by: Evan Quan <evan.quan@amd.com></div>
<div style="direction:ltr"></div>
</div>
<div><br>
</div>
<div class="x_ms-outlook-ios-signature">获取 <a href="https://aka.ms/o0ukef">Outlook for iOS</a></div>
</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> Feng, Kenneth <Kenneth.Feng@amd.com><br>
<b>发送时间:</b> Thursday, July 18, 2019 5:49:56 PM<br>
<b>收件人:</b> Wang, Kevin(Yang) <Kevin1.Wang@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>抄送:</b> Quan, Evan <Evan.Quan@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Xu, Feifei <Feifei.Xu@amd.com><br>
<b>主题:</b> RE: [PATCH v2] drm/amd/powerplay: change sysfs pp_dpm_xxx format for navi10</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:11pt;">
<div class="PlainText">Reviewed-by: Kenneth Feng <kenneth.feng@amd.com><br>
<br>
<br>
<br>
-----Original Message-----<br>
From: Wang, Kevin(Yang) <br>
Sent: Thursday, July 18, 2019 5:43 PM<br>
To: amd-gfx@lists.freedesktop.org<br>
Cc: Feng, Kenneth <Kenneth.Feng@amd.com>; Quan, Evan <Evan.Quan@amd.com>; Huang, Ray <Ray.Huang@amd.com>; Xu, Feifei <Feifei.Xu@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com><br>
Subject: [PATCH v2] drm/amd/powerplay: change sysfs pp_dpm_xxx format for navi10<br>
<br>
v2:<br>
set average clock value on level 1 when current clock equal min or max clock (fine grained dpm support).<br>
<br>
the navi10 gfxclk (sclk) support fine grained DPM, so use level 1 to show current dpm freq in sysfs pp_dpm_xxx<br>
<br>
Change-Id: I14daa6e30c52c89795708ec06660862bb4591036<br>
Signed-off-by: Kevin Wang <kevin1.wang@amd.com><br>
---<br>
 drivers/gpu/drm/amd/powerplay/navi10_ppt.c | 47 +++++++++++++++++++---<br>
 1 file changed, 41 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
index 895a4e592d5a..1f721b85c0f6 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c<br>
@@ -627,11 +627,26 @@ static int navi10_get_current_clk_freq_by_table(struct smu_context *smu,<br>
         return ret;<br>
 }<br>
 <br>
+static bool navi10_is_support_fine_grained_dpm(struct smu_context *smu, <br>
+enum smu_clk_type clk_type) {<br>
+       PPTable_t *pptable = smu->smu_table.driver_pptable;<br>
+       DpmDescriptor_t *dpm_desc = NULL;<br>
+       uint32_t clk_index = 0;<br>
+<br>
+       clk_index = smu_clk_get_index(smu, clk_type);<br>
+       dpm_desc = &pptable->DpmDescriptor[clk_index];<br>
+<br>
+       /* 0 - Fine grained DPM, 1 - Discrete DPM */<br>
+       return dpm_desc->SnapToDiscrete == 0 ? true : false; }<br>
+<br>
 static int navi10_print_clk_levels(struct smu_context *smu,<br>
                         enum smu_clk_type clk_type, char *buf)  {<br>
         int i, size = 0, ret = 0;<br>
         uint32_t cur_value = 0, value = 0, count = 0;<br>
+       uint32_t freq_values[3] = {0};<br>
+       uint32_t mark_index = 0;<br>
 <br>
         switch (clk_type) {<br>
         case SMU_GFXCLK:<br>
@@ -644,22 +659,42 @@ static int navi10_print_clk_levels(struct smu_context *smu,<br>
                 ret = smu_get_current_clk_freq(smu, clk_type, &cur_value);<br>
                 if (ret)<br>
                         return size;<br>
+<br>
                 /* 10KHz -> MHz */<br>
                 cur_value = cur_value / 100;<br>
 <br>
-               size += sprintf(buf, "current clk: %uMhz\n", cur_value);<br>
-<br>
                 ret = smu_get_dpm_level_count(smu, clk_type, &count);<br>
                 if (ret)<br>
                         return size;<br>
 <br>
-               for (i = 0; i < count; i++) {<br>
-                       ret = smu_get_dpm_freq_by_index(smu, clk_type, i, &value);<br>
+               if (!navi10_is_support_fine_grained_dpm(smu, clk_type)) {<br>
+                       for (i = 0; i < count; i++) {<br>
+                               ret = smu_get_dpm_freq_by_index(smu, clk_type, i, &value);<br>
+                               if (ret)<br>
+                                       return size;<br>
+<br>
+                               size += sprintf(buf + size, "%d: %uMhz %s\n", i, value,<br>
+                                               cur_value == value ? "*" : "");<br>
+                       }<br>
+               } else {<br>
+                       ret = smu_get_dpm_freq_by_index(smu, clk_type, 0, &freq_values[0]);<br>
+                       if (ret)<br>
+                               return size;<br>
+                       ret = smu_get_dpm_freq_by_index(smu, clk_type, count - 1,
<br>
+&freq_values[2]);<br>
                         if (ret)<br>
                                 return size;<br>
 <br>
-                       size += sprintf(buf + size, "%d: %uMhz %s\n", i, value,<br>
-                                       cur_value == value ? "*" : "");<br>
+                       freq_values[1] = cur_value;<br>
+                       mark_index = cur_value == freq_values[0] ? 0 :<br>
+                                    cur_value == freq_values[2] ? 2 : 1;<br>
+                       if (mark_index != 1)<br>
+                               freq_values[1] = (freq_values[0] + freq_values[2]) / 2;<br>
+<br>
+                       for (i = 0; i < 3; i++) {<br>
+                               size += sprintf(buf + size, "%d: %uMhz %s\n", i, freq_values[i],<br>
+                                               i == mark_index ? "*" : "");<br>
+                       }<br>
+<br>
                 }<br>
                 break;<br>
         default:<br>
--<br>
2.22.0<br>
<br>
</div>
</span></font>
</body>
</html>