[PATCH 2/2] drm/amdgpu: expose the current temperature and shader/memory clocks

Samuel Pitoiset samuel.pitoiset at gmail.com
Mon Feb 13 22:01:32 UTC 2017


The clocks are returned in Mhz and the temperature in millidegrees.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 27 +++++++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h           |  8 +++++++-
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index f275a6b54e9f..bae3ab8407b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -59,9 +59,10 @@
  * - 3.7.0 - Add support for VCE clock list packet
  * - 3.8.0 - Add support raster config init in the kernel
  * - 3.9.0 - Add support for memory query info about VRAM and GTT.
+ * - 3.10.0 - Add support for clocks/temperature query info.
  */
 #define KMS_DRIVER_MAJOR	3
-#define KMS_DRIVER_MINOR	9
+#define KMS_DRIVER_MINOR	10
 #define KMS_DRIVER_PATCHLEVEL	0
 
 int amdgpu_vram_limit = 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index d5f9d6a4b661..f032d0882bc5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -241,6 +241,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 	uint32_t ui32 = 0;
 	uint64_t ui64 = 0;
 	int i, found;
+	int ui32_size = sizeof(ui32);
 
 	if (!info->return_size || !info->return_pointer)
 		return -EINVAL;
@@ -597,6 +598,32 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			return -EINVAL;
 		}
 	}
+	case AMDGPU_INFO_CURRENT_GPU_SCLK:
+		/* get sclk in Mhz */
+		if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
+					    (void *)&ui32, &ui32_size)) {
+			ui32 /= 100;
+			return copy_to_user(out, &ui32,
+					    min(size, 4u)) ? -EFAULT : 0;
+		}
+		return -EINVAL;
+	case AMDGPU_INFO_CURRENT_GPU_MCLK:
+		/* get mclk in Mhz */
+		if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
+					    (void *)&ui32, &ui32_size)) {
+			ui32 /= 100;
+			return copy_to_user(out, &ui32,
+					    min(size, 4u)) ? -EFAULT : 0;
+		}
+		return -EINVAL;
+	case AMDGPU_INFO_CURRENT_GPU_TEMP:
+		/* get temperature in millidegrees C */
+		if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
+					    (void *)&ui32, &ui32_size)) {
+			return copy_to_user(out, &ui32,
+					    min(size, 4u)) ? -EFAULT : 0;
+		}
+		return -EINVAL;
 	default:
 		DRM_DEBUG_KMS("Invalid request %d\n", info->query);
 		return -EINVAL;
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 07e3710f91cc..0db7a481046a 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -532,8 +532,14 @@ struct drm_amdgpu_cs_chunk_data {
 	#define AMDGPU_INFO_VBIOS_SIZE		0x1
 	/* Subquery id: Query vbios image */
 	#define AMDGPU_INFO_VBIOS_IMAGE		0x2
+/* Query the current shader clock */
+#define AMDGPU_INFO_CURRENT_GPU_SCLK		0x1c
+/* Query the current memory clock */
+#define AMDGPU_INFO_CURRENT_GPU_MCLK		0x1d
+/* Query the current temperature */
+#define AMDGPU_INFO_CURRENT_GPU_TEMP		0x1e
 /* Query UVD handles */
-#define AMDGPU_INFO_NUM_HANDLES			0x1C
+#define AMDGPU_INFO_NUM_HANDLES			0x1f
 
 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT	0
 #define AMDGPU_INFO_MMR_SE_INDEX_MASK	0xff
-- 
2.11.1



More information about the amd-gfx mailing list