From 2937f69cc038a6305b353fa4926aa8c8f0ba44f6 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 8 Feb 2021 16:10:26 +1000 Subject: [PATCH] llvmpipe: add a mutex around debug resource tracking The debug resource tracking triggers an asan warning, add a mutex around it to avoid multi-thread failures with vulkan CTS test: dEQP-VK.api.object_management.multithreaded_per_thread_device.buffer_uniform_small Reviewed-by: Adam Jackson Reviewed-by: Eric Anholt Part-of: --- src/gallium/drivers/llvmpipe/lp_texture.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 2bf223d..7f27cbb 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -56,6 +56,7 @@ #ifdef DEBUG static struct llvmpipe_resource resource_list; +static mtx_t resource_list_mutex = _MTX_INITIALIZER_NP; #endif static unsigned id_counter = 0; @@ -307,7 +308,9 @@ llvmpipe_resource_create_all(struct pipe_screen *_screen, lpr->id = id_counter++; #ifdef DEBUG + mtx_lock(&resource_list_mutex); insert_at_tail(&resource_list, lpr); + mtx_unlock(&resource_list_mutex); #endif return &lpr->base; @@ -374,8 +377,10 @@ llvmpipe_resource_destroy(struct pipe_screen *pscreen, } } #ifdef DEBUG + mtx_lock(&resource_list_mutex); if (lpr->next) remove_from_list(lpr); + mtx_unlock(&resource_list_mutex); #endif FREE(lpr); @@ -510,7 +515,9 @@ llvmpipe_resource_from_handle(struct pipe_screen *screen, lpr->id = id_counter++; #ifdef DEBUG + mtx_lock(&resource_list_mutex); insert_at_tail(&resource_list, lpr); + mtx_unlock(&resource_list_mutex); #endif return &lpr->base; @@ -871,6 +878,7 @@ llvmpipe_print_resources(void) unsigned n = 0, total = 0; debug_printf("LLVMPIPE: current resources:\n"); + mtx_lock(&resource_list_mutex); foreach(lpr, &resource_list) { unsigned size = llvmpipe_resource_size(&lpr->base); debug_printf("resource %u at %p, size %ux%ux%u: %u bytes, refcount %u\n", @@ -880,6 +888,7 @@ llvmpipe_print_resources(void) total += size; n++; } + mtx_unlock(&resource_list_mutex); debug_printf("LLVMPIPE: total size of %u resources: %u\n", n, total); } #endif -- 2.7.4