[Mesa-dev] [PATCH 4/7] r600g, radeonsi: add a bunch of useful queries for the HUD

Marek Olšák maraeo at gmail.com
Mon Feb 24 15:48:31 PST 2014


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

---
 src/gallium/drivers/radeon/r600_pipe_common.c     |  6 ++++-
 src/gallium/drivers/radeon/r600_pipe_common.h     |  4 +++
 src/gallium/drivers/radeon/r600_query.c           | 32 +++++++++++++++++++++++
 src/gallium/winsys/radeon/drm/radeon_drm_cs.c     |  2 ++
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.c | 26 +++++++++++++++---
 src/gallium/winsys/radeon/drm/radeon_drm_winsys.h |  1 +
 src/gallium/winsys/radeon/drm/radeon_winsys.h     |  6 ++++-
 7 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index 3aa718d..21bddb6 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -429,7 +429,11 @@ static int r600_get_driver_query_info(struct pipe_screen *screen,
 		{"draw-calls", R600_QUERY_DRAW_CALLS, 0},
 		{"requested-VRAM", R600_QUERY_REQUESTED_VRAM, rscreen->info.vram_size, TRUE},
 		{"requested-GTT", R600_QUERY_REQUESTED_GTT, rscreen->info.gart_size, TRUE},
-		{"buffer-wait-time", R600_QUERY_BUFFER_WAIT_TIME, 0, FALSE}
+		{"buffer-wait-time", R600_QUERY_BUFFER_WAIT_TIME, 0, FALSE},
+		{"num-cs-flushes", R600_QUERY_NUM_CS_FLUSHES, 0, FALSE},
+		{"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},
 	};
 
 	if (!info)
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
index fc61af1..4d6232f 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -50,6 +50,10 @@
 #define R600_QUERY_REQUESTED_VRAM	(PIPE_QUERY_DRIVER_SPECIFIC + 1)
 #define R600_QUERY_REQUESTED_GTT	(PIPE_QUERY_DRIVER_SPECIFIC + 2)
 #define R600_QUERY_BUFFER_WAIT_TIME	(PIPE_QUERY_DRIVER_SPECIFIC + 3)
+#define R600_QUERY_NUM_CS_FLUSHES	(PIPE_QUERY_DRIVER_SPECIFIC + 4)
+#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)
 
 /* read caches */
 #define R600_CONTEXT_INV_VERTEX_CACHE		(1 << 0)
diff --git a/src/gallium/drivers/radeon/r600_query.c b/src/gallium/drivers/radeon/r600_query.c
index 915d37a..eb76ae9 100644
--- a/src/gallium/drivers/radeon/r600_query.c
+++ b/src/gallium/drivers/radeon/r600_query.c
@@ -79,6 +79,10 @@ static struct r600_resource *r600_new_query_buffer(struct r600_common_context *c
 	case R600_QUERY_REQUESTED_VRAM:
 	case R600_QUERY_REQUESTED_GTT:
 	case R600_QUERY_BUFFER_WAIT_TIME:
+	case R600_QUERY_NUM_CS_FLUSHES:
+	case R600_QUERY_NUM_BYTES_MOVED:
+	case R600_QUERY_VRAM_USAGE:
+	case R600_QUERY_GTT_USAGE:
 		return NULL;
 	}
 
@@ -374,6 +378,10 @@ static struct pipe_query *r600_create_query(struct pipe_context *ctx, unsigned q
 	case R600_QUERY_REQUESTED_VRAM:
 	case R600_QUERY_REQUESTED_GTT:
 	case R600_QUERY_BUFFER_WAIT_TIME:
+	case R600_QUERY_NUM_CS_FLUSHES:
+	case R600_QUERY_NUM_BYTES_MOVED:
+	case R600_QUERY_VRAM_USAGE:
+	case R600_QUERY_GTT_USAGE:
 		skip_allocation = true;
 		break;
 	default:
@@ -427,11 +435,19 @@ static void r600_begin_query(struct pipe_context *ctx, struct pipe_query *query)
 		return;
 	case R600_QUERY_REQUESTED_VRAM:
 	case R600_QUERY_REQUESTED_GTT:
+	case R600_QUERY_VRAM_USAGE:
+	case R600_QUERY_GTT_USAGE:
 		rquery->begin_result = 0;
 		return;
 	case R600_QUERY_BUFFER_WAIT_TIME:
 		rquery->begin_result = rctx->ws->query_value(rctx->ws, RADEON_BUFFER_WAIT_TIME_NS);
 		return;
+	case R600_QUERY_NUM_CS_FLUSHES:
+		rquery->begin_result = rctx->ws->query_value(rctx->ws, RADEON_NUM_CS_FLUSHES);
+		return;
+	case R600_QUERY_NUM_BYTES_MOVED:
+		rquery->begin_result = rctx->ws->query_value(rctx->ws, RADEON_NUM_BYTES_MOVED);
+		return;
 	}
 
 	/* Discard the old query buffers. */
@@ -478,6 +494,18 @@ static void r600_end_query(struct pipe_context *ctx, struct pipe_query *query)
 	case R600_QUERY_BUFFER_WAIT_TIME:
 		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_BUFFER_WAIT_TIME_NS);
 		return;
