Path: blob/21.2-virgl/src/intel/vulkan/tests/state_pool_test_helper.h
4547 views
/*1* Copyright © 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include <pthread.h>2425struct job {26struct anv_state_pool *pool;27unsigned id;28pthread_t thread;29} jobs[NUM_THREADS];3031pthread_barrier_t barrier;3233static void *alloc_states(void *void_job)34{35struct job *job = void_job;3637const unsigned chunk_size = 1 << (job->id % STATES_PER_THREAD_LOG2);38const unsigned num_chunks = STATES_PER_THREAD / chunk_size;3940struct anv_state states[chunk_size];4142pthread_barrier_wait(&barrier);4344for (unsigned c = 0; c < num_chunks; c++) {45for (unsigned i = 0; i < chunk_size; i++) {46states[i] = anv_state_pool_alloc(job->pool, 16, 16);47memset(states[i].map, 139, 16);48ASSERT(states[i].offset != 0);49}5051for (unsigned i = 0; i < chunk_size; i++)52anv_state_pool_free(job->pool, states[i]);53}5455return NULL;56}5758static void run_state_pool_test(struct anv_state_pool *state_pool)59{60pthread_barrier_init(&barrier, NULL, NUM_THREADS);6162for (unsigned i = 0; i < NUM_THREADS; i++) {63jobs[i].pool = state_pool;64jobs[i].id = i;65pthread_create(&jobs[i].thread, NULL, alloc_states, &jobs[i]);66}6768for (unsigned i = 0; i < NUM_THREADS; i++)69pthread_join(jobs[i].thread, NULL);70}717273