From: Marek Olšák Date: Thu, 16 Jan 2020 02:17:51 +0000 (-0500) Subject: radeonsi: print shader cache stats with AMD_DEBUG=cache_stats X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c046551e60342616a0a216bf1fb54b92b9d7313f;p=mesa.git radeonsi: print shader cache stats with AMD_DEBUG=cache_stats Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- diff --git a/src/gallium/auxiliary/util/u_live_shader_cache.c b/src/gallium/auxiliary/util/u_live_shader_cache.c index 9299348e0af..9c59b5fd3cf 100644 --- a/src/gallium/auxiliary/util/u_live_shader_cache.c +++ b/src/gallium/auxiliary/util/u_live_shader_cache.c @@ -118,8 +118,10 @@ util_live_shader_cache_get(struct pipe_context *ctx, struct util_live_shader *shader = entry ? entry->data : NULL; /* Increase the refcount. */ - if (shader) + if (shader) { pipe_reference(NULL, &shader->reference); + cache->hits++; + } simple_mtx_unlock(&cache->lock); /* Return if the shader already exists. */ @@ -148,6 +150,7 @@ util_live_shader_cache_get(struct pipe_context *ctx, } else { _mesa_hash_table_insert(cache->hashtable, shader->sha1, shader); } + cache->misses++; simple_mtx_unlock(&cache->lock); return shader; diff --git a/src/gallium/auxiliary/util/u_live_shader_cache.h b/src/gallium/auxiliary/util/u_live_shader_cache.h index 9ee0803a1c5..5d8cfc1bafc 100644 --- a/src/gallium/auxiliary/util/u_live_shader_cache.h +++ b/src/gallium/auxiliary/util/u_live_shader_cache.h @@ -59,6 +59,8 @@ struct util_live_shader_cache { void *(*create_shader)(struct pipe_context *, const struct pipe_shader_state *state); void (*destroy_shader)(struct pipe_context *, void *); + + unsigned hits, misses; }; struct util_live_shader { diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index 55bd2b0324f..a11902e6031 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -80,6 +80,7 @@ static const struct debug_named_value debug_options[] = { { "tex", DBG(TEX), "Print texture info" }, { "compute", DBG(COMPUTE), "Print compute info" }, { "vm", DBG(VM), "Print virtual addresses when creating resources" }, + { "cache_stats", DBG(CACHE_STATS), "Print shader cache statistics." }, /* Driver options: */ { "forcedma", DBG(FORCE_SDMA), "Use SDMA for all operations when possible." }, @@ -771,6 +772,18 @@ static void si_destroy_screen(struct pipe_screen* pscreen) if (!sscreen->ws->unref(sscreen->ws)) return; + if (sscreen->debug_flags & DBG(CACHE_STATS)) { + printf("live shader cache: hits = %u, misses = %u\n", + sscreen->live_shader_cache.hits, + sscreen->live_shader_cache.misses); + printf("memory shader cache: hits = %u, misses = %u\n", + sscreen->num_memory_shader_cache_hits, + sscreen->num_memory_shader_cache_misses); + printf("disk shader cache: hits = %u, misses = %u\n", + sscreen->num_disk_shader_cache_hits, + sscreen->num_disk_shader_cache_misses); + } + simple_mtx_destroy(&sscreen->aux_context_lock); struct u_log_context *aux_log = ((struct si_context *)sscreen->aux_context)->log; diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 523385228cc..ed25c14f740 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -169,6 +169,7 @@ enum { DBG_TEX, DBG_COMPUTE, DBG_VM, + DBG_CACHE_STATS, /* Driver options: */ DBG_FORCE_SDMA, @@ -540,7 +541,10 @@ struct si_screen { * are loading shaders on demand. This is a monotonic counter. */ unsigned num_shaders_created; - unsigned num_shader_cache_hits; + unsigned num_memory_shader_cache_hits; + unsigned num_memory_shader_cache_misses; + unsigned num_disk_shader_cache_hits; + unsigned num_disk_shader_cache_misses; /* GPU load thread. */ simple_mtx_t gpu_load_mutex; diff --git a/src/gallium/drivers/radeonsi/si_query.c b/src/gallium/drivers/radeonsi/si_query.c index 8776dde4521..d0f7986d4b4 100644 --- a/src/gallium/drivers/radeonsi/si_query.c +++ b/src/gallium/drivers/radeonsi/si_query.c @@ -251,7 +251,7 @@ static bool si_query_sw_begin(struct si_context *sctx, break; case SI_QUERY_NUM_SHADER_CACHE_HITS: query->begin_result = - p_atomic_read(&sctx->screen->num_shader_cache_hits); + p_atomic_read(&sctx->screen->num_memory_shader_cache_hits); break; case SI_QUERY_PD_NUM_PRIMS_ACCEPTED: query->begin_result = sctx->compute_num_verts_accepted; @@ -425,7 +425,7 @@ static bool si_query_sw_end(struct si_context *sctx, break; case SI_QUERY_NUM_SHADER_CACHE_HITS: query->end_result = - p_atomic_read(&sctx->screen->num_shader_cache_hits); + p_atomic_read(&sctx->screen->num_memory_shader_cache_hits); break; case SI_QUERY_PD_NUM_PRIMS_ACCEPTED: query->end_result = sctx->compute_num_verts_accepted; diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 18cc1bd265a..fcf99088164 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -246,10 +246,11 @@ bool si_shader_cache_load_shader(struct si_screen *sscreen, if (entry) { if (si_load_shader_binary(shader, entry->data)) { - p_atomic_inc(&sscreen->num_shader_cache_hits); + p_atomic_inc(&sscreen->num_memory_shader_cache_hits); return true; } } + p_atomic_inc(&sscreen->num_memory_shader_cache_misses); if (!sscreen->disk_shader_cache) return false; @@ -268,7 +269,7 @@ bool si_shader_cache_load_shader(struct si_screen *sscreen, free(buffer); si_shader_cache_insert_shader(sscreen, ir_sha1_cache_key, shader, false); - p_atomic_inc(&sscreen->num_shader_cache_hits); + p_atomic_inc(&sscreen->num_disk_shader_cache_hits); return true; } } else { @@ -281,6 +282,7 @@ bool si_shader_cache_load_shader(struct si_screen *sscreen, } free(buffer); + p_atomic_inc(&sscreen->num_disk_shader_cache_misses); return false; }