X-Git-Url: https://git.liburcu.org/?p=urcu.git;a=blobdiff_plain;f=tests%2Ftest_urcu_hash.c;h=56bd41f977dd868ca9b4f6270f05b0c10a673095;hp=ba8f9e93c2697e126786c7d16e9cd9e7bc3f339c;hb=14756542cf5e8f90662ea8bd922d1349f44228fe;hpb=273399de2e11da5cfea7b412a4bdd904467e9126 diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index ba8f9e9..56bd41f 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -38,7 +38,7 @@ #endif #define HASH_SIZE 32 -#define RAND_POOL 10000 +#define RAND_POOL 1000000 /* Make this big enough to include the POWER5+ L3 cacheline size of 256B */ #define CACHE_LINE_SIZE 4096 @@ -70,6 +70,12 @@ static inline pid_t gettid(void) #include #include +struct wr_count { + unsigned long update_ops; + unsigned long add; + unsigned long remove; +}; + static unsigned int __thread rand_lookup; static unsigned long __thread nr_add; static unsigned long __thread nr_addexist; @@ -381,8 +387,8 @@ void free_node_cb(struct rcu_head *head) void *thr_writer(void *_count) { - struct rcu_ht_node *node; - unsigned long long *count = _count; + struct rcu_ht_node *node, *ret_node; + struct wr_count *count = _count; int ret; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", @@ -404,9 +410,9 @@ void *thr_writer(void *_count) ht_node_init(node, (void *)(unsigned long)(rand_r(&rand_lookup) % RAND_POOL), sizeof(void *)); - ret = ht_add_unique(test_ht, node); + ret_node = ht_add_unique(test_ht, node); rcu_read_unlock(); - if (ret) { + if (ret_node != node) { free(node); nr_addexist++; } else @@ -454,7 +460,9 @@ void *thr_writer(void *_count) 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 = nr_writes; + count->update_ops = nr_writes; + count->add = nr_add; + count->remove = nr_del; return ((void*)2); } @@ -476,8 +484,11 @@ int main(int argc, char **argv) int err; pthread_t *tid_reader, *tid_writer; void *tret; - unsigned long long *count_reader, *count_writer; - unsigned long long tot_reads = 0, tot_writes = 0; + unsigned long long *count_reader; + struct wr_count *count_writer; + unsigned long long tot_reads = 0, tot_writes = 0, + tot_add = 0, tot_remove = 0; + unsigned long count, removed; int i, a, ret; if (argc < 4) { @@ -558,6 +569,10 @@ int main(int argc, char **argv) count_writer = malloc(sizeof(*count_writer) * nr_writers); test_ht = ht_new(test_hash, test_compare, 0x42UL, HASH_SIZE, call_rcu); + + err = create_all_cpu_call_rcu_data(0); + assert(!err); + next_aff = 0; for (i = 0; i < nr_readers; i++) { @@ -591,26 +606,27 @@ int main(int argc, char **argv) err = pthread_join(tid_writer[i], &tret); if (err != 0) exit(1); - tot_writes += count_writer[i]; + tot_writes += count_writer[i].update_ops; + tot_add += count_writer[i].add; + tot_remove += count_writer[i].remove; } - ret = ht_destroy(test_ht); - if (ret) { - unsigned long count, removed; - - ht_count_nodes(test_ht, &count, &removed); + ht_count_nodes(test_ht, &count, &removed); + if (count || removed) printf("WARNING: nodes left in the hash table upon destroy: " "%lu nodes + %lu logically removed.\n", count, removed); - } + (void) ht_destroy(test_ht); printf_verbose("final delete: %d items\n", ret); printf_verbose("total number of reads : %llu, writes %llu\n", tot_reads, tot_writes); printf("SUMMARY %-25s testdur %4lu nr_readers %3u rdur %6lu " "nr_writers %3u " - "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu\n", + "wdelay %6lu nr_reads %12llu nr_writes %12llu nr_ops %12llu " + "nr_add %12llu nr_remove %12llu nr_leaked %12llu\n", argv[0], duration, nr_readers, rduration, nr_writers, wdelay, tot_reads, tot_writes, - tot_reads + tot_writes); + tot_reads + tot_writes, tot_add, tot_remove, + tot_add - tot_remove - count); free(tid_reader); free(tid_writer); free(count_reader);