]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Throttle: use ceph::timespan
authorSage Weil <sage@redhat.com>
Tue, 23 Oct 2018 13:22:08 +0000 (08:22 -0500)
committerKefu Chai <kchai@redhat.com>
Wed, 21 Nov 2018 03:56:33 +0000 (11:56 +0800)
This will play nice with ceph::condition_variable_debug.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/Throttle.cc
src/common/Throttle.h

index 0bb27d71357f61eec880afe77edc5b3b48181eca..f130045b6aff0451ce9f7b48734e5b64d7ef6042 100644 (file)
@@ -395,24 +395,24 @@ bool BackoffThrottle::set_params(
   return true;
 }
 
-std::chrono::duration<double> BackoffThrottle::_get_delay(uint64_t c) const
+ceph::timespan BackoffThrottle::_get_delay(uint64_t c) const
 {
   if (max == 0)
-    return std::chrono::duration<double>(0);
+    return ceph::timespan(0);
 
   double r = ((double)current) / ((double)max);
   if (r < low_threshold) {
-    return std::chrono::duration<double>(0);
+    return ceph::timespan(0);
   } else if (r < high_threshold) {
-    return c * std::chrono::duration<double>(
+    return c * ceph::make_timespan(
       (r - low_threshold) * s0);
   } else {
-    return c * std::chrono::duration<double>(
+    return c * ceph::make_timespan(
       high_delay_per_count + ((r - high_threshold) * s1));
   }
 }
 
-std::chrono::duration<double> BackoffThrottle::get(uint64_t c)
+ceph::timespan BackoffThrottle::get(uint64_t c)
 {
   locker l(lock);
   auto delay = _get_delay(c);
@@ -423,7 +423,7 @@ std::chrono::duration<double> BackoffThrottle::get(uint64_t c)
   }
 
   // fast path
-  if (delay == std::chrono::duration<double>(0) &&
+  if (delay == ceph::make_timespan(0) &&
       waiters.empty() &&
       ((max == 0) || (current == 0) || ((current + c) <= max))) {
     current += c;
@@ -432,7 +432,7 @@ std::chrono::duration<double> BackoffThrottle::get(uint64_t c)
       logger->set(l_backoff_throttle_val, current);
     }
 
-    return std::chrono::duration<double>(0);
+    return ceph::make_timespan(0);
   }
 
   auto ticket = _push_waiter();
@@ -444,20 +444,20 @@ std::chrono::duration<double> BackoffThrottle::get(uint64_t c)
     waited = true;
   }
 
-  auto start = std::chrono::system_clock::now();
+  auto start = ceph::real_clock::now();
   delay = _get_delay(c);
   while (true) {
     if (!((max == 0) || (current == 0) || (current + c) <= max)) {
       (*ticket)->wait(l);
       waited = true;
-    } else if (delay > std::chrono::duration<double>(0)) {
+    } else if (delay > ceph::timespan(0)) {
       (*ticket)->wait_for(l, delay);
       waited = true;
     } else {
       break;
     }
     ceph_assert(ticket == waiters.begin());
-    delay = _get_delay(c) - (std::chrono::system_clock::now() - start);
+    delay = _get_delay(c) - (ceph::real_clock::now() - start);
   }
   waiters.pop_front();
   _kick_waiters();
@@ -471,7 +471,7 @@ std::chrono::duration<double> BackoffThrottle::get(uint64_t c)
     }
   }
 
-  return std::chrono::system_clock::now() - start;
+  return ceph::real_clock::now() - start;
 }
 
 uint64_t BackoffThrottle::put(uint64_t c)
index 46ff1c51702f8528e25bc1cf4ed7cfce84a55e55..1f46c35fdfc40d0a0d69ff479ff80dde4b5caac0 100644 (file)
@@ -199,7 +199,7 @@ class BackoffThrottle {
   uint64_t max = 0;
   uint64_t current = 0;
 
-  std::chrono::duration<double> _get_delay(uint64_t c) const;
+  ceph::timespan _get_delay(uint64_t c) const;
 
 public:
   /**
@@ -218,8 +218,8 @@ public:
     uint64_t throttle_max,
     ostream *errstream);
 
-  std::chrono::duration<double> get(uint64_t c = 1);
-  std::chrono::duration<double> wait() {
+  ceph::timespan get(uint64_t c = 1);
+  ceph::timespan wait() {
     return get(0);
   }
   uint64_t put(uint64_t c = 1);