<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div dir="auto"><span style="font-family:-apple-system, HelveticaNeue;font-size:14.6667px;display:inline !important">Reviewed-by: Asad Kamal <</span><a href="mailto:asad.kamal@amd.com" class="ms-outlook-linkify" style="font-family: -apple-system, HelveticaNeue; font-size: 14.6667px; color: rgb(0, 120, 212);">asad.kamal@amd.com</a><span style="font-family:-apple-system, HelveticaNeue;font-size:14.6667px;display:inline !important">></span><br>
</div>
<div dir="auto">
<div><br>
</div>
</div>
<div id="ms-outlook-mobile-signature" dir="auto">Thanks & Rega<span>rds</span></div>
<div id="ms-outlook-mobile-signature" dir="auto"><span>Asad</span></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 Lijo Lazar <lijo.lazar@amd.com><br>
<b>Sent:</b> Friday, September 15, 2023 6:29:37 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Kamal, Asad <Asad.Kamal@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Subject:</b> [PATCH] drm/amd/pm: Round Q10 format values in SMU v13.0.6</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Instead of neglecting fractional part, round the Q10 format values in<br>
SMU v13.0.6 metrics table.<br>
<br>
Signed-off-by: Lijo Lazar <lijo.lazar@amd.com><br>
---<br>
.../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 70 ++++++++++---------<br>
1 file changed, 36 insertions(+), 34 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c<br>
index f9c1219f0c4f..11a6cd96c601 100644<br>
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c<br>
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c<br>
@@ -244,6 +244,8 @@ struct PPTable_t {<br>
};<br>
<br>
#define SMUQ10_TO_UINT(x) ((x) >> 10)<br>
+#define SMUQ10_FRAC(x) ((x) & 0x3ff)<br>
+#define SMUQ10_ROUND(x) ((SMUQ10_TO_UINT(x)) + ((SMUQ10_FRAC(x)) >= 0x200))<br>
<br>
struct smu_v13_0_6_dpm_map {<br>
enum smu_clk_type clk_type;<br>
@@ -389,25 +391,25 @@ static int smu_v13_0_6_setup_driver_pptable(struct smu_context *smu)<br>
return -ETIME;<br>
<br>
pptable->MaxSocketPowerLimit =<br>
- SMUQ10_TO_UINT(metrics->MaxSocketPowerLimit);<br>
+ SMUQ10_ROUND(metrics->MaxSocketPowerLimit);<br>
pptable->MaxGfxclkFrequency =<br>
- SMUQ10_TO_UINT(metrics->MaxGfxclkFrequency);<br>
+ SMUQ10_ROUND(metrics->MaxGfxclkFrequency);<br>
pptable->MinGfxclkFrequency =<br>
- SMUQ10_TO_UINT(metrics->MinGfxclkFrequency);<br>
+ SMUQ10_ROUND(metrics->MinGfxclkFrequency);<br>
<br>
for (i = 0; i < 4; ++i) {<br>
pptable->FclkFrequencyTable[i] =<br>
- SMUQ10_TO_UINT(metrics->FclkFrequencyTable[i]);<br>
+ SMUQ10_ROUND(metrics->FclkFrequencyTable[i]);<br>
pptable->UclkFrequencyTable[i] =<br>
- SMUQ10_TO_UINT(metrics->UclkFrequencyTable[i]);<br>
- pptable->SocclkFrequencyTable[i] = SMUQ10_TO_UINT(<br>
+ SMUQ10_ROUND(metrics->UclkFrequencyTable[i]);<br>
+ pptable->SocclkFrequencyTable[i] = SMUQ10_ROUND(<br>
metrics->SocclkFrequencyTable[i]);<br>
pptable->VclkFrequencyTable[i] =<br>
- SMUQ10_TO_UINT(metrics->VclkFrequencyTable[i]);<br>
+ SMUQ10_ROUND(metrics->VclkFrequencyTable[i]);<br>
pptable->DclkFrequencyTable[i] =<br>
- SMUQ10_TO_UINT(metrics->DclkFrequencyTable[i]);<br>
+ SMUQ10_ROUND(metrics->DclkFrequencyTable[i]);<br>
pptable->LclkFrequencyTable[i] =<br>
- SMUQ10_TO_UINT(metrics->LclkFrequencyTable[i]);<br>
+ SMUQ10_ROUND(metrics->LclkFrequencyTable[i]);<br>
}<br>
<br>
/* use AID0 serial number by default */<br>
@@ -730,50 +732,50 @@ static int smu_v13_0_6_get_smu_metrics_data(struct smu_context *smu,<br>
smu_cmn_get_smc_version(smu, NULL, &smu_version);<br>
if (smu_version >= 0x552F00) {<br>
xcc_id = GET_INST(GC, 0);<br>
- *value = SMUQ10_TO_UINT(metrics->GfxclkFrequency[xcc_id]);<br>
+ *value = SMUQ10_ROUND(metrics->GfxclkFrequency[xcc_id]);<br>
} else {<br>
*value = 0;<br>
}<br>
break;<br>
case METRICS_CURR_SOCCLK:<br>
case METRICS_AVERAGE_SOCCLK:<br>
- *value = SMUQ10_TO_UINT(metrics->SocclkFrequency[0]);<br>
+ *value = SMUQ10_ROUND(metrics->SocclkFrequency[0]);<br>
break;<br>
case METRICS_CURR_UCLK:<br>
case METRICS_AVERAGE_UCLK:<br>
- *value = SMUQ10_TO_UINT(metrics->UclkFrequency);<br>
+ *value = SMUQ10_ROUND(metrics->UclkFrequency);<br>
break;<br>
case METRICS_CURR_VCLK:<br>
- *value = SMUQ10_TO_UINT(metrics->VclkFrequency[0]);<br>
+ *value = SMUQ10_ROUND(metrics->VclkFrequency[0]);<br>
break;<br>
case METRICS_CURR_DCLK:<br>
- *value = SMUQ10_TO_UINT(metrics->DclkFrequency[0]);<br>
+ *value = SMUQ10_ROUND(metrics->DclkFrequency[0]);<br>
break;<br>
case METRICS_CURR_FCLK:<br>
- *value = SMUQ10_TO_UINT(metrics->FclkFrequency);<br>
+ *value = SMUQ10_ROUND(metrics->FclkFrequency);<br>
break;<br>
case METRICS_AVERAGE_GFXACTIVITY:<br>
- *value = SMUQ10_TO_UINT(metrics->SocketGfxBusy);<br>
+ *value = SMUQ10_ROUND(metrics->SocketGfxBusy);<br>
break;<br>
case METRICS_AVERAGE_MEMACTIVITY:<br>
- *value = SMUQ10_TO_UINT(metrics->DramBandwidthUtilization);<br>
+ *value = SMUQ10_ROUND(metrics->DramBandwidthUtilization);<br>
break;<br>
case METRICS_CURR_SOCKETPOWER:<br>
- *value = SMUQ10_TO_UINT(metrics->SocketPower) << 8;<br>
+ *value = SMUQ10_ROUND(metrics->SocketPower) << 8;<br>
break;<br>
case METRICS_TEMPERATURE_HOTSPOT:<br>
- *value = SMUQ10_TO_UINT(metrics->MaxSocketTemperature) *<br>
+ *value = SMUQ10_ROUND(metrics->MaxSocketTemperature) *<br>
SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
break;<br>
case METRICS_TEMPERATURE_MEM:<br>
- *value = SMUQ10_TO_UINT(metrics->MaxHbmTemperature) *<br>
+ *value = SMUQ10_ROUND(metrics->MaxHbmTemperature) *<br>
SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
break;<br>
/* This is the max of all VRs and not just SOC VR.<br>
* No need to define another data type for the same.<br>
*/<br>
case METRICS_TEMPERATURE_VRSOC:<br>
- *value = SMUQ10_TO_UINT(metrics->MaxVrTemperature) *<br>
+ *value = SMUQ10_ROUND(metrics->MaxVrTemperature) *<br>
SMU_TEMPERATURE_UNITS_PER_CENTIGRADES;<br>
break;<br>
default:<br>
@@ -1996,33 +1998,33 @@ static ssize_t smu_v13_0_6_get_gpu_metrics(struct smu_context *smu, void **table<br>
smu_cmn_init_soft_gpu_metrics(gpu_metrics, 1, 3);<br>
<br>
gpu_metrics->temperature_hotspot =<br>
- SMUQ10_TO_UINT(metrics->MaxSocketTemperature);<br>
+ SMUQ10_ROUND(metrics->MaxSocketTemperature);<br>
/* Individual HBM stack temperature is not reported */<br>
gpu_metrics->temperature_mem =<br>
- SMUQ10_TO_UINT(metrics->MaxHbmTemperature);<br>
+ SMUQ10_ROUND(metrics->MaxHbmTemperature);<br>
/* Reports max temperature of all voltage rails */<br>
gpu_metrics->temperature_vrsoc =<br>
- SMUQ10_TO_UINT(metrics->MaxVrTemperature);<br>
+ SMUQ10_ROUND(metrics->MaxVrTemperature);<br>
<br>
gpu_metrics->average_gfx_activity =<br>
- SMUQ10_TO_UINT(metrics->SocketGfxBusy);<br>
+ SMUQ10_ROUND(metrics->SocketGfxBusy);<br>
gpu_metrics->average_umc_activity =<br>
- SMUQ10_TO_UINT(metrics->DramBandwidthUtilization);<br>
+ SMUQ10_ROUND(metrics->DramBandwidthUtilization);<br>
<br>
gpu_metrics->average_socket_power =<br>
- SMUQ10_TO_UINT(metrics->SocketPower);<br>
+ SMUQ10_ROUND(metrics->SocketPower);<br>
/* Energy counter reported in 15.259uJ (2^-16) units */<br>
gpu_metrics->energy_accumulator = metrics->SocketEnergyAcc;<br>
<br>
gpu_metrics->current_gfxclk =<br>
- SMUQ10_TO_UINT(metrics->GfxclkFrequency[xcc0]);<br>
+ SMUQ10_ROUND(metrics->GfxclkFrequency[xcc0]);<br>
gpu_metrics->current_socclk =<br>
- SMUQ10_TO_UINT(metrics->SocclkFrequency[inst0]);<br>
- gpu_metrics->current_uclk = SMUQ10_TO_UINT(metrics->UclkFrequency);<br>
+ SMUQ10_ROUND(metrics->SocclkFrequency[inst0]);<br>
+ gpu_metrics->current_uclk = SMUQ10_ROUND(metrics->UclkFrequency);<br>
gpu_metrics->current_vclk0 =<br>
- SMUQ10_TO_UINT(metrics->VclkFrequency[inst0]);<br>
+ SMUQ10_ROUND(metrics->VclkFrequency[inst0]);<br>
gpu_metrics->current_dclk0 =<br>
- SMUQ10_TO_UINT(metrics->DclkFrequency[inst0]);<br>
+ SMUQ10_ROUND(metrics->DclkFrequency[inst0]);<br>
<br>
gpu_metrics->average_gfxclk_frequency = gpu_metrics->current_gfxclk;<br>
gpu_metrics->average_socclk_frequency = gpu_metrics->current_socclk;<br>
@@ -2047,9 +2049,9 @@ static ssize_t smu_v13_0_6_get_gpu_metrics(struct smu_context *smu, void **table<br>
gpu_metrics->system_clock_counter = ktime_get_boottime_ns();<br>
<br>
gpu_metrics->gfx_activity_acc =<br>
- SMUQ10_TO_UINT(metrics->SocketGfxBusyAcc);<br>
+ SMUQ10_ROUND(metrics->SocketGfxBusyAcc);<br>
gpu_metrics->mem_activity_acc =<br>
- SMUQ10_TO_UINT(metrics->DramBandwidthUtilizationAcc);<br>
+ SMUQ10_ROUND(metrics->DramBandwidthUtilizationAcc);<br>
<br>
gpu_metrics->firmware_timestamp = metrics->Timestamp;<br>
<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>