X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_hash_rw.c;h=3eb72924cd79a3d0651efbf7832198d9df8d1bb7;hp=7145ca41306111722ea28b6aaf52d063669d00c4;hb=1de4df4b770e5e90440008becc5e14a15c75c6e0;hpb=18ca7a5b5573e511a66f118ec863df82a6d247e4 diff --git a/tests/test_urcu_hash_rw.c b/tests/test_urcu_hash_rw.c index 7145ca4..3eb7292 100644 --- a/tests/test_urcu_hash_rw.c +++ b/tests/test_urcu_hash_rw.c @@ -80,7 +80,7 @@ void *test_hash_rw_thr_reader(void *_count) for (;;) { rcu_read_lock(); cds_lfht_test_lookup(test_ht, - (void *)(((unsigned long) rand_r(&rand_lookup) % lookup_pool_size) + lookup_pool_offset), + (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % lookup_pool_size) + lookup_pool_offset), sizeof(void *), &iter); node = cds_lfht_iter_get_test_node(&iter); if (node == NULL) { @@ -88,28 +88,29 @@ void *test_hash_rw_thr_reader(void *_count) printf("[ERROR] Lookup cannot find initial node.\n"); exit(-1); } - lookup_fail++; + URCU_TLS(lookup_fail)++; } else { - lookup_ok++; + URCU_TLS(lookup_ok)++; } - debug_yield_read(); + rcu_debug_yield_read(); if (caa_unlikely(rduration)) loop_sleep(rduration); rcu_read_unlock(); - nr_reads++; + URCU_TLS(nr_reads)++; if (caa_unlikely(!test_duration_read())) break; - if (caa_unlikely((nr_reads & ((1 << 10) - 1)) == 0)) + if (caa_unlikely((URCU_TLS(nr_reads) & ((1 << 10) - 1)) == 0)) rcu_quiescent_state(); } rcu_unregister_thread(); - *count = nr_reads; + *count = URCU_TLS(nr_reads); printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "reader", pthread_self(), (unsigned long)gettid()); printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n", - pthread_self(), lookup_fail, lookup_ok); + pthread_self(), URCU_TLS(lookup_fail), + URCU_TLS(lookup_ok)); return ((void*)1); } @@ -136,10 +137,10 @@ void *test_hash_rw_thr_writer(void *_count) for (;;) { if ((addremove == AR_ADD || add_only) - || (addremove == AR_RANDOM && rand_r(&rand_lookup) & 1)) { + || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) { node = malloc(sizeof(struct lfht_test_node)); lfht_test_node_init(node, - (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset), + (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset), sizeof(void *)); rcu_read_lock(); if (add_unique) { @@ -159,36 +160,36 @@ void *test_hash_rw_thr_writer(void *_count) rcu_read_unlock(); if (add_unique && ret_node != &node->node) { free(node); - nr_addexist++; + URCU_TLS(nr_addexist)++; } else { if (add_replace && ret_node) { call_rcu(&to_test_node(ret_node)->head, free_node_cb); - nr_addexist++; + URCU_TLS(nr_addexist)++; } else { - nr_add++; + URCU_TLS(nr_add)++; } } } else { /* May delete */ rcu_read_lock(); cds_lfht_test_lookup(test_ht, - (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset), + (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset), sizeof(void *), &iter); ret = cds_lfht_del(test_ht, cds_lfht_iter_get_node(&iter)); rcu_read_unlock(); if (ret == 0) { node = cds_lfht_iter_get_test_node(&iter); call_rcu(&node->head, free_node_cb); - nr_del++; + URCU_TLS(nr_del)++; } else - nr_delnoent++; + URCU_TLS(nr_delnoent)++; } #if 0 - //if (nr_writes % 100000 == 0) { - if (nr_writes % 1000 == 0) { + //if (URCU_TLS(nr_writes) % 100000 == 0) { + if (URCU_TLS(nr_writes) % 1000 == 0) { rcu_read_lock(); - if (rand_r(&rand_lookup) & 1) { + if (rand_r(&URCU_TLS(rand_lookup)) & 1) { ht_resize(test_ht, 1); } else { ht_resize(test_ht, -1); @@ -196,12 +197,12 @@ void *test_hash_rw_thr_writer(void *_count) rcu_read_unlock(); } #endif //0 - nr_writes++; + URCU_TLS(nr_writes)++; if (caa_unlikely(!test_duration_write())) break; if (caa_unlikely(wdelay)) loop_sleep(wdelay); - if (caa_unlikely((nr_writes & ((1 << 10) - 1)) == 0)) + if (caa_unlikely((URCU_TLS(nr_writes) & ((1 << 10) - 1)) == 0)) rcu_quiescent_state(); } @@ -210,12 +211,13 @@ void *test_hash_rw_thr_writer(void *_count) printf_verbose("thread_end %s, thread id : %lx, tid %lu\n", "writer", pthread_self(), (unsigned long)gettid()); printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, " - "nr_delnoent %lu\n", pthread_self(), nr_add, - nr_addexist, nr_del, nr_delnoent); - count->update_ops = nr_writes; - count->add = nr_add; - count->add_exist = nr_addexist; - count->remove = nr_del; + "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add), + URCU_TLS(nr_addexist), URCU_TLS(nr_del), + URCU_TLS(nr_delnoent)); + count->update_ops = URCU_TLS(nr_writes); + count->add = URCU_TLS(nr_add); + count->add_exist = URCU_TLS(nr_addexist); + count->remove = URCU_TLS(nr_del); return ((void*)2); } @@ -227,16 +229,18 @@ int test_hash_rw_populate_hash(void) if (!init_populate) return 0; + printf("Starting rw test\n"); + if ((add_unique || add_replace) && init_populate * 10 > init_pool_size) { printf("WARNING: required to populate %lu nodes (-k), but random " "pool is quite small (%lu values) and we are in add_unique (-u) or add_replace (-s) mode. Try with a " "larger random pool (-p option). This may take a while...\n", init_populate, init_pool_size); } - while (nr_add < init_populate) { + while (URCU_TLS(nr_add) < init_populate) { node = malloc(sizeof(struct lfht_test_node)); lfht_test_node_init(node, - (void *)(((unsigned long) rand_r(&rand_lookup) % init_pool_size) + init_pool_offset), + (void *)(((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % init_pool_size) + init_pool_offset), sizeof(void *)); rcu_read_lock(); if (add_unique) { @@ -256,16 +260,16 @@ int test_hash_rw_populate_hash(void) rcu_read_unlock(); if (add_unique && ret_node != &node->node) { free(node); - nr_addexist++; + URCU_TLS(nr_addexist)++; } else { if (add_replace && ret_node) { call_rcu(&to_test_node(ret_node)->head, free_node_cb); - nr_addexist++; + URCU_TLS(nr_addexist)++; } else { - nr_add++; + URCU_TLS(nr_add)++; } } - nr_writes++; + URCU_TLS(nr_writes)++; } return 0; }