[PATCH 1/2] drm/amdgpu: add sclk/uclk sensor support for navi

Alex Deucher alexdeucher at gmail.com
Wed Jul 17 14:35:39 UTC 2019


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

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

diff --git a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
index 7f11c641b7b8..146412c012a9 100644
--- a/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
+++ b/drivers/gpu/drm/amd/powerplay/navi10_ppt.c
@@ -1303,6 +1303,35 @@ static int navi10_thermal_get_temperature(struct smu_context *smu,
 	return 0;
 }
 
+static int navi10_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 navi10_read_sensor(struct smu_context *smu,
 				 enum amd_pp_sensors sensor,
 				 void *data, uint32_t *size)
@@ -1331,6 +1360,11 @@ static int navi10_read_sensor(struct smu_context *smu,
 		ret = navi10_thermal_get_temperature(smu, sensor, (uint32_t *)data);
 		*size = 4;
 		break;
+	case AMDGPU_PP_SENSOR_GFX_SCLK:
+	case AMDGPU_PP_SENSOR_GFX_MCLK:
+		ret = navi10_get_avg_clocks(smu, sensor, (uint32_t *)data);
+		*size = 4;
+		break;
 	default:
 		return -EINVAL;
 	}
-- 
2.20.1



More information about the amd-gfx mailing list