[PATCH] drm/amd/amdgpu: Expose some power info through AMDGPU_INFO

Christian König ckoenig.leichtzumerken at gmail.com
Tue Apr 13 13:20:26 UTC 2021



Am 13.04.21 um 15:09 schrieb Sun, Roy:
> [AMD Official Use Only - Internal Distribution Only]
>
> ping
>
> -----Original Message-----
> From: Roy Sun <Roy.Sun at amd.com>
> Sent: Monday, April 12, 2021 8:15 PM
> To: amd-gfx at lists.freedesktop.org
> Cc: Sun, Roy <Roy.Sun at amd.com>
> Subject: [PATCH] drm/amd/amdgpu: Expose some power info through AMDGPU_INFO
>
> Add interface to get the mm clock, temperature and memory load
>
> Signed-off-by: Roy Sun <Roy.Sun at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 50 +++++++++++++++++++++++++
>   include/uapi/drm/amdgpu_drm.h           | 12 ++++++
>   2 files changed, 62 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index b2e774aeab45..e5b16e0819ce 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -971,6 +971,56 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
>   			}
>   			ui32 /= 100;
>   			break;
> +		case AMDGPU_INFO_SENSOR_UVD_VCLK:
> +			/* get mm vclk in Mhz */

Maybe drop the comment, it looks redundant.

> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_UVD_VCLK,

In general I would not repeat that code over and over again, but rather 
translate the parameter and then call amdgpu_dpm_read_sensor() once.

But this is just my top level view on code I don't know well.

Regards,
Christian.

> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			ui32 /= 100;
> +			break;
> +		case AMDGPU_INFO_SENSOR_UVD_DCLK:
> +			/* get mm dclk in Mhz */
> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_UVD_DCLK,
> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			ui32 /= 100;
> +			break;
> +		case AMDGPU_INFO_SENSOR_HOTSPOT_TEMP:
> +			/* get junction temperature */
> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			break;
> +		case AMDGPU_INFO_SENSOR_EDGE_TEMP:
> +			/* get current edge temperature */
> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_EDGE_TEMP,
> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			break;
> +		case AMDGPU_INFO_SENSOR_MEM_TEMP:
> +			/* get current memory temperature */
> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_MEM_TEMP,
> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			break;
> +		case AMDGPU_INFO_SENSOR_MEM_LOAD:
> +			/* get memory load */
> +			if (amdgpu_dpm_read_sensor(adev,
> +						   AMDGPU_PP_SENSOR_MEM_LOAD,
> +						   (void *)&ui32, &ui32_size)) {
> +				return -EINVAL;
> +			}
> +			break;
>   		default:
>   			DRM_DEBUG_KMS("Invalid request %d\n",
>   				      info->sensor_info.type);
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 8b832f7458f2..484c72e17c72 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -780,6 +780,18 @@ struct drm_amdgpu_cs_chunk_data {
>   	#define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_SCLK		0x8
>   	/* Subquery id: Query GPU stable pstate memory clock */
>   	#define AMDGPU_INFO_SENSOR_STABLE_PSTATE_GFX_MCLK		0x9
> +	/* Subquery id: Query GPU mm vclk */
> +	#define AMDGPU_INFO_SENSOR_UVD_VCLK		0xa
> +	/* Subquery id: Query GPU mm dclk */
> +	#define AMDGPU_INFO_SENSOR_UVD_DCLK		0xb
> +	/* Subquery id: Query junction temperature */
> +	#define AMDGPU_INFO_SENSOR_HOTSPOT_TEMP		0xc
> +	/* Subquery id: Query edge temperature */
> +	#define AMDGPU_INFO_SENSOR_EDGE_TEMP		0xd
> +	/* Subquery id: Query memory temperature */
> +	#define AMDGPU_INFO_SENSOR_MEM_TEMP		0xe
> +	/* Subquery id: Query Memory load */
> +	#define AMDGPU_INFO_SENSOR_MEM_LOAD		0xf
>   /* Number of VRAM page faults on CPU access. */
>   #define AMDGPU_INFO_NUM_VRAM_CPU_PAGE_FAULTS	0x1E
>   #define AMDGPU_INFO_VRAM_LOST_COUNTER		0x1F
> --
> 2.31.1
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx



More information about the amd-gfx mailing list