<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">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Series is:</p>
<p style="margin-top:0;margin-bottom:0">Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</p>
</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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Evan Quan <evan.quan@amd.com><br>
<b>Sent:</b> Thursday, January 24, 2019 5:59:18 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Quan, Evan<br>
<b>Subject:</b> [PATCH 2/2] drm/amd/powerplay: avoid frequent metrics table export</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">That's unnecessary. Also it makes more sense to show all the clocks<br>
on one metrics table export.<br>
<br>
Change-Id: I6350911934dbd85dc701de17ccc0e9cbddda4648<br>
Signed-off-by: Evan Quan <evan.quan@amd.com><br>
---<br>
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c    | 43 +++++++++++++------<br>
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.h    |  3 ++<br>
 2 files changed, 33 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
index 13f124125f5a..7b49a9a13a4a 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
@@ -1958,16 +1958,36 @@ static uint32_t vega20_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)<br>
         return (mem_clk * 100);<br>
 }<br>
 <br>
+static int vega20_get_metrics_table(struct pp_hwmgr *hwmgr, SmuMetrics_t *metrics_table)<br>
+{<br>
+       struct vega20_hwmgr *data =<br>
+                       (struct vega20_hwmgr *)(hwmgr->backend);<br>
+       int ret = 0;<br>
+<br>
+       if (!data->metrics_time || time_after(jiffies, data->metrics_time + HZ / 2)) {<br>
+               ret = smum_smc_table_manager(hwmgr, (uint8_t *)metrics_table,<br>
+                               TABLE_SMU_METRICS, true);<br>
+               if (ret) {<br>
+                       pr_info("Failed to export SMU metrics table!\n");<br>
+                       return ret;<br>
+               }<br>
+               memcpy(&data->metrics_table, metrics_table, sizeof(SmuMetrics_t));<br>
+               data->metrics_time = jiffies;<br>
+       } else<br>
+               memcpy(metrics_table, &data->metrics_table, sizeof(SmuMetrics_t));<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
 static int vega20_get_gpu_power(struct pp_hwmgr *hwmgr,<br>
                 uint32_t *query)<br>
 {<br>
         int ret = 0;<br>
         SmuMetrics_t metrics_table;<br>
 <br>
-       ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table, TABLE_SMU_METRICS, true);<br>
-       PP_ASSERT_WITH_CODE(!ret,<br>
-                       "Failed to export SMU METRICS table!",<br>
-                       return ret);<br>
+       ret = vega20_get_metrics_table(hwmgr, &metrics_table);<br>
+       if (ret)<br>
+               return ret;<br>
 <br>
         *query = metrics_table.CurrSocketPower << 8;<br>
 <br>
@@ -1998,10 +2018,9 @@ static int vega20_get_current_activity_percent(struct pp_hwmgr *hwmgr,<br>
         int ret = 0;<br>
         SmuMetrics_t metrics_table;<br>
 <br>
-       ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table, TABLE_SMU_METRICS, true);<br>
-       PP_ASSERT_WITH_CODE(!ret,<br>
-                       "Failed to export SMU METRICS table!",<br>
-                       return ret);<br>
+       ret = vega20_get_metrics_table(hwmgr, &metrics_table);<br>
+       if (ret)<br>
+               return ret;<br>
 <br>
         *activity_percent = metrics_table.AverageGfxActivity;<br>
 <br>
@@ -2019,11 +2038,9 @@ static int vega20_read_sensor(struct pp_hwmgr *hwmgr, int idx,<br>
 <br>
         switch (idx) {<br>
         case AMDGPU_PP_SENSOR_GFX_SCLK:<br>
-               ret = smum_smc_table_manager(hwmgr, (uint8_t *)&metrics_table,<br>
-                               TABLE_SMU_METRICS, true);<br>
-               PP_ASSERT_WITH_CODE(!ret,<br>
-                               "Failed to export SMU METRICS table!",<br>
-                               return ret);<br>
+               ret = vega20_get_metrics_table(hwmgr, &metrics_table);<br>
+               if (ret)<br>
+                       return ret;<br>
 <br>
                 *((uint32_t *)value) = metrics_table.AverageGfxclkFrequency * 100;<br>
                 *size = 4;<br>
diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h<br>
index 25faaa5c5b10..37f5f5e657da 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.h<br>
@@ -520,6 +520,9 @@ struct vega20_hwmgr {<br>
         /* ---- Gfxoff ---- */<br>
         bool                           gfxoff_allowed;<br>
         uint32_t                       counter_gfxoff;<br>
+<br>
+       unsigned long                  metrics_time;<br>
+       SmuMetrics_t                   metrics_table;<br>
 };<br>
 <br>
 #define VEGA20_DPM2_NEAR_TDP_DEC                      10<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
</div>
</span></font></div>
</body>
</html>