<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">Acked-by: Slava Abramov <slava.abramov@amd.com></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 Tom St Denis <tom.stdenis@amd.com><br>
<b>Sent:</b> Wednesday, June 20, 2018 12:48:52 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> StDenis, Tom<br>
<b>Subject:</b> [PATCH] drm/amd/amdgpu: Add a GPU_LOAD entry to sysfs (v2)</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">This adds what should be a stable interface to read GPU<br>
load from userspace.<br>
<br>
(v2): Fix comments and name of file per recommendations.<br>
<br>
Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 47 ++++++++++++++++++++++++++++++++++<br>
1 file changed, 47 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
index 113edffb5960..49138ac2be24 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c<br>
@@ -918,6 +918,43 @@ static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,<br>
return -EINVAL;<br>
}<br>
<br>
+/**<br>
+ * DOC: busy_percent<br>
+ *<br>
+ * The firmware computes a percentage of load based on the activity<br>
+ * level in the IP cores.<br>
+ */<br>
+static ssize_t amdgpu_get_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>
+ /* sanity check PP is enabled */<br>
+ if (!(adev->powerplay.pp_funcs &&<br>
+ adev->powerplay.pp_funcs->read_sensor))<br>
+ return -EINVAL;<br>
+<br>
+ /* read the IP busy sensor */<br>
+ r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,<br>
+ (void *)&value, &size);<br>
+ if (r)<br>
+ return r;<br>
+<br>
+ return snprintf(buf, PAGE_SIZE, "%d\n", value);<br>
+}<br>
+<br>
+static ssize_t amdgpu_set_busy_percent(struct device *dev,<br>
+ struct device_attribute *attr,<br>
+ const char *buf,<br>
+ size_t count)<br>
+{<br>
+ return -EINVAL;<br>
+}<br>
+<br>
+<br>
static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);<br>
static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,<br>
amdgpu_get_dpm_forced_performance_level,<br>
@@ -951,6 +988,8 @@ static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,<br>
static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,<br>
amdgpu_get_pp_od_clk_voltage,<br>
amdgpu_set_pp_od_clk_voltage);<br>
+static DEVICE_ATTR(gpu_busy_percent, S_IRUGO | S_IWUSR,<br>
+ amdgpu_get_busy_percent, amdgpu_set_busy_percent);<br>
<br>
static ssize_t amdgpu_hwmon_show_temp(struct device *dev,<br>
struct device_attribute *attr,<br>
@@ -1854,6 +1893,13 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)<br>
"pp_od_clk_voltage\n");<br>
return ret;<br>
}<br>
+ ret = device_create_file(adev->dev,<br>
+ &dev_attr_gpu_busy_percent);<br>
+ if (ret) {<br>
+ DRM_ERROR("failed to create device file "<br>
+ "gpu_busy_level\n");<br>
+ return ret;<br>
+ }<br>
ret = amdgpu_debugfs_pm_init(adev);<br>
if (ret) {<br>
DRM_ERROR("Failed to register debugfs file for dpm!\n");<br>
@@ -1889,6 +1935,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)<br>
&dev_attr_pp_power_profile_mode);<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>
}<br>
<br>
void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)<br>
-- <br>
2.14.4<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>