]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/HeartbeatMap: use relaxed order
authorKefu Chai <kchai@redhat.com>
Sat, 1 Aug 2020 15:38:15 +0000 (23:38 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 4 Aug 2020 03:20:49 +0000 (11:20 +0800)
use memory_order_relaxed instead of memory_order_seq_cst, as the
ordering of storing of `timeout` and `suicide_timeout` does not matter,
and we don't need to synchorinize the cache for the consistent memory
view of local core. what we need is but the atomic read/write operation
of these individual variables.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/HeartbeatMap.cc

index 6069b0b351d7d7122bd0f4ffafccc26b14a2791b..54442709229550cac3f9527494ef76c4e7f192de 100644 (file)
@@ -70,13 +70,13 @@ bool HeartbeatMap::_check(const heartbeat_handle_d *h, const char *who,
                          ceph::coarse_mono_time now)
 {
   bool healthy = true;
-  if (auto was = h->timeout.load();
+  if (auto was = h->timeout.load(std::memory_order_relaxed);
       !clock::is_zero(was) && was < now) {
     ldout(m_cct, 1) << who << " '" << h->name << "'"
                    << " had timed out after " << h->grace << dendl;
     healthy = false;
   }
-  if (auto was = h->suicide_timeout.load();
+  if (auto was = h->suicide_timeout.load(std::memory_order_relaxed);
       !clock::is_zero(was) && was < now) {
     ldout(m_cct, 1) << who << " '" << h->name << "'"
                    << " had suicide timed out after " << h->suicide_grace << dendl;
@@ -96,13 +96,13 @@ void HeartbeatMap::reset_timeout(heartbeat_handle_d *h,
   const auto now = clock::now();
   _check(h, "reset_timeout", now);
 
-  h->timeout = now + grace;
+  h->timeout.store(now + grace, std::memory_order_relaxed);
   h->grace = grace;
 
   if (suicide_grace > ceph::timespan::zero()) {
-    h->suicide_timeout = now + suicide_grace;
+    h->suicide_timeout.store(now + suicide_grace, std::memory_order_relaxed);
   } else {
-    h->suicide_timeout = clock::zero();
+    h->suicide_timeout.store(clock::zero(), std::memory_order_relaxed);
   }
   h->suicide_grace = suicide_grace;
 }
@@ -112,8 +112,8 @@ void HeartbeatMap::clear_timeout(heartbeat_handle_d *h)
   ldout(m_cct, 20) << "clear_timeout '" << h->name << "'" << dendl;
   auto now = clock::now();
   _check(h, "clear_timeout", now);
-  h->timeout = clock::zero();
-  h->suicide_timeout = clock::zero();
+  h->timeout.store(clock::zero(), std::memory_order_relaxed);
+  h->suicide_timeout.store(clock::zero(), std::memory_order_relaxed);
 }
 
 bool HeartbeatMap::is_healthy()