From: Mathieu Desnoyers Date: Sat, 26 Sep 2009 22:19:27 +0000 (-0400) Subject: qsbr: adaptative usleep period X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=539718ae00831b55601635e6f065cb2aaf2aa7ae;p=urcu.git qsbr: adaptative usleep period Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu-qsbr-static.h b/urcu-qsbr-static.h index d18fabd..f1300f3 100644 --- a/urcu-qsbr-static.h +++ b/urcu-qsbr-static.h @@ -222,16 +222,16 @@ static inline void _rcu_read_unlock(void) static inline void _rcu_quiescent_state(void) { long gp_ctr; - struct timeval current_time; + struct timeval current_time, delta_time; smp_mb(); gettimeofday(¤t_time, NULL); - if (current_time.tv_sec - urcu_reader_status.qs_time_last.tv_sec >= 1) + timersub(¤t_time, &urcu_reader_status.qs_time_last, &delta_time); + if (delta_time.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); + (unsigned long)delta_time.tv_usec); urcu_reader_status.qs_time_last = current_time; /* * volatile accesses can be reordered by the compiler when put in the @@ -259,15 +259,15 @@ static inline void _rcu_thread_offline(void) static inline void _rcu_thread_online(void) { - struct timeval current_time; + struct timeval current_time, delta_time; gettimeofday(¤t_time, NULL); - if (current_time.tv_sec - urcu_reader_status.qs_time_last.tv_sec >= 1) + timersub(¤t_time, &urcu_reader_status.qs_time_last, &delta_time); + if (delta_time.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); + (unsigned long)delta_time.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)); diff --git a/urcu-qsbr.c b/urcu-qsbr.c index 5f06bfa..a71ee66 100644 --- a/urcu-qsbr.c +++ b/urcu-qsbr.c @@ -119,7 +119,7 @@ static void wait_for_quiescent_state(void) while (rcu_gp_ongoing(&index->urcu_reader_status->qs_gp)) { if (wait_loops++ == RCU_QS_ACTIVE_ATTEMPTS) { /* adapted wait time, in us */ - usleep(LOAD_SHARED(index->urcu_reader_status->qs_time_delta_usec)); + usleep(LOAD_SHARED(index->urcu_reader_status->qs_time_delta_usec) / 4); wait_loops = 0; } else { #ifndef HAS_INCOHERENT_CACHES