<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 style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Split this first patch into two, one to add the new sensor type and vega20 implementation, and one to add the new sysfs file.  Then make the sysfs file change the last one in the series.  With that fixed, the series is:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Evan Quan <evan.quan@amd.com><br>
<b>Sent:</b> Thursday, April 25, 2019 4:05 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Deucher, Alexander; Xu, Feifei; Quan, Evan; Russell, Kent; Freehill, Chris<br>
<b>Subject:</b> [PATCH 1/3] drm/amd/powerplay: expose Vega20 realtime memory utilization</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">A new sysfs interface mem_busy_percent is added for telling<br>
how busy the VRAM is(in percentage).<br>
<br>
Change-Id: I302f7594000a1ad609d71563d8ab3872f37bfb8d<br>
Signed-off-by: Evan Quan <evan.quan@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c        | 40 +++++++++++++++++++<br>
 .../gpu/drm/amd/include/kgd_pp_interface.h    |  1 +<br>
 .../drm/amd/powerplay/hwmgr/vega20_hwmgr.c    | 16 +++++++-<br>
 3 files changed, 55 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
index b80873348624..eab58771132c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
@@ -1354,6 +1354,32 @@ static ssize_t amdgpu_get_busy_percent(struct device *dev,<br>
         return snprintf(buf, PAGE_SIZE, "%d\n", value);<br>
 }<br>
 <br>
+/**<br>
+ * DOC: mem_busy_percent<br>
+ *<br>
+ * The amdgpu driver provides a sysfs API for reading how busy the VRAM<br>
+ * is as a percentage.  The file mem_busy_percent is used for this.<br>
+ * The SMU firmware computes a percentage of load based on the<br>
+ * aggregate activity level in the IP cores.<br>
+ */<br>
+static ssize_t amdgpu_get_memory_busy_percent(struct device *dev,<br>
+               struct device_attribute *attr,<br>
+               char *buf)<br>
+{<br>
+       struct drm_device *ddev = dev_get_drvdata(dev);<br>
+       struct amdgpu_device *adev = ddev->dev_private;<br>
+       int r, value, size = sizeof(value);<br>
+<br>
+       /* read the IP busy sensor */<br>
+       r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,<br>
+                                  (void *)&value, &size);<br>
+<br>
+       if (r)<br>
+               return r;<br>
+<br>
+       return snprintf(buf, PAGE_SIZE, "%d\n", value);<br>
+}<br>
+<br>
 /**<br>
  * DOC: pcie_bw<br>
  *<br>
@@ -1423,6 +1449,8 @@ static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,<br>
                 amdgpu_set_pp_od_clk_voltage);<br>
 static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,<br>
                 amdgpu_get_busy_percent, NULL);<br>
+static DEVICE_ATTR(mem_busy_percent, S_IRUGO,<br>
+               amdgpu_get_memory_busy_percent, NULL);<br>
 static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL);<br>
 static DEVICE_ATTR(ppfeatures, S_IRUGO | S_IWUSR,<br>
                 amdgpu_get_ppfeature_status,<br>
@@ -2805,6 +2833,16 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)<br>
                                 "gpu_busy_level\n");<br>
                 return ret;<br>
         }<br>
+       /* APU does not have its own dedicated memory */<br>
+       if (!(adev->flags & AMD_IS_APU)) {<br>
+               ret = device_create_file(adev->dev,<br>
+                               &dev_attr_mem_busy_percent);<br>
+               if (ret) {<br>
+                       DRM_ERROR("failed to create device file "<br>
+                                       "mem_busy_percent\n");<br>
+                       return ret;<br>
+               }<br>
+       }<br>
         /* PCIe Perf counters won't work on APU nodes */<br>
         if (!(adev->flags & AMD_IS_APU)) {<br>
                 ret = device_create_file(adev->dev, &dev_attr_pcie_bw);<br>
@@ -2870,6 +2908,8 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)<br>
                 device_remove_file(adev->dev,<br>
                                 &dev_attr_pp_od_clk_voltage);<br>
         device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);<br>
+       if (!(adev->flags & AMD_IS_APU))<br>
+               device_remove_file(adev->dev, &dev_attr_mem_busy_percent);<br>
         if (!(adev->flags & AMD_IS_APU))<br>
                 device_remove_file(adev->dev, &dev_attr_pcie_bw);<br>
         if ((adev->asic_type >= CHIP_VEGA10) &&<br>
diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
index 30788d510576..9f661bf96ed0 100644<br>
--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
+++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h<br>
@@ -109,6 +109,7 @@ enum amd_pp_sensors {<br>
         AMDGPU_PP_SENSOR_UVD_DCLK,<br>
         AMDGPU_PP_SENSOR_VCE_ECCLK,<br>
         AMDGPU_PP_SENSOR_GPU_LOAD,<br>
+       AMDGPU_PP_SENSOR_MEM_LOAD,<br>
         AMDGPU_PP_SENSOR_GFX_MCLK,<br>
         AMDGPU_PP_SENSOR_GPU_TEMP,<br>
         AMDGPU_PP_SENSOR_EDGE_TEMP = AMDGPU_PP_SENSOR_GPU_TEMP,<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 abd3df9a0211..7534eb628803 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega20_hwmgr.c<br>
@@ -2094,6 +2094,7 @@ static int vega20_get_current_clk_freq(struct pp_hwmgr *hwmgr,<br>
 }<br>
 <br>
 static int vega20_get_current_activity_percent(struct pp_hwmgr *hwmgr,<br>
+               int idx,<br>
                 uint32_t *activity_percent)<br>
 {<br>
         int ret = 0;<br>
@@ -2103,7 +2104,17 @@ static int vega20_get_current_activity_percent(struct pp_hwmgr *hwmgr,<br>
         if (ret)<br>
                 return ret;<br>
 <br>
-       *activity_percent = metrics_table.AverageGfxActivity;<br>
+       switch (idx) {<br>
+       case AMDGPU_PP_SENSOR_GPU_LOAD:<br>
+               *activity_percent = metrics_table.AverageGfxActivity;<br>
+               break;<br>
+       case AMDGPU_PP_SENSOR_MEM_LOAD:<br>
+               *activity_percent = metrics_table.AverageUclkActivity;<br>
+               break;<br>
+       default:<br>
+               pr_err("Invalid index for retrieving clock activity\n");<br>
+               return -EINVAL;<br>
+       }<br>
 <br>
         return ret;<br>
 }<br>
@@ -2134,7 +2145,8 @@ static int vega20_read_sensor(struct pp_hwmgr *hwmgr, int idx,<br>
                         *size = 4;<br>
                 break;<br>
         case AMDGPU_PP_SENSOR_GPU_LOAD:<br>
-               ret = vega20_get_current_activity_percent(hwmgr, (uint32_t *)value);<br>
+       case AMDGPU_PP_SENSOR_MEM_LOAD:<br>
+               ret = vega20_get_current_activity_percent(hwmgr, idx, (uint32_t *)value);<br>
                 if (!ret)<br>
                         *size = 4;<br>
                 break;<br>
-- <br>
2.21.0<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></div>
</span></font></div>
</body>
</html>