[Mesa-dev] [PATCH 01/10] radeonsi: add a driver query for shader cache hits

Marek Olšák maraeo at gmail.com
Sat Oct 29 11:17:16 UTC 2016


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

This is an 8-month old patch.
---
 src/gallium/drivers/radeon/r600_pipe_common.h   | 1 +
 src/gallium/drivers/radeon/r600_query.c         | 9 +++++++++
 src/gallium/drivers/radeon/r600_query.h         | 1 +
 src/gallium/drivers/radeonsi/si_state_shaders.c | 6 +++++-
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
index d49f9d3..9356274 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -373,20 +373,21 @@ struct r600_common_screen {
 	pipe_mutex			aux_context_lock;
 
 	/* This must be in the screen, because UE4 uses one context for
 	 * compilation and another one for rendering.
 	 */
 	unsigned			num_compilations;
 	/* Along with ST_DEBUG=precompile, this should show if applications
 	 * are loading shaders on demand. This is a monotonic counter.
 	 */
 	unsigned			num_shaders_created;
+	unsigned			num_shader_cache_hits;
 
 	/* GPU load thread. */
 	pipe_mutex			gpu_load_mutex;
 	pipe_thread			gpu_load_thread;
 	unsigned			gpu_load_counter_busy;
 	unsigned			gpu_load_counter_idle;
 	volatile unsigned		gpu_load_stop_thread; /* bool */
 
 	char				renderer_string[100];
 
diff --git a/src/gallium/drivers/radeon/r600_query.c b/src/gallium/drivers/radeon/r600_query.c
index 047f597..9c9694a 100644
--- a/src/gallium/drivers/radeon/r600_query.c
+++ b/src/gallium/drivers/radeon/r600_query.c
@@ -132,20 +132,24 @@ static bool r600_query_sw_begin(struct r600_common_context *rctx,
 	}
 	case R600_QUERY_GPU_LOAD:
 		query->begin_result = r600_gpu_load_begin(rctx->screen);
 		break;
 	case R600_QUERY_NUM_COMPILATIONS:
 		query->begin_result = p_atomic_read(&rctx->screen->num_compilations);
 		break;
 	case R600_QUERY_NUM_SHADERS_CREATED:
 		query->begin_result = p_atomic_read(&rctx->screen->num_shaders_created);
 		break;
+	case R600_QUERY_NUM_SHADER_CACHE_HITS:
+		query->begin_result =
+			p_atomic_read(&rctx->screen->num_shader_cache_hits);
+		break;
 	case R600_QUERY_GPIN_ASIC_ID:
 	case R600_QUERY_GPIN_NUM_SIMD:
 	case R600_QUERY_GPIN_NUM_RB:
 	case R600_QUERY_GPIN_NUM_SPI:
 	case R600_QUERY_GPIN_NUM_SE:
 		break;
 	default:
 		unreachable("r600_query_sw_begin: bad query type");
 	}
 
@@ -211,20 +215,24 @@ static bool r600_query_sw_end(struct r600_common_context *rctx,
 		break;
 	case R600_QUERY_NUM_COMPILATIONS:
 		query->end_result = p_atomic_read(&rctx->screen->num_compilations);
 		break;
 	case R600_QUERY_NUM_SHADERS_CREATED:
 		query->end_result = p_atomic_read(&rctx->screen->num_shaders_created);
 		break;
 	case R600_QUERY_BACK_BUFFER_PS_DRAW_RATIO:
 		query->end_result = rctx->last_tex_ps_draw_ratio;
 		break;
+	case R600_QUERY_NUM_SHADER_CACHE_HITS:
+		query->end_result =
+			p_atomic_read(&rctx->screen->num_shader_cache_hits);
+		break;
 	case R600_QUERY_GPIN_ASIC_ID:
 	case R600_QUERY_GPIN_NUM_SIMD:
 	case R600_QUERY_GPIN_NUM_RB:
 	case R600_QUERY_GPIN_NUM_SPI:
 	case R600_QUERY_GPIN_NUM_SE:
 		break;
 	default:
 		unreachable("r600_query_sw_end: bad query type");
 	}
 
