X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=tests%2Ftest_urcu_hash.c;h=a2b5b7bca656902dc11b3d3e3d2902a8235df0c0;hb=2d72fae24ceebe2efa486b5bad421f39917ec0a6;hp=3c7cc350d4d02ef7a200893ec2843d2349e1024c;hpb=20adf7802bcec449566b9cbb900504fd409f62db;p=userspace-rcu.git diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c index 3c7cc35..a2b5b7b 100644 --- a/tests/test_urcu_hash.c +++ b/tests/test_urcu_hash.c @@ -82,13 +82,13 @@ int (*get_populate_hash_cb(void))(void) return test_hash_cb[test_choice].populate_hash; } -unsigned int __thread rand_lookup; -unsigned long __thread nr_add; -unsigned long __thread nr_addexist; -unsigned long __thread nr_del; -unsigned long __thread nr_delnoent; -unsigned long __thread lookup_fail; -unsigned long __thread lookup_ok; +DEFINE_URCU_TLS(unsigned int, rand_lookup); +DEFINE_URCU_TLS(unsigned long, nr_add); +DEFINE_URCU_TLS(unsigned long, nr_addexist); +DEFINE_URCU_TLS(unsigned long, nr_del); +DEFINE_URCU_TLS(unsigned long, nr_delnoent); +DEFINE_URCU_TLS(unsigned long, lookup_fail); +DEFINE_URCU_TLS(unsigned long, lookup_ok); struct cds_lfht *test_ht; @@ -114,6 +114,7 @@ unsigned long init_pool_size = DEFAULT_RAND_POOL, lookup_pool_size = DEFAULT_RAND_POOL, write_pool_size = DEFAULT_RAND_POOL; int validate_lookup; +unsigned long nr_hash_chains; /* 0: normal table, other: number of hash chains */ int count_pipe[2]; @@ -125,8 +126,8 @@ int use_affinity = 0; pthread_mutex_t affinity_mutex = PTHREAD_MUTEX_INITIALIZER; -unsigned long long __thread nr_writes; -unsigned long long __thread nr_reads; +DEFINE_URCU_TLS(unsigned long long, nr_writes); +DEFINE_URCU_TLS(unsigned long long, nr_reads); unsigned int nr_readers; unsigned int nr_writers; @@ -200,7 +201,8 @@ unsigned long test_compare(const void *key1, size_t key1_len, void *thr_count(void *arg) { printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", - "counter", pthread_self(), (unsigned long)gettid()); + "counter", (unsigned long) pthread_self(), + (unsigned long) gettid()); rcu_register_thread(); @@ -290,6 +292,7 @@ printf(" [not -u nor -s] Add entries (supports redundant keys).\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(" [-U] Uniqueness test.\n"); + printf(" [-C] Number of hash chains.\n"); printf("\n\n"); } @@ -456,6 +459,9 @@ int main(int argc, char **argv) case 'U': test_choice = TEST_HASH_UNIQUE; break; + case 'C': + nr_hash_chains = atol(argv[++i]); + break; } } @@ -528,8 +534,11 @@ int main(int argc, char **argv) lookup_pool_offset, lookup_pool_size); printf_verbose("Update pool size offset %lu size %lu.\n", write_pool_offset, write_pool_size); + printf_verbose("Number of hash chains: %lu.\n", + nr_hash_chains); printf_verbose("thread %-6s, thread id : %lx, tid %lu\n", - "main", pthread_self(), (unsigned long)gettid()); + "main", (unsigned long) pthread_self(), + (unsigned long) gettid()); tid_reader = malloc(sizeof(*tid_reader) * nr_readers); tid_writer = malloc(sizeof(*tid_writer) * nr_writers); @@ -553,6 +562,10 @@ int main(int argc, char **argv) (opt_auto_resize ? CDS_LFHT_AUTO_RESIZE : 0) | CDS_LFHT_ACCOUNTING, NULL); } + if (!test_ht) { + printf("Error allocating hash table.\n"); + return -1; + } /* * Hash Population needs to be seen as a RCU reader