gallium/radeon: add a HUD query for monitoring the CS thread activity
authorMarek Olšák <marek.olsak@amd.com>
Sat, 11 Feb 2017 19:24:07 +0000 (20:24 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 15 Feb 2017 13:35:52 +0000 (14:35 +0100)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeon/r600_query.c
src/gallium/drivers/radeon/r600_query.h
src/gallium/drivers/radeon/radeon_winsys.h
src/gallium/winsys/amdgpu/drm/amdgpu_winsys.c
src/gallium/winsys/radeon/drm/radeon_drm_winsys.c

index 05741d33c9fa67b3d1a97c5913c20b2b2ad8f7b8..bcc573169b28e5a981dcad90532c6890097115d3 100644 (file)
@@ -26,7 +26,7 @@
 #include "r600_cs.h"
 #include "util/u_memory.h"
 #include "util/u_upload_mgr.h"
-
+#include "os/os_time.h"
 #include "tgsi/tgsi_text.h"
 
 struct r600_hw_query_params {
@@ -43,6 +43,10 @@ struct r600_query_sw {
 
        uint64_t begin_result;
        uint64_t end_result;
+
+       uint64_t begin_time;
+       uint64_t end_time;
+
        /* Fence for GPU_FINISHED. */
        struct pipe_fence_handle *fence;
 };
@@ -76,6 +80,7 @@ static enum radeon_value_id winsys_id_from_type(unsigned type)
        case R600_QUERY_GPU_TEMPERATURE: return RADEON_GPU_TEMPERATURE;
        case R600_QUERY_CURRENT_GPU_SCLK: return RADEON_CURRENT_SCLK;
        case R600_QUERY_CURRENT_GPU_MCLK: return RADEON_CURRENT_MCLK;
+       case R600_QUERY_CS_THREAD_BUSY: return RADEON_CS_THREAD_TIME;
        default: unreachable("query type does not correspond to winsys id");
        }
 }
@@ -84,6 +89,7 @@ static bool r600_query_sw_begin(struct r600_common_context *rctx,
                                struct r600_query *rquery)
 {
        struct r600_query_sw *query = (struct r600_query_sw *)rquery;
+       enum radeon_value_id ws_id;
 
        switch(query->b.type) {
        case PIPE_QUERY_TIMESTAMP_DISJOINT:
@@ -148,6 +154,11 @@ static bool r600_query_sw_begin(struct r600_common_context *rctx,
                query->begin_result = rctx->ws->query_value(rctx->ws, ws_id);
                break;
        }
+       case R600_QUERY_CS_THREAD_BUSY:
+               ws_id = winsys_id_from_type(query->b.type);
+               query->begin_result = rctx->ws->query_value(rctx->ws, ws_id);
+               query->begin_time = os_time_get_nano();
+               break;
        case R600_QUERY_GPU_LOAD:
        case R600_QUERY_GPU_SHADERS_BUSY:
        case R600_QUERY_GPU_TA_BUSY:
@@ -200,6 +211,7 @@ static bool r600_query_sw_end(struct r600_common_context *rctx,
                              struct r600_query *rquery)
 {
        struct r600_query_sw *query = (struct r600_query_sw *)rquery;
+       enum radeon_value_id ws_id;
 
        switch(query->b.type) {
        case PIPE_QUERY_TIMESTAMP_DISJOINT:
@@ -263,6 +275,11 @@ static bool r600_query_sw_end(struct r600_common_context *rctx,
                query->end_result = rctx->ws->query_value(rctx->ws, ws_id);
                break;
        }
+       case R600_QUERY_CS_THREAD_BUSY:
+               ws_id = winsys_id_from_type(query->b.type);
+               query->end_result = rctx->ws->query_value(rctx->ws, ws_id);
+               query->end_time = os_time_get_nano();
+               break;
        case R600_QUERY_GPU_LOAD:
        case R600_QUERY_GPU_SHADERS_BUSY:
        case R600_QUERY_GPU_TA_BUSY:
@@ -337,6 +354,10 @@ static bool r600_query_sw_get_result(struct r600_common_context *rctx,
                return result->b;
        }
 
+       case R600_QUERY_CS_THREAD_BUSY:
+               result->u64 = (query->end_result - query->begin_result) * 100 /
+                             (query->end_time - query->begin_time);
+               return true;
        case R600_QUERY_GPIN_ASIC_ID:
                result->u32 = 0;
                return true;
@@ -1742,6 +1763,7 @@ static struct pipe_driver_query_info r600_driver_query_list[] = {
        X("num-fb-cache-flushes",       NUM_FB_CACHE_FLUSHES,   UINT64, AVERAGE),
        X("num-L2-invalidates",         NUM_L2_INVALIDATES,     UINT64, AVERAGE),
        X("num-L2-writebacks",          NUM_L2_WRITEBACKS,      UINT64, AVERAGE),
+       X("CS-thread-busy",             CS_THREAD_BUSY,         UINT64, AVERAGE),
        X("requested-VRAM",             REQUESTED_VRAM,         BYTES, AVERAGE),
        X("requested-GTT",              REQUESTED_GTT,          BYTES, AVERAGE),
        X("mapped-VRAM",                MAPPED_VRAM,            BYTES, AVERAGE),
index 5de80d966c76c1e721609791fba1a0a93293256d..84b834c1f71b4b77832279098a342048fd57a174 100644 (file)
@@ -55,6 +55,7 @@ enum {
        R600_QUERY_NUM_FB_CACHE_FLUSHES,
        R600_QUERY_NUM_L2_INVALIDATES,
        R600_QUERY_NUM_L2_WRITEBACKS,
+       R600_QUERY_CS_THREAD_BUSY,
        R600_QUERY_REQUESTED_VRAM,
        R600_QUERY_REQUESTED_GTT,
        R600_QUERY_MAPPED_VRAM,
index 881bd5f2e455714290d07628c5a4fd7a20ae479a..432550dbef43e19e79ed9fa7db719652003402bd 100644 (file)
@@ -94,6 +94,7 @@ enum radeon_value_id {
     RADEON_CURRENT_SCLK,
     RADEON_CURRENT_MCLK,
     RADEON_GPU_RESET_COUNTER, /* DRM 2.43.0 */
+    RADEON_CS_THREAD_TIME,
 };
 
 /* Each group of four has the same priority. */
index c3dfda53f09fa6f89af398167eec48a65ccbb04f..db0087c094e3389877c301f08c56290503dea15b 100644 (file)
@@ -465,6 +465,8 @@ static uint64_t amdgpu_query_value(struct radeon_winsys *rws,
    case RADEON_GPU_RESET_COUNTER:
       assert(0);
       return 0;
+   case RADEON_CS_THREAD_TIME:
+      return util_queue_get_thread_time_nano(&ws->cs_queue, 0);
    }
    return 0;
 }
index cacd683879b76b587e50a0dba42369ec4a85f88b..bdcf1946595d397534676883f59bcc82cc0b3d45 100644 (file)
@@ -669,6 +669,8 @@ static uint64_t radeon_query_value(struct radeon_winsys *rws,
         radeon_get_drm_value(ws->fd, RADEON_INFO_GPU_RESET_COUNTER,
                              "gpu-reset-counter", (uint32_t*)&retval);
         return retval;
+    case RADEON_CS_THREAD_TIME:
+        return util_queue_get_thread_time_nano(&ws->cs_queue, 0);
     }
     return 0;
 }