crimson/net: utilize lowres_system_clock with better performance
authorYingxin Cheng <yingxincheng@gmail.com>
Mon, 1 Apr 2019 14:05:42 +0000 (22:05 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 5 Apr 2019 03:21:19 +0000 (11:21 +0800)
Signed-off-by: Yingxin Cheng <yingxincheng@gmail.com>
src/crimson/net/ProtocolV2.cc
src/include/utime.h

index 6ac9caf3cc7d6b3f648c1ac037d030a4be81ade5..da096a68664c1a2126651484b7ea8d276262388d 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "ProtocolV2.h"
 
+#include <seastar/core/lowres_clock.hh>
+
 #include "include/msgr.h"
 #include "include/random.h"
 
@@ -1387,7 +1389,7 @@ seastar::future<> ProtocolV2::read_message(utime_t throttle_stamp)
 {
   return read_frame_payload()
   .then([this, throttle_stamp] {
-    utime_t recv_stamp = ceph_clock_now();
+    utime_t recv_stamp{seastar::lowres_system_clock::now()};
 
     // we need to get the size before std::moving segments data
     const size_t cur_msg_size = get_current_msg_size();
@@ -1429,7 +1431,7 @@ seastar::future<> ProtocolV2::read_message(utime_t throttle_stamp)
 
     message->set_throttle_stamp(throttle_stamp);
     message->set_recv_stamp(recv_stamp);
-    message->set_recv_complete_stamp(ceph_clock_now());
+    message->set_recv_complete_stamp(utime_t{seastar::lowres_system_clock::now()});
 
     // check received seq#.  if it is old, drop the message.
     // note that incoming messages may skip ahead.  this is convenient for the
@@ -1512,7 +1514,7 @@ void ProtocolV2::execute_ready()
               return conn.policy.throttler_bytes->get(cur_msg_size);
             }).then([this] {
               // TODO: throttle_dispatch_queue() logic
-              utime_t throttle_stamp = ceph_clock_now();
+              utime_t throttle_stamp{seastar::lowres_system_clock::now()};
               return read_message(throttle_stamp);
             });
           }
@@ -1531,7 +1533,7 @@ void ProtocolV2::execute_ready()
               last_keepalive_ack_to_send = keepalive_frame.timestamp();
               logger().debug("{} got KEEPALIVE2 {}",
                              conn, last_keepalive_ack_to_send);
-              conn.last_keepalive = ceph_clock_now();
+              conn.last_keepalive = utime_t{seastar::lowres_system_clock::now()};
               notify_keepalive_ack();
             });
           case Tag::KEEPALIVE2_ACK:
index bc9f6429a12c1be8e4198b844886b40e5e39f2f4..3d852b4587a828fd3cbbdfbc1fbbe1406f8be010 100644 (file)
 #include <time.h>
 #include <errno.h>
 
+#if defined(WITH_SEASTAR)
+#include <seastar/core/lowres_clock.hh>
+#endif
+
 #include "include/types.h"
 #include "include/timegm.h"
 #include "common/strtol.h"
@@ -77,6 +81,15 @@ public:
   explicit utime_t(const std::chrono::time_point<Clock>& t)
     : utime_t(Clock::to_timespec(t)) {} // forward to timespec ctor
 
+#if defined(WITH_SEASTAR)
+  explicit utime_t(const seastar::lowres_system_clock::time_point& t) {
+    tv.tv_sec = std::time_t(std::chrono::duration_cast<std::chrono::seconds>(
+        t.time_since_epoch()).count());
+    tv.tv_nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(
+        t.time_since_epoch() % std::chrono::seconds(1)).count();
+  }
+#endif
+
   utime_t(const struct timeval &v) {
     set_from_timeval(&v);
   }