rcuja: Use urcu_get_thread_id()
[userspace-rcu.git] / tests / test_urcu_ja_range.c
index 3d231456aab4b7f4d51937118d35744bdaf31d3a..93ac706c40e7d1b6544d04588f6404471e02a734 100644 (file)
@@ -71,7 +71,7 @@ DEFINE_URCU_TLS(unsigned long long, nr_reads);
 unsigned int nr_readers;
 unsigned int nr_writers;
 
-static unsigned int add_ratio = 50;
+static unsigned int add_ratio = 50, range_max_len = 0;
 static uint64_t key_mul = 1ULL;
 
 static int add_unique, add_replace;
@@ -159,6 +159,7 @@ printf("        [not -u nor -s] Add entries (supports redundant keys).\n");
        printf("        [-B] Key bits for multithread test (default: 32).\n");
        printf("        [-m factor] Key multiplication factor.\n");
        printf("        [-l] Memory leak detection.\n");
+       printf("        [-L len] Range max len.\n");
        printf("\n\n");
 }
 
@@ -196,8 +197,10 @@ void *test_ja_rw_thr_reader(void *_count)
        struct cds_ja_range *range;
        uint64_t key;
 
-       printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
-                       "reader", pthread_self(), (unsigned long) gettid());
+       printf_verbose("thread_begin %s, tid %lu\n",
+                       "reader", urcu_get_thread_id());
+
+       URCU_TLS(rand_lookup) = (unsigned int) urcu_get_thread_id() ^ time(NULL);
 
        set_affinity();
 
@@ -211,9 +214,11 @@ void *test_ja_rw_thr_reader(void *_count)
        for (;;) {
                rcu_read_lock();
 
-               /* note: only looking up ulong keys */
-               key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % lookup_pool_size) + lookup_pool_offset;
+               key = (uint64_t) rand_r(&URCU_TLS(rand_lookup));
+               key += (uint64_t) rand_r(&URCU_TLS(rand_lookup)) << 32ULL;
+               key = (key % lookup_pool_size) + lookup_pool_offset;
                key *= key_mul;
+
                range = cds_ja_range_lookup(test_ja, key);
                if (!range) {
                        if (validate_lookup) {
@@ -247,10 +252,10 @@ void *test_ja_rw_thr_reader(void *_count)
        rcu_unregister_thread();
 
        *count = URCU_TLS(nr_reads);
-       printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
-                       "reader", pthread_self(), (unsigned long) gettid());
-       printf_verbose("readid : %lx, lookupfail %lu, lookupok %lu\n",
-                       pthread_self(), URCU_TLS(lookup_fail),
+       printf_verbose("thread_end %s, tid %lu\n",
+                       "reader", urcu_get_thread_id());
+       printf_verbose("read tid : %lu, lookupfail %lu, lookupok %lu\n",
+                       urcu_get_thread_id(), URCU_TLS(lookup_fail),
                        URCU_TLS(lookup_ok));
        return ((void*)1);
 }
@@ -267,8 +272,10 @@ void *test_ja_rw_thr_writer(void *_count)
        struct wr_count *count = _count;
        int ret;
 
-       printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
-                       "writer", pthread_self(), (unsigned long) gettid());
+       printf_verbose("thread_begin %s, tid %lu\n",
+                       "writer", urcu_get_thread_id());
+
+       URCU_TLS(rand_lookup) = (unsigned int) urcu_get_thread_id() ^ time(NULL);
 
        set_affinity();
 
@@ -285,9 +292,14 @@ void *test_ja_rw_thr_writer(void *_count)
                        struct cds_ja_range *range;
                        uint64_t start, end, tmp;
 
-                       /* note: only inserting ulong keys */
-                       start = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset;
-                       end = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset;
+                       start = (uint64_t) rand_r(&URCU_TLS(rand_lookup));
+                       start += (uint64_t) rand_r(&URCU_TLS(rand_lookup)) << 32ULL;
+                       start = (start % write_pool_size) + write_pool_offset;
+
+                       end = (uint64_t) rand_r(&URCU_TLS(rand_lookup));
+                       end += (uint64_t) rand_r(&URCU_TLS(rand_lookup)) << 32ULL;
+                       end = (end % write_pool_size) + write_pool_offset;
+
                        start *= key_mul;
                        end *= key_mul;
                        if (start > end) {
@@ -295,10 +307,17 @@ void *test_ja_rw_thr_writer(void *_count)
                                start = end;
                                end = tmp;
                        }
+                       if (end - start > range_max_len) {
+                               end = start + range_max_len;
+                       }
                        rcu_read_lock();
