From: Mohamad Gebai Date: Fri, 15 Feb 2019 19:22:49 +0000 (-0500) Subject: osd: use steady clock in prepare_to_stop() X-Git-Tag: v15.0.0~218^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f50138e66d621d2e29526079649567b3faa271f3;p=ceph.git osd: use steady clock in prepare_to_stop() Signed-off-by: Mohamad Gebai --- diff --git a/src/common/condition_variable_debug.h b/src/common/condition_variable_debug.h index 3241502ff812..d12e7956fff8 100644 --- a/src/common/condition_variable_debug.h +++ b/src/common/condition_variable_debug.h @@ -50,6 +50,21 @@ public: timespec ts = ceph::real_clock::to_timespec(when); return _wait_until(lock.mutex(), &ts); } + template + bool wait_for( + std::unique_lock& lock, + const std::chrono::duration& awhile, + Pred pred) { + ceph::real_time when{ceph::real_clock::now()}; + when += awhile; + timespec ts = ceph::real_clock::to_timespec(when); + while (!pred()) { + if ( _wait_until(lock.mutex(), &ts) == std::cv_status::timeout) { + return pred(); + } + } + return true; + } void notify_one(); void notify_all(bool sloppy = false); private: diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 8550064567ec..0cc2a974d686 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -271,8 +271,7 @@ OSDService::OSDService(OSD *osd) : cur_state(NONE), cur_ratio(0), physical_ratio(0), epoch_lock("OSDService::epoch_lock"), - boot_epoch(0), up_epoch(0), bind_epoch(0), - is_stopping_lock("OSDService::is_stopping_lock") + boot_epoch(0), up_epoch(0), bind_epoch(0) #ifdef PG_DEBUG_REFS , pgid_lock("OSDService::pgid_lock") #endif @@ -1420,7 +1419,7 @@ void OSDService::set_epochs(const epoch_t *_boot_epoch, const epoch_t *_up_epoch bool OSDService::prepare_to_stop() { - std::lock_guard l(is_stopping_lock); + std::unique_lock l(is_stopping_lock); if (get_state() != NOT_STOPPING) return false; @@ -1436,13 +1435,9 @@ bool OSDService::prepare_to_stop() osdmap->get_epoch(), true // request ack )); - utime_t now = ceph_clock_now(); - utime_t timeout; - timeout.set_from_double(now + cct->_conf->osd_mon_shutdown_timeout); - while ((ceph_clock_now() < timeout) && - (get_state() != STOPPING)) { - is_stopping_cond.WaitUntil(is_stopping_lock, timeout); - } + const auto timeout = ceph::make_timespan(cct->_conf->osd_mon_shutdown_timeout); + is_stopping_cond.wait_for(l, timeout, + [this] { return get_state() == STOPPING; }); } dout(0) << __func__ << " starting shutdown" << dendl; set_state(STOPPING); @@ -1451,11 +1446,11 @@ bool OSDService::prepare_to_stop() void OSDService::got_stop_ack() { - std::lock_guard l(is_stopping_lock); + std::scoped_lock l(is_stopping_lock); if (get_state() == PREPARING_TO_STOP) { dout(0) << __func__ << " starting shutdown" << dendl; set_state(STOPPING); - is_stopping_cond.Signal(); + is_stopping_cond.notify_all(); } else { dout(10) << __func__ << " ignoring msg" << dendl; } diff --git a/src/osd/OSD.h b/src/osd/OSD.h index bf054d701125..9aae481a1515 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1008,8 +1008,8 @@ public: void request_osdmap_update(epoch_t e); // -- stopping -- - Mutex is_stopping_lock; - Cond is_stopping_cond; + ceph::mutex is_stopping_lock = ceph::make_mutex("OSDService::is_stopping_lock"); + ceph::condition_variable is_stopping_cond; enum { NOT_STOPPING, PREPARING_TO_STOP,