From: Xiaowei Chen Date: Mon, 16 Nov 2015 02:56:22 +0000 (-0500) Subject: osdservice: state changed to atomic_t to decrease thread context switch. X-Git-Tag: v10.0.1~36^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a8b746411efdf31fc6f60c15b5caacf54af5bc20;p=ceph.git osdservice: state changed to atomic_t to decrease thread context switch. service.is_stopping is in the key IO path, hot call, better use spinlock. Signed-off-by: Xiaowei Chen --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 1c69f4025f64..2a9d88427999 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -1021,13 +1021,13 @@ void OSDService::set_epochs(const epoch_t *_boot_epoch, const epoch_t *_up_epoch bool OSDService::prepare_to_stop() { Mutex::Locker l(is_stopping_lock); - if (state != NOT_STOPPING) + if (get_state() != NOT_STOPPING) return false; OSDMapRef osdmap = get_osdmap(); if (osdmap && osdmap->is_up(whoami)) { dout(0) << __func__ << " telling mon we are shutting down" << dendl; - state = PREPARING_TO_STOP; + set_state(PREPARING_TO_STOP); monc->send_mon_message(new MOSDMarkMeDown(monc->get_fsid(), osdmap->get_inst(whoami), osdmap->get_epoch(), @@ -1037,28 +1037,27 @@ bool OSDService::prepare_to_stop() utime_t timeout; timeout.set_from_double(now + cct->_conf->osd_mon_shutdown_timeout); while ((ceph_clock_now(cct) < timeout) && - (state != STOPPING)) { + (get_state() != STOPPING)) { is_stopping_cond.WaitUntil(is_stopping_lock, timeout); } } dout(0) << __func__ << " starting shutdown" << dendl; - state = STOPPING; + set_state(STOPPING); return true; } void OSDService::got_stop_ack() { Mutex::Locker l(is_stopping_lock); - if (state == PREPARING_TO_STOP) { + if (get_state() == PREPARING_TO_STOP) { dout(0) << __func__ << " starting shutdown" << dendl; - state = STOPPING; + set_state(STOPPING); is_stopping_cond.Signal(); } else { dout(10) << __func__ << " ignoring msg" << dendl; } } - MOSDMap *OSDService::build_incremental_map_msg(epoch_t since, epoch_t to, OSDSuperblock& sblock) { diff --git a/src/osd/OSD.h b/src/osd/OSD.h index b8f2f4001ad1..65a0d604509f 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -970,14 +970,19 @@ public: enum { NOT_STOPPING, PREPARING_TO_STOP, - STOPPING } state; + STOPPING }; + atomic_t state; + int get_state() { + return state.read(); + } + void set_state(int s) { + state.set(s); + } bool is_stopping() { - Mutex::Locker l(is_stopping_lock); - return state == STOPPING; + return get_state() == STOPPING; } bool is_preparing_to_stop() { - Mutex::Locker l(is_stopping_lock); - return state == PREPARING_TO_STOP; + return get_state() == PREPARING_TO_STOP; } bool prepare_to_stop(); void got_stop_ack();