]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
msg: use deque for dispatcher pointers
authorPatrick Donnelly <pdonnell@redhat.com>
Sun, 29 Jul 2018 19:18:09 +0000 (12:18 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 15 Aug 2018 04:20:55 +0000 (21:20 -0700)
To improve cache locality.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/msg/Messenger.h

index 52bc323fede2bb8bb196669241745643b3319ccc..491b3df830f0e8a76d6b65e1828497b7dd138638 100644 (file)
@@ -18,6 +18,7 @@
 #define CEPH_MESSENGER_H
 
 #include <map>
+#include <deque>
 
 #include "Message.h"
 #include "Dispatcher.h"
@@ -41,8 +42,8 @@ class Timer;
 
 class Messenger {
 private:
-  list<Dispatcher*> dispatchers;
-  list <Dispatcher*> fast_dispatchers;
+  std::deque<Dispatcher*> dispatchers;
+  std::deque<Dispatcher*> fast_dispatchers;
   ZTracer::Endpoint trace_endpoint;
 
 protected:
@@ -593,11 +594,9 @@ public:
    *
    * @param m The Message we are testing.
    */
-  bool ms_can_fast_dispatch(const Message *m) {
-    for (list<Dispatcher*>::iterator p = fast_dispatchers.begin();
-        p != fast_dispatchers.end();
-        ++p) {
-      if ((*p)->ms_can_fast_dispatch(m))
+  bool ms_can_fast_dispatch(const Message* m) {
+    for (const auto &dispatcher : fast_dispatchers) {
+      if (dispatcher->ms_can_fast_dispatch(m))
        return true;
     }
     return false;
@@ -610,13 +609,11 @@ public:
    * of one reference to it.
    * If none of our Dispatchers can handle it, ceph_abort().
    */
-  void ms_fast_dispatch(Message *m) {
+  void ms_fast_dispatch(Messagem) {
     m->set_dispatch_stamp(ceph_clock_now());
-    for (list<Dispatcher*>::iterator p = fast_dispatchers.begin();
-        p != fast_dispatchers.end();
-        ++p) {
-      if ((*p)->ms_can_fast_dispatch(m)) {
-       (*p)->ms_fast_dispatch(m);
+    for (const auto &dispatcher : fast_dispatchers) {
+      if (dispatcher->ms_can_fast_dispatch(m)) {
+       dispatcher->ms_fast_dispatch(m);
        return;
       }
     }
@@ -625,11 +622,9 @@ public:
   /**
    *
    */
-  void ms_fast_preprocess(Message *m) {
-    for (list<Dispatcher*>::iterator p = fast_dispatchers.begin();
-        p != fast_dispatchers.end();
-        ++p) {
-      (*p)->ms_fast_preprocess(m);
+  void ms_fast_preprocess(Message* m) {
+    for (const auto &dispatcher : fast_dispatchers) {
+      dispatcher->ms_fast_preprocess(m);
     }
   }
   /**
@@ -640,12 +635,10 @@ public:
    *  @param m The Message to deliver. We take ownership of
    *  one reference to it.
    */
-  void ms_deliver_dispatch(Message *m) {
+  void ms_deliver_dispatch(Messagem) {
     m->set_dispatch_stamp(ceph_clock_now());
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p) {
-      if ((*p)->ms_dispatch(m))
+    for (const auto &dispatcher : dispatchers) {
+      if (dispatcher->ms_dispatch(m))
        return;
     }
     lsubdout(cct, ms, 0) << "ms_deliver_dispatch: unhandled message " << m << " " << *m << " from "
@@ -661,10 +654,9 @@ public:
    * @param con Pointer to the new Connection.
    */
   void ms_deliver_handle_connect(Connection *con) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p)
-      (*p)->ms_handle_connect(con);
+    for (const auto& dispatcher : dispatchers) {
+      dispatcher->ms_handle_connect(con);
+    }
   }
 
   /**
@@ -675,10 +667,9 @@ public:
    * @param con Pointer to the new Connection.
    */
   void ms_deliver_handle_fast_connect(Connection *con) {
-    for (list<Dispatcher*>::iterator p = fast_dispatchers.begin();
-         p != fast_dispatchers.end();
-         ++p)
-      (*p)->ms_handle_fast_connect(con);
+    for (const auto& dispatcher : fast_dispatchers) {
+      dispatcher->ms_handle_fast_connect(con);
+    }
   }
 
   /**
@@ -688,10 +679,9 @@ public:
    * @param con Pointer to the new Connection.
    */
   void ms_deliver_handle_accept(Connection *con) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p)
-      (*p)->ms_handle_accept(con);
+    for (const auto& dispatcher : dispatchers) {
+      dispatcher->ms_handle_accept(con);
+    }
   }
 
   /**
@@ -701,10 +691,9 @@ public:
    * @param con Pointer to the new Connection.
    */
   void ms_deliver_handle_fast_accept(Connection *con) {
-    for (list<Dispatcher*>::iterator p = fast_dispatchers.begin();
-         p != fast_dispatchers.end();
-         ++p)
-      (*p)->ms_handle_fast_accept(con);
+    for (const auto& dispatcher : fast_dispatchers) {
+      dispatcher->ms_handle_fast_accept(con);
+    }
   }
 
   /**
@@ -715,10 +704,8 @@ public:
    * @param con Pointer to the broken Connection.
    */
   void ms_deliver_handle_reset(Connection *con) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p) {
-      if ((*p)->ms_handle_reset(con))
+    for (const auto& dispatcher : dispatchers) {
+      if (dispatcher->ms_handle_reset(con))
        return;
     }
   }
@@ -730,10 +717,9 @@ public:
    * @param con Pointer to the broken Connection.
    */
   void ms_deliver_handle_remote_reset(Connection *con) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p)
-      (*p)->ms_handle_remote_reset(con);
+    for (const auto& dispatcher : dispatchers) {
+      dispatcher->ms_handle_remote_reset(con);
+    }
   }
 
   /**
@@ -745,10 +731,8 @@ public:
    * @param con Pointer to the broken Connection.
    */
   void ms_deliver_handle_refused(Connection *con) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-         p != dispatchers.end();
-         ++p) {
-      if ((*p)->ms_handle_refused(con))
+    for (const auto& dispatcher : dispatchers) {
+      if (dispatcher->ms_handle_refused(con))
         return;
     }
   }
@@ -762,10 +746,8 @@ public:
    */
   AuthAuthorizer *ms_deliver_get_authorizer(int peer_type, bool force_new) {
     AuthAuthorizer *a = 0;
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p) {
-      if ((*p)->ms_get_authorizer(peer_type, &a, force_new))
+    for (const auto& dispatcher : dispatchers) {
+      if (dispatcher->ms_get_authorizer(peer_type, &a, force_new))
        return a;
     }
     return NULL;
@@ -788,11 +770,9 @@ public:
                                    int protocol, bufferlist& authorizer, bufferlist& authorizer_reply,
                                    bool& isvalid, CryptoKey& session_key,
                                    std::unique_ptr<AuthAuthorizerChallenge> *challenge) {
-    for (list<Dispatcher*>::iterator p = dispatchers.begin();
-        p != dispatchers.end();
-        ++p) {
-      if ((*p)->ms_verify_authorizer(con, peer_type, protocol, authorizer, authorizer_reply,
-                                    isvalid, session_key, challenge))
+    for (const auto& dispatcher : dispatchers) {
+      if (dispatcher->ms_verify_authorizer(con, peer_type, protocol, authorizer, authorizer_reply,
+                                           isvalid, session_key, challenge))
        return true;
     }
     return false;