diff options
author | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-09-15 14:52:26 -0700 |
---|---|---|
committer | Jason Ekstrand <jason.ekstrand@intel.com> | 2015-09-17 17:44:20 -0700 |
commit | 74bf7aa07c0e87cafb1a9fb085a2fe99a548c8de (patch) | |
tree | df314392b2cc040870b69f4c5b4a10387fd0b8b9 /src/vulkan/tests | |
parent | 222ddac810fae965507b16702eb4e4c6eee97e16 (diff) |
anv/allocator: Take the device mutex when growing a block pool
We don't have any locking issues yet because we use the pool size itself as
a mutex in block_pool_alloc to guarantee that only one thread is resizing
at a time. However, we are about to add support for growing the block pool
at both ends. This introduces two potential races:
1) You could have two block_pool_alloc() calls that both try to grow the
block pool, one from each end.
2) The relocation handling code will now have to think about not only the
bo that we use for the block pool but also the offset from the start of
that bo to the center of the block pool. It's possible that the block
pool growing code could race with the relocation handling code and get
a bo and offset out of sync.
Grabbing the device mutex solves both of these problems. Thanks to (2), we
can't really do anything more granular.
Diffstat (limited to 'src/vulkan/tests')
-rw-r--r-- | src/vulkan/tests/block_pool_no_free.c | 2 | ||||
-rw-r--r-- | src/vulkan/tests/state_pool.c | 4 | ||||
-rw-r--r-- | src/vulkan/tests/state_pool_free_list_only.c | 2 | ||||
-rw-r--r-- | src/vulkan/tests/state_pool_no_free.c | 2 |
4 files changed, 10 insertions, 0 deletions
diff --git a/src/vulkan/tests/block_pool_no_free.c b/src/vulkan/tests/block_pool_no_free.c index 898a82b090..d40504c4a8 100644 --- a/src/vulkan/tests/block_pool_no_free.c +++ b/src/vulkan/tests/block_pool_no_free.c @@ -51,6 +51,7 @@ static void run_test() struct anv_device device; struct anv_block_pool pool; + pthread_mutex_init(&device.mutex, NULL); anv_block_pool_init(&pool, &device, 16); for (unsigned i = 0; i < NUM_THREADS; i++) { @@ -95,6 +96,7 @@ static void run_test() } anv_block_pool_finish(&pool); + pthread_mutex_destroy(&device.mutex); } int main(int argc, char **argv) diff --git a/src/vulkan/tests/state_pool.c b/src/vulkan/tests/state_pool.c index e235ee9b39..878ec19a59 100644 --- a/src/vulkan/tests/state_pool.c +++ b/src/vulkan/tests/state_pool.c @@ -38,6 +38,8 @@ int main(int argc, char **argv) struct anv_block_pool block_pool; struct anv_state_pool state_pool; + pthread_mutex_init(&device.mutex, NULL); + for (unsigned i = 0; i < NUM_RUNS; i++) { anv_block_pool_init(&block_pool, &device, 256); anv_state_pool_init(&state_pool, &block_pool); @@ -50,4 +52,6 @@ int main(int argc, char **argv) anv_state_pool_finish(&state_pool); anv_block_pool_finish(&block_pool); } + + pthread_mutex_destroy(&device.mutex); } diff --git a/src/vulkan/tests/state_pool_free_list_only.c b/src/vulkan/tests/state_pool_free_list_only.c index 9e89cf6425..2f4eb47fe4 100644 --- a/src/vulkan/tests/state_pool_free_list_only.c +++ b/src/vulkan/tests/state_pool_free_list_only.c @@ -37,6 +37,7 @@ int main(int argc, char **argv) struct anv_block_pool block_pool; struct anv_state_pool state_pool; + pthread_mutex_init(&device.mutex, NULL); anv_block_pool_init(&block_pool, &device, 4096); anv_state_pool_init(&state_pool, &block_pool); @@ -61,4 +62,5 @@ int main(int argc, char **argv) anv_state_pool_finish(&state_pool); anv_block_pool_finish(&block_pool); + pthread_mutex_destroy(&device.mutex); } diff --git a/src/vulkan/tests/state_pool_no_free.c b/src/vulkan/tests/state_pool_no_free.c index 4b3ca78974..4b248c2ee6 100644 --- a/src/vulkan/tests/state_pool_no_free.c +++ b/src/vulkan/tests/state_pool_no_free.c @@ -58,6 +58,7 @@ static void run_test() struct anv_block_pool block_pool; struct anv_state_pool state_pool; + pthread_mutex_init(&device.mutex, NULL); anv_block_pool_init(&block_pool, &device, 64); anv_state_pool_init(&state_pool, &block_pool); @@ -106,6 +107,7 @@ static void run_test() anv_state_pool_finish(&state_pool); anv_block_pool_finish(&block_pool); + pthread_mutex_destroy(&device.mutex); } int main(int argc, char **argv) |