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 9299348..9c59b5f 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 9ee0803..5d8cfc1 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 55bd2b0..a11902e 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 5233852..ed25c14 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 8776dde..d0f7986 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 18cc1bd..fcf9908 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;
 }