X-Git-Url: http://git.liburcu.org/?p=userspace-rcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_qsbr.c;h=b3cad835aba53b65144a66ae44104cafde45882b;hp=b986fd825fabc4d8663ab395f95d875631453133;hb=f90535ef41a3ddef0c8bcd76a6ecb89f3fd09fc3;hpb=a0b7f7ea3fc3339a1c42caffd53ce9f056e5b901 diff --git a/tests/test_urcu_qsbr.c b/tests/test_urcu_qsbr.c index b986fd8..b3cad83 100644 --- a/tests/test_urcu_qsbr.c +++ b/tests/test_urcu_qsbr.c @@ -31,10 +31,11 @@ #include #include #include -#include #include #include +#include +#include "cpuset.h" #ifdef __linux__ #include @@ -103,12 +104,6 @@ static int use_affinity = 0; pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; -#ifndef HAVE_CPU_SET_T -typedef unsigned long cpu_set_t; -# define CPU_ZERO(cpuset) do { *(cpuset) = 0; } while(0) -# define CPU_SET(cpu, cpuset) do { *(cpuset) |= (1UL << (cpu)); } while(0) -#endif - static void set_affinity(void) { cpu_set_t mask; @@ -153,8 +148,8 @@ static int test_duration_read(void) return !test_stop; } -static unsigned long long __thread nr_writes; -static unsigned long long __thread nr_reads; +static DEFINE_URCU_TLS(unsigned long long, nr_writes); +static DEFINE_URCU_TLS(unsigned long long, nr_reads); static unsigned int nr_readers; static unsigned int nr_writers; @@ -221,7 +216,8 @@ void *thr_reader(void *_count) struct test_array *local_ptr; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); @@ -241,9 +237,9 @@ void *thr_reader(void *_count) if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); - nr_reads++; + URCU_TLS(nr_reads)++; /* QS each 1024 reads */ - if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0)) + if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0)) rcu_quiescent_state(); if (caa_unlikely(!test_duration_read())) break; @@ -255,9 +251,10 @@ void *thr_reader(void *_count) rcu_register_thread(); rcu_unregister_thread(); - *count = nr_reads; + *count = URCU_TLS(nr_reads); printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", - "reader", pthread_self(), (unsigned long)gettid()); + "reader", (unsigned long) pthread_self(), + (unsigned long) gettid()); return ((void*)1); } @@ -268,7 +265,8 @@ void *thr_writer(void *_count) struct test_array *new, *old; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); @@ -290,7 +288,7 @@ void *thr_writer(void *_count) old->a = 0; test_array_free(old); rcu_copy_mutex_unlock(); - nr_writes++; + URCU_TLS(nr_writes)++; if (caa_unlikely(!test_duration_write())) break; if (caa_unlikely(wdelay)) @@ -298,8 +296,9 @@ void *thr_writer(void *_count) } printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); - *count = nr_writes; + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); + *count = URCU_TLS(nr_writes); return ((void*)2); } @@ -403,13 +402,14 @@ int main(int argc, char **argv) printf_verbose("Writer delay : %lu loops.\n", wdelay); printf_verbose("Reader duration : %lu loops.\n", rduration); printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", - "main", pthread_self(), (unsigned long)gettid()); + "main", (unsigned long) pthread_self(), + (unsigned long) gettid()); test_array = calloc(1, sizeof(*test_array) * ARRAY_SIZE); - tid_reader = malloc(sizeof(*tid_reader) * nr_readers); - tid_writer = malloc(sizeof(*tid_writer) * nr_writers); - count_reader = malloc(sizeof(*count_reader) * nr_readers); - count_writer = malloc(sizeof(*count_writer) * nr_writers); + tid_reader = calloc(nr_readers, sizeof(*tid_reader)); + tid_writer = calloc(nr_writers, sizeof(*tid_writer)); + count_reader = calloc(nr_readers, sizeof(*count_reader)); + count_writer = calloc(nr_writers, sizeof(*count_writer)); next_aff = 0;