From: Mathieu Desnoyers Date: Tue, 9 Mar 2010 14:25:11 +0000 (-0500) Subject: rbtree test: improvement X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=40f1014da7f4aab3412494ebcd3ffcf89546ab91;p=urcu.git rbtree test: improvement Signed-off-by: Mathieu Desnoyers --- diff --git a/tests/test_urcu_rbtree.c b/tests/test_urcu_rbtree.c index 1bccc0e..405c0da 100644 --- a/tests/test_urcu_rbtree.c +++ b/tests/test_urcu_rbtree.c @@ -41,6 +41,9 @@ /* hardcoded number of CPUs */ #define NR_CPUS 16384 +/* number of insert/delete */ +#define NR_RAND 3 + #if defined(_syscall0) _syscall0(pid_t, gettid) #elif defined(__NR_gettid) @@ -245,7 +248,8 @@ void *thr_writer(void *_count) { unsigned long long *count = _count; struct rcu_rbtree_node *node; - void *key[3]; + void *key[NR_RAND]; + int i; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "writer", pthread_self(), (unsigned long)gettid()); @@ -262,45 +266,25 @@ void *thr_writer(void *_count) for (;;) { rcu_copy_mutex_lock(); - node = rbtree_alloc(); - key[0] = (void *)(unsigned long)(rand() % 2048); - node->key = key[0]; - rcu_rbtree_insert(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - - node = rbtree_alloc(); - key[1] = (void *)(unsigned long)(rand() % 2048); - node->key = key[1]; - rcu_rbtree_insert(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - - node = rbtree_alloc(); - key[2] = (void *)(unsigned long)(rand() % 2048); - node->key = key[2]; - rcu_rbtree_insert(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - + for (i = 0; i < NR_RAND; i++) { + node = rbtree_alloc(); + key[i] = (void *)(unsigned long)(rand() % 2048); + node->key = key[i]; + rcu_rbtree_insert(&rbtree_root, node, tree_comp, + rbtree_alloc, rbtree_free); + } if (unlikely(wduration)) loop_sleep(wduration); - node = rcu_rbtree_search(rbtree_root, key[2], tree_comp); - assert(node); - rcu_rbtree_remove(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - defer_rcu((void (*)(void *))rbtree_free, node); - - node = rcu_rbtree_search(rbtree_root, key[1], tree_comp); - assert(node); - rcu_rbtree_remove(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - defer_rcu((void (*)(void *))rbtree_free, node); - - node = rcu_rbtree_search(rbtree_root, key[0], tree_comp); - assert(node); - rcu_rbtree_remove(&rbtree_root, node, tree_comp, rbtree_alloc, - rbtree_free); - defer_rcu((void (*)(void *))rbtree_free, node); + for (i = 0; i < NR_RAND; i++) { + node = rcu_rbtree_search(rbtree_root, key[i], + tree_comp); + assert(node != &rcu_rbtree_nil); + rcu_rbtree_remove(&rbtree_root, node, tree_comp, + rbtree_alloc, rbtree_free); + defer_rcu((void (*)(void *))rbtree_free, node); + } rcu_copy_mutex_unlock(); nr_writes++;