From 9e4e7ad18c86159520b330fab94b93f7ab6d221c Mon Sep 17 00:00:00 2001 From: Olivier Dion Date: Fri, 31 Mar 2023 10:53:43 -0400 Subject: [PATCH] benchmark: Use uatomic for accessing global states Global states accesses were protected via memory barriers. Use the uatomic API with the CMM memory model so that TSAN can understand the ordering imposed by the synchronization flags. Change-Id: I1bf5702c5ac470f308c478effe39e424a3158060 Co-authored-by: Mathieu Desnoyers Signed-off-by: Olivier Dion Signed-off-by: Mathieu Desnoyers --- tests/benchmark/Makefile.am | 91 +++++++++++++------------ tests/benchmark/common-states.c | 1 + tests/benchmark/common-states.h | 51 ++++++++++++++ tests/benchmark/test_mutex.c | 32 +-------- tests/benchmark/test_perthreadlock.c | 32 +-------- tests/benchmark/test_rwlock.c | 32 +-------- tests/benchmark/test_urcu.c | 33 +-------- tests/benchmark/test_urcu_assign.c | 33 +-------- tests/benchmark/test_urcu_bp.c | 33 +-------- tests/benchmark/test_urcu_defer.c | 33 +-------- tests/benchmark/test_urcu_gc.c | 34 ++------- tests/benchmark/test_urcu_hash.c | 6 +- tests/benchmark/test_urcu_hash.h | 15 ---- tests/benchmark/test_urcu_hash_rw.c | 10 +-- tests/benchmark/test_urcu_hash_unique.c | 10 +-- tests/benchmark/test_urcu_lfq.c | 20 ++---- tests/benchmark/test_urcu_lfs.c | 20 ++---- tests/benchmark/test_urcu_lfs_rcu.c | 20 ++---- tests/benchmark/test_urcu_qsbr.c | 33 +-------- tests/benchmark/test_urcu_qsbr_gc.c | 34 ++------- tests/benchmark/test_urcu_wfcq.c | 22 +++--- tests/benchmark/test_urcu_wfq.c | 20 ++---- tests/benchmark/test_urcu_wfs.c | 22 +++--- 23 files changed, 177 insertions(+), 460 deletions(-) create mode 100644 tests/benchmark/common-states.c create mode 100644 tests/benchmark/common-states.h diff --git a/tests/benchmark/Makefile.am b/tests/benchmark/Makefile.am index 382939b..9700092 100644 --- a/tests/benchmark/Makefile.am +++ b/tests/benchmark/Makefile.am @@ -3,6 +3,7 @@ # SPDX-License-Identifier: MIT AM_CPPFLAGS += -I$(top_srcdir)/src -I$(top_srcdir)/tests/common +AM_CPPFLAGS += -include $(top_srcdir)/tests/benchmark/common-states.h TEST_EXTENSIONS = .tap TAP_LOG_DRIVER_FLAGS = --merge --comments @@ -11,6 +12,8 @@ TAP_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' \ URCU_TESTS_BUILDDIR='$(abs_top_builddir)/tests' \ $(SHELL) $(top_srcdir)/tests/utils/tap-driver.sh +noinst_HEADERS = common-states.h + SCRIPT_LIST = \ runpaul-phase1.sh \ runpaul-phase2.sh \ @@ -65,163 +68,163 @@ URCU_CDS_LIB=$(top_builddir)/src/liburcu-cds.la DEBUG_YIELD_LIB=$(builddir)/../common/libdebug-yield.la -test_urcu_SOURCES = test_urcu.c +test_urcu_SOURCES = test_urcu.c common-states.c test_urcu_LDADD = $(URCU_LIB) -test_urcu_dynamic_link_SOURCES = test_urcu.c +test_urcu_dynamic_link_SOURCES = test_urcu.c common-states.c test_urcu_dynamic_link_LDADD = $(URCU_LIB) test_urcu_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) -test_urcu_timing_SOURCES = test_urcu_timing.c +test_urcu_timing_SOURCES = test_urcu_timing.c common-states.c test_urcu_timing_LDADD = $(URCU_LIB) -test_urcu_yield_SOURCES = test_urcu.c +test_urcu_yield_SOURCES = test_urcu.c common-states.c test_urcu_yield_LDADD = $(URCU_LIB) $(DEBUG_YIELD_LIB) test_urcu_yield_CFLAGS = -DDEBUG_YIELD $(AM_CFLAGS) -test_urcu_qsbr_SOURCES = test_urcu_qsbr.c +test_urcu_qsbr_SOURCES = test_urcu_qsbr.c common-states.c test_urcu_qsbr_LDADD = $(URCU_QSBR_LIB) -test_urcu_qsbr_timing_SOURCES = test_urcu_qsbr_timing.c +test_urcu_qsbr_timing_SOURCES = test_urcu_qsbr_timing.c common-states.c test_urcu_qsbr_timing_LDADD = $(URCU_QSBR_LIB) -test_urcu_mb_SOURCES = test_urcu.c +test_urcu_mb_SOURCES = test_urcu.c common-states.c test_urcu_mb_LDADD = $(URCU_MB_LIB) test_urcu_mb_CFLAGS = -DRCU_MB $(AM_CFLAGS) -test_urcu_signal_SOURCES = test_urcu.c +test_urcu_signal_SOURCES = test_urcu.c common-states.c test_urcu_signal_LDADD = $(URCU_SIGNAL_LIB) test_urcu_signal_CFLAGS = -DRCU_SIGNAL $(AM_CFLAGS) -test_urcu_signal_dynamic_link_SOURCES = test_urcu.c +test_urcu_signal_dynamic_link_SOURCES = test_urcu.c common-states.c test_urcu_signal_dynamic_link_LDADD = $(URCU_SIGNAL_LIB) test_urcu_signal_dynamic_link_CFLAGS = -DRCU_SIGNAL -DDYNAMIC_LINK_TEST \ $(AM_CFLAGS) -test_urcu_signal_timing_SOURCES = test_urcu_timing.c +test_urcu_signal_timing_SOURCES = test_urcu_timing.c common-states.c test_urcu_signal_timing_LDADD = $(URCU_SIGNAL_LIB) test_urcu_signal_timing_CFLAGS= -DRCU_SIGNAL $(AM_CFLAGS) -test_urcu_signal_yield_SOURCES = test_urcu.c +test_urcu_signal_yield_SOURCES = test_urcu.c common-states.c test_urcu_signal_yield_LDADD = $(URCU_SIGNAL_LIB) $(DEBUG_YIELD_LIB) test_urcu_signal_yield_CFLAGS = -DRCU_SIGNAL -DDEBUG_YIELD $(AM_CFLAGS) -test_rwlock_timing_SOURCES = test_rwlock_timing.c +test_rwlock_timing_SOURCES = test_rwlock_timing.c common-states.c test_rwlock_timing_LDADD = $(URCU_SIGNAL_LIB) -test_rwlock_SOURCES = test_rwlock.c +test_rwlock_SOURCES = test_rwlock.c common-states.c test_rwlock_LDADD = $(URCU_SIGNAL_LIB) -test_perthreadlock_timing_SOURCES = test_perthreadlock_timing.c +test_perthreadlock_timing_SOURCES = test_perthreadlock_timing.c common-states.c test_perthreadlock_timing_LDADD = $(URCU_SIGNAL_LIB) -test_perthreadlock_SOURCES = test_perthreadlock.c +test_perthreadlock_SOURCES = test_perthreadlock.c common-states.c test_perthreadlock_LDADD = $(URCU_SIGNAL_LIB) -test_mutex_SOURCES = test_mutex.c +test_mutex_SOURCES = test_mutex.c common-states.c -test_looplen_SOURCES = test_looplen.c +test_looplen_SOURCES = test_looplen.c common-states.c -test_urcu_gc_SOURCES = test_urcu_gc.c +test_urcu_gc_SOURCES = test_urcu_gc.c common-states.c test_urcu_gc_LDADD = $(URCU_LIB) -test_urcu_signal_gc_SOURCES = test_urcu_gc.c +test_urcu_signal_gc_SOURCES = test_urcu_gc.c common-states.c test_urcu_signal_gc_LDADD = $(URCU_SIGNAL_LIB) test_urcu_signal_gc_CFLAGS = -DRCU_SIGNAL $(AM_CFLAGS) -test_urcu_mb_gc_SOURCES = test_urcu_gc.c +test_urcu_mb_gc_SOURCES = test_urcu_gc.c common-states.c test_urcu_mb_gc_LDADD = $(URCU_MB_LIB) test_urcu_mb_gc_CFLAGS = -DRCU_MB $(AM_CFLAGS) -test_urcu_qsbr_gc_SOURCES = test_urcu_qsbr_gc.c +test_urcu_qsbr_gc_SOURCES = test_urcu_qsbr_gc.c common-states.c test_urcu_qsbr_gc_LDADD = $(URCU_QSBR_LIB) -test_urcu_qsbr_lgc_SOURCES = test_urcu_qsbr_gc.c +test_urcu_qsbr_lgc_SOURCES = test_urcu_qsbr_gc.c common-states.c test_urcu_qsbr_lgc_LDADD = $(URCU_QSBR_LIB) test_urcu_qsbr_lgc_CFLAGS = -DTEST_LOCAL_GC $(AM_CFLAGS) -test_urcu_lgc_SOURCES = test_urcu_gc.c +test_urcu_lgc_SOURCES = test_urcu_gc.c common-states.c test_urcu_lgc_LDADD = $(URCU_LIB) test_urcu_lgc_CFLAGS = -DTEST_LOCAL_GC $(AM_CFLAGS) -test_urcu_signal_lgc_SOURCES = test_urcu_gc.c +test_urcu_signal_lgc_SOURCES = test_urcu_gc.c common-states.c test_urcu_signal_lgc_LDADD = $(URCU_SIGNAL_LIB) test_urcu_signal_lgc_CFLAGS = -DRCU_SIGNAL -DTEST_LOCAL_GC $(AM_CFLAGS) -test_urcu_mb_lgc_SOURCES = test_urcu_gc.c +test_urcu_mb_lgc_SOURCES = test_urcu_gc.c common-states.c test_urcu_mb_lgc_LDADD = $(URCU_MB_LIB) test_urcu_mb_lgc_CFLAGS = -DTEST_LOCAL_GC -DRCU_MB $(AM_CFLAGS) -test_urcu_qsbr_dynamic_link_SOURCES = test_urcu_qsbr.c +test_urcu_qsbr_dynamic_link_SOURCES = test_urcu_qsbr.c common-states.c test_urcu_qsbr_dynamic_link_LDADD = $(URCU_QSBR_LIB) test_urcu_qsbr_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) -test_urcu_defer_SOURCES = test_urcu_defer.c +test_urcu_defer_SOURCES = test_urcu_defer.c common-states.c test_urcu_defer_LDADD = $(URCU_LIB) test_cycles_per_loop_SOURCES = test_cycles_per_loop.c -test_urcu_assign_SOURCES = test_urcu_assign.c +test_urcu_assign_SOURCES = test_urcu_assign.c common-states.c test_urcu_assign_LDADD = $(URCU_LIB) -test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c +test_urcu_assign_dynamic_link_SOURCES = test_urcu_assign.c common-states.c test_urcu_assign_dynamic_link_LDADD = $(URCU_LIB) test_urcu_assign_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) -test_urcu_bp_SOURCES = test_urcu_bp.c +test_urcu_bp_SOURCES = test_urcu_bp.c common-states.c test_urcu_bp_LDADD = $(URCU_BP_LIB) -test_urcu_bp_dynamic_link_SOURCES = test_urcu_bp.c +test_urcu_bp_dynamic_link_SOURCES = test_urcu_bp.c common-states.c test_urcu_bp_dynamic_link_LDADD = $(URCU_BP_LIB) test_urcu_bp_dynamic_link_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) -test_urcu_lfq_SOURCES = test_urcu_lfq.c +test_urcu_lfq_SOURCES = test_urcu_lfq.c common-states.c test_urcu_lfq_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_lfq_dynlink_SOURCES = test_urcu_lfq.c +test_urcu_lfq_dynlink_SOURCES = test_urcu_lfq.c common-states.c test_urcu_lfq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_lfq_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_wfq_SOURCES = test_urcu_wfq.c +test_urcu_wfq_SOURCES = test_urcu_wfq.c common-states.c test_urcu_wfq_LDADD = $(URCU_COMMON_LIB) -test_urcu_wfq_dynlink_SOURCES = test_urcu_wfq.c +test_urcu_wfq_dynlink_SOURCES = test_urcu_wfq.c common-states.c test_urcu_wfq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_wfq_dynlink_LDADD = $(URCU_COMMON_LIB) -test_urcu_wfcq_SOURCES = test_urcu_wfcq.c +test_urcu_wfcq_SOURCES = test_urcu_wfcq.c common-states.c test_urcu_wfcq_LDADD = $(URCU_COMMON_LIB) -test_urcu_wfcq_dynlink_SOURCES = test_urcu_wfcq.c +test_urcu_wfcq_dynlink_SOURCES = test_urcu_wfcq.c common-states.c test_urcu_wfcq_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_wfcq_dynlink_LDADD = $(URCU_COMMON_LIB) -test_urcu_lfs_SOURCES = test_urcu_lfs.c +test_urcu_lfs_SOURCES = test_urcu_lfs.c common-states.c test_urcu_lfs_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_lfs_rcu_SOURCES = test_urcu_lfs_rcu.c +test_urcu_lfs_rcu_SOURCES = test_urcu_lfs_rcu.c common-states.c test_urcu_lfs_rcu_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c +test_urcu_lfs_dynlink_SOURCES = test_urcu_lfs.c common-states.c test_urcu_lfs_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_lfs_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_lfs_rcu_dynlink_SOURCES = test_urcu_lfs_rcu.c +test_urcu_lfs_rcu_dynlink_SOURCES = test_urcu_lfs_rcu.c common-states.c test_urcu_lfs_rcu_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_lfs_rcu_dynlink_LDADD = $(URCU_LIB) $(URCU_CDS_LIB) -test_urcu_wfs_SOURCES = test_urcu_wfs.c +test_urcu_wfs_SOURCES = test_urcu_wfs.c common-states.c test_urcu_wfs_LDADD = $(URCU_COMMON_LIB) -test_urcu_wfs_dynlink_SOURCES = test_urcu_wfs.c +test_urcu_wfs_dynlink_SOURCES = test_urcu_wfs.c common-states.c test_urcu_wfs_dynlink_CFLAGS = -DDYNAMIC_LINK_TEST $(AM_CFLAGS) test_urcu_wfs_dynlink_LDADD = $(URCU_COMMON_LIB) test_urcu_hash_SOURCES = test_urcu_hash.c test_urcu_hash.h \ - test_urcu_hash_rw.c test_urcu_hash_unique.c + test_urcu_hash_rw.c test_urcu_hash_unique.c common-states.c test_urcu_hash_CFLAGS = -DRCU_QSBR $(AM_CFLAGS) test_urcu_hash_LDADD = $(URCU_QSBR_LIB) $(URCU_COMMON_LIB) $(URCU_CDS_LIB) diff --git a/tests/benchmark/common-states.c b/tests/benchmark/common-states.c new file mode 100644 index 0000000..6e70351 --- /dev/null +++ b/tests/benchmark/common-states.c @@ -0,0 +1 @@ +volatile int _test_go = 0, _test_stop = 0; diff --git a/tests/benchmark/common-states.h b/tests/benchmark/common-states.h new file mode 100644 index 0000000..dfbbfe5 --- /dev/null +++ b/tests/benchmark/common-states.h @@ -0,0 +1,51 @@ +/* Common states for benchmarks. */ + +#include + +#include + +extern volatile int _test_go, _test_stop; + +static inline void complete_sleep(unsigned int seconds) +{ + while (seconds != 0) { + seconds = sleep(seconds); + } +} + +static inline void begin_test(void) +{ + uatomic_store(&_test_go, 1, CMM_RELEASE); +} + +static inline void end_test(void) +{ + uatomic_store(&_test_stop, 1, CMM_RELAXED); +} + +static inline void test_for(unsigned int duration) +{ + begin_test(); + complete_sleep(duration); + end_test(); +} + +static inline void wait_until_go(void) +{ + while (!uatomic_load(&_test_go, CMM_ACQUIRE)) + { + } +} + +/* + * returns 0 if test should end. + */ +static inline int test_duration_write(void) +{ + return !uatomic_load(&_test_stop, CMM_RELAXED); +} + +static inline int test_duration_read(void) +{ + return !uatomic_load(&_test_stop, CMM_RELAXED); +} diff --git a/tests/benchmark/test_mutex.c b/tests/benchmark/test_mutex.c index bbad448..6254e15 100644 --- a/tests/benchmark/test_mutex.c +++ b/tests/benchmark/test_mutex.c @@ -35,8 +35,6 @@ struct test_array { static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -static volatile int test_go, test_stop; - static unsigned long wdelay; static volatile struct test_array test_array = { 8 }; @@ -97,19 +95,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -133,9 +118,7 @@ void *thr_reader(void *data) set_affinity(); - while (!test_go) - { - } + wait_until_go(); for (;;) { int v; @@ -168,10 +151,7 @@ void *thr_writer(void *data) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { pthread_mutex_lock(&lock); @@ -311,13 +291,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_perthreadlock.c b/tests/benchmark/test_perthreadlock.c index bc7652f..2cc50d1 100644 --- a/tests/benchmark/test_perthreadlock.c +++ b/tests/benchmark/test_perthreadlock.c @@ -39,8 +39,6 @@ struct per_thread_lock { static struct per_thread_lock *per_thread_lock; -static volatile int test_go, test_stop; - static unsigned long wdelay; static volatile struct test_array test_array = { 8 }; @@ -103,19 +101,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -161,9 +146,7 @@ void *thr_reader(void *data) set_affinity(); - while (!test_go) - { - } + wait_until_go(); for (;;) { int v; @@ -197,10 +180,7 @@ void *thr_writer(void *data) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { for (tidx = 0; tidx < (long)nr_readers; tidx++) { @@ -345,13 +325,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_rwlock.c b/tests/benchmark/test_rwlock.c index dbd0854..b275f78 100644 --- a/tests/benchmark/test_rwlock.c +++ b/tests/benchmark/test_rwlock.c @@ -39,8 +39,6 @@ struct test_array { */ pthread_rwlock_t lock; -static volatile int test_go, test_stop; - static unsigned long wdelay; static volatile struct test_array test_array = { 8 }; @@ -102,19 +100,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -133,9 +118,7 @@ void *thr_reader(void *_count) set_affinity(); - while (!test_go) - { - } + wait_until_go(); for (;;) { int a, ret; @@ -180,10 +163,7 @@ void *thr_writer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { int ret; @@ -341,13 +321,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu.c b/tests/benchmark/test_urcu.c index 8b19f22..053993a 100644 --- a/tests/benchmark/test_urcu.c +++ b/tests/benchmark/test_urcu.c @@ -30,8 +30,6 @@ #endif #include -static volatile int test_go, test_stop; - static unsigned long wdelay; static int *test_rcu_pointer; @@ -93,19 +91,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -128,10 +113,7 @@ void *thr_reader(void *_count) rcu_register_thread(); urcu_posix_assert(!rcu_read_ongoing()); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -172,10 +154,7 @@ void *thr_writer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { new = malloc(sizeof(int)); @@ -323,13 +302,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_assign.c b/tests/benchmark/test_urcu_assign.c index 1272231..d0272a7 100644 --- a/tests/benchmark/test_urcu_assign.c +++ b/tests/benchmark/test_urcu_assign.c @@ -34,8 +34,6 @@ struct test_array { int a; }; -static volatile int test_go, test_stop; - static unsigned long wdelay; static struct test_array *test_rcu_pointer; @@ -97,19 +95,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -187,10 +172,7 @@ void *thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -226,10 +208,7 @@ void *thr_writer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_copy_mutex_lock(); @@ -380,13 +359,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_bp.c b/tests/benchmark/test_urcu_bp.c index a797c9d..5da7132 100644 --- a/tests/benchmark/test_urcu_bp.c +++ b/tests/benchmark/test_urcu_bp.c @@ -30,8 +30,6 @@ #endif #include -static volatile int test_go, test_stop; - static unsigned long wdelay; static int *test_rcu_pointer; @@ -93,19 +91,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -128,10 +113,7 @@ void *thr_reader(void *_count) rcu_register_thread(); urcu_posix_assert(!rcu_read_ongoing()); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -168,10 +150,7 @@ void *thr_writer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { new = malloc(sizeof(int)); @@ -318,13 +297,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_defer.c b/tests/benchmark/test_urcu_defer.c index d2bd36e..56ac28d 100644 --- a/tests/benchmark/test_urcu_defer.c +++ b/tests/benchmark/test_urcu_defer.c @@ -35,8 +35,6 @@ struct test_array { int a; }; -static volatile int test_go, test_stop; - static unsigned long wdelay; static struct test_array *test_rcu_pointer; @@ -98,19 +96,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -135,10 +120,7 @@ void *thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -189,10 +171,7 @@ void *thr_writer(void *data) exit(-1); } - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { new = malloc(sizeof(*new)); @@ -345,13 +324,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_gc.c b/tests/benchmark/test_urcu_gc.c index e2f6498..d52a51d 100644 --- a/tests/benchmark/test_urcu_gc.c +++ b/tests/benchmark/test_urcu_gc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "thread-id.h" #include "../common/debug-yield.h" @@ -34,8 +35,6 @@ struct test_array { int a; }; -static volatile int test_go, test_stop; - static unsigned long wdelay; static struct test_array *test_rcu_pointer; @@ -106,19 +105,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -143,10 +129,7 @@ void *thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -217,10 +200,7 @@ void *thr_writer(void *data) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { #ifndef TEST_LOCAL_GC @@ -385,13 +365,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_hash.c b/tests/benchmark/test_urcu_hash.c index c0b574d..606851b 100644 --- a/tests/benchmark/test_urcu_hash.c +++ b/tests/benchmark/test_urcu_hash.c @@ -82,8 +82,6 @@ DEFINE_URCU_TLS(unsigned long, lookup_ok); struct cds_lfht *test_ht; -volatile int test_go, test_stop; - unsigned long wdelay; unsigned long duration; @@ -635,14 +633,14 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); remain = duration; do { remain = sleep(remain); } while (remain > 0); - test_stop = 1; + end_test(); end_pthread_join: for (i_thr = 0; i_thr < nr_readers_created; i_thr++) { diff --git a/tests/benchmark/test_urcu_hash.h b/tests/benchmark/test_urcu_hash.h index 530a68b..0ecb781 100644 --- a/tests/benchmark/test_urcu_hash.h +++ b/tests/benchmark/test_urcu_hash.h @@ -111,8 +111,6 @@ cds_lfht_iter_get_test_node(struct cds_lfht_iter *iter) return to_test_node(cds_lfht_iter_get_node(iter)); } -extern volatile int test_go, test_stop; - extern unsigned long wdelay; extern unsigned long duration; @@ -160,19 +158,6 @@ extern pthread_mutex_t affinity_mutex; void set_affinity(void); -/* - * returns 0 if test should end. - */ -static inline int test_duration_write(void) -{ - return !test_stop; -} - -static inline int test_duration_read(void) -{ - return !test_stop; -} - extern DECLARE_URCU_TLS(unsigned long long, nr_writes); extern DECLARE_URCU_TLS(unsigned long long, nr_reads); diff --git a/tests/benchmark/test_urcu_hash_rw.c b/tests/benchmark/test_urcu_hash_rw.c index 0c4ab20..b76603e 100644 --- a/tests/benchmark/test_urcu_hash_rw.c +++ b/tests/benchmark/test_urcu_hash_rw.c @@ -59,10 +59,7 @@ void *test_hash_rw_thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -119,10 +116,7 @@ void *test_hash_rw_thr_writer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_lfht_node *ret_node = NULL; diff --git a/tests/benchmark/test_urcu_hash_unique.c b/tests/benchmark/test_urcu_hash_unique.c index b8381b5..487baa8 100644 --- a/tests/benchmark/test_urcu_hash_unique.c +++ b/tests/benchmark/test_urcu_hash_unique.c @@ -57,10 +57,7 @@ void *test_hash_unique_thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct lfht_test_node *node; @@ -122,10 +119,7 @@ void *test_hash_unique_thr_writer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { /* diff --git a/tests/benchmark/test_urcu_lfq.c b/tests/benchmark/test_urcu_lfq.c index 2217760..66cf78c 100644 --- a/tests/benchmark/test_urcu_lfq.c +++ b/tests/benchmark/test_urcu_lfq.c @@ -33,8 +33,6 @@ #include #include -static volatile int test_go, test_stop; - static unsigned long rduration; static unsigned long duration; @@ -96,12 +94,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop; + return test_duration_read(); } static int test_duration_enqueue(void) { - return !test_stop; + return test_duration_write(); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -132,10 +130,7 @@ void *thr_enqueuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct test *node = malloc(sizeof(*node)); @@ -188,10 +183,7 @@ void *thr_dequeuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_lfq_node_rcu *qnode; @@ -361,7 +353,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -371,7 +363,7 @@ int main(int argc, char **argv) } } - test_stop = 1; + end_test(); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_lfs.c b/tests/benchmark/test_urcu_lfs.c index c070021..933f0b3 100644 --- a/tests/benchmark/test_urcu_lfs.c +++ b/tests/benchmark/test_urcu_lfs.c @@ -45,8 +45,6 @@ enum test_sync { static enum test_sync test_sync; -static volatile int test_go, test_stop; - static unsigned long rduration; static unsigned long duration; @@ -110,12 +108,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop; + return test_duration_read(); } static int test_duration_enqueue(void) { - return !test_stop; + return test_duration_write(); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -145,10 +143,7 @@ static void *thr_enqueuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct test *node = malloc(sizeof(*node)); @@ -247,10 +242,7 @@ static void *thr_dequeuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); urcu_posix_assert(test_pop || test_pop_all); @@ -445,7 +437,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -455,7 +447,7 @@ int main(int argc, char **argv) } } - test_stop = 1; + end_test(); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_lfs_rcu.c b/tests/benchmark/test_urcu_lfs_rcu.c index 7aabc1d..cb9236d 100644 --- a/tests/benchmark/test_urcu_lfs_rcu.c +++ b/tests/benchmark/test_urcu_lfs_rcu.c @@ -37,8 +37,6 @@ #include -static volatile int test_go, test_stop; - static unsigned long rduration; static unsigned long duration; @@ -100,12 +98,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop; + return test_duration_read(); } static int test_duration_enqueue(void) { - return !test_stop; + return test_duration_write(); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -136,10 +134,7 @@ void *thr_enqueuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct test *node = malloc(sizeof(*node)); @@ -191,10 +186,7 @@ void *thr_dequeuer(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_lfs_node_rcu *snode; @@ -363,7 +355,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -373,7 +365,7 @@ int main(int argc, char **argv) } } - test_stop = 1; + end_test(); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_qsbr.c b/tests/benchmark/test_urcu_qsbr.c index cb09b38..a33dbd3 100644 --- a/tests/benchmark/test_urcu_qsbr.c +++ b/tests/benchmark/test_urcu_qsbr.c @@ -30,8 +30,6 @@ #endif #include "urcu-qsbr.h" -static volatile int test_go, test_stop; - static unsigned long wdelay; static int *test_rcu_pointer; @@ -92,19 +90,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -131,10 +116,7 @@ void *thr_reader(void *_count) urcu_posix_assert(!rcu_read_ongoing()); rcu_thread_online(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { rcu_read_lock(); @@ -178,10 +160,7 @@ void *thr_writer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { new = malloc(sizeof(int)); @@ -329,13 +308,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_qsbr_gc.c b/tests/benchmark/test_urcu_qsbr_gc.c index 47d23bc..00f6757 100644 --- a/tests/benchmark/test_urcu_qsbr_gc.c +++ b/tests/benchmark/test_urcu_qsbr_gc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "thread-id.h" #include "../common/debug-yield.h" @@ -32,8 +33,6 @@ struct test_array { int a; }; -static volatile int test_go, test_stop; - static unsigned long wdelay; static struct test_array *test_rcu_pointer; @@ -104,19 +103,6 @@ static void set_affinity(void) #endif /* HAVE_SCHED_SETAFFINITY */ } -/* - * returns 0 if test should end. - */ -static int test_duration_write(void) -{ - return !test_stop; -} - -static int test_duration_read(void) -{ - return !test_stop; -} - static DEFINE_URCU_TLS(unsigned long long, nr_writes); static DEFINE_URCU_TLS(unsigned long long, nr_reads); @@ -140,10 +126,7 @@ void *thr_reader(void *_count) rcu_register_thread(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { _rcu_read_lock(); @@ -217,10 +200,7 @@ void *thr_writer(void *data) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { #ifndef TEST_LOCAL_GC @@ -385,13 +365,7 @@ int main(int argc, char **argv) exit(1); } - cmm_smp_mb(); - - test_go = 1; - - sleep(duration); - - test_stop = 1; + test_for(duration); for (i_thr = 0; i_thr < nr_readers; i_thr++) { err = pthread_join(tid_reader[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_wfcq.c b/tests/benchmark/test_urcu_wfcq.c index 7f18af0..71bca10 100644 --- a/tests/benchmark/test_urcu_wfcq.c +++ b/tests/benchmark/test_urcu_wfcq.c @@ -42,7 +42,7 @@ static enum test_sync test_sync; static int test_force_sync; -static volatile int test_go, test_stop_enqueue, test_stop_dequeue; +static volatile int test_stop_enqueue, test_stop_dequeue; static unsigned long rduration; @@ -108,12 +108,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop_dequeue; + return !uatomic_load(&test_stop_dequeue, CMM_RELAXED); } static int test_duration_enqueue(void) { - return !test_stop_enqueue; + return !uatomic_load(&test_stop_enqueue, CMM_RELAXED); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -141,10 +141,7 @@ static void *thr_enqueuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_wfcq_node *node = malloc(sizeof(*node)); @@ -252,10 +249,7 @@ static void *thr_dequeuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { if (test_dequeue && test_splice) { @@ -468,7 +462,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -478,7 +472,7 @@ int main(int argc, char **argv) } } - test_stop_enqueue = 1; + uatomic_store(&test_stop_enqueue, 1, CMM_RELEASE); if (test_wait_empty) { while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) { @@ -489,7 +483,7 @@ int main(int argc, char **argv) } } - test_stop_dequeue = 1; + uatomic_store(&test_stop_dequeue, 1, CMM_RELAXED); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_wfq.c b/tests/benchmark/test_urcu_wfq.c index c11f639..b17df5a 100644 --- a/tests/benchmark/test_urcu_wfq.c +++ b/tests/benchmark/test_urcu_wfq.c @@ -37,8 +37,6 @@ #include #include -static volatile int test_go, test_stop; - static unsigned long rduration; static unsigned long duration; @@ -100,12 +98,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop; + return test_duration_read(); } static int test_duration_enqueue(void) { - return !test_stop; + return test_duration_write(); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -129,10 +127,7 @@ void *thr_enqueuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_wfq_node *node = malloc(sizeof(*node)); @@ -171,10 +166,7 @@ void *thr_dequeuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_wfq_node *node = cds_wfq_dequeue_blocking(&q); @@ -329,7 +321,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -339,7 +331,7 @@ int main(int argc, char **argv) } } - test_stop = 1; + end_test(); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); diff --git a/tests/benchmark/test_urcu_wfs.c b/tests/benchmark/test_urcu_wfs.c index 9b9c2f8..39704f4 100644 --- a/tests/benchmark/test_urcu_wfs.c +++ b/tests/benchmark/test_urcu_wfs.c @@ -45,7 +45,7 @@ static enum test_sync test_sync; static int test_force_sync; -static volatile int test_go, test_stop_enqueue, test_stop_dequeue; +static volatile int test_stop_enqueue, test_stop_dequeue; static unsigned long rduration; @@ -111,12 +111,12 @@ static void set_affinity(void) */ static int test_duration_dequeue(void) { - return !test_stop_dequeue; + return !uatomic_load(&test_stop_dequeue, CMM_RELAXED); } static int test_duration_enqueue(void) { - return !test_stop_enqueue; + return !uatomic_load(&test_stop_enqueue, CMM_RELAXED); } static DEFINE_URCU_TLS(unsigned long long, nr_dequeues); @@ -143,10 +143,7 @@ static void *thr_enqueuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); for (;;) { struct cds_wfs_node *node = malloc(sizeof(*node)); @@ -236,10 +233,7 @@ static void *thr_dequeuer(void *_count) set_affinity(); - while (!test_go) - { - } - cmm_smp_mb(); + wait_until_go(); urcu_posix_assert(test_pop || test_pop_all); @@ -455,7 +449,7 @@ int main(int argc, char **argv) cmm_smp_mb(); - test_go = 1; + begin_test(); for (i_thr = 0; i_thr < duration; i_thr++) { sleep(1); @@ -465,7 +459,7 @@ int main(int argc, char **argv) } } - test_stop_enqueue = 1; + uatomic_store(&test_stop_enqueue, 1, CMM_RELEASE); if (test_wait_empty) { while (nr_enqueuers != uatomic_read(&test_enqueue_stopped)) { @@ -476,7 +470,7 @@ int main(int argc, char **argv) } } - test_stop_dequeue = 1; + uatomic_store(&test_stop_dequeue, 1, CMM_RELAXED); for (i_thr = 0; i_thr < nr_enqueuers; i_thr++) { err = pthread_join(tid_enqueuer[i_thr], &tret); -- 2.34.1