diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2018-01-24 18:34:26 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2018-02-19 14:18:50 -0500 |
commit | 2976fc2622b1e77236bea9f88a68f6ac5d2fa6ab (patch) | |
tree | 266dcf91630828400f338b382c8ebc5134d4963e /drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | |
parent | 2bd376bf8f4db03f30ea9d9832a75bc29c2e6e6a (diff) |
drm/amdgpu/pm: report gpu average power via hwmon API
Expose power via hwmon.
Acked-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Rex Zhu <Rex.Zhu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c index eaf91d0e831e..17f9f3ad9bd1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | |||
@@ -1170,6 +1170,38 @@ static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev, | |||
1170 | return snprintf(buf, PAGE_SIZE, "vddnb\n"); | 1170 | return snprintf(buf, PAGE_SIZE, "vddnb\n"); |
1171 | } | 1171 | } |
1172 | 1172 | ||
1173 | static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev, | ||
1174 | struct device_attribute *attr, | ||
1175 | char *buf) | ||
1176 | { | ||
1177 | struct amdgpu_device *adev = dev_get_drvdata(dev); | ||
1178 | struct drm_device *ddev = adev->ddev; | ||
1179 | struct pp_gpu_power query = {0}; | ||
1180 | int r, size = sizeof(query); | ||
1181 | unsigned uw; | ||
1182 | |||
1183 | /* Can't get power when the card is off */ | ||
1184 | if ((adev->flags & AMD_IS_PX) && | ||
1185 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) | ||
1186 | return -EINVAL; | ||
1187 | |||
1188 | /* sanity check PP is enabled */ | ||
1189 | if (!(adev->powerplay.pp_funcs && | ||
1190 | adev->powerplay.pp_funcs->read_sensor)) | ||
1191 | return -EINVAL; | ||
1192 | |||
1193 | /* get the voltage */ | ||
1194 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, | ||
1195 | (void *)&query, &size); | ||
1196 | if (r) | ||
1197 | return r; | ||
1198 | |||
1199 | /* convert to microwatts */ | ||
1200 | uw = (query.average_gpu_power >> 8) * 1000000; | ||
1201 | |||
1202 | return snprintf(buf, PAGE_SIZE, "%u\n", uw); | ||
1203 | } | ||
1204 | |||
1173 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0); | 1205 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0); |
1174 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0); | 1206 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0); |
1175 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1); | 1207 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1); |
@@ -1182,6 +1214,7 @@ static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0) | |||
1182 | static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0); | 1214 | static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0); |
1183 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0); | 1215 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0); |
1184 | static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0); | 1216 | static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0); |
1217 | static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0); | ||
1185 | 1218 | ||
1186 | static struct attribute *hwmon_attributes[] = { | 1219 | static struct attribute *hwmon_attributes[] = { |
1187 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 1220 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
@@ -1196,6 +1229,7 @@ static struct attribute *hwmon_attributes[] = { | |||
1196 | &sensor_dev_attr_in0_label.dev_attr.attr, | 1229 | &sensor_dev_attr_in0_label.dev_attr.attr, |
1197 | &sensor_dev_attr_in1_input.dev_attr.attr, | 1230 | &sensor_dev_attr_in1_input.dev_attr.attr, |
1198 | &sensor_dev_attr_in1_label.dev_attr.attr, | 1231 | &sensor_dev_attr_in1_label.dev_attr.attr, |
1232 | &sensor_dev_attr_power1_average.dev_attr.attr, | ||
1199 | NULL | 1233 | NULL |
1200 | }; | 1234 | }; |
1201 | 1235 | ||