r600g,radeonsi: add driver queries for GPU temperature and shader+memory clocks
authorMarek Olšák <marek.olsak@amd.com>
Mon, 23 Feb 2015 23:50:20 +0000 (00:50 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 28 Apr 2015 14:05:45 +0000 (16:05 +0200)
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
src/gallium/drivers/radeon/r600_pipe_common.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/r600_query.c
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
src/gallium/winsys/radeon/drm/radeon_winsys.h

index c6d79181d195ef5cb3102c4d84bcd4cf937d4899..97eed13633128811cfcb126c64b4cb51df06f0fe 100644 (file)
@@ -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];
index 384a9a6a2000b52303acff0f63613db96aff27e7..c23072c49de11e8c8443d1dd01afd399b6812d4d 100644 (file)
@@ -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)
index 6a35ab8190a6b817de2342f0687fa5148c5612f7..758064af712f0ca4e8c4ea519a2c7a3c01f35c73 100644 (file)
@@ -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;
        }
index 2b12f4da46676a94a783ec27cdbd91365c752413..b3e3cb29429f82dd565a04c1870106802a204db8 100644 (file)
 #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;
 }
index a8cc60a33e40c751f7fc348b6ab2c108f0f6f222..996a2017b07d65cd9d4d4af64af127220deb1b3b 100644 (file)
@@ -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 {