]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Timer: use mono_clock for clock_t
authorKefu Chai <kchai@redhat.com>
Wed, 3 Feb 2021 17:34:44 +0000 (01:34 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 4 Feb 2021 11:26:52 +0000 (19:26 +0800)
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 <kchai@redhat.com>
src/common/Timer.h

index 32ca733b361e40e561646f92f951f698d7128db0..033d1103a660dcf58a7e9052dc71fb754e6075c5 100644 (file)
@@ -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<clock_t::time_point, Context*>;
   scheduled_map_t schedule;
   using event_lookup_map_t = std::map<Context*, scheduled_map_t::iterator>;