llvmpipe: add a mutex around debug resource tracking
authorDave Airlie <airlied@redhat.com>
Mon, 8 Feb 2021 06:10:26 +0000 (16:10 +1000)
committerDave Airlie <airlied@redhat.com>
Wed, 10 Feb 2021 22:34:05 +0000 (08:34 +1000)
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 <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8912>

src/gallium/drivers/llvmpipe/lp_texture.c

index 2bf223d..7f27cbb 100644 (file)
@@ -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