drm/amdgpu: fix avg vs input power reporting on smu7
Alex Deucher
maintainerPATCH 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
@@ -3995,6 +3995,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 )
@@ -4038,7 +4039,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
Alex Deucher
maintainerPATCH 2/3 drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL
For backwards compatibility with userspace.
--- 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
@@ -1105,7 +1105,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
RE: [PATCH 2/3] drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL
[AMD Official Use Only - General]
Best Regards,
Kevin
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, November 10, 2023 6:14 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 2/3] drm/amdgpu: fall back to INPUT power for AVG power via INFO IOCTL
For backwards compatibility with userspace.
--- 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
@@ -1105,7 +1105,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 ;
--
2.41.0
Alex Deucher
maintainerPATCH 3/3 drm/amdgpu: add new INFO IOCTL query for input power
In reply to Alex DeucherSome chips provide both average and input power. Previously we just exposed average power, add a new query for input power.
Example userspace:
https://github.com/Umio-Yasuno/libdrm-amdgpu-sys-rs/tree/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
@@ -1114,6 +1114,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
@@ -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
Re: [PATCH 3/3] drm/amdgpu: add new INFO IOCTL query for input power
Quoted 4 lines · Alex Deucher
Some chips provide both average and input power. Previously we just exposed average power, add a new query for input power.
Input looks like a misnomer (not the supply side, but the power consumed). Better to rename to instantaneous or current power. I guess that will require rename of AMDGPU_PP_SENSOR_GPU_INPUT_POWER too.
Thanks,
Lijo
Quoted 42 lines
Example userspace:
https://github.com/Umio-Yasuno/libdrm-amdgpu-sys-rs/tree/input_powerSigned-off-by Alex Deucher <[email protected]>--- 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@@ -1114,6 +1114,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@@ -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
Re: [PATCH 3/3] drm/amdgpu: add new INFO IOCTL query for input power
Quoted 4 lines · Lijo
On 11/10/2023 3:44 AM, Alex Deucher wrote:
Quoted 8 lines
Quoted 4 lines
Some chips provide both average and input power. Previously we just exposed average power, add a new query for input power.
Input looks like a misnomer (not the supply side, but the power consumed). Better to rename to instantaneous or current power. I guess that will require rename of
AMDGPU_PP_SENSOR_GPU_INPUT_POWERtoo.
It aligns with the sysfs naming. E.g.,
https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
power[1-*]_input Instantaneous power use
Unit: microWatt
RO
Alex
Quoted 46 lines
Thanks,
LijoQuoted 42 lines
Example userspace:
https://github.com/Umio-Yasuno/libdrm-amdgpu-sys-rs/tree/input_powerSigned-off-by Alex Deucher <[email protected]>--- 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@@ -1114,6 +1114,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@@ -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