-                       range = cds_ja_range_add(test_ja, start, end, NULL);
-                       if (!range) {
-                               fprintf(stderr, "Error in cds_ja_add: %d\n", ret);
+                       ret = cds_ja_range_add(test_ja, start, end, NULL);
+                       if (ret) {
+                               if (ret == -EEXIST) {
+                                       URCU_TLS(nr_addexist)++;
+                               } else {
+                                       assert(0);
+                               }
                        } else {
                                URCU_TLS(nr_add)++;
                        }
@@ -308,8 +327,9 @@ void *test_ja_rw_thr_writer(void *_count)
                        uint64_t key;
 
                        /* May delete */
-                       /* note: only deleting ulong keys */
-                       key = ((unsigned long) rand_r(&URCU_TLS(rand_lookup)) % write_pool_size) + write_pool_offset;
+                       key = (uint64_t) rand_r(&URCU_TLS(rand_lookup));
+                       key += (uint64_t) rand_r(&URCU_TLS(rand_lookup)) << 32ULL;
+                       key = (key % write_pool_size) + write_pool_offset;
                        key *= key_mul;
 
                        rcu_read_lock();
@@ -339,10 +359,11 @@ void *test_ja_rw_thr_writer(void *_count)
 
        rcu_unregister_thread();
 
-       printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
-                       "writer", pthread_self(), (unsigned long) gettid());
-       printf_verbose("info id %lx: nr_add %lu, nr_addexist %lu, nr_del %lu, "
-                       "nr_delnoent %lu\n", pthread_self(), URCU_TLS(nr_add),
+       printf_verbose("thread_end %s, tid %lu\n",
+                       "writer", urcu_get_thread_id());
+       printf_verbose("info tid %lu: nr_add %lu, nr_addexist %lu, nr_del %lu, "
+                       "nr_delnoent %lu\n", urcu_get_thread_id(),
+                       URCU_TLS(nr_add),
                        URCU_TLS(nr_addexist), URCU_TLS(nr_del),
                        URCU_TLS(nr_delnoent));
        count->update_ops = URCU_TLS(nr_writes);
@@ -371,13 +392,16 @@ int do_mt_populate_ja(void)
                key = (unsigned long) iter;
                key *= key_mul;
                rcu_read_lock();
-               range = cds_ja_range_add(test_ja, key, key, NULL);
+               ret = cds_ja_range_add(test_ja, key, key, NULL);
                URCU_TLS(nr_add)++;
                URCU_TLS(nr_writes)++;
                rcu_read_unlock();
-               if (!range) {
-                       fprintf(stderr, "Error adding range %" PRIu64 "\n",
-                               key);
+               /* Hash table resize only occurs in call_rcu thread */
+               if (!(iter % 100))
+                       rcu_quiescent_state();
+               if (ret) {
+                       fprintf(stderr, "Error (%d) adding range %" PRIu64 "\n",
+                               ret, key);
                        assert(0);
                }
        }
@@ -401,8 +425,9 @@ int do_mt_test(void)
        count_reader = malloc(sizeof(*count_reader) * nr_readers);
        count_writer = malloc(sizeof(*count_writer) * nr_writers);
 
-       printf("Allocating Judy Array for ranges\n");
-       test_ja = cds_ja_range_new();
+       printf("Allocating %u-bit Judy Array for ranges\n",
+               key_bits);
+       test_ja = cds_ja_range_new(key_bits);
        if (!test_ja) {
                printf("Error allocating judy array.\n");
                ret = -1;
@@ -458,6 +483,9 @@ int do_mt_test(void)
        }
        rcu_thread_online_qsbr();
 
+       ret = cds_ja_range_validate(test_ja);
+       assert(!ret);
+
        ret = cds_ja_range_destroy(test_ja, NULL);
        if (ret) {
                fprintf(stderr, "Error destroying judy array\n");
@@ -586,6 +614,9 @@ int main(int argc, char **argv)
                case 'l':
                        leak_detection = 1;
                        break;
+               case 'L':
+                       range_max_len = atol(argv[++i]);
+                       break;
                }
        }
 
@@ -604,12 +635,14 @@ 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("Range max len: %lu.\n",
+               range_max_len);
        if (validate_lookup)
                printf_verbose("Validating lookups.\n");
        if (leak_detection)
                printf_verbose("Memory leak dection activated.\n");
-       printf_verbose("thread %-6s, thread id : %lx, tid %lu\n",
-                       "main", pthread_self(), (unsigned long)gettid());
+       printf_verbose("thread %-6s, tid %lu\n",
+                       "main", urcu_get_thread_id());
 
        memset(&act, 0, sizeof(act));
        ret = sigemptyset(&act.sa_mask);
This page took 0.027555 seconds and 4 git commands to generate.