[2/2] drm/amdgpu: add sclk/uclk sensor support for vega20

Submitted by Alex Deucher on July 17, 2019, 2:35 p.m.

Details

Message ID 20190717143540.30090-2-alexander.deucher@amd.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Alex Deucher July 17, 2019, 2:35 p.m.
Query the metrics table to get the average sclk and uclk.

Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
index 9204e4e50d09..763d73af6cd1 100644
--- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c
@@ -3117,6 +3117,36 @@  static int vega20_thermal_get_temperature(struct smu_context *smu,
 
 	return 0;
 }
+
+static int vega20_get_avg_clocks(struct smu_context *smu,
+				 enum amd_pp_sensors sensor,
+				 uint32_t *value)
+{
+	SmuMetrics_t metrics;
+	int ret = 0;
+
+	if (!value)
+		return -EINVAL;
+
+	ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, (void *)&metrics, false);
+	if (ret)
+		return ret;
+
+	switch (sensor) {
+	case AMDGPU_PP_SENSOR_GFX_SCLK:
+		*value = metrics.AverageGfxclkFrequency * 100;
+		break;
+	case AMDGPU_PP_SENSOR_GFX_MCLK:
+		*value = metrics.AverageUclkFrequency * 100;
+		break;
+	default:
+		pr_err("Invalid sensor for retrieving avg clock\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int vega20_read_sensor(struct smu_context *smu,
 				 enum amd_pp_sensors sensor,
 				 void *data, uint32_t *size)
@@ -3147,6 +3177,11 @@  static int vega20_read_sensor(struct smu_context *smu,
 		ret = vega20_thermal_get_temperature(smu, sensor, (uint32_t *)data);
 		*size = 4;
 		break;
+	case AMDGPU_PP_SENSOR_GFX_SCLK:
+	case AMDGPU_PP_SENSOR_GFX_MCLK:
+		ret = vega20_get_avg_clocks(smu, sensor, (uint32_t *)data);
+		*size = 4;
+		break;
 	default:
 		return -EINVAL;
 	}

Comments

I think the AMDGPU_PP_SENSOR_GFX_SCLK and AMDGPU_PP_SENSOR_GFX_MCLK requests are handled in smu_v11_0_read_sensor.
It means it cannot reach navi10_ppt.c and vega20_ppt.c.
Maybe this should be fixed in smu_v11_0_read_sensor.

Regards,
Evan
> -----Original Message-----

> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Alex

> Deucher

> Sent: Wednesday, July 17, 2019 10:36 PM

> To: amd-gfx@lists.freedesktop.org

> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>

> Subject: [PATCH 2/2] drm/amdgpu: add sclk/uclk sensor support for vega20

> 

> Query the metrics table to get the average sclk and uclk.

> 

> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

> ---

>  drivers/gpu/drm/amd/powerplay/vega20_ppt.c | 35

> ++++++++++++++++++++++

>  1 file changed, 35 insertions(+)

> 

> diff --git a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c

> b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c

> index 9204e4e50d09..763d73af6cd1 100644

> --- a/drivers/gpu/drm/amd/powerplay/vega20_ppt.c

> +++ b/drivers/gpu/drm/amd/powerplay/vega20_ppt.c

> @@ -3117,6 +3117,36 @@ static int vega20_thermal_get_temperature(struct

> smu_context *smu,

> 

>  	return 0;

>  }

> +

> +static int vega20_get_avg_clocks(struct smu_context *smu,

> +				 enum amd_pp_sensors sensor,

> +				 uint32_t *value)

> +{

> +	SmuMetrics_t metrics;

> +	int ret = 0;

> +

> +	if (!value)

> +		return -EINVAL;

> +

> +	ret = smu_update_table(smu, SMU_TABLE_SMU_METRICS, (void

> *)&metrics, false);

> +	if (ret)

> +		return ret;

> +

> +	switch (sensor) {

> +	case AMDGPU_PP_SENSOR_GFX_SCLK:

> +		*value = metrics.AverageGfxclkFrequency * 100;

> +		break;

> +	case AMDGPU_PP_SENSOR_GFX_MCLK:

> +		*value = metrics.AverageUclkFrequency * 100;

> +		break;

> +	default:

> +		pr_err("Invalid sensor for retrieving avg clock\n");

> +		return -EINVAL;

> +	}

> +

> +	return 0;

> +}

> +

>  static int vega20_read_sensor(struct smu_context *smu,

>  				 enum amd_pp_sensors sensor,

>  				 void *data, uint32_t *size)

> @@ -3147,6 +3177,11 @@ static int vega20_read_sensor(struct smu_context

> *smu,

>  		ret = vega20_thermal_get_temperature(smu, sensor,

> (uint32_t *)data);

>  		*size = 4;

>  		break;

> +	case AMDGPU_PP_SENSOR_GFX_SCLK:

> +	case AMDGPU_PP_SENSOR_GFX_MCLK:

> +		ret = vega20_get_avg_clocks(smu, sensor, (uint32_t *)data);

> +		*size = 4;

> +		break;

>  	default:

>  		return -EINVAL;

>  	}

> --

> 2.20.1

> 

> _______________________________________________

> amd-gfx mailing list

> amd-gfx@lists.freedesktop.org

> https://lists.freedesktop.org/mailman/listinfo/amd-gfx