X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_defer.c;h=1575e9c3523a45e07d96e4eae59af99acad54d63;hp=0961b8d2de85335efea234f63769e1bce98f00eb;hb=a0b7f7ea3fc3339a1c42caffd53ce9f056e5b901;hpb=48f9433c41294bad0a9cb31515c35260703d691a diff --git a/tests/test_urcu_defer.c b/tests/test_urcu_defer.c index 0961b8d..1575e9c 100644 --- a/tests/test_urcu_defer.c +++ b/tests/test_urcu_defer.c @@ -3,7 +3,7 @@ * * Userspace RCU library - test program (with automatic reclamation) * - * Copyright February 2009 - Mathieu Desnoyers + * Copyright February 2009 - Mathieu Desnoyers * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ */ #define _GNU_SOURCE +#include "../config.h" #include #include #include @@ -30,13 +31,14 @@ #include #include #include -#include #include +#include -#include "../arch.h" +#include -/* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ -#define CACHE_LINE_SIZE 4096 +#ifdef __linux__ +#include +#endif /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -61,8 +63,8 @@ static inline pid_t gettid(void) #else #define debug_yield_read() #endif -#include "../urcu.h" -#include "../urcu-defer.h" +#include +#include struct test_array { int a; @@ -79,10 +81,13 @@ static unsigned long duration; /* read-side C.S. duration, in loops */ static unsigned long rduration; +/* write-side C.S. duration, in loops */ +static unsigned long wduration; + static inline void loop_sleep(unsigned long l) { while(l-- != 0) - cpu_relax(); + caa_cpu_relax(); } static int verbose_mode; @@ -99,6 +104,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) { cpu_set_t mask; @@ -108,6 +119,7 @@ static void set_affinity(void) if (!use_affinity) return; +#if HAVE_SCHED_SETAFFINITY ret = pthread_mutex_lock(&affinity_mutex); if (ret) { perror("Error in pthread mutex lock"); @@ -119,9 +131,15 @@ static void set_affinity(void) perror("Error in pthread mutex unlock"); exit(-1); } + CPU_ZERO(&mask); CPU_SET(cpu, &mask); +#if SCHED_SETAFFINITY_ARGS == 2 + sched_setaffinity(0, &mask); +#else sched_setaffinity(0, sizeof(mask), &mask); +#endif +#endif /* HAVE_SCHED_SETAFFINITY */ } /* @@ -141,7 +159,7 @@ static unsigned long long __thread nr_writes; static unsigned long long __thread 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; @@ -184,7 +202,7 @@ void *thr_reader(void *_count) while (!test_go) { } - smp_mb(); + cmm_smp_mb(); for (;;) { rcu_read_lock(); @@ -192,11 +210,11 @@ void *thr_reader(void *_count) 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())) + if (caa_unlikely(!test_duration_read())) break; } @@ -221,35 +239,42 @@ 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()); 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) { } - smp_mb(); + cmm_smp_mb(); for (;;) { new = malloc(sizeof(*new)); new->a = 8; old = rcu_xchg_pointer(&test_rcu_pointer, new); - call_rcu(free, old); - call_rcu(test_cb1, old); - call_rcu(test_cb1, (void *)-2L); - call_rcu(test_cb1, (void *)-2L); - call_rcu(test_cb1, old); - call_rcu(test_cb2, (void *)-2L); - call_rcu(test_cb2, (void *)-4L); - call_rcu(test_cb2, (void *)-2L); + if (caa_unlikely(wduration)) + loop_sleep(wduration); + defer_rcu(free, old); + defer_rcu(test_cb1, old); + defer_rcu(test_cb1, (void *)-2L); + defer_rcu(test_cb1, (void *)-2L); + defer_rcu(test_cb1, old); + 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())) + if (caa_unlikely(!test_duration_write())) break; - if (unlikely(wdelay)) + if (caa_unlikely(wdelay)) loop_sleep(wdelay); } @@ -269,6 +294,7 @@ void show_usage(int argc, char **argv) #endif printf(" [-d delay] (writer period (us))"); printf(" [-c duration] (reader C.S. duration (in loops))"); + printf(" [-e duration] (writer C.S. duration (in loops))"); printf(" [-v] (verbose output)"); printf(" [-a cpu#] [-a cpu#]... (affinity)"); printf("\n"); @@ -342,6 +368,13 @@ int main(int argc, char **argv) } wdelay = atol(argv[++i]); break; + case 'e': + if (argc < i + 2) { + show_usage(argc, argv); + return -1; + } + wduration = atol(argv[++i]); + break; case 'v': verbose_mode = 1; break; @@ -375,7 +408,7 @@ int main(int argc, char **argv) exit(1); } - smp_mb(); + cmm_smp_mb(); test_go = 1; @@ -398,10 +431,10 @@ int main(int argc, char **argv) printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, tot_writes); - printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu " + printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu wdur %6lu " "nr_writers %3u " "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu\n", - argv[0], duration, nr_readers, rduration, + argv[0], duration, nr_readers, rduration, wduration, nr_writers, wdelay, tot_reads, tot_writes, tot_reads + tot_writes); free(tid_reader);