[Mesa-dev] [PATCH 1/2] r600g, radeonsi: add driver queries for GPU temperature and shader+memory clocks

Marek Olšák maraeo at gmail.com
Mon Apr 27 07:46:27 PDT 2015


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/drivers/radeon/r600_pipe_common.c     | 13 +++++++++++--
 src/gallium/drivers/radeon/r600_pipe_common.h     |  3 +++
 src/gallium/drivers/radeon/r600_query.c           | 21 +++++++++++++++++++++
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 19 +++++++++++++++++++
 src/gallium/winsys/radeon/drm/radeon_winsys.h     |  5 ++++-
 5 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index c6d7918..97eed13 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -665,12 +665,21 @@ static int r600_get_driver_query_info(struct pipe_screen *screen,
 		{"num-bytes-moved", R600_QUERY_NUM_BYTES_MOVED, 0, TRUE},
 		{"VRAM-usage", R600_QUERY_VRAM_USAGE, rscreen->info.vram_size, TRUE},
 		{"GTT-usage", R600_QUERY_GTT_USAGE, rscreen->info.gart_size, TRUE},
+		{"temperature", R600_QUERY_GPU_TEMPERATURE, 100, FALSE},
+		{"shader-clock", R600_QUERY_CURRENT_GPU_SCLK, 0, FALSE},
+		{"memory-clock", R600_QUERY_CURRENT_GPU_MCLK, 0, FALSE}
 	};
+	unsigned num_queries;
+
+	if (rscreen->info.drm_major == 2 && rscreen->info.drm_minor >= 42)
+		num_queries = Elements(list);
+	else
+		num_queries = 8;
 
 	if (!info)
-		return Elements(list);
+		return num_queries;
 
-	if (index >= Elements(list))
+	if (index >= num_queries)
 		return 0;
 
 	*info = list[index];
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
index 384a9a6..c23072c 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -55,6 +55,9 @@
 #define R600_QUERY_NUM_BYTES_MOVED	(PIPE_QUERY_DRIVER_SPECIFIC + 5)
 #define R600_QUERY_VRAM_USAGE		(PIPE_QUERY_DRIVER_SPECIFIC + 6)
 #define R600_QUERY_GTT_USAGE		(PIPE_QUERY_DRIVER_SPECIFIC + 7)
+#define R600_QUERY_GPU_TEMPERATURE	(PIPE_QUERY_DRIVER_SPECIFIC + 8)
+#define R600_QUERY_CURRENT_GPU_SCLK	(PIPE_QUERY_DRIVER_SPECIFIC + 9)
+#define R600_QUERY_CURRENT_GPU_MCLK	(PIPE_QUERY_DRIVER_SPECIFIC + 10)
 
 #define R600_CONTEXT_STREAMOUT_FLUSH		(1u << 0)
 #define R600_CONTEXT_PRIVATE_FLAG		(1u << 1)
diff --git a/src/gallium/drivers/radeon/r600_query.c b/src/gallium/drivers/radeon/r600_query.c
index 6a35ab8..758064a 100644
--- a/src/gallium/drivers/radeon/r600_query.c
+++ b/src/gallium/drivers/radeon/r600_query.c
@@ -86,6 +86,9 @@ static struct r600_resource *r600_new_query_buffer(struct r600_common_context *c
 	case R600_QUERY_NUM_BYTES_MOVED:
 	case R600_QUERY_VRAM_USAGE:
 	case R600_QUERY_GTT_USAGE:
+	case R600_QUERY_GPU_TEMPERATURE:
+	case R600_QUERY_CURRENT_GPU_SCLK:
+	case R600_QUERY_CURRENT_GPU_MCLK:
 		return NULL;
 	}
 
@@ -382,6 +385,9 @@ static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned q
 	case R600_QUERY_NUM_BYTES_MOVED:
 	case R600_QUERY_VRAM_USAGE:
 	case R600_QUERY_GTT_USAGE:
+	case R600_QUERY_GPU_TEMPERATURE:
+	case R600_QUERY_CURRENT_GPU_SCLK:
+	case R600_QUERY_CURRENT_GPU_MCLK:
 		skip_allocation = true;
 		break;
 	default:
@@ -439,6 +445,9 @@ static void r600_begin_query(struct pipe_context *ctx, struct pipe_query *query)
 	case R600_QUERY_REQUESTED_GTT:
 	case R600_QUERY_VRAM_USAGE:
 	case R600_QUERY_GTT_USAGE:
+	case R600_QUERY_GPU_TEMPERATURE:
+	case R600_QUERY_CURRENT_GPU_SCLK:
+	case R600_QUERY_CURRENT_GPU_MCLK:
 		rquery->begin_result = 0;
 		return;
 	case R600_QUERY_BUFFER_WAIT_TIME:
@@ -513,6 +522,15 @@ static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query)
 	case R600_QUERY_GTT_USAGE:
 		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_GTT_USAGE);
 		return;
+	case R600_QUERY_GPU_TEMPERATURE:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_GPU_TEMPERATURE) / 1000;
+		return;
+	case R600_QUERY_CURRENT_GPU_SCLK:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_CURRENT_SCLK) * 1000000;
+		return;
+	case R600_QUERY_CURRENT_GPU_MCLK:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_CURRENT_MCLK) * 1000000;
+		return;
 	}
 
 	r600_emit_query_end(rctx, rquery);
@@ -570,6 +588,9 @@ static boolean r600_get_query_buffer_result(struct r600_common_context *ctx,
 	case R600_QUERY_NUM_BYTES_MOVED:
 	case R600_QUERY_VRAM_USAGE:
 	case R600_QUERY_GTT_USAGE:
+	case R600_QUERY_GPU_TEMPERATURE:
+	case R600_QUERY_CURRENT_GPU_SCLK:
+	case R600_QUERY_CURRENT_GPU_MCLK:
 		result->u64 = query->end_result - query->begin_result;
 		return TRUE;
 	}
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 2b12f4d..b3e3cb2 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -49,6 +49,13 @@
 #define RADEON_INFO_ACTIVE_CU_COUNT 0x20
 #endif
 
+#ifndef RADEON_INFO_CURRENT_GPU_TEMP
+#define RADEON_INFO_CURRENT_GPU_TEMP	0x21
+#define RADEON_INFO_CURRENT_GPU_SCLK	0x22
+#define RADEON_INFO_CURRENT_GPU_MCLK	0x23
+#define RADEON_INFO_READ_REG		0x24
+#endif
+
 static struct util_hash_table *fd_tab = NULL;
 pipe_static_mutex(fd_tab_mutex);
 
@@ -559,6 +566,18 @@ static uint64_t radeon_query_value(struct radeon_winsys *rws,
         radeon_get_drm_value(ws->fd, RADEON_INFO_GTT_USAGE,
                              "gtt-usage", (uint32_t*)&retval);
         return retval;
+    case RADEON_GPU_TEMPERATURE:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_CURRENT_GPU_TEMP,
+                             "gpu-temp", (uint32_t*)&retval);
+        return retval;
+    case RADEON_CURRENT_SCLK:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_CURRENT_GPU_SCLK,
+                             "current-gpu-sclk", (uint32_t*)&retval);
+        return retval;
+    case RADEON_CURRENT_MCLK:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_CURRENT_GPU_MCLK,
+                             "current-gpu-mclk", (uint32_t*)&retval);
+        return retval;
     }
     return 0;
 }
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index a8cc60a..996a201 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -169,7 +169,10 @@ enum radeon_value_id {
     RADEON_NUM_CS_FLUSHES,
     RADEON_NUM_BYTES_MOVED,
     RADEON_VRAM_USAGE,
-    RADEON_GTT_USAGE
+    RADEON_GTT_USAGE,
+    RADEON_GPU_TEMPERATURE,
+    RADEON_CURRENT_SCLK,
+    RADEON_CURRENT_MCLK
 };
 
 enum radeon_bo_priority {
-- 
2.1.0



More information about the mesa-dev mailing list