X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=tests%2Ftest_urcu_ja.c;h=bc976030ce26635c4ef2b39baa13a0a275d298d9;hb=34ffee3e641b4d4200d64ac67bce398115acdf6c;hp=b3e6ed078fca822e23ec5f290762f5307af365ad;hpb=1a0c0717179caba65cc3de374b93af5027fcab9d;p=userspace-rcu.git diff --git a/tests/test_urcu_ja.c b/tests/test_urcu_ja.c index b3e6ed0..bc97603 100644 --- a/tests/test_urcu_ja.c +++ b/tests/test_urcu_ja.c @@ -71,6 +71,8 @@ DEFINE_URCU_TLS(unsigned long long, nr_reads); unsigned int nr_readers; unsigned int nr_writers; +static unsigned int add_ratio = 50; + static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; void set_affinity(void) @@ -129,7 +131,7 @@ void free_node_cb(struct rcu_head *head) { struct ja_test_node *node = caa_container_of(head, struct ja_test_node, node.head); - free(node); + poison_free(node); } #if 0 @@ -163,7 +165,7 @@ void show_usage(int argc, char **argv) printf(" [-v] (verbose output)\n"); printf(" [-a cpu#] [-a cpu#]... (affinity)\n"); printf(" [not -u nor -s] Add entries (supports redundant keys).\n"); - printf(" [-i] Add only (no removal).\n"); + printf(" [-r] Add ratio (in %% of add+removal).\n"); printf(" [-k nr_nodes] Number of nodes to insert initially.\n"); printf(" [-R offset] Lookup pool offset.\n"); printf(" [-S offset] Write pool offset.\n"); @@ -609,7 +611,7 @@ void *test_ja_rw_thr_reader(void *_count) } else { URCU_TLS(lookup_ok)++; } - debug_yield_read(); + rcu_debug_yield_read(); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); @@ -631,6 +633,12 @@ void *test_ja_rw_thr_reader(void *_count) return ((void*)1); } +static +int is_add(void) +{ + return ((unsigned int) rand_r(&URCU_TLS(rand_lookup)) % 100) < add_ratio; +} + static void *test_ja_rw_thr_writer(void *_count) { @@ -652,8 +660,8 @@ void *test_ja_rw_thr_writer(void *_count) cmm_smp_mb(); for (;;) { - if ((addremove == AR_ADD || add_only) - || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) { + if ((addremove == AR_ADD) + || (addremove == AR_RANDOM && is_add())) { struct ja_test_node *node = malloc(sizeof(*node)); /* note: only inserting ulong keys */ @@ -681,15 +689,16 @@ void *test_ja_rw_thr_writer(void *_count) node = cds_hlist_first_entry_rcu(&head, struct ja_test_node, node.list); if (node) { ret = cds_ja_del(test_ja, key, &node->node); - if (ret) { + if (!ret) { call_rcu(&node->node.head, free_node_cb); - URCU_TLS(nr_delnoent)++; - } else { URCU_TLS(nr_del)++; + } else { + URCU_TLS(nr_delnoent)++; } } else { URCU_TLS(nr_delnoent)++; } + rcu_read_unlock(); } URCU_TLS(nr_writes)++; @@ -905,8 +914,8 @@ int main(int argc, char **argv) case 'v': verbose_mode = 1; break; - case 'i': - add_only = 1; + case 'r': + add_ratio = atoi(argv[++i]); break; case 'k': init_populate = atol(argv[++i]); @@ -945,8 +954,7 @@ int main(int argc, char **argv) duration, nr_readers, nr_writers); printf_verbose("Writer delay : %lu loops.\n", wdelay); printf_verbose("Reader duration : %lu loops.\n", rduration); - printf_verbose("Mode:%s.\n", - add_only ? " add only" : " add/delete"); + printf_verbose("Add ratio: %u%%.\n", add_ratio); printf_verbose("Init pool size offset %lu size %lu.\n", init_pool_offset, init_pool_size); printf_verbose("Lookup pool size offset %lu size %lu.\n",