X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_wfq.c;h=b4138ea6fc4308fdbf01f1bc1dd4b76cd0e55e7c;hb=b5002bee0cfd9fab20edc7d2bfaa9d0c75628f5b;hp=2399c7ad1055064952273316c53152ce6ea0bb51;hpb=ee566d46ed91f8e332460626573399237c312b4d;p=urcu.git diff --git a/tests/test_urcu_wfq.c b/tests/test_urcu_wfq.c index 2399c7a..b4138ea 100644 --- a/tests/test_urcu_wfq.c +++ b/tests/test_urcu_wfq.c @@ -34,11 +34,15 @@ #include #include #include -#include #include #include #include +#include + +#ifdef __linux__ +#include +#endif /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -61,9 +65,12 @@ static inline pid_t gettid(void) #ifndef DYNAMIC_LINK_TEST #define _LGPL_SOURCE #endif + +/* Remove deprecation warnings from test build. */ +#define CDS_WFQ_DEPRECATED + #include -#include -#include +#include static volatile int test_go, test_stop; @@ -74,10 +81,10 @@ static unsigned long duration; /* read-side C.S. duration, in loops */ static unsigned long wdelay; -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; @@ -102,9 +109,10 @@ typedef unsigned long cpu_set_t; 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; @@ -145,128 +153,107 @@ static int test_duration_enqueue(void) return !test_stop; } -static unsigned long long __thread nr_dequeues; -static unsigned long long __thread nr_enqueues; +static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); +static DEFINE_URCU_TLS(unsigned long long, nr_enqueues); -static unsigned long long __thread nr_successful_dequeues; -static unsigned long long __thread nr_successful_enqueues; +static DEFINE_URCU_TLS(unsigned long long, nr_successful_dequeues); +static DEFINE_URCU_TLS(unsigned long long, nr_successful_enqueues); static unsigned int nr_enqueuers; static unsigned int nr_dequeuers; -static struct rcu_wfq_queue q; +static struct cds_wfq_queue q; void *thr_enqueuer(void *_count) { unsigned long long *count = _count; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "enqueuer", pthread_self(), (unsigned long)gettid()); + "enqueuer", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); - rcu_register_thread(); - while (!test_go) { } - smp_mb(); + cmm_smp_mb(); for (;;) { - struct rcu_wfq_node *node = malloc(sizeof(*node)); + struct cds_wfq_node *node = malloc(sizeof(*node)); if (!node) goto fail; - rcu_wfq_node_init(node); - rcu_wfq_enqueue(&q, node); - nr_successful_enqueues++; + cds_wfq_node_init(node); + cds_wfq_enqueue(&q, node); + URCU_TLS(nr_successful_enqueues)++; - if (unlikely(wdelay)) + if (caa_unlikely(wdelay)) loop_sleep(wdelay); fail: - nr_enqueues++; - if (unlikely(!test_duration_enqueue())) + URCU_TLS(nr_enqueues)++; + if (caa_unlikely(!test_duration_enqueue())) break; } - rcu_unregister_thread(); - - count[0] = nr_enqueues; - count[1] = nr_successful_enqueues; + count[0] = URCU_TLS(nr_enqueues); + count[1] = URCU_TLS(nr_successful_enqueues); printf_verbose("enqueuer thread_end, thread id : %lx, tid %lu, " "enqueues %llu successful_enqueues %llu\n", - pthread_self(), (unsigned long)gettid(), nr_enqueues, - nr_successful_enqueues); + pthread_self(), + (unsigned long) gettid(), + URCU_TLS(nr_enqueues), URCU_TLS(nr_successful_enqueues)); return ((void*)1); } -static void rcu_release_node(struct urcu_ref *ref) -{ - struct rcu_wfq_node *node = container_of(ref, struct rcu_wfq_node, ref); - defer_rcu(free, node); - //synchronize_rcu(); - //free(node); -} - void *thr_dequeuer(void *_count) { unsigned long long *count = _count; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "dequeuer", pthread_self(), (unsigned long)gettid()); + "dequeuer", (unsigned long) pthread_self(), + (unsigned long) gettid()); set_affinity(); - rcu_defer_register_thread(); - rcu_register_thread(); - while (!test_go) { } - smp_mb(); + cmm_smp_mb(); for (;;) { - struct rcu_wfq_node *node = - rcu_wfq_dequeue_blocking(&q, rcu_release_node); + struct cds_wfq_node *node = cds_wfq_dequeue_blocking(&q); if (node) { - urcu_ref_put(&node->ref, rcu_release_node); - nr_successful_dequeues++; + free(node); + URCU_TLS(nr_successful_dequeues)++; } - nr_dequeues++; - if (unlikely(!test_duration_dequeue())) + URCU_TLS(nr_dequeues)++; + if (caa_unlikely(!test_duration_dequeue())) break; - if (unlikely(rduration)) + if (caa_unlikely(rduration)) loop_sleep(rduration); } - rcu_unregister_thread(); - rcu_defer_unregister_thread(); - printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " "dequeues %llu, successful_dequeues %llu\n", - pthread_self(), (unsigned long)gettid(), nr_dequeues, - nr_successful_dequeues); - count[0] = nr_dequeues; - count[1] = nr_successful_dequeues; + pthread_self(), + (unsigned long) gettid(), + URCU_TLS(nr_dequeues), URCU_TLS(nr_successful_dequeues)); + count[0] = URCU_TLS(nr_dequeues); + count[1] = URCU_TLS(nr_successful_dequeues); return ((void*)2); } -static void release_node(struct urcu_ref *ref) -{ - struct rcu_wfq_node *node = container_of(ref, struct rcu_wfq_node, ref); - free(node); -} - -void test_end(struct rcu_wfq_queue *q, unsigned long long *nr_dequeues) +void test_end(struct cds_wfq_queue *q, unsigned long long *nr_dequeues) { - struct rcu_wfq_node *node; + struct cds_wfq_node *node; do { - node = rcu_wfq_dequeue_blocking(q, release_node); + node = cds_wfq_dequeue_blocking(q); if (node) { - urcu_ref_put(&node->ref, release_node); + free(node); (*nr_dequeues)++; } } while (node); @@ -357,13 +344,14 @@ int main(int argc, char **argv) printf_verbose("Writer delay : %lu loops.\n", rduration); printf_verbose("Reader duration : %lu loops.\n", wdelay); 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_enqueuer = malloc(sizeof(*tid_enqueuer) * nr_enqueuers); tid_dequeuer = malloc(sizeof(*tid_dequeuer) * nr_dequeuers); count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers); count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers); - rcu_wfq_init(&q); + cds_wfq_init(&q); next_aff = 0; @@ -380,7 +368,7 @@ int main(int argc, char **argv) exit(1); } - smp_mb(); + cmm_smp_mb(); test_go = 1;