]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Event: Change time precision from millisecond to microsecond
authorHaomai Wang <haomaiwang@gmail.com>
Sat, 20 Sep 2014 08:09:19 +0000 (16:09 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Wed, 8 Oct 2014 06:04:59 +0000 (14:04 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/msg/AsyncConnection.cc
src/msg/AsyncMessenger.cc
src/msg/Event.cc
src/msg/Event.h

index a9fc8f2b6f81fb7338daca167b3799077de78237..730eb57fe911f4813ae9bd2cce5808bb0feb09d2 100644 (file)
@@ -695,7 +695,7 @@ void AsyncConnection::process()
             async_msgr->ms_fast_dispatch(message);
             lock.Lock();
           } else {
-            center->create_time_event(0, EventCallbackRef(new C_handle_dispatch(async_msgr, message)));
+            center->create_time_event(1, EventCallbackRef(new C_handle_dispatch(async_msgr, message)));
           }
 
           break;
@@ -1765,9 +1765,8 @@ void AsyncConnection::fault()
     ldout(async_msgr->cct, 10) << __func__ << " waiting " << backoff << dendl;
   }
 
-  uint64_t milliseconds = double(backoff) * 1000;
   // woke up again;
-  center->create_time_event(milliseconds, read_handler);
+  center->create_time_event(backoff, read_handler);
 }
 
 void AsyncConnection::was_session_reset()
index f5c5ddfeb609873cce37c4ac73ecbd088d866662..0a7f82b8068828e375e3dbf8f63197b91f5fde61 100644 (file)
@@ -282,7 +282,7 @@ void *Worker::entry()
   while (!done) {
     ldout(msgr->cct, 20) << __func__ << " calling event process" << dendl;
 
-    r = center.process_events(30000);
+    r = center.process_events(30000000);
     if (r < 0) {
       ldout(msgr->cct,20) << __func__ << " process events failed: "
                           << cpp_strerror(errno) << dendl;
index c98021944afeceacf2f0da1124d4a6f5f8537b14..4fa714e9ec513af0fce63566100eff47be683303 100644 (file)
@@ -136,19 +136,19 @@ void EventCenter::delete_file_event(int fd, int mask)
                  << " now mask is " << event->mask << dendl;
 }
 
-uint64_t EventCenter::create_time_event(uint64_t milliseconds, EventCallbackRef ctxt)
+uint64_t EventCenter::create_time_event(uint64_t microseconds, EventCallbackRef ctxt)
 {
   uint64_t id = time_event_next_id++;
 
-  ldout(cct, 10) << __func__ << " id=" << id << " expire time=" << milliseconds << dendl;
+  ldout(cct, 10) << __func__ << " id=" << id << " trigger after " << microseconds << "us"<< dendl;
   EventCenter::TimeEvent event;
   utime_t expire;
   struct timeval tv;
 
   expire = ceph_clock_now(cct);
   expire.copy_to_timeval(&tv);
-  tv.tv_sec += milliseconds / 1000;
-  tv.tv_usec += (milliseconds % 1000) * 1000;
+  tv.tv_sec += microseconds / 1000000;
+  tv.tv_usec += microseconds % 1000000;
   expire.set_from_timeval(&tv);
 
   event.id = id;
@@ -231,7 +231,7 @@ int EventCenter::process_time_events()
   return processed;
 }
 
-int EventCenter::process_events(int timeout_millionseconds)
+int EventCenter::process_events(int timeout_microseconds)
 {
   struct timeval tv;
   int numevents;
@@ -239,23 +239,28 @@ int EventCenter::process_events(int timeout_millionseconds)
 
   utime_t period, shortest, now = ceph_clock_now(cct);
   now.copy_to_timeval(&tv);
-  if (timeout_millionseconds > 0) {
-    tv.tv_sec += timeout_millionseconds / 1000;
-    tv.tv_usec += (timeout_millionseconds % 1000) * 1000;
+  if (timeout_microseconds > 0) {
+    tv.tv_sec += timeout_microseconds / 1000000;
+    tv.tv_usec += timeout_microseconds % 1000000;
   }
   shortest.set_from_timeval(&tv);
 
   {
     map<utime_t, uint64_t>::iterator it = time_to_ids.begin();
-    if (it != time_to_ids.end() && shortest > it->first) {
+    if (it != time_to_ids.end() && shortest >= it->first) {
       ldout(cct, 10) << __func__ << " shortest is " << shortest << " it->first is " << it->first << dendl;
       shortest = it->first;
       trigger_time = true;
-      period = now - shortest;
-      period.copy_to_timeval(&tv);
+      if (shortest > now) {
+        period = now - shortest;
+        period.copy_to_timeval(&tv);
+      } else {
+        tv.tv_sec = 0;
+        tv.tv_usec = 0;
+      }
     } else {
-      tv.tv_sec = timeout_millionseconds / 1000;
-      tv.tv_usec = (timeout_millionseconds % 1000) * 1000;
+      tv.tv_sec = timeout_microseconds / 1000000;
+      tv.tv_usec = timeout_microseconds % 1000000;
     }
 
     next_wake = shortest;
index d761ea874e51c3934255a22d64031945903975ad..b956298c75e84ff0e88aed003f2837b4874eec78 100644 (file)
@@ -113,7 +113,7 @@ class EventCenter {
   uint64_t create_time_event(uint64_t milliseconds, EventCallbackRef ctxt);
   void delete_file_event(int fd, int mask);
   void delete_time_event(uint64_t id);
-  int process_events(int timeout_milliseconds);
+  int process_events(int timeout_microseconds);
   void wakeup();
 
   // Used by external thread