X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;ds=sidebyside;f=tests%2Ftest_urcu_ja.c;h=2832650435378569b99ac09254a29e25f24f33f3;hb=46fc422ba060312d3a7acad1da698a3efccced5f;hp=ab23982033e87c646c3ddc0b986daaadf3f62a87;hpb=d7069878f7d6a1265bf18148f2fafa706312cc2e;p=userspace-rcu.git diff --git a/tests/test_urcu_ja.c b/tests/test_urcu_ja.c index ab23982..2832650 100644 --- a/tests/test_urcu_ja.c +++ b/tests/test_urcu_ja.c @@ -71,6 +71,11 @@ 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 int add_unique, add_replace; + static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER; void set_affinity(void) @@ -129,7 +134,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 @@ -162,9 +167,11 @@ void show_usage(int argc, char **argv) printf(" [-c duration] (reader C.S. duration (in loops))\n"); printf(" [-v] (verbose output)\n"); printf(" [-a cpu#] [-a cpu#]... (affinity)\n"); + printf(" [-u] Add unique keys.\n"); + printf(" [-s] Replace existing keys.\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"); @@ -172,8 +179,9 @@ printf(" [not -u nor -s] Add entries (supports redundant keys).\n"); printf(" [-N size] Write pool size.\n"); printf(" [-O size] Init pool size.\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(" [-t] 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 +607,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 +640,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,28 +667,43 @@ 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)); + struct cds_ja_node *ret_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); - URCU_TLS(nr_add)++; - rcu_read_unlock(); - if (ret) { - fprintf(stderr, "Error (%d) adding node %" PRIu64 "\n", - ret, key); - assert(0); + if (add_unique) { + ret_node = cds_ja_add_unique(test_ja, key, &node->node); + if (ret_node != &node->node) { + free(node); + URCU_TLS(nr_addexist)++; + } else { + URCU_TLS(nr_add)++; + } + } else if (add_replace) { + assert(0); /* not implemented yet. */ + } else { + ret = cds_ja_add(test_ja, key, &node->node); + if (ret) { + fprintf(stderr, "Error in cds_ja_add: %d\n", ret); + free(node); + } else { + URCU_TLS(nr_add)++; + } } + rcu_read_unlock(); } else { struct ja_test_node *node; /* 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(); @@ -690,6 +720,7 @@ void *test_ja_rw_thr_writer(void *_count) } else { URCU_TLS(nr_delnoent)++; } + rcu_read_unlock(); } URCU_TLS(nr_writes)++; @@ -720,7 +751,7 @@ static int do_mt_populate_ja(void) { struct cds_hlist_head head; - uint64_t key; + uint64_t iter; int ret; if (!init_populate) @@ -728,11 +759,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); @@ -820,13 +853,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); @@ -905,11 +938,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]); @@ -932,12 +965,21 @@ int main(int argc, char **argv) case 'V': validate_lookup = 1; break; - case 's': + case 't': sanity_test = 1; break; case 'B': key_bits = atol(argv[++i]); break; + case 'm': + key_mul = atoll(argv[++i]); + break; + case 'u': + add_unique = 1; + break; + case 's': + add_replace = 1; + break; } } @@ -945,14 +987,19 @@ 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("Mode:%s%s.\n", + " add/remove", + add_unique ? " uniquify" : ( add_replace ? " replace" : " insert")); + 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", lookup_pool_offset, lookup_pool_size); printf_verbose("Update pool size offset %lu size %lu.\n", write_pool_offset, write_pool_size); + if (validate_lookup) + printf_verbose("Validating lookups.\n"); printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", "main", pthread_self(), (unsigned long)gettid()); @@ -979,16 +1026,17 @@ int main(int argc, char **argv) if (sanity_test) { ret = do_sanity_test(); - if (ret) { - fprintf(stderr, "Error in sanity test\n"); - } } else { - do_mt_test(); + ret = do_mt_test(); } rcu_unregister_thread(); free_all_cpu_call_rcu_data(); - return 0; + + if (ret) { + printf("Test ended with error: %d\n", ret); + } + return ret; #if 0 /*