]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
Squashed 'src/dmclock/' changes from 93f760c57c..1bbd42b8fe
authorKefu Chai <kchai@redhat.com>
Thu, 19 Oct 2017 05:19:16 +0000 (13:19 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 19 Oct 2017 05:19:16 +0000 (13:19 +0800)
1bbd42b8fe Merge pull request #41 from tchaikov/wip-client-info-ptr
cb7901e99a ClientRec: instead of a copy of ClientInfo, keep a pointer of it

git-subtree-dir: src/dmclock
git-subtree-split: 1bbd42b8fe212dbff68c2b470813e936859705d6

sim/src/test_dmclock_main.cc
src/dmclock_server.h
test/test_dmclock_server.cc

index f59b735465ba20f13f2ecb82a110e7e74fe1d87e..ce9a31e404e84398293526cdd0d69d4e0a3473af 100644 (file)
@@ -118,8 +118,8 @@ int main(int argc, char* argv[]) {
       return i;
     };
 
-    auto client_info_f = [=](const ClientId& c) -> test::dmc::ClientInfo {
-      return client_info[ret_client_group_f(c)];
+    auto client_info_f = [=](const ClientId& c) -> const test::dmc::ClientInfo* {
+      return &client_info[ret_client_group_f(c)];
     };
 
     auto client_disp_filter = [=] (const ClientId& i) -> bool {
index 8f0e1925e05c3ae084860ea41d60d3143441299b..b3178c52a0909101022545e66f16c617bf6571e2 100644 (file)
@@ -305,14 +305,14 @@ namespace crimson {
 
       public:
 
-       ClientInfo            info;
+       const ClientInfo*     info;
        bool                  idle;
        Counter               last_tick;
        uint32_t              cur_rho;
        uint32_t              cur_delta;
 
        ClientRec(C _client,
-                 const ClientInfo& _info,
+                 const ClientInfo* _info,
                  Counter current_tick) :
          client(_client),
          prev_tag(0.0, 0.0, 0.0, TimeZero),
@@ -474,7 +474,7 @@ namespace crimson {
 
 
       // a function that can be called to look up client information
-      using ClientInfoFunc = std::function<ClientInfo(const C&)>;
+      using ClientInfoFunc = std::function<const ClientInfo*(const C&)>;
 
 
       bool empty() const {
@@ -788,7 +788,7 @@ namespace crimson {
       }
 
 
-      inline const ClientInfo get_cli_info(ClientRec& client) const {
+      inline const ClientInfo* get_cli_info(ClientRec& client) const {
        if (is_dynamic_cli_info_f) {
          client.info = client_info_f(client.client);
        }
@@ -812,7 +812,7 @@ namespace crimson {
        if (client_map.end() != client_it) {
          temp_client = &(*client_it->second); // address of obj of shared_ptr
        } else {
-         ClientInfo info = client_info_f(client_id);
+         const ClientInfo* info = client_info_f(client_id);
          ClientRecRef client_rec =
            std::make_shared<ClientRec>(client_id, info, tick);
          resv_heap.push(client_rec);
@@ -882,8 +882,10 @@ namespace crimson {
        RequestTag tag(0, 0, 0, time);
 
        if (!client.has_request()) {
+         const ClientInfo* client_info = get_cli_info(client);
+         assert(client_info);
          tag = RequestTag(client.get_req_tag(),
-                          get_cli_info(client),
+                          *client_info,
                           req_params,
                           time,
                           cost,
@@ -893,8 +895,10 @@ namespace crimson {
          client.update_req_tag(tag, tick);
        }
 #else
+       const ClientInfo* client_info = get_cli_info(client);
+       assert(client_info);
        RequestTag tag(client.get_req_tag(),
-                      get_cli_info(client),
+                      *client_info,
                       req_params,
                       time,
                       cost,
@@ -949,7 +953,9 @@ namespace crimson {
 #ifndef DO_NOT_DELAY_TAG_CALC
        if (top.has_request()) {
          ClientReq& next_first = top.next_request();
-         next_first.tag = RequestTag(tag, get_cli_info(top),
+         const ClientInfo* client_info = get_cli_info(top);
+         assert(client_info);
+         next_first.tag = RequestTag(tag, *client_info,
                                      top.cur_delta, top.cur_rho,
                                      next_first.tag.arrival,
                                       0.0, anticipation_timeout);
@@ -974,7 +980,7 @@ namespace crimson {
       // data_mtx should be held when called
       void reduce_reservation_tags(ClientRec& client) {
        for (auto& r : client.requests) {
-         r.tag.reservation -= client.info.reservation_inv;
+         r.tag.reservation -= client.info->reservation_inv;
 
 #ifndef DO_NOT_DELAY_TAG_CALC
          // reduce only for front tag. because next tags' value are invalid
@@ -982,7 +988,7 @@ namespace crimson {
 #endif
        }
        // don't forget to update previous tag
-       client.prev_tag.reservation -= client.info.reservation_inv;
+       client.prev_tag.reservation -= client.info->reservation_inv;
        resv_heap.promote(client);
       }
 
index 1d74e58683b82a12739429373676134f4aa4d916..7e6e13463ba950bfc239e8c1e2846ce9425d4c43 100644 (file)
@@ -54,12 +54,12 @@ namespace crimson {
       dmc::ClientInfo ci1(reservation, weight, 0.0);
       dmc::ClientInfo ci2(reservation, weight, 1.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return ci1;
-       else if (client2 == c) return ci2;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &ci1;
+       else if (client2 == c) return &ci2;
        else {
          ADD_FAILURE() << "got request from neither of two clients";
-         return ci1; // must return
+         return nullptr;
        }
       };
 
@@ -91,7 +91,9 @@ namespace crimson {
       double reservation = 100.0;
 
       dmc::ClientInfo ci(reservation, 1.0, 0.0);
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo { return ci; };
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &ci;
+      };
       auto server_ready_f = [] () -> bool { return true; };
       auto submit_req_f = [] (const ClientId& c,
                              std::unique_ptr<Request> req,
@@ -186,7 +188,9 @@ namespace crimson {
       dmc::ClientInfo ci(1.0, 0.0, 0.0);
       Queue pq;
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo { return ci; };
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &ci;
+      };
       auto server_ready_f = [] () -> bool { return true; };
       auto submit_req_f = [&] (const ClientId& c,
                               std::unique_ptr<Request> req,
@@ -241,8 +245,8 @@ namespace crimson {
 
       dmc::ClientInfo info1(0.0, 1.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info1;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info1;
       };
 
       Queue pq(client_info_f, true);
@@ -309,8 +313,8 @@ namespace crimson {
 
       dmc::ClientInfo info1(0.0, 1.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info1;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info1;
       };
 
       Queue pq(client_info_f, true);
@@ -391,8 +395,8 @@ namespace crimson {
 
       dmc::ClientInfo info1(0.0, 1.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info1;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info1;
       };
 
       Queue pq(client_info_f, true);
@@ -473,8 +477,8 @@ namespace crimson {
 
       dmc::ClientInfo info1(0.0, 1.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info1;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info1;
       };
 
       Queue pq(client_info_f, true);
@@ -542,12 +546,12 @@ namespace crimson {
 
       QueueRef pq;
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return info1;
-       else if (client2 == c) return info2;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &info1;
+       else if (client2 == c) return &info2;
        else {
          ADD_FAILURE() << "client info looked up for non-existant client";
-         return info1;
+         return nullptr;
        }
       };
 
@@ -595,12 +599,12 @@ namespace crimson {
       dmc::ClientInfo info1(2.0, 0.0, 0.0);
       dmc::ClientInfo info2(1.0, 0.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return info1;
-       else if (client2 == c) return info2;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &info1;
+       else if (client2 == c) return &info2;
        else {
          ADD_FAILURE() << "client info looked up for non-existant client";
-         return info1;
+         return nullptr;
        }
       };
 
@@ -652,12 +656,12 @@ namespace crimson {
 
       QueueRef pq;
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return info1;
-       else if (client2 == c) return info2;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &info1;
+       else if (client2 == c) return &info2;
        else {
          ADD_FAILURE() << "client info looked up for non-existant client";
-         return info1;
+         return nullptr;
        }
       };
 
@@ -749,12 +753,12 @@ namespace crimson {
 
       QueueRef pq;
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return info1[cli_info_group];
-       else if (client2 == c) return info2[cli_info_group];
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &info1[cli_info_group];
+       else if (client2 == c) return &info2[cli_info_group];
        else {
          ADD_FAILURE() << "client info looked up for non-existant client";
-         return info1[0];
+         return nullptr;
        }
       };
 
@@ -838,12 +842,12 @@ namespace crimson {
       dmc::ClientInfo info1(1.0, 0.0, 0.0);
       dmc::ClientInfo info2(1.0, 0.0, 0.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       if (client1 == c) return info1;
-       else if (client2 == c) return info2;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       if (client1 == c) return &info1;
+       else if (client2 == c) return &info2;
        else {
          ADD_FAILURE() << "client info looked up for non-existant client";
-         return info1;
+         return nullptr;
        }
       };
 
@@ -898,8 +902,8 @@ namespace crimson {
 
       dmc::ClientInfo info(1.0, 1.0, 1.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info;
       };
 
       QueueRef pq(new Queue(client_info_f, false));
@@ -925,8 +929,8 @@ namespace crimson {
 
       dmc::ClientInfo info(1.0, 0.0, 1.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info;
       };
 
       QueueRef pq(new Queue(client_info_f, false));
@@ -956,8 +960,8 @@ namespace crimson {
 
       dmc::ClientInfo info(0.0, 1.0, 1.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info;
       };
 
       QueueRef pq(new Queue(client_info_f, true));
@@ -987,8 +991,8 @@ namespace crimson {
 
       dmc::ClientInfo info(1.0, 0.0, 1.0);
 
-      auto client_info_f = [&] (ClientId c) -> dmc::ClientInfo {
-       return info;
+      auto client_info_f = [&] (ClientId c) -> const dmc::ClientInfo* {
+       return &info;
       };
 
       QueueRef pq(new Queue(client_info_f, true));