From 15624fcf55bff9d16f3eaa461e4a3010bbe0e4ba Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 15 Sep 2015 17:57:40 -0700 Subject: [PATCH] anv/tests: Refactor the block_pool_no_free test This simply breaks the monotonicity check out into its own function --- src/vulkan/tests/block_pool_no_free.c | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/vulkan/tests/block_pool_no_free.c b/src/vulkan/tests/block_pool_no_free.c index d40504c4a87..71eb90103ef 100644 --- a/src/vulkan/tests/block_pool_no_free.c +++ b/src/vulkan/tests/block_pool_no_free.c @@ -46,6 +46,41 @@ static void *alloc_blocks(void *_job) return NULL; } +static void validate_monotonic(uint32_t **blocks) +{ + /* A list of indices, one per thread */ + unsigned next[NUM_THREADS]; + memset(next, 0, sizeof(next)); + + int highest = -1; + while (true) { + /* First, we find which thread has the highest next element */ + int thread_max = -1; + int max_thread_idx = -1; + for (unsigned i = 0; i < NUM_THREADS; i++) { + if (next[i] >= BLOCKS_PER_THREAD) + continue; + + if (thread_max < blocks[i][next[i]]) { + thread_max = blocks[i][next[i]]; + max_thread_idx = i; + } + } + + /* The only way this can happen is if all of the next[] values are at + * BLOCKS_PER_THREAD, in which case, we're done. + */ + if (thread_max == -1) + break; + + /* That next element had better be higher than the previous highest */ + assert(blocks[max_thread_idx][next[max_thread_idx]] > highest); + + highest = blocks[max_thread_idx][next[max_thread_idx]]; + next[max_thread_idx]++; + } +} + static void run_test() { struct anv_device device; @@ -63,37 +98,11 @@ static void run_test() for (unsigned i = 0; i < NUM_THREADS; i++) pthread_join(jobs[i].thread, NULL); - /* A list of indices, one per thread */ - unsigned next[NUM_THREADS]; - memset(next, 0, sizeof(next)); + uint32_t *block_ptrs[NUM_THREADS]; + for (unsigned i = 0; i < NUM_THREADS; i++) + block_ptrs[i] = jobs[i].blocks; - int highest = -1; - while (true) { - /* First, we find which thread has the highest next element */ - int thread_max = -1; - int max_thread_idx = -1; - for (unsigned i = 0; i < NUM_THREADS; i++) { - if (next[i] >= BLOCKS_PER_THREAD) - continue; - - if (thread_max < jobs[i].blocks[next[i]]) { - thread_max = jobs[i].blocks[next[i]]; - max_thread_idx = i; - } - } - - /* The only way this can happen is if all of the next[] values are at - * BLOCKS_PER_THREAD, in which case, we're done. - */ - if (thread_max == -1) - break; - - /* That next element had better be higher than the previous highest */ - assert(jobs[max_thread_idx].blocks[next[max_thread_idx]] > highest); - - highest = jobs[max_thread_idx].blocks[next[max_thread_idx]]; - next[max_thread_idx]++; - } + validate_monotonic(block_ptrs); anv_block_pool_finish(&pool); pthread_mutex_destroy(&device.mutex);