From b10c8ba83ff83cc8bed4bd62832020f9572e0e92 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 26 Jun 2013 17:39:21 -0400 Subject: [PATCH] rcuja: fix randomness seed (per-thread), use u64 keyspace for random range Signed-off-by: Mathieu Desnoyers --- rcuja/rcuja-range.c | 2 +- tests/test_urcu_ja.c | 4 ++++ tests/test_urcu_ja.h | 22 +--------------------- tests/test_urcu_ja_range.c | 26 +++++++++++++++++++------- tests/test_urcu_ja_range.h | 22 +--------------------- 5 files changed, 26 insertions(+), 50 deletions(-) diff --git a/rcuja/rcuja-range.c b/rcuja/rcuja-range.c index 7e4585e..26a0c2e 100644 --- a/rcuja/rcuja-range.c +++ b/rcuja/rcuja-range.c @@ -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: diff --git a/tests/test_urcu_ja.c b/tests/test_urcu_ja.c index 8c7e727..22c336b 100644 --- a/tests/test_urcu_ja.c +++ b/tests/test_urcu_ja.c @@ -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(); diff --git a/tests/test_urcu_ja.h b/tests/test_urcu_ja.h index 873b493..1dab429 100644 --- a/tests/test_urcu_ja.h +++ b/tests/test_urcu_ja.h @@ -38,10 +38,7 @@ #include #include - -#ifdef __linux__ -#include -#endif +#include "thread-id.h" #define DEFAULT_RAND_POOL 1000000 @@ -61,23 +58,6 @@ #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 diff --git a/tests/test_urcu_ja_range.c b/tests/test_urcu_ja_range.c index 18f36d5..c10becd 100644 --- a/tests/test_urcu_ja_range.c +++ b/tests/test_urcu_ja_range.c @@ -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(); diff --git a/tests/test_urcu_ja_range.h b/tests/test_urcu_ja_range.h index e9bbdbc..1f8c2a2 100644 --- a/tests/test_urcu_ja_range.h +++ b/tests/test_urcu_ja_range.h @@ -38,10 +38,7 @@ #include #include - -#ifdef __linux__ -#include -#endif +#include "thread-id.h" #define DEFAULT_RAND_POOL 1000000 @@ -61,23 +58,6 @@ #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 -- 2.34.1