Skip to content

Commit b374d82

Browse files
Tom St Denisalexdeucher
authored andcommitted
drm/amd/amdgpu: Add a GPU_LOAD entry to sysfs (v3)
This adds what should be a stable interface to read GPU load from userspace. (v2): Fix comments and name of file per recommendations. (v3): Add chapter to amdgpu.rst as well. Signed-off-by: Tom St Denis <tom.stdenis@amd.com> Acked-by: Slava Abramov <slava.abramov@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent a315f23 commit b374d82

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎Documentation/gpu/amdgpu.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,8 @@ pp_power_profile_mode
115115
.. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
116116
:doc: pp_power_profile_mode
117117

118+
busy_percent
119+
~~~~~~~~~~~~
120+
121+
.. kernel-doc:: drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
122+
:doc: busy_percent

‎drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,36 @@ static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
918918
return -EINVAL;
919919
}
920920

921+
/**
922+
* DOC: busy_percent
923+
*
924+
* The amdgpu driver provides a sysfs API for reading how busy the GPU
925+
* is as a percentage. The file gpu_busy_percent is used for this.
926+
* The SMU firmware computes a percentage of load based on the
927+
* aggregate activity level in the IP cores.
928+
*/
929+
static ssize_t amdgpu_get_busy_percent(struct device *dev,
930+
struct device_attribute *attr,
931+
char *buf)
932+
{
933+
struct drm_device *ddev = dev_get_drvdata(dev);
934+
struct amdgpu_device *adev = ddev->dev_private;
935+
int r, value, size = sizeof(value);
936+
937+
/* sanity check PP is enabled */
938+
if (!(adev->powerplay.pp_funcs &&
939+
adev->powerplay.pp_funcs->read_sensor))
940+
return -EINVAL;
941+
942+
/* read the IP busy sensor */
943+
r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
944+
(void *)&value, &size);
945+
if (r)
946+
return r;
947+
948+
return snprintf(buf, PAGE_SIZE, "%d\n", value);
949+
}
950+
921951
static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
922952
static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,
923953
amdgpu_get_dpm_forced_performance_level,
@@ -951,6 +981,8 @@ static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,
951981
static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
952982
amdgpu_get_pp_od_clk_voltage,
953983
amdgpu_set_pp_od_clk_voltage);
984+
static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,
985+
amdgpu_get_busy_percent, NULL);
954986

955987
static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
956988
struct device_attribute *attr,
@@ -1854,6 +1886,13 @@ int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
18541886
"pp_od_clk_voltage\n");
18551887
return ret;
18561888
}
1889+
ret = device_create_file(adev->dev,
1890+
&dev_attr_gpu_busy_percent);
1891+
if (ret) {
1892+
DRM_ERROR("failed to create device file "
1893+
"gpu_busy_level\n");
1894+
return ret;
1895+
}
18571896
ret = amdgpu_debugfs_pm_init(adev);
18581897
if (ret) {
18591898
DRM_ERROR("Failed to register debugfs file for dpm!\n");
@@ -1889,6 +1928,7 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
18891928
&dev_attr_pp_power_profile_mode);
18901929
device_remove_file(adev->dev,
18911930
&dev_attr_pp_od_clk_voltage);
1931+
device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
18921932
}
18931933

18941934
void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)

0 commit comments

Comments
 (0)