radeonsi: use simple_mtx_t instead of mtx_t
authorMarek Olšák <marek.olsak@amd.com>
Thu, 26 Sep 2019 17:37:45 +0000 (13:37 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 8 Oct 2019 00:05:07 +0000 (20:05 -0400)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_dma_cs.c
src/gallium/drivers/radeonsi/si_gpu_load.c
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader.h
src/gallium/drivers/radeonsi/si_state_shaders.c
src/gallium/drivers/radeonsi/si_texture.c

index 9fe2bb5cf4b7680f3f936df0e35321fc10fa31ef..e9876ef9b69e417aae0bab0980ba4175dc38bd1b 100644 (file)
@@ -150,11 +150,11 @@ static void si_create_compute_state_async(void *job, int thread_index)
        void *ir_binary = si_get_ir_binary(sel, false, false);
 
        /* Try to load the shader from the shader cache. */
-       mtx_lock(&sscreen->shader_cache_mutex);
+       simple_mtx_lock(&sscreen->shader_cache_mutex);
 
        if (ir_binary &&
            si_shader_cache_load_shader(sscreen, ir_binary, shader)) {
-               mtx_unlock(&sscreen->shader_cache_mutex);
+               simple_mtx_unlock(&sscreen->shader_cache_mutex);
 
                si_shader_dump_stats_for_shader_db(sscreen, shader, debug);
                si_shader_dump(sscreen, shader, debug, stderr, true);
@@ -162,7 +162,7 @@ static void si_create_compute_state_async(void *job, int thread_index)
                if (!si_shader_binary_upload(sscreen, shader, 0))
                        program->shader.compilation_failed = true;
        } else {
-               mtx_unlock(&sscreen->shader_cache_mutex);
+               simple_mtx_unlock(&sscreen->shader_cache_mutex);
 
                if (!si_shader_create(sscreen, compiler, &program->shader, debug)) {
                        program->shader.compilation_failed = true;
@@ -202,10 +202,10 @@ static void si_create_compute_state_async(void *job, int thread_index)
                        S_00B84C_LDS_SIZE(shader->config.lds_size);
 
                if (ir_binary) {
-                       mtx_lock(&sscreen->shader_cache_mutex);
+                       simple_mtx_lock(&sscreen->shader_cache_mutex);
                        if (!si_shader_cache_insert_shader(sscreen, ir_binary, shader, true))
                                FREE(ir_binary);
-                       mtx_unlock(&sscreen->shader_cache_mutex);
+                       simple_mtx_unlock(&sscreen->shader_cache_mutex);
                }
        }
 
index d7b7681f8e5820f142fc1698d2de80f9f7c91123..c5d6a6e39cd6e02cec132eade77282a3ac9c20a6 100644 (file)
@@ -232,8 +232,8 @@ void si_screen_clear_buffer(struct si_screen *sscreen, struct pipe_resource *dst
 {
        struct si_context *ctx = (struct si_context*)sscreen->aux_context;
 
-       mtx_lock(&sscreen->aux_context_lock);
+       simple_mtx_lock(&sscreen->aux_context_lock);
        si_sdma_clear_buffer(ctx, dst, offset, size, value);
        sscreen->aux_context->flush(sscreen->aux_context, NULL, 0);
-       mtx_unlock(&sscreen->aux_context_lock);
+       simple_mtx_unlock(&sscreen->aux_context_lock);
 }
index 7c2e43b3fddcac65e1750adbddfd56d81900eda9..33cd5642230fafdf732b9e87fb9b71ba0a347c82 100644 (file)
@@ -175,12 +175,12 @@ static uint64_t si_read_mmio_counter(struct si_screen *sscreen,
 {
        /* Start the thread if needed. */
        if (!sscreen->gpu_load_thread) {
-               mtx_lock(&sscreen->gpu_load_mutex);
+               simple_mtx_lock(&sscreen->gpu_load_mutex);
                /* Check again inside the mutex. */
                if (!sscreen->gpu_load_thread)
                        sscreen->gpu_load_thread =
                                u_thread_create(si_gpu_load_thread, sscreen);
-               mtx_unlock(&sscreen->gpu_load_mutex);
+               simple_mtx_unlock(&sscreen->gpu_load_mutex);
        }
 
        unsigned busy = p_atomic_read(&sscreen->mmio_counters.array[busy_index]);
index 0515ed067ffbadb816cbce3b9176cac1d41cd1b0..baf60117a0845bd21a3d4c6c06ed5c7431f29158 100644 (file)
@@ -733,7 +733,7 @@ static void si_destroy_screen(struct pipe_screen* pscreen)
        if (!sscreen->ws->unref(sscreen->ws))
                return;
 
-       mtx_destroy(&sscreen->aux_context_lock);
+       simple_mtx_destroy(&sscreen->aux_context_lock);
 
        struct u_log_context *aux_log = ((struct si_context *)sscreen->aux_context)->log;
        if (aux_log) {
@@ -766,13 +766,13 @@ static void si_destroy_screen(struct pipe_screen* pscreen)
                        FREE(part);
                }
        }
-       mtx_destroy(&sscreen->shader_parts_mutex);
+       simple_mtx_destroy(&sscreen->shader_parts_mutex);
        si_destroy_shader_cache(sscreen);
 
        si_destroy_perfcounters(sscreen);
        si_gpu_load_kill_thread(sscreen);
 
-       mtx_destroy(&sscreen->gpu_load_mutex);
+       simple_mtx_destroy(&sscreen->gpu_load_mutex);
 
        slab_destroy_parent(&sscreen->pool_transfers);
 
@@ -990,8 +990,8 @@ radeonsi_screen_create_impl(struct radeon_winsys *ws,
                       1 << util_logbase2(sscreen->force_aniso));
        }
 
-       (void) mtx_init(&sscreen->aux_context_lock, mtx_plain);
-       (void) mtx_init(&sscreen->gpu_load_mutex, mtx_plain);
+       (void) simple_mtx_init(&sscreen->aux_context_lock, mtx_plain);
+       (void) simple_mtx_init(&sscreen->gpu_load_mutex, mtx_plain);
 
        si_init_gs_info(sscreen);
        if (!si_init_shader_cache(sscreen)) {
@@ -1163,7 +1163,7 @@ radeonsi_screen_create_impl(struct radeon_winsys *ws,
        sscreen->dcc_msaa_allowed =
                !(sscreen->debug_flags & DBG(NO_DCC_MSAA));
 
-       (void) mtx_init(&sscreen->shader_parts_mutex, mtx_plain);
+       (void) simple_mtx_init(&sscreen->shader_parts_mutex, mtx_plain);
        sscreen->use_monolithic_shaders =
                (sscreen->debug_flags & DBG(MONOLITHIC_SHADERS)) != 0;
 
index 1906bdf16b2c41a9264236f474170610ec3ecb1a..2a090297a66a0d036618ad34bad133901907b3af 100644 (file)
@@ -513,7 +513,7 @@ struct si_screen {
        /* Auxiliary context. Mainly used to initialize resources.
         * It must be locked prior to using and flushed before unlocking. */
        struct pipe_context             *aux_context;
-       mtx_t                           aux_context_lock;
+       simple_mtx_t                    aux_context_lock;
 
        /* This must be in the screen, because UE4 uses one context for
         * compilation and another one for rendering.
@@ -526,7 +526,7 @@ struct si_screen {
        unsigned                        num_shader_cache_hits;
 
        /* GPU load thread. */
-       mtx_t                           gpu_load_mutex;
+       simple_mtx_t                    gpu_load_mutex;
        thrd_t                          gpu_load_thread;
        union si_mmio_counters  mmio_counters;
        volatile unsigned               gpu_load_stop_thread; /* bool */
@@ -562,7 +562,7 @@ struct si_screen {
                unsigned L2_to_cp;
        } barrier_flags;
 
-       mtx_t                   shader_parts_mutex;
+       simple_mtx_t                    shader_parts_mutex;
        struct si_shader_part           *vs_prologs;
        struct si_shader_part           *tcs_epilogs;
        struct si_shader_part           *gs_prologs;
@@ -581,7 +581,7 @@ struct si_screen {
         * - GS and CS aren't cached, but it's certainly possible to cache
         *   those as well.
         */
-       mtx_t                   shader_cache_mutex;
+       simple_mtx_t                    shader_cache_mutex;
        struct hash_table               *shader_cache;
 
        /* Shader compiler queue for multithreaded compilation. */
index fc45691d8d59c2647407de6ae4e9b122a4a20ebd..446b3e393ee81986835940b982637c79704fb562 100644 (file)
@@ -7247,12 +7247,12 @@ si_get_shader_part(struct si_screen *sscreen,
 {
        struct si_shader_part *result;
 
-       mtx_lock(&sscreen->shader_parts_mutex);
+       simple_mtx_lock(&sscreen->shader_parts_mutex);
 
        /* Find existing. */
        for (result = *list; result; result = result->next) {
                if (memcmp(&result->key, key, sizeof(*key)) == 0) {
-                       mtx_unlock(&sscreen->shader_parts_mutex);
+                       simple_mtx_unlock(&sscreen->shader_parts_mutex);
                        return result;
                }
        }
@@ -7313,7 +7313,7 @@ si_get_shader_part(struct si_screen *sscreen,
 
 out:
        si_llvm_dispose(&ctx);
-       mtx_unlock(&sscreen->shader_parts_mutex);
+       simple_mtx_unlock(&sscreen->shader_parts_mutex);
        return result;
 }
 
index 8b5c70068e41e9d4ec88b0d0b2c94424c41386d7..f71cb040e7a37606d9050c9f8727fc80b5429ed8 100644 (file)
 #include "tgsi/tgsi_scan.h"
 #include "util/u_inlines.h"
 #include "util/u_queue.h"
+#include "util/simple_mtx.h"
 
 #include "ac_binary.h"
 #include "ac_llvm_build.h"
@@ -310,7 +311,7 @@ struct si_shader_selector {
        struct util_queue_fence ready;
        struct si_compiler_ctx_state compiler_ctx_state;
 
-       mtx_t           mutex;
+       simple_mtx_t            mutex;
        struct si_shader        *first_variant; /* immutable after the first variant */
        struct si_shader        *last_variant; /* mutable */
 
index 832e59828949c0da0279d2c95a2c5ffd3fba5722..bbdd0d08b42905e1434bbfd76456a4201824a767 100644 (file)
@@ -327,7 +327,7 @@ static void si_destroy_shader_cache_entry(struct hash_entry *entry)
 
 bool si_init_shader_cache(struct si_screen *sscreen)
 {
-       (void) mtx_init(&sscreen->shader_cache_mutex, mtx_plain);
+       (void) simple_mtx_init(&sscreen->shader_cache_mutex, mtx_plain);
        sscreen->shader_cache =
                _mesa_hash_table_create(NULL,
                                        si_shader_cache_key_hash,
@@ -341,7 +341,7 @@ void si_destroy_shader_cache(struct si_screen *sscreen)
        if (sscreen->shader_cache)
                _mesa_hash_table_destroy(sscreen->shader_cache,
                                         si_destroy_shader_cache_entry);
-       mtx_destroy(&sscreen->shader_cache_mutex);
+       simple_mtx_destroy(&sscreen->shader_cache_mutex);
 }
 
 /* SHADER STATES */
@@ -2221,14 +2221,14 @@ current_not_ready:
        if (thread_index < 0)
                util_queue_fence_wait(&sel->ready);
 
-       mtx_lock(&sel->mutex);
+       simple_mtx_lock(&sel->mutex);
 
        /* Find the shader variant. */
        for (iter = sel->first_variant; iter; iter = iter->next_variant) {
                /* Don't check the "current" shader. We checked it above. */
                if (current != iter &&
                    memcmp(&iter->key, key, sizeof(*key)) == 0) {
-                       mtx_unlock(&sel->mutex);
+                       simple_mtx_unlock(&sel->mutex);
 
                        if (unlikely(!util_queue_fence_is_signalled(&iter->ready))) {
                                /* If it's an optimized shader and its compilation has
@@ -2257,7 +2257,7 @@ current_not_ready:
        /* Build a new shader. */
        shader = CALLOC_STRUCT(si_shader);
        if (!shader) {
-               mtx_unlock(&sel->mutex);
+               simple_mtx_unlock(&sel->mutex);
                return -ENOMEM;
        }
 
@@ -2314,11 +2314,11 @@ current_not_ready:
                                assert(0);
                        }
 
-                       mtx_lock(&previous_stage_sel->mutex);
+                       simple_mtx_lock(&previous_stage_sel->mutex);
                        ok = si_check_missing_main_part(sscreen,
                                                        previous_stage_sel,
                                                        compiler_state, &shader1_key);
-                       mtx_unlock(&previous_stage_sel->mutex);
+                       simple_mtx_unlock(&previous_stage_sel->mutex);
                }
 
                if (ok) {
@@ -2328,7 +2328,7 @@ current_not_ready:
 
                if (!ok) {
                        FREE(shader);
-                       mtx_unlock(&sel->mutex);
+                       simple_mtx_unlock(&sel->mutex);
                        return -ENOMEM; /* skip the draw call */
                }
        }
@@ -2373,7 +2373,7 @@ current_not_ready:
 
                /* Use the default (unoptimized) shader for now. */
                memset(&key->opt, 0, sizeof(key->opt));
-               mtx_unlock(&sel->mutex);
+               simple_mtx_unlock(&sel->mutex);
 
                if (sscreen->options.sync_compile)
                        util_queue_fence_wait(&shader->ready);
@@ -2394,7 +2394,7 @@ current_not_ready:
                sel->last_variant = shader;
        }
 
-       mtx_unlock(&sel->mutex);
+       simple_mtx_unlock(&sel->mutex);
 
        assert(!shader->is_optimized);
        si_build_shader_variant(shader, thread_index, false);
@@ -2511,14 +2511,14 @@ static void si_init_shader_selector_async(void *job, int thread_index)
                }
 
                /* Try to load the shader from the shader cache. */
-               mtx_lock(&sscreen->shader_cache_mutex);
+               simple_mtx_lock(&sscreen->shader_cache_mutex);
 
                if (ir_binary &&
                    si_shader_cache_load_shader(sscreen, ir_binary, shader)) {
-                       mtx_unlock(&sscreen->shader_cache_mutex);
+                       simple_mtx_unlock(&sscreen->shader_cache_mutex);
                        si_shader_dump_stats_for_shader_db(sscreen, shader, debug);
                } else {
-                       mtx_unlock(&sscreen->shader_cache_mutex);
+                       simple_mtx_unlock(&sscreen->shader_cache_mutex);
 
                        /* Compile the shader if it hasn't been loaded from the cache. */
                        if (si_compile_tgsi_shader(sscreen, compiler, shader,
@@ -2530,10 +2530,10 @@ static void si_init_shader_selector_async(void *job, int thread_index)
                        }
 
                        if (ir_binary) {
-                               mtx_lock(&sscreen->shader_cache_mutex);
+                               simple_mtx_lock(&sscreen->shader_cache_mutex);
                                if (!si_shader_cache_insert_shader(sscreen, ir_binary, shader, true))
                                        FREE(ir_binary);
-                               mtx_unlock(&sscreen->shader_cache_mutex);
+                               simple_mtx_unlock(&sscreen->shader_cache_mutex);
                        }
                }
 
@@ -2933,7 +2933,7 @@ static void *si_create_shader_selector(struct pipe_context *ctx,
        if (sel->info.properties[TGSI_PROPERTY_FS_POST_DEPTH_COVERAGE])
                sel->db_shader_control |= S_02880C_PRE_SHADER_DEPTH_COVERAGE_ENABLE(1);
 
-       (void) mtx_init(&sel->mutex, mtx_plain);
+       (void) simple_mtx_init(&sel->mutex, mtx_plain);
 
        si_schedule_initial_compile(sctx, sel->info.processor, &sel->ready,
                                    &sel->compiler_ctx_state, sel,
@@ -3281,7 +3281,7 @@ void si_destroy_shader_selector(struct si_context *sctx,
                si_delete_shader(sctx, sel->gs_copy_shader);
 
        util_queue_fence_destroy(&sel->ready);
-       mtx_destroy(&sel->mutex);
+       simple_mtx_destroy(&sel->mutex);
        free(sel->tokens);
        ralloc_free(sel->nir);
        free(sel);
@@ -3564,18 +3564,18 @@ static bool si_update_gs_ring_buffers(struct si_context *sctx)
 
 static void si_shader_lock(struct si_shader *shader)
 {
-       mtx_lock(&shader->selector->mutex);
+       simple_mtx_lock(&shader->selector->mutex);
        if (shader->previous_stage_sel) {
                assert(shader->previous_stage_sel != shader->selector);
-               mtx_lock(&shader->previous_stage_sel->mutex);
+               simple_mtx_lock(&shader->previous_stage_sel->mutex);
        }
 }
 
 static void si_shader_unlock(struct si_shader *shader)
 {
        if (shader->previous_stage_sel)
-               mtx_unlock(&shader->previous_stage_sel->mutex);
-       mtx_unlock(&shader->selector->mutex);
+               simple_mtx_unlock(&shader->previous_stage_sel->mutex);
+       simple_mtx_unlock(&shader->selector->mutex);
 }
 
 /**
index 3d35fb41cf0cd9c266daab2b19da82c52468ba09..a74d9c352322db34eb335476e45ecaeff608e5a4 100644 (file)
@@ -412,7 +412,7 @@ void si_eliminate_fast_color_clear(struct si_context *sctx,
        struct pipe_context *ctx = &sctx->b;
 
        if (ctx == sscreen->aux_context)
-               mtx_lock(&sscreen->aux_context_lock);
+               simple_mtx_lock(&sscreen->aux_context_lock);
 
        unsigned n = sctx->num_decompress_calls;
        ctx->flush_resource(ctx, &tex->buffer.b.b);
@@ -422,7 +422,7 @@ void si_eliminate_fast_color_clear(struct si_context *sctx,
                ctx->flush(ctx, NULL, 0);
 
        if (ctx == sscreen->aux_context)
-               mtx_unlock(&sscreen->aux_context_lock);
+               simple_mtx_unlock(&sscreen->aux_context_lock);
 }
 
 void si_texture_discard_cmask(struct si_screen *sscreen,
@@ -515,14 +515,14 @@ bool si_texture_disable_dcc(struct si_context *sctx,
                return false;
 
        if (&sctx->b == sscreen->aux_context)
-               mtx_lock(&sscreen->aux_context_lock);
+               simple_mtx_lock(&sscreen->aux_context_lock);
 
        /* Decompress DCC. */
        si_decompress_dcc(sctx, tex);
        sctx->b.flush(&sctx->b, NULL, 0);
 
        if (&sctx->b == sscreen->aux_context)
-               mtx_unlock(&sscreen->aux_context_lock);
+               simple_mtx_unlock(&sscreen->aux_context_lock);
 
        return si_texture_discard_dcc(sscreen, tex);
 }
@@ -1486,12 +1486,12 @@ si_texture_create_object(struct pipe_screen *screen,
                        u_box_1d(0, buf->b.b.width0, &box);
 
                        assert(tex->surface.dcc_retile_map_offset <= UINT_MAX);
-                       mtx_lock(&sscreen->aux_context_lock);
+                       simple_mtx_lock(&sscreen->aux_context_lock);
                        sctx->dma_copy(&sctx->b, &tex->buffer.b.b, 0,
                                       tex->surface.dcc_retile_map_offset, 0, 0,
                                       &buf->b.b, 0, &box);
                        sscreen->aux_context->flush(sscreen->aux_context, NULL, 0);
-                       mtx_unlock(&sscreen->aux_context_lock);
+                       simple_mtx_unlock(&sscreen->aux_context_lock);
 
                        si_resource_reference(&buf, NULL);
                }