@@ -1634,20 +1642,21 @@ err:
 
 #define X(name_, query_type_, type_, result_type_) \
 	XFULL(name_, query_type_, type_, result_type_, ~(unsigned)0)
 
 #define XG(group_, name_, query_type_, type_, result_type_) \
 	XFULL(name_, query_type_, type_, result_type_, R600_QUERY_GROUP_##group_)
 
 static struct pipe_driver_query_info r600_driver_query_list[] = {
 	X("num-compilations",		NUM_COMPILATIONS,	UINT64, CUMULATIVE),
 	X("num-shaders-created",	NUM_SHADERS_CREATED,	UINT64, CUMULATIVE),
+	X("num-shader-cache-hits",	NUM_SHADER_CACHE_HITS,	UINT64, CUMULATIVE),
 	X("draw-calls",			DRAW_CALLS,		UINT64, AVERAGE),
 	X("spill-draw-calls",		SPILL_DRAW_CALLS,	UINT64, AVERAGE),
 	X("compute-calls",		COMPUTE_CALLS,		UINT64, AVERAGE),
 	X("spill-compute-calls",	SPILL_COMPUTE_CALLS,	UINT64, AVERAGE),
 	X("dma-calls",			DMA_CALLS,		UINT64, AVERAGE),
 	X("num-vs-flushes",		NUM_VS_FLUSHES,		UINT64, AVERAGE),
 	X("num-ps-flushes",		NUM_PS_FLUSHES,		UINT64, AVERAGE),
 	X("num-cs-flushes",		NUM_CS_FLUSHES,		UINT64, AVERAGE),
 	X("requested-VRAM",		REQUESTED_VRAM,		BYTES, AVERAGE),
 	X("requested-GTT",		REQUESTED_GTT,		BYTES, AVERAGE),
diff --git a/src/gallium/drivers/radeon/r600_query.h b/src/gallium/drivers/radeon/r600_query.h
index 14c433d..0e14753 100644
--- a/src/gallium/drivers/radeon/r600_query.h
+++ b/src/gallium/drivers/radeon/r600_query.h
@@ -61,20 +61,21 @@ enum {
 	R600_QUERY_NUM_EVICTIONS,
 	R600_QUERY_VRAM_USAGE,
 	R600_QUERY_GTT_USAGE,
 	R600_QUERY_GPU_TEMPERATURE,
 	R600_QUERY_CURRENT_GPU_SCLK,
 	R600_QUERY_CURRENT_GPU_MCLK,
 	R600_QUERY_GPU_LOAD,
 	R600_QUERY_NUM_COMPILATIONS,
 	R600_QUERY_NUM_SHADERS_CREATED,
 	R600_QUERY_BACK_BUFFER_PS_DRAW_RATIO,
+	R600_QUERY_NUM_SHADER_CACHE_HITS,
 	R600_QUERY_GPIN_ASIC_ID,
 	R600_QUERY_GPIN_NUM_SIMD,
 	R600_QUERY_GPIN_NUM_RB,
 	R600_QUERY_GPIN_NUM_SPI,
 	R600_QUERY_GPIN_NUM_SE,
 
 	R600_QUERY_FIRST_PERFCOUNTER = PIPE_QUERY_DRIVER_SPECIFIC + 100,
 };
 
 enum {
diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c
index e4ceb3b..9976085 100644
--- a/src/gallium/drivers/radeonsi/si_state_shaders.c
+++ b/src/gallium/drivers/radeonsi/si_state_shaders.c
@@ -206,21 +206,25 @@ static bool si_shader_cache_insert_shader(struct si_screen *sscreen,
 
 static bool si_shader_cache_load_shader(struct si_screen *sscreen,
 					void *tgsi_binary,
 				        struct si_shader *shader)
 {
 	struct hash_entry *entry =
 		_mesa_hash_table_search(sscreen->shader_cache, tgsi_binary);
 	if (!entry)
 		return false;
 
-	return si_load_shader_binary(shader, entry->data);
+	if (!si_load_shader_binary(shader, entry->data))
+		return false;
+
+	p_atomic_inc(&sscreen->b.num_shader_cache_hits);
+	return true;
 }
 
 static uint32_t si_shader_cache_key_hash(const void *key)
 {
 	/* The first dword is the key size. */
 	return util_hash_crc32(key, *(uint32_t*)key);
 }
 
 static bool si_shader_cache_key_equals(const void *a, const void *b)
 {
-- 
2.7.4



More information about the mesa-dev mailing list