#include "anv_private.h"
#include "test_common.h"
-#define NUM_THREADS 8
-#define STATES_PER_THREAD_LOG2 10
-#define STATES_PER_THREAD (1 << STATES_PER_THREAD_LOG2)
-#define NUM_RUNS 64
-
#include "state_pool_test_helper.h"
int main(void)
{
+ const unsigned num_threads = 8;
+ const unsigned states_per_thread = 1 << 10;
+
struct anv_physical_device physical_device = { };
struct anv_device device = {};
struct anv_state_pool state_pool;
pthread_mutex_init(&device.mutex, NULL);
anv_bo_cache_init(&device.bo_cache, &device);
- for (unsigned i = 0; i < NUM_RUNS; i++) {
+ const unsigned num_runs = 64;
+ for (unsigned i = 0; i < num_runs; i++) {
anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 256);
/* Grab one so a zero offset is impossible */
anv_state_pool_alloc(&state_pool, 16, 16);
- run_state_pool_test(&state_pool);
+ run_state_pool_test(&state_pool, num_threads, states_per_thread);
anv_state_pool_finish(&state_pool);
}
#include "anv_private.h"
#include "test_common.h"
-#define NUM_THREADS 8
#define STATES_PER_THREAD_LOG2 12
#define STATES_PER_THREAD (1 << STATES_PER_THREAD_LOG2)
int main(void)
{
+ const unsigned num_threads = 8;
+ const unsigned states_per_thread = 1 << 12;
+
struct anv_physical_device physical_device = { };
struct anv_device device = {};
struct anv_state_pool state_pool;
* actually ever resize anything.
*/
{
- struct anv_state states[NUM_THREADS * STATES_PER_THREAD];
- for (unsigned i = 0; i < NUM_THREADS * STATES_PER_THREAD; i++) {
+ struct anv_state states[num_threads * states_per_thread];
+ for (unsigned i = 0; i < ARRAY_SIZE(states); i++) {
states[i] = anv_state_pool_alloc(&state_pool, 16, 16);
ASSERT(states[i].offset != 0);
}
- for (unsigned i = 0; i < NUM_THREADS * STATES_PER_THREAD; i++)
+ for (unsigned i = 0; i < ARRAY_SIZE(states); i++)
anv_state_pool_free(&state_pool, states[i]);
}
- run_state_pool_test(&state_pool);
+ run_state_pool_test(&state_pool, num_threads, states_per_thread);
anv_state_pool_finish(&state_pool);
anv_bo_cache_finish(&device.bo_cache);
#include <pthread.h>
+#include "util/u_math.h"
+
struct job {
- struct anv_state_pool *pool;
+ struct state_pool_test_context *ctx;
unsigned id;
pthread_t thread;
-} jobs[NUM_THREADS];
+};
+
+struct state_pool_test_context {
+ struct anv_state_pool *pool;
+ unsigned states_per_thread;
+ pthread_barrier_t barrier;
-pthread_barrier_t barrier;
+ struct job *jobs;
+};
static void *alloc_states(void *void_job)
{
struct job *job = void_job;
+ struct state_pool_test_context *ctx = job->ctx;
- const unsigned chunk_size = 1 << (job->id % STATES_PER_THREAD_LOG2);
- const unsigned num_chunks = STATES_PER_THREAD / chunk_size;
+ const unsigned states_per_thread_log2 = util_logbase2(ctx->states_per_thread);
+ const unsigned chunk_size = 1 << (job->id % states_per_thread_log2);
+ const unsigned num_chunks = ctx->states_per_thread / chunk_size;
struct anv_state states[chunk_size];
- pthread_barrier_wait(&barrier);
+ pthread_barrier_wait(&ctx->barrier);
for (unsigned c = 0; c < num_chunks; c++) {
for (unsigned i = 0; i < chunk_size; i++) {
- states[i] = anv_state_pool_alloc(job->pool, 16, 16);
+ states[i] = anv_state_pool_alloc(ctx->pool, 16, 16);
memset(states[i].map, 139, 16);
ASSERT(states[i].offset != 0);
}
for (unsigned i = 0; i < chunk_size; i++)
- anv_state_pool_free(job->pool, states[i]);
+ anv_state_pool_free(ctx->pool, states[i]);
}
return NULL;
}
-static void run_state_pool_test(struct anv_state_pool *state_pool)
+static void run_state_pool_test(struct anv_state_pool *state_pool, unsigned num_threads,
+ unsigned states_per_thread)
{
- pthread_barrier_init(&barrier, NULL, NUM_THREADS);
+ struct state_pool_test_context ctx = {
+ .pool = state_pool,
+ .states_per_thread = states_per_thread,
+ .jobs = calloc(num_threads, sizeof(struct job)),
+ };
+ pthread_barrier_init(&ctx.barrier, NULL, num_threads);
+
+ for (unsigned i = 0; i < num_threads; i++) {
+ struct job *job = &ctx.jobs[i];
+ job->ctx = &ctx;
+ job->id = i;
+ pthread_create(&job->thread, NULL, alloc_states, job);
+ }
- for (unsigned i = 0; i < NUM_THREADS; i++) {
- jobs[i].pool = state_pool;
- jobs[i].id = i;
- pthread_create(&jobs[i].thread, NULL, alloc_states, &jobs[i]);
+ for (unsigned i = 0; i < num_threads; i++) {
+ struct job *job = &ctx.jobs[i];
+ pthread_join(job->thread, NULL);
}
- for (unsigned i = 0; i < NUM_THREADS; i++)
- pthread_join(jobs[i].thread, NULL);
+ free(ctx.jobs);
}