]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: use the steady clock on tick 20001/head
authorMohamad Gebai <mgebai@suse.com>
Thu, 30 Nov 2017 17:55:23 +0000 (12:55 -0500)
committerMohamad Gebai <mgebai@suse.com>
Thu, 18 Jan 2018 08:40:18 +0000 (09:40 +0100)
Signed-off-by: Mohamad Gebai <mgebai@suse.com>
src/common/ceph_time.h
src/mds/CDir.h
src/mds/MDBalancer.cc
src/mds/MDBalancer.h

index afe8aead7cee1a0e2865daa49359dd0de48bb87d..9b08a92acc69a69efbfe3a90daf7476f68b42c40 100644 (file)
@@ -84,6 +84,10 @@ namespace ceph {
        return (t == time_point::min());
       }
 
+      static time_point zero() {
+        return time_point::min();
+      }
+
       // Allow conversion to/from any clock with the same interface as
       // std::chrono::system_clock)
       template<typename Clock, typename Duration>
@@ -237,6 +241,14 @@ namespace ceph {
        return time_point(seconds(ts.tv_sec) + nanoseconds(ts.tv_nsec));
       }
 
+      static bool is_zero(const time_point& t) {
+        return (t == time_point::min());
+      }
+
+      static time_point zero() {
+        return time_point::min();
+      }
+
       // A monotonic clock's timepoints are only meaningful to the
       // computer on which they were generated. Thus having an
       // optional skew is meaningless.
index 45b2998b3d24d00ec67268b9d00b51978094f1d6..6846bb7485bc72bdb465bddeb68edb17b0c57eb6 100644 (file)
@@ -360,7 +360,7 @@ protected:
   dirfrag_load_vec_t pop_auth_subtree;
   dirfrag_load_vec_t pop_auth_subtree_nested;
  
-  utime_t last_popularity_sample;
+  mono_time last_popularity_sample;
 
   load_spread_t pop_spread;
 
index ae3d9a9553a883751847dd79731edefca7977a48..f4aef11e68dac744c27c18129b4db08c91449aae 100644 (file)
@@ -35,6 +35,7 @@
 #include <map>
 using std::map;
 using std::vector;
+using std::chrono::duration_cast;
 
 #include "common/config.h"
 #include "common/errno.h"
@@ -148,31 +149,35 @@ void MDBalancer::handle_export_pins(void)
 void MDBalancer::tick()
 {
   static int num_bal_times = g_conf->mds_bal_max;
-  static utime_t first = ceph_clock_now();
-  utime_t now = ceph_clock_now();
-  utime_t elapsed = now;
-  elapsed -= first;
+  static mono_time first = mono_clock::now();
+  mono_time now = mono_clock::now();
+  ceph::timespan elapsed = now - first;
 
   if (g_conf->mds_bal_export_pin) {
     handle_export_pins();
   }
 
   // sample?
-  if ((double)now - (double)last_sample > g_conf->mds_bal_sample_interval) {
+  if (chrono::duration<double> (now - last_sample).count() >
+    g_conf->mds_bal_sample_interval) {
     dout(15) << "tick last_sample now " << now << dendl;
     last_sample = now;
   }
 
+  // We can use duration_cast below, although the result is an int,
+  // because the values from g_conf are also integers.
   // balance?
-  if (last_heartbeat == utime_t())
+  if (mono_clock::is_zero(last_heartbeat))
     last_heartbeat = now;
   if (mds->get_nodeid() == 0 &&
       g_conf->mds_bal_interval > 0 &&
       (num_bal_times ||
        (g_conf->mds_bal_max_until >= 0 &&
-       elapsed.sec() > g_conf->mds_bal_max_until)) &&
+        duration_cast<chrono::seconds>(elapsed).count() >
+          g_conf->mds_bal_max_until)) &&
       mds->is_active() &&
-      now.sec() - last_heartbeat.sec() >= g_conf->mds_bal_interval) {
+      duration_cast<chrono::seconds>(now - last_heartbeat).count() >=
+       g_conf->mds_bal_interval) {
     last_heartbeat = now;
     send_heartbeat();
     num_bal_times--;
index d23185b22f898e1ffe278178813bfc62b5683991..4b8e8030ddc4d9c3614fd066ac7225695a63563e 100644 (file)
@@ -128,8 +128,8 @@ private:
   string bal_code;
   string bal_version;
 
-  utime_t last_heartbeat;
-  utime_t last_sample;
+  mono_time last_heartbeat = mono_clock::zero();
+  mono_time last_sample = mono_clock::zero();
   utime_t rebalance_time; //ensure a consistent view of load for rebalance
 
   // Dirfrags which are marked to be passed on to MDCache::[split|merge]_dir