From 1972bd9a06c1e59bd823a597bd4bcc7790008a55 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Thu, 4 Feb 2021 01:34:44 +0800 Subject: [PATCH] common/Timer: use mono_clock for clock_t there is chance that the system clock is adjust by chrony or ntpd, so that a timer scheduled at epoch time 12:34 would never get scheduled if the system clock is changed to 12:35 when the system clock is still 12:33. if we have event which schedules itself when it is fired, there is chance that this event could be put in a black hole if the system clock is adjusted in the way explained above. this could be a serious issue if we rely on the timer to do critical things. but we *might* suffer from this issue even if we use mono_clock for clock_t in Timer, because in older libstdc++ and libc++, condition_variable::wait_until() and condition_variable::wait_for() were still using pthread_cond_timedwait(). this is fixed after glibc introduced pthread_cond_clockwait() in v2.3.0. for more details, see https://reviews.llvm.org/D65339 and https://gcc.gnu.org/legacy-ml/gcc-patches/2019-09/msg00190.html Signed-off-by: Kefu Chai --- src/common/Timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/Timer.h b/src/common/Timer.h index 32ca733b361e4..033d1103a660d 100644 --- a/src/common/Timer.h +++ b/src/common/Timer.h @@ -36,7 +36,7 @@ class SafeTimer void timer_thread(); void _shutdown(); - using clock_t = ceph::real_clock; + using clock_t = ceph::mono_clock; using scheduled_map_t = std::multimap; scheduled_map_t schedule; using event_lookup_map_t = std::map; -- 2.39.5