From fa3acba368eafa8aebf744adbcea41dc27594c00 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 23 Oct 2018 08:22:08 -0500 Subject: [PATCH] common/Throttle: use ceph::timespan This will play nice with ceph::condition_variable_debug. Signed-off-by: Sage Weil --- src/common/Throttle.cc | 24 ++++++++++++------------ src/common/Throttle.h | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/common/Throttle.cc b/src/common/Throttle.cc index 0bb27d71357..f130045b6af 100644 --- a/src/common/Throttle.cc +++ b/src/common/Throttle.cc @@ -395,24 +395,24 @@ bool BackoffThrottle::set_params( return true; } -std::chrono::duration BackoffThrottle::_get_delay(uint64_t c) const +ceph::timespan BackoffThrottle::_get_delay(uint64_t c) const { if (max == 0) - return std::chrono::duration(0); + return ceph::timespan(0); double r = ((double)current) / ((double)max); if (r < low_threshold) { - return std::chrono::duration(0); + return ceph::timespan(0); } else if (r < high_threshold) { - return c * std::chrono::duration( + return c * ceph::make_timespan( (r - low_threshold) * s0); } else { - return c * std::chrono::duration( + return c * ceph::make_timespan( high_delay_per_count + ((r - high_threshold) * s1)); } } -std::chrono::duration 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 BackoffThrottle::get(uint64_t c) } // fast path - if (delay == std::chrono::duration(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 BackoffThrottle::get(uint64_t c) logger->set(l_backoff_throttle_val, current); } - return std::chrono::duration(0); + return ceph::make_timespan(0); } auto ticket = _push_waiter(); @@ -444,20 +444,20 @@ std::chrono::duration 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(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 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) diff --git a/src/common/Throttle.h b/src/common/Throttle.h index 46ff1c51702..1f46c35fdfc 100644 --- a/src/common/Throttle.h +++ b/src/common/Throttle.h @@ -199,7 +199,7 @@ class BackoffThrottle { uint64_t max = 0; uint64_t current = 0; - std::chrono::duration _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 get(uint64_t c = 1); - std::chrono::duration wait() { + ceph::timespan get(uint64_t c = 1); + ceph::timespan wait() { return get(0); } uint64_t put(uint64_t c = 1); -- 2.39.5