+	case R600_QUERY_NUM_CS_FLUSHES:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_NUM_CS_FLUSHES);
+		return;
+	case R600_QUERY_NUM_BYTES_MOVED:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_NUM_BYTES_MOVED);
+		return;
+	case R600_QUERY_VRAM_USAGE:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_VRAM_USAGE);
+		return;
+	case R600_QUERY_GTT_USAGE:
+		rquery->end_result = rctx->ws->query_value(rctx->ws, RADEON_GTT_USAGE);
+		return;
 	}
 
 	r600_emit_query_end(rctx, rquery);
@@ -520,6 +548,10 @@ static boolean r600_get_query_buffer_result(struct r600_common_context *ctx,
 	case R600_QUERY_REQUESTED_VRAM:
 	case R600_QUERY_REQUESTED_GTT:
 	case R600_QUERY_BUFFER_WAIT_TIME:
+	case R600_QUERY_NUM_CS_FLUSHES:
+	case R600_QUERY_NUM_BYTES_MOVED:
+	case R600_QUERY_VRAM_USAGE:
+	case R600_QUERY_GTT_USAGE:
 		result->u64 = query->end_result - query->begin_result;
 		return TRUE;
 	}
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
index f6b9d62..2e07fa5 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
@@ -603,6 +603,8 @@ static void radeon_drm_cs_flush(struct radeon_winsys_cs *rcs, unsigned flags, ui
     /* Prepare a new CS. */
     cs->base.buf = cs->csc->buf;
     cs->base.cdw = 0;
+
+    cs->ws->num_cs_flushes++;
 }
 
 static void radeon_drm_cs_destroy(struct radeon_winsys_cs *rcs)
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
index 44cd0d1..1cec3a5 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.c
@@ -101,6 +101,12 @@
 #define RADEON_INFO_VCE_FW_VERSION 0x1b
 #endif
 
+#ifndef RADEON_INFO_NUM_BYTES_MOVED
+#define RADEON_INFO_NUM_BYTES_MOVED         0x1c
+#define RADEON_INFO_VRAM_USAGE              0x1d
+#define RADEON_INFO_GTT_USAGE               0x1e
+#endif
+
 #ifndef RADEON_CS_RING_UVD
 #define RADEON_CS_RING_UVD	3
 #endif
@@ -523,7 +529,7 @@ static uint64_t radeon_query_value(struct radeon_winsys *rws,
                                    enum radeon_value_id value)
 {
     struct radeon_drm_winsys *ws = (struct radeon_drm_winsys*)rws;
-    uint64_t ts = 0;
+    uint64_t retval = 0;
 
     switch (value) {
     case RADEON_REQUESTED_VRAM_MEMORY:
@@ -539,8 +545,22 @@ static uint64_t radeon_query_value(struct radeon_winsys *rws,
         }
 
         radeon_get_drm_value(ws->fd, RADEON_INFO_TIMESTAMP, "timestamp",
-                             (uint32_t*)&ts);
-        return ts;
+                             (uint32_t*)&retval);
+        return retval;
+    case RADEON_NUM_CS_FLUSHES:
+        return ws->num_cs_flushes;
+    case RADEON_NUM_BYTES_MOVED:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_BYTES_MOVED,
+                             "num-bytes-moved", (uint32_t*)&retval);
+        return retval;
+    case RADEON_VRAM_USAGE:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_VRAM_USAGE,
+                             "vram-usage", (uint32_t*)&retval);
+        return retval;
+    case RADEON_GTT_USAGE:
+        radeon_get_drm_value(ws->fd, RADEON_INFO_GTT_USAGE,
+                             "gtt-usage", (uint32_t*)&retval);
+        return retval;
     }
     return 0;
 }
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
index ed90194..a10b890 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_winsys.h
@@ -49,6 +49,7 @@ struct radeon_drm_winsys {
     uint64_t allocated_vram;
     uint64_t allocated_gtt;
     uint64_t buffer_wait_time; /* time spent in buffer_wait in ns */
+    uint64_t num_cs_flushes;
 
     enum radeon_generation gen;
     struct radeon_info info;
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index 4e614ec..a692408 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -158,7 +158,11 @@ enum radeon_value_id {
     RADEON_REQUESTED_VRAM_MEMORY,
     RADEON_REQUESTED_GTT_MEMORY,
     RADEON_BUFFER_WAIT_TIME_NS,
-    RADEON_TIMESTAMP
+    RADEON_TIMESTAMP,
+    RADEON_NUM_CS_FLUSHES,
+    RADEON_NUM_BYTES_MOVED,
+    RADEON_VRAM_USAGE,
+    RADEON_GTT_USAGE
 };
 
 struct winsys_handle;
-- 
1.8.3.2



More information about the mesa-dev mailing list