From ee72ef6e12984db43cdf8a1f0194c9302b33e46c Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sat, 26 Sep 2009 16:01:53 -0400 Subject: [PATCH] qsbr: Use adaptative wait delay Use a wait delay based on the last Q.S. duration of the thread we are waiting for. Signed-off-by: Mathieu Desnoyers --- urcu-qsbr-static.h | 23 +++++++++++++++++++++++ urcu-qsbr.c | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/urcu-qsbr-static.h b/urcu-qsbr-static.h index 9cc5db4..d18fabd 100644 --- a/urcu-qsbr-static.h +++ b/urcu-qsbr-static.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -181,6 +182,8 @@ extern unsigned long urcu_gp_ctr; struct urcu_reader_status { unsigned long qs_gp; unsigned long gp_waiting; + unsigned long qs_time_delta_usec; + struct timeval qs_time_last; }; extern struct urcu_reader_status __thread urcu_reader_status; @@ -219,8 +222,17 @@ static inline void _rcu_read_unlock(void) static inline void _rcu_quiescent_state(void) { long gp_ctr; + struct timeval current_time; smp_mb(); + gettimeofday(¤t_time, NULL); + if (current_time.tv_sec - urcu_reader_status.qs_time_last.tv_sec >= 1) + _STORE_SHARED(urcu_reader_status.qs_time_delta_usec, 1000000); + else + _STORE_SHARED(urcu_reader_status.qs_time_delta_usec, + (unsigned long)current_time.tv_usec + - (unsigned long)urcu_reader_status.qs_time_last.tv_usec); + urcu_reader_status.qs_time_last = current_time; /* * volatile accesses can be reordered by the compiler when put in the * same expression. @@ -247,6 +259,17 @@ static inline void _rcu_thread_offline(void) static inline void _rcu_thread_online(void) { + struct timeval current_time; + + gettimeofday(¤t_time, NULL); + if (current_time.tv_sec - urcu_reader_status.qs_time_last.tv_sec >= 1) + _STORE_SHARED(urcu_reader_status.qs_time_delta_usec, 1000000); + else + _STORE_SHARED(urcu_reader_status.qs_time_delta_usec, + (unsigned long)current_time.tv_usec + - (unsigned long)urcu_reader_status.qs_time_last.tv_usec); + urcu_reader_status.qs_time_last = current_time; + _STORE_SHARED(urcu_reader_status.qs_time_delta_usec, 0); _STORE_SHARED(urcu_reader_status.qs_gp, LOAD_SHARED(urcu_gp_ctr)); smp_mb(); } diff --git a/urcu-qsbr.c b/urcu-qsbr.c index c275b66..5f06bfa 100644 --- a/urcu-qsbr.c +++ b/urcu-qsbr.c @@ -31,6 +31,7 @@ #include #include #include +#include #define BUILD_QSBR_LIB #include "urcu-qsbr-static.h" @@ -117,7 +118,8 @@ static void wait_for_quiescent_state(void) index->urcu_reader_status->gp_waiting = 1; while (rcu_gp_ongoing(&index->urcu_reader_status->qs_gp)) { if (wait_loops++ == RCU_QS_ACTIVE_ATTEMPTS) { - sched_yield(); /* ideally sched_yield_to() */ + /* adapted wait time, in us */ + usleep(LOAD_SHARED(index->urcu_reader_status->qs_time_delta_usec)); wait_loops = 0; } else { #ifndef HAS_INCOHERENT_CACHES -- 2.34.1