X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=tests%2Ftest_urcu_ja.c;h=bad6784a446db3ecb1857de5c459dc93ffd66d13;hb=48cbe00177cd135553ee34d2f443c351b53b6d25;hp=e8f6887d6bd4b2818e034b34fc037af4e424de95;hpb=6da38aec631555f2a9b200cb51d64947f5c67004;p=userspace-rcu.git diff --git a/tests/test_urcu_ja.c b/tests/test_urcu_ja.c index e8f6887..bad6784 100644 --- a/tests/test_urcu_ja.c +++ b/tests/test_urcu_ja.c @@ -71,6 +71,9 @@ DEFINE_URCU_TLS(unsigned long long, nr_reads); unsigned int nr_readers; unsigned int nr_writers; +static unsigned int add_ratio = 50; +static uint64_t key_mul = 1ULL; + static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; void set_affinity(void) @@ -129,7 +132,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,8 +166,8 @@ 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(" [-k nr_nodes] Number of nodes to insert initially.\n"); + printf(" [-r ratio] Add ratio (in %% of add+removal).\n"); + printf(" [-k] Populate init nodes.\n"); printf(" [-R offset] Lookup pool offset.\n"); printf(" [-S offset] Write pool offset.\n"); printf(" [-T offset] Init pool offset.\n"); @@ -174,6 +177,7 @@ printf(" [not -u nor -s] Add entries (supports redundant keys).\n"); printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n"); printf(" [-s] Do sanity test.\n"); printf(" [-B] Key bits for multithread test (default: 32).\n"); + printf(" [-m factor] Key multiplication factor.\n"); printf("\n\n"); } @@ -599,6 +603,7 @@ void *test_ja_rw_thr_reader(void *_count) /* note: only looking up ulong keys */ key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % lookup_pool_size) + lookup_pool_offset; + key *= key_mul; head = cds_ja_lookup(test_ja, key); if (cds_hlist_empty(&head)) { if (validate_lookup) { @@ -631,6 +636,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,12 +663,13 @@ 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 */ key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset; + key *= key_mul; ja_test_node_init(node, key); rcu_read_lock(); ret = cds_ja_add(test_ja, key, &node->node); @@ -674,6 +686,7 @@ void *test_ja_rw_thr_writer(void *_count) /* May delete */ /* note: only deleting ulong keys */ key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset; + key *= key_mul; rcu_read_lock(); @@ -721,7 +734,7 @@ static int do_mt_populate_ja(void) { struct cds_hlist_head head; - uint64_t key; + uint64_t iter; int ret; if (!init_populate) @@ -729,11 +742,13 @@ int do_mt_populate_ja(void) printf("Starting rw test\n"); - for (key = init_pool_offset; key < init_pool_offset + init_pool_size; key++) { + for (iter = init_pool_offset; iter < init_pool_offset + init_pool_size; iter++) { struct ja_test_node *node = malloc(sizeof(*node)); + uint64_t key; /* note: only inserting ulong keys */ - key = (unsigned long) key; + key = (unsigned long) iter; + key *= key_mul; ja_test_node_init(node, key); rcu_read_lock(); ret = cds_ja_add(test_ja, key, &node->node); @@ -821,13 +836,13 @@ int do_mt_test(void) tot_add_exist += count_writer[i].add_exist; tot_remove += count_writer[i].remove; } + rcu_thread_online_qsbr(); ret = cds_ja_destroy(test_ja, free_node_cb); if (ret) { fprintf(stderr, "Error destroying judy array\n"); goto end; } - rcu_thread_online_qsbr(); free(tid_reader); free(tid_writer); @@ -906,11 +921,11 @@ 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]); + init_populate = 1; break; case 'R': lookup_pool_offset = atol(argv[++i]); @@ -939,6 +954,9 @@ int main(int argc, char **argv) case 'B': key_bits = atol(argv[++i]); break; + case 'm': + key_mul = atoll(argv[++i]); + break; } } @@ -946,8 +964,8 @@ 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("Key multiplication factor: %" PRIu64 ".\n", key_mul); 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",