X-Git-Url: https://git.lttng.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_defer.c;h=9fea8c1f419bd9ff76f3d75d3464296b86d5481a;hp=2cbb0416739a44aaf6d8dbd9ae2523ffbe843816;hb=2953b501ab1dcf908d07de9b414a08397519f5b6;hpb=5481ddb381061bda64aebc039900d21cac6a6caf diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c index 2cbb041..9fea8c1 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -31,11 +31,15 @@ #include #include #include -#include -#include #include #include +#include +#include "cpuset.h" + +#ifdef __linux__ +#include +#endif /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -58,7 +62,7 @@ static inline pid_t gettid(void) #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE #else -#define debug_yield_read() +#define rcu_debug_yield_read() #endif #include #include @@ -81,10 +85,10 @@ static unsigned long rduration; /* write-side C.S. duration, in loops */ static unsigned long wduration; -static inline void loop_sleep(unsigned long l) +static inline void loop_sleep(unsigned long loops) { - while(l-- != 0) - cpu_relax(); + while (loops-- != 0) + caa_cpu_relax(); } static int verbose_mode; @@ -101,17 +105,12 @@ 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) { +#if HAVE_SCHED_SETAFFINITY cpu_set_t mask; - int cpu; - int ret; + int cpu, ret; +#endif /* HAVE_SCHED_SETAFFINITY */ if (!use_affinity) return; @@ -152,11 +151,11 @@ 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 long long __attribute__((aligned(CACHE_LINE_SIZE))) *tot_nr_writes; +unsigned long long __attribute__((aligned(CAA_CACHE_LINE_SIZE))) *tot_nr_writes; static unsigned int nr_readers; static unsigned int nr_writers; @@ -190,7 +189,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(); @@ -204,22 +204,23 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); local_ptr = rcu_dereference(test_rcu_pointer); - debug_yield_read(); + rcu_debug_yield_read(); if (local_ptr) assert(local_ptr->a == 8); - if (unlikely(rduration)) + if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); - nr_reads++; - if (unlikely(!test_duration_read())) + URCU_TLS(nr_reads)++; + if (caa_unlikely(!test_duration_read())) break; } 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); } @@ -236,13 +237,19 @@ void *thr_writer(void *data) { unsigned long wtidx = (unsigned long)data; struct test_array *new, *old = NULL; + int ret; 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(); - rcu_defer_register_thread(); + ret = rcu_defer_register_thread(); + if (ret) { + printf("Error in rcu_defer_register_thread\n"); + exit(-1); + } while (!test_go) { @@ -253,7 +260,7 @@ void *thr_writer(void *data) new = malloc(sizeof(*new)); new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); - if (unlikely(wduration)) + if (caa_unlikely(wduration)) loop_sleep(wduration); defer_rcu(free, old); defer_rcu(test_cb1, old); @@ -263,18 +270,19 @@ void *thr_writer(void *data) defer_rcu(test_cb2, (void *)-2L); defer_rcu(test_cb2, (void *)-4L); defer_rcu(test_cb2, (void *)-2L); - nr_writes++; - if (unlikely(!test_duration_write())) + URCU_TLS(nr_writes)++; + if (caa_unlikely(!test_duration_write())) break; - if (unlikely(wdelay)) + if (caa_unlikely(wdelay)) loop_sleep(wdelay); } rcu_defer_unregister_thread(); printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", - "writer", pthread_self(), (unsigned long)gettid()); - tot_nr_writes[wtidx] = nr_writes; + "writer", (unsigned long) pthread_self(), + (unsigned long) gettid()); + tot_nr_writes[wtidx] = URCU_TLS(nr_writes); return ((void*)2); } @@ -330,10 +338,10 @@ int main(int argc, char **argv) switch (argv[i][1]) { #ifdef DEBUG_YIELD case 'r': - yield_active |= YIELD_READ; + rcu_yield_active |= RCU_YIELD_READ; break; case 'w': - yield_active |= YIELD_WRITE; + rcu_yield_active |= RCU_YIELD_WRITE; break; #endif case 'a': @@ -378,7 +386,8 @@ 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()); tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers);