From: Kefu Chai Date: Wed, 3 Feb 2021 17:34:44 +0000 (+0800) Subject: common/Timer: use mono_clock for clock_t X-Git-Tag: v17.1.0~3037^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1972bd9a06c1e59bd823a597bd4bcc7790008a55;p=ceph.git 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 --- diff --git a/src/common/Timer.h b/src/common/Timer.h index 32ca733b361e..033d1103a660 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;