]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdservice: state changed to atomic_t to decrease thread context switch. 6492/head
authorXiaowei Chen <cxwshawn@gmail.com>
Mon, 16 Nov 2015 02:56:22 +0000 (21:56 -0500)
committerXiaowei Chen <cxwshawn@gmail.com>
Mon, 16 Nov 2015 02:56:26 +0000 (21:56 -0500)
    service.is_stopping is in the key IO path, hot call, better use spinlock.

Signed-off-by: Xiaowei Chen <chen.xiaowei@h3c.com>
src/osd/OSD.cc
src/osd/OSD.h

index 1c69f4025f64fd63e3184c5937687a666bc22695..2a9d88427999504e9b1b21552220e92dc6779150 100644 (file)
@@ -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)
 {
index b8f2f4001ad19cbabbca34ed44b4ac25b26d9ae1..65a0d604509fe92ec2769e52d5d49ec1ffe3b6e1 100644 (file)
@@ -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();