Skip to contentSkip to conversation

drm/amdgpu: fix avg vs input power reporting on smu7

PATCH In review Alex Deucher 3 participants 5 messages Oct 2, 2023

Subsystems (4)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/3 drm/amdgpu: fix avg vs input power reporting on smu7

Hawaii, Bonaire, Fiji, and Tonga support average power, the others support current power.

---
 .../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c +16 -1
index 5a2371484a58..8052fe3379b0 100644
@@ -3997,6 +3997,7 @@ static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
 	uint32_t sclk, mclk, activity_percent;
 	uint32_t offset, val_vid;
 	struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
+	struct amdgpu_device *adev = hwmgr->adev;
 
 	/* size must be at least 4 bytes for all sensors */
 	if (*size < 4)
@@ -4040,7 +4041,21 @@ static int smu7_read_sensor(struct pp_hwmgr *hwmgr, int idx,
 		*size = 4;
 		return 0;
 	case AMDGPU_PP_SENSOR_GPU_INPUT_POWER:
-		return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
+		if ((adev->asic_type != CHIP_HAWAII) &&
+		    (adev->asic_type != CHIP_BONAIRE) &&
+		    (adev->asic_type != CHIP_FIJI) &&
+		    (adev->asic_type != CHIP_TONGA))
+			return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
+		else
+			return -EOPNOTSUPP;
+	case AMDGPU_PP_SENSOR_GPU_AVG_POWER:
+		if ((adev->asic_type != CHIP_HAWAII) &&
+		    (adev->asic_type != CHIP_BONAIRE) &&
+		    (adev->asic_type != CHIP_FIJI) &&
+		    (adev->asic_type != CHIP_TONGA))
+			return -EOPNOTSUPP;
+		else
+			return smu7_get_gpu_power(hwmgr, (uint32_t *)value);
 	case AMDGPU_PP_SENSOR_VDDGFX:
 		if ((data->vr_config & VRCONF_VDDGFX_MASK) ==
 		    (VR_SVI2_PLANE_2 << VRCONF_VDDGFX_SHIFT))
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 2/3 drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL

For backwards compatibility with userspace.

Fixes 47f1724db4fe ("drm/amd: Introduce `AMDGPU_PP_SENSOR_GPU_INPUT_POWER`")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -1
index 081bd28e2443..ce71f853931a 100644
@@ -1077,7 +1077,12 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			if (amdgpu_dpm_read_sensor(adev,
 						   AMDGPU_PP_SENSOR_GPU_AVG_POWER,
 						   (void *)&ui32, &ui32_size)) {
-				return -EINVAL;
+				/* fall back to input power for backwards compat */
+				if (amdgpu_dpm_read_sensor(adev,
+							   AMDGPU_PP_SENSOR_GPU_INPUT_POWER,
+							   (void *)&ui32, &ui32_size)) {
+					return -EINVAL;
+				}
 			}
 			ui32 >>= 8;
 			break;
Signature · 1 line
2.41.0
#2 lore raw

Re: [2/3] drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL

Quoted 14 lines · Alex Deucher

For backwards compatibility with userspace.

Fixes 47f1724db4fe ("drm/amd: Introduce `AMDGPU_PP_SENSOR_GPU_INPUT_POWER`")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index 081bd28e2443..ce71f853931a 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1080

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -1
@@ -1077,7 +1077,12 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  			if (amdgpu_dpm_read_sensor(adev,
  						   AMDGPU_PP_SENSOR_GPU_AVG_POWER,
  						   (void *)&ui32, &ui32_size)) {
-				return -EINVAL;

In order to encourage userspace software to move to the new dedicated IOCTL, what do you think about having a dev_warn_once() here?

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
+				/* fall back to input power for backwards compat */
+				if (amdgpu_dpm_read_sensor(adev,
+							   AMDGPU_PP_SENSOR_GPU_INPUT_POWER,
+							   (void *)&ui32, &ui32_size)) {
+					return -EINVAL;
+				}
  			}
  			ui32 >>= 8;
  			break;
#3 lore raw

Re: [2/3] drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL

Quoted 11 lines · Mario Limonciello
Quoted 9 lines · Alex Deucher

For backwards compatibility with userspace.

Fixes 47f1724db4fe ("drm/amd: Introduce `AMDGPU_PP_SENSOR_GPU_INPUT_POWER`")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1080

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -1
index 081bd28e2443..ce71f853931a 100644
@@ -1077,7 +1077,12 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
                      if (amdgpu_dpm_read_sensor(adev,
                                                 AMDGPU_PP_SENSOR_GPU_AVG_POWER,
                                                 (void *)&ui32, &ui32_size)) {
-                             return -EINVAL;

In order to encourage userspace software to move to the new dedicated IOCTL, what do you think about having a dev_warn_once() here?

I'm not opposed, but I think it will probably just lead to more bug reports. We need to type up the mesa side anyway before we can push patch 3.

Alex

Quoted 11 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
+                             /* fall back to input power for backwards compat */
+                             if (amdgpu_dpm_read_sensor(adev,
+                                                        AMDGPU_PP_SENSOR_GPU_INPUT_POWER,
+                                                        (void *)&ui32, &ui32_size)) {
+                                     return -EINVAL;
+                             }
                      }
                      ui32 >>= 8;
                      break;
author maintainer
#4 lore raw

PATCH 3/3 drm/amdgpu: add new INFO IOCTL query for input power

In reply to Alex Deucher

Some chips provide both average and input power. Previously we just exposed average power, add a new query for input power.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 9 +++++++++
 include/uapi/drm/amdgpu_drm.h           | 2 ++
 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -0
index ce71f853931a..fdf8af570af0 100644
@@ -1086,6 +1086,15 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			}
 			ui32 >>= 8;
 			break;
+		case AMDGPU_INFO_SENSOR_GPU_INPUT_POWER:
+			/* get input GPU power */
+			if (amdgpu_dpm_read_sensor(adev,
+						   AMDGPU_PP_SENSOR_GPU_INPUT_POWER,
+						   (void *)&ui32, &ui32_size)) {
+				return -EINVAL;
+			}
+			ui32 >>= 8;
+			break;
 		case AMDGPU_INFO_SENSOR_VDDNB:
 			/* get VDDNB in millivolts */
 			if (amdgpu_dpm_read_sensor(adev,
include/uapi/drm/amdgpu_drm.h +2 -0
index 984fc16577ca..4152123c3d86 100644
@@ -865,6 +865,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
 	#define AMDGPU_INFO_SENSOR_PEAK_PSTATE_GFX_SCLK			0xa
 	/* Subquery id: Query GPU peak pstate memory clock */
 	#define AMDGPU_INFO_SENSOR_PEAK_PSTATE_GFX_MCLK			0xb
+	/* Subquery id: Query input GPU power	*/
+	#define AMDGPU_INFO_SENSOR_GPU_INPUT_POWER	0xc
 /* Number of VRAM page faults on CPU access. */
 #define AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS	0x1E
 #define AMDGPU_INFO_VRAM_LOST_COUNTER		0x1F
Signature · 1 line
2.41.0