radeonsi: print shader cache stats with AMD_DEBUG=cache_stats
authorMarek Olšák <marek.olsak@amd.com>
Thu, 16 Jan 2020 02:17:51 +0000 (21:17 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Sat, 25 Jan 2020 01:29:29 +0000 (20:29 -0500)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2929>

src/gallium/auxiliary/util/u_live_shader_cache.c
src/gallium/auxiliary/util/u_live_shader_cache.h
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_query.c
src/gallium/drivers/radeonsi/si_state_shaders.c

index 9299348e0af54d5d1f28cdce5d1440fea43228b0..9c59b5fd3cfb5e529d1c7083ce5aa347c4f57b22 100644 (file)
@@ -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;
index 9ee0803a1c5a2d64c4860774bc6333d23ed170ed..5d8cfc1bafc26aed615515efe164ddda9e7eb436 100644 (file)
@@ -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 {
index 55bd2b0324f70261f731aeabb996c68f1d3088bc..a11902e6031dbbcdaf26ab3c4d623343dd21638e 100644 (file)
@@ -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;
index 523385228cc9e838c45512e002a323697a2132d3..ed25c14f740b85b3f3a2662b8b4a44abe097f651 100644 (file)
@@ -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;
index 8776dde452175845be520272ccbe503f990f2f76..d0f7986d4b4c4679aa62cb4e1f628f5f09e4cd6f 100644 (file)
@@ -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;
index 18cc1bd265a70ab42ee1eb2086be1eec9a6ab011..fcf99088164db333caa5e34b392fe05c6700c740 100644 (file)
@@ -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;
 }