X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_hash.c;h=1e1cf47423942dbac3279c12e777dfc3270a7d52;hb=973e5e1b7837176071749d727e37bdfe9e3c4f0e;hp=89063b98626042262341fdcc27e5b6ee28c0277c;hpb=48ed1c184a1aa1da7d84c2d0bc1b9528627248ac;p=urcu.git diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index 89063b9..1e1cf47 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -194,6 +194,26 @@ void sigusr1_handler(int signo) } } +static +void sigusr2_handler(int signo) +{ + unsigned long count, removed, approx_before, approx_after; + + /* Accounting */ + printf("Counting nodes... "); + fflush(stdout); + cds_lfht_count_nodes(test_ht, &approx_before, &count, &removed, + &approx_after); + printf("done.\n"); + printf("Approximation before node accounting: %lu nodes.\n", + approx_before); + printf("Accounting of nodes in the hash table: " + "%lu nodes + %lu logically removed.\n", + count, removed); + printf("Approximation after node accounting: %lu nodes.\n", + approx_after); +} + /* * returns 0 if test should end. */ @@ -384,6 +404,7 @@ void *thr_reader(void *_count) { unsigned long long *count = _count; struct cds_lfht_node *node; + struct cds_lfht_iter iter; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "reader", pthread_self(), (unsigned long)gettid()); @@ -399,9 +420,10 @@ void *thr_reader(void *_count) for (;;) { rcu_read_lock(); - node = cds_lfht_lookup(test_ht, + cds_lfht_lookup(test_ht, (void *)(((unsigned long) rand_r(&rand_lookup) % lookup_pool_size) + lookup_pool_offset), - sizeof(void *)); + sizeof(void *), &iter); + node = cds_lfht_iter_get_node(&iter); if (node == NULL) { if (validate_lookup) { printf("[ERROR] Lookup cannot find initial node.\n"); @@ -444,6 +466,7 @@ void free_node_cb(struct rcu_head *head) void *thr_writer(void *_count) { struct cds_lfht_node *node, *ret_node; + struct cds_lfht_iter iter; struct wr_count *count = _count; int ret; @@ -490,9 +513,10 @@ void *thr_writer(void *_count) } else { /* May delete */ rcu_read_lock(); - node = cds_lfht_lookup(test_ht, + cds_lfht_lookup(test_ht, (void *)(((unsigned long) rand_r(&rand_lookup) % write_pool_size) + write_pool_offset), - sizeof(void *)); + sizeof(void *), &iter); + node = cds_lfht_iter_get_node(&iter); if (node) ret = cds_lfht_del(test_ht, node); else @@ -619,7 +643,7 @@ int main(int argc, char **argv) struct wr_count *count_writer; unsigned long long tot_reads = 0, tot_writes = 0, tot_add = 0, tot_add_exist = 0, tot_remove = 0; - unsigned long count, removed; + unsigned long count, removed, approx_before, approx_after; int i, a, ret; struct sigaction act; unsigned int remain; @@ -761,6 +785,13 @@ int main(int argc, char **argv) perror("sigaction"); return -1; } + act.sa_handler = sigusr2_handler; + act.sa_flags = SA_RESTART; + ret = sigaction(SIGUSR2, &act, NULL); + if (ret == -1) { + perror("sigaction"); + return -1; + } printf_verbose("running test for %lu seconds, %u readers, %u writers.\n", duration, nr_readers, nr_writers); @@ -842,11 +873,18 @@ int main(int argc, char **argv) } printf("Counting nodes... "); fflush(stdout); - cds_lfht_count_nodes(test_ht, &count, &removed); + cds_lfht_count_nodes(test_ht, &approx_before, &count, &removed, + &approx_after); printf("done.\n"); - if (count || removed) + if (count || removed) { + printf("Approximation before node accounting: %lu nodes.\n", + approx_before); printf("WARNING: nodes left in the hash table upon destroy: " - "%lu nodes + %lu logically removed.\n", count, removed); + "%lu nodes + %lu logically removed.\n", + count, removed); + printf("Approximation after node accounting: %lu nodes.\n", + approx_after); + } ret = cds_lfht_destroy(test_ht, NULL); if (ret)