rcuja: fix randomness seed (per-thread), use u64 keyspace for random range
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 26 Jun 2013 21:39:21 +0000 (17:39 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 26 Jun 2013 21:39:21 +0000 (17:39 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rcuja/rcuja-range.c
tests/test_urcu_ja.c
tests/test_urcu_ja.h
tests/test_urcu_ja_range.c
tests/test_urcu_ja_range.h

index 7e4585ef942d76f1811f3c958fff3138ac120ca3..26a0c2e97b50e8d58987913772c25d93a29cfc1e 100644 (file)
@@ -276,7 +276,7 @@ int cds_ja_range_add(struct cds_ja *ja,
        unsigned int nr_ranges, i;
        int ret;
 
-       if (start > end || end == UINT64_MAX)
+       if (start > end || end == UINT64_MAX || end > ja->key_max)
                return -EINVAL;
 
 retry:
index 8c7e7277019edfe33570e5e9df897eebbeff5f68..22c336bd77a704cec5c9058d686ed93441dc5f06 100644 (file)
@@ -853,6 +853,8 @@ void *test_ja_rw_thr_reader(void *_count)
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "reader", pthread_self(), (unsigned long) gettid());
 
+       URCU_TLS(rand_lookup) = urcu_get_thread_id() ^ time(NULL);
+
        set_affinity();
 
        rcu_register_thread();
@@ -916,6 +918,8 @@ void *test_ja_rw_thr_writer(void *_count)
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long) gettid());
 
+       URCU_TLS(rand_lookup) = urcu_get_thread_id() ^ time(NULL);
+
        set_affinity();
 
        rcu_register_thread();
index 873b493bc0c0739347f05167b42104259a5a914a..1dab42910e06c345152e9d966913bec23b7c4d49 100644 (file)
 #include <signal.h>
 
 #include <urcu/tls-compat.h>
-
-#ifdef __linux__
-#include <syscall.h>
-#endif
+#include "thread-id.h"
 
 #define DEFAULT_RAND_POOL      1000000
 
 #define poison_free(ptr)       free(ptr)
 #endif
 
-
-
-#if defined(_syscall0)
-_syscall0(pid_t, gettid)
-#elif defined(__NR_gettid)
-static inline pid_t gettid(void)
-{
-       return syscall(__NR_gettid);
-}
-#else
-#warning "use pid as tid"
-static inline pid_t gettid(void)
-{
-       return getpid();
-}
-#endif
-
 #ifndef DYNAMIC_LINK_TEST
 #define _LGPL_SOURCE
 #else
index 18f36d5f4d9826993b8480c5294dcc17b7651c06..c10becdebcf07297c6fb52e28367b4fee64902ef 100644 (file)
@@ -200,6 +200,8 @@ void *test_ja_rw_thr_reader(void *_count)
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "reader", pthread_self(), (unsigned long) gettid());
 
+       URCU_TLS(rand_lookup) = (unsigned int) gettid() ^ time(NULL);
+
        set_affinity();
 
        rcu_register_thread();
@@ -212,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) {
@@ -271,6 +275,8 @@ void *test_ja_rw_thr_writer(void *_count)
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "writer", pthread_self(), (unsigned long) gettid());
 
+       URCU_TLS(rand_lookup) = (unsigned int) gettid() ^ time(NULL);
+
        set_affinity();
 
        rcu_register_thread();
@@ -286,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) {
@@ -316,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();
index e9bbdbc3ed7eb8f57e30c26b8789ba609a6bfdd9..1f8c2a2f046d48a5aea3ece45cec14412e53f2f0 100644 (file)
 #include <signal.h>
 
 #include <urcu/tls-compat.h>
-
-#ifdef __linux__
-#include <syscall.h>
-#endif
+#include "thread-id.h"
 
 #define DEFAULT_RAND_POOL      1000000
 
 #define poison_free(ptr)       free(ptr)
 #endif
 
-
-
-#if defined(_syscall0)
-_syscall0(pid_t, gettid)
-#elif defined(__NR_gettid)
-static inline pid_t gettid(void)
-{
-       return syscall(__NR_gettid);
-}
-#else
-#warning "use pid as tid"
-static inline pid_t gettid(void)
-{
-       return getpid();
-}
-#endif
-
 #ifndef DYNAMIC_LINK_TEST
 #define _LGPL_SOURCE
 #else
This page took 0.028548 seconds and 4 git commands to generate.