]> git.lttng.org Git - userspace-rcu.git/commitdiff
lfq/lfs tests: use call_rcu
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 5 Sep 2011 01:25:21 +0000 (21:25 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 5 Sep 2011 01:25:21 +0000 (21:25 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/Makefile.am
tests/test_urcu_lfq.c
tests/test_urcu_lfs.c

index 399fe9cad7ebac30df8de2f106ea45b6d463a741..9f5fbb130bf4eea10e9fc6bb77ac0ae3bbe6cf45 100644 (file)
@@ -165,8 +165,8 @@ test_urcu_wfq_dynlink_SOURCES = test_urcu_wfq.c
 test_urcu_wfq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_wfq_dynlink_LDADD = $(URCU_COMMON_LIB)
 
-test_urcu_lfs_SOURCES = test_urcu_lfs.c $(URCU_CDS_LIB) $(URCU_DEFER)
-test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c $(URCU_DEFER)
+test_urcu_lfs_SOURCES = test_urcu_lfs.c $(URCU) $(URCU_CDS_LIB)
+test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c $(URCU)
 test_urcu_lfs_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS)
 test_urcu_lfs_dynlink_LDADD = $(URCU_CDS_LIB)
 
index b61a7d4815788af2bcd9e197dc319a8eb053791a..2d701f2913a7244b36a24b2e493d515d05377847 100644 (file)
@@ -157,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)
@@ -176,12 +181,12 @@ 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_node_init_rcu(&node->list);
                rcu_read_lock();
-               cds_lfq_enqueue_rcu(&q, node);
+               cds_lfq_enqueue_rcu(&q, &node->list);
                rcu_read_unlock();
                nr_successful_enqueues++;
 
@@ -205,6 +210,14 @@ fail:
 
 }
 
+static
+void free_node_cb(struct rcu_head *head)
+{
+       struct test *node =
+               caa_container_of(head, struct test, rcu);
+       free(node);
+}
+
 void *thr_dequeuer(void *_count)
 {
        unsigned long long *count = _count;
@@ -228,14 +241,16 @@ void *thr_dequeuer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               struct cds_lfq_node_rcu *node;
+               struct cds_lfq_node_rcu *qnode;
+               struct test *node;
 
                rcu_read_lock();
-               node = cds_lfq_dequeue_rcu(&q);
+               qnode = cds_lfq_dequeue_rcu(&q);
+               node = caa_container_of(qnode, struct test, list);
                rcu_read_unlock();
 
                if (node) {
-                       defer_rcu(free, node);
+                       call_rcu(&node->rcu, free_node_cb);
                        nr_successful_dequeues++;
                }
 
@@ -259,17 +274,18 @@ void *thr_dequeuer(void *_count)
 
 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 {
-               rcu_read_lock();
-               node = cds_lfq_dequeue_rcu(q);
-               rcu_read_unlock();
-               if (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)
@@ -364,6 +380,8 @@ int main(int argc, char **argv)
        count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers);
        count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers);
        cds_lfq_init_rcu(&q, call_rcu);
+       err = create_all_cpu_call_rcu_data(0);
+       assert(!err);
 
        next_aff = 0;
 
index 252454d29aeb46d4758e30b2a7f6b864cc8e3b65..e02fa58b49f4e24acb910628ca31e1025352771b 100644 (file)
@@ -157,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_lfs_node_rcu list;
+       struct rcu_head rcu;
+};
+
 static struct cds_lfs_stack_rcu s;
 
 void *thr_enqueuer(void *_count)
@@ -176,12 +181,12 @@ void *thr_enqueuer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               struct cds_lfs_node_rcu *node = malloc(sizeof(*node));
+               struct test *node = malloc(sizeof(*node));
                if (!node)
                        goto fail;
-               cds_lfs_node_init_rcu(node);
+               cds_lfs_node_init_rcu(&node->list);
                /* No rcu read-side is needed for push */
-               cds_lfs_push_rcu(&s, node);
+               cds_lfs_push_rcu(&s, &node->list);
                nr_successful_enqueues++;
 
                if (unlikely(wdelay))
@@ -204,6 +209,14 @@ fail:
 
 }
 
+static
+void free_node_cb(struct rcu_head *head)
+{
+       struct test *node =
+               caa_container_of(head, struct test, rcu);
+       free(node);
+}
+
 void *thr_dequeuer(void *_count)
 {
        unsigned long long *count = _count;
@@ -227,13 +240,15 @@ void *thr_dequeuer(void *_count)
        cmm_smp_mb();
 
        for (;;) {
-               struct cds_lfs_node_rcu *node;
+               struct cds_lfs_node_rcu *snode;
+               struct test *node;
 
                rcu_read_lock();
-               node = cds_lfs_pop_rcu(&s);
+               snode = cds_lfs_pop_rcu(&s);
+               node = caa_container_of(snode, struct test, list);
                rcu_read_unlock();
                if (node) {
-                       defer_rcu(free, node);
+                       call_rcu(&node->rcu, free_node_cb);
                        nr_successful_dequeues++;
                }
                nr_dequeues++;
@@ -257,15 +272,18 @@ void *thr_dequeuer(void *_count)
 
 void test_end(struct cds_lfs_stack_rcu *s, unsigned long long *nr_dequeues)
 {
-       struct cds_lfs_node_rcu *node;
+       struct cds_lfs_node_rcu *snode;
 
        do {
-               node = cds_lfs_pop_rcu(s);
-               if (node) {
+               snode = cds_lfs_pop_rcu(s);
+               if (snode) {
+                       struct test *node;
+
+                       node = caa_container_of(snode, struct test, list);
                        free(node);
                        (*nr_dequeues)++;
                }
-       } while (node);
+       } while (snode);
 }
 
 void show_usage(int argc, char **argv)
@@ -360,6 +378,8 @@ int main(int argc, char **argv)
        count_enqueuer = malloc(2 * sizeof(*count_enqueuer) * nr_enqueuers);
        count_dequeuer = malloc(2 * sizeof(*count_dequeuer) * nr_dequeuers);
        cds_lfs_init_rcu(&s);
+       err = create_all_cpu_call_rcu_data(0);
+       assert(!err);
 
        next_aff = 0;
 
This page took 0.033724 seconds and 4 git commands to generate.