unsigned int nr_readers;
unsigned int nr_writers;
+static unsigned int add_ratio = 50;
+static uint64_t key_mul = 1ULL;
+
static pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
void set_affinity(void)
{
struct ja_test_node *node =
caa_container_of(head, struct ja_test_node, node.head);
- free(node);
+ poison_free(node);
}
#if 0
printf(" [-v] (verbose output)\n");
printf(" [-a cpu#] [-a cpu#]... (affinity)\n");
printf(" [not -u nor -s] Add entries (supports redundant keys).\n");
- printf(" [-i] Add only (no removal).\n");
- printf(" [-k nr_nodes] Number of nodes to insert initially.\n");
+ printf(" [-r ratio] Add ratio (in %% of add+removal).\n");
+ printf(" [-k] Populate init nodes.\n");
printf(" [-R offset] Lookup pool offset.\n");
printf(" [-S offset] Write pool offset.\n");
printf(" [-T offset] Init pool offset.\n");
printf(" [-V] Validate lookups of init values (use with filled init pool, same lookup range, with different write range).\n");
printf(" [-s] Do sanity test.\n");
printf(" [-B] Key bits for multithread test (default: 32).\n");
+ printf(" [-m factor] Key multiplication factor.\n");
printf("\n\n");
}
/* note: only looking up ulong keys */
key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % lookup_pool_size) + lookup_pool_offset;
+ key *= key_mul;
head = cds_ja_lookup(test_ja, key);
if (cds_hlist_empty(&head)) {
if (validate_lookup) {
return ((void*)1);
}
+static
+int is_add(void)
+{
+ return ((unsigned int) rand_r(&URCU_TLS(rand_lookup)) % 100) < add_ratio;
+}
+
static
void *test_ja_rw_thr_writer(void *_count)
{
cmm_smp_mb();
for (;;) {
- if ((addremove == AR_ADD || add_only)
- || (addremove == AR_RANDOM && rand_r(&URCU_TLS(rand_lookup)) & 1)) {
+ if ((addremove == AR_ADD)
+ || (addremove == AR_RANDOM && is_add())) {
struct ja_test_node *node = malloc(sizeof(*node));
+ struct cds_ja_node *ret_node;
/* note: only inserting ulong keys */
key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset;
+ key *= key_mul;
ja_test_node_init(node, key);
rcu_read_lock();
- ret = cds_ja_add(test_ja, key, &node->node);
- URCU_TLS(nr_add)++;
+ ret_node = cds_ja_add_unique(test_ja, key, &node->node);
rcu_read_unlock();
- if (ret) {
- fprintf(stderr, "Error (%d) adding node %" PRIu64 "\n",
- ret, key);
- assert(0);
+ if (ret_node != &node->node) {
+ free(node);
+ URCU_TLS(nr_addexist)++;
+ } else {
+ URCU_TLS(nr_add)++;
}
} else {
struct ja_test_node *node;
/* May delete */
/* note: only deleting ulong keys */
key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset;
+ key *= key_mul;
rcu_read_lock();
int do_mt_populate_ja(void)
{
struct cds_hlist_head head;
- uint64_t key;
+ uint64_t iter;
int ret;
if (!init_populate)
printf("Starting rw test\n");
- for (key = init_pool_offset; key < init_pool_offset + init_pool_size; key++) {
+ for (iter = init_pool_offset; iter < init_pool_offset + init_pool_size; iter++) {
struct ja_test_node *node = malloc(sizeof(*node));
+ uint64_t key;
/* note: only inserting ulong keys */
- key = (unsigned long) key;
+ key = (unsigned long) iter;
+ key *= key_mul;
ja_test_node_init(node, key);
rcu_read_lock();
ret = cds_ja_add(test_ja, key, &node->node);
tot_add_exist += count_writer[i].add_exist;
tot_remove += count_writer[i].remove;
}
+ rcu_thread_online_qsbr();
ret = cds_ja_destroy(test_ja, free_node_cb);
if (ret) {
fprintf(stderr, "Error destroying judy array\n");
goto end;
}
- rcu_thread_online_qsbr();
free(tid_reader);
free(tid_writer);
case 'v':
verbose_mode = 1;
break;
- case 'i':
- add_only = 1;
+ case 'r':
+ add_ratio = atoi(argv[++i]);
break;
case 'k':
- init_populate = atol(argv[++i]);
+ init_populate = 1;
break;
case 'R':
lookup_pool_offset = atol(argv[++i]);
case 'B':
key_bits = atol(argv[++i]);
break;
+ case 'm':
+ key_mul = atoll(argv[++i]);
+ break;
}
}
duration, nr_readers, nr_writers);
printf_verbose("Writer delay : %lu loops.\n", wdelay);
printf_verbose("Reader duration : %lu loops.\n", rduration);
- printf_verbose("Mode:%s.\n",
- add_only ? " add only" : " add/delete");
+ printf_verbose("Add ratio: %u%%.\n", add_ratio);
+ printf_verbose("Key multiplication factor: %" PRIu64 ".\n", key_mul);
printf_verbose("Init pool size offset %lu size %lu.\n",
init_pool_offset, init_pool_size);
printf_verbose("Lookup pool size offset %lu size %lu.\n",