X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_lfq.c;h=11e7eb37b265c43a404d26c1d017e58cbfbc9fb1;hb=cc6b0c208a9707f8a64609a51167290caeace288;hp=5fd0ff38cb0ecd15a462072394a18ac7598a3ae1;hpb=6ade67d5cb23ae9e2c18e7c2a62e3202552fb9e2;p=urcu.git diff --git a/tests/test_urcu_lfq.c b/tests/test_urcu_lfq.c index 5fd0ff3..11e7eb3 100644 --- a/tests/test_urcu_lfq.c +++ b/tests/test_urcu_lfq.c @@ -34,12 +34,15 @@ #include #include #include -#include #include #include #include +#ifdef __linux__ +#include +#endif + /* hardcoded number of CPUs */ #define NR_CPUS 16384 @@ -62,7 +65,7 @@ static inline pid_t gettid(void) #define _LGPL_SOURCE #endif #include -#include +#include #include static volatile int test_go, test_stop; @@ -154,6 +157,11 @@ static unsigned long long __thread nr_successful_enqueues; static unsigned int nr_enqueuers; static unsigned int nr_dequeuers; +struct test { + struct cds_lfq_node_rcu list; + struct rcu_head rcu; +}; + static struct cds_lfq_queue_rcu q; void *thr_enqueuer(void *_count) @@ -173,18 +181,20 @@ void *thr_enqueuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfq_node_rcu *node = malloc(sizeof(*node)); + struct test *node = malloc(sizeof(*node)); if (!node) goto fail; - cds_lfq_node_init_rcu(node); - cds_lfq_enqueue_rcu(&q, node); + cds_lfq_node_init_rcu(&node->list); + rcu_read_lock(); + cds_lfq_enqueue_rcu(&q, &node->list); + rcu_read_unlock(); nr_successful_enqueues++; - if (unlikely(wdelay)) + if (caa_unlikely(wdelay)) loop_sleep(wdelay); fail: nr_enqueues++; - if (unlikely(!test_duration_enqueue())) + if (caa_unlikely(!test_duration_enqueue())) break; } @@ -200,17 +210,18 @@ fail: } -static void rcu_release_node(struct urcu_ref *ref) +static +void free_node_cb(struct rcu_head *head) { - struct cds_lfq_node_rcu *node = caa_container_of(ref, struct cds_lfq_node_rcu, ref); - defer_rcu(free, node); - //synchronize_rcu(); - //free(node); + struct test *node = + caa_container_of(head, struct test, rcu); + free(node); } void *thr_dequeuer(void *_count) { unsigned long long *count = _count; + int ret; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "dequeuer", pthread_self(), (unsigned long)gettid()); @@ -230,24 +241,28 @@ void *thr_dequeuer(void *_count) cmm_smp_mb(); for (;;) { - struct cds_lfq_node_rcu *node = cds_lfq_dequeue_rcu(&q, - rcu_release_node); + struct cds_lfq_node_rcu *qnode; + struct test *node; + + rcu_read_lock(); + qnode = cds_lfq_dequeue_rcu(&q); + node = caa_container_of(qnode, struct test, list); + rcu_read_unlock(); if (node) { - urcu_ref_put(&node->ref, rcu_release_node); + call_rcu(&node->rcu, free_node_cb); nr_successful_dequeues++; } nr_dequeues++; - if (unlikely(!test_duration_dequeue())) + 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, @@ -257,23 +272,20 @@ void *thr_dequeuer(void *_count) return ((void*)2); } -static void release_node(struct urcu_ref *ref) -{ - struct cds_lfq_node_rcu *node = caa_container_of(ref, struct cds_lfq_node_rcu, ref); - free(node); -} - void test_end(struct cds_lfq_queue_rcu *q, unsigned long long *nr_dequeues) { - struct cds_lfq_node_rcu *node; + struct cds_lfq_node_rcu *snode; do { - node = cds_lfq_dequeue_rcu(q, release_node); - if (node) { - urcu_ref_put(&node->ref, release_node); + snode = cds_lfq_dequeue_rcu(q); + if (snode) { + struct test *node; + + node = caa_container_of(snode, struct test, list); + free(node); /* no more concurrent access */ (*nr_dequeues)++; } - } while (node); + } while (snode); } void show_usage(int argc, char **argv) @@ -367,7 +379,9 @@ int main(int argc, char **argv) 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); - cds_lfq_init_rcu(&q); + cds_lfq_init_rcu(&q, call_rcu); + err = create_all_cpu_call_rcu_data(0); + assert(!err); next_aff = 0; @@ -412,6 +426,8 @@ int main(int argc, char **argv) } test_end(&q, &end_dequeues); + err = cds_lfq_destroy_rcu(&q); + assert(!err); printf_verbose("total number of enqueues : %llu, dequeues %llu\n", tot_enqueues, tot_dequeues); @@ -434,6 +450,7 @@ int main(int argc, char **argv) tot_successful_enqueues, tot_successful_dequeues + end_dequeues); + free_all_cpu_call_rcu_data(); free(count_enqueuer); free(count_dequeuer); free(tid_enqueuer);