enum test_hash {
TEST_HASH_RW,
+ TEST_HASH_UNIQUE,
};
struct test_hash_cb {
test_hash_rw_thr_writer,
test_hash_rw_populate_hash,
},
+ [TEST_HASH_UNIQUE] = {
+ test_hash_unique_sigusr1_handler,
+ test_hash_unique_sigusr2_handler,
+ test_hash_unique_thr_reader,
+ test_hash_unique_thr_writer,
+ test_hash_unique_populate_hash,
+ },
+
};
static enum test_hash test_choice = TEST_HASH_RW;
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_GLOBAL(unsigned int, rand_lookup);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, nr_add);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, nr_addexist);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, nr_del);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, nr_delnoent);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, lookup_fail);
+__DEFINE_URCU_TLS_GLOBAL(unsigned long, lookup_ok);
struct cds_lfht *test_ht;
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];
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;
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();
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(" [-U] Uniqueness test.\n");
+ printf(" [-C] Number of hash chains.\n");
printf("\n\n");
}
case 'V':
validate_lookup = 1;
break;
-
+ case 'U':
+ test_choice = TEST_HASH_UNIQUE;
+ break;
+ case 'C':
+ nr_hash_chains = atol(argv[++i]);
+ break;
}
}
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);
- count_reader = malloc(sizeof(*count_reader) * nr_readers);
- count_writer = malloc(sizeof(*count_writer) * nr_writers);
+ tid_reader = calloc(nr_readers, sizeof(*tid_reader));
+ tid_writer = calloc(nr_writers, sizeof(*tid_writer));
+ count_reader = calloc(nr_readers, sizeof(*count_reader));
+ count_writer = calloc(nr_writers, sizeof(*count_writer));
err = create_all_cpu_call_rcu_data(0);
if (err) {
(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