]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Revert "Merge pull request #8346 from yuyuyu101/wip-async-clock"
authorSage Weil <sage@redhat.com>
Sat, 30 Apr 2016 23:21:02 +0000 (19:21 -0400)
committerSage Weil <sage@redhat.com>
Sat, 30 Apr 2016 23:21:02 +0000 (19:21 -0400)
This reverts commit 37117823d108dcd5145421adc0121eea75633851, reversing
changes made to 5ff4988c09ccc2af6ff72f30d053b5864a8c8e14.

This broke the build:

msg/async/Event.cc: In member function 'int EventCenter::process_time_events()':
error: msg/async/Event.cc:280:30: cannot bind 'std::basic_ostream' lvalue to 'std::basic_ostream&&'
ldout(cct, 10) << __func__ << " cur time is " << now << dendl;
^

and elsewhere...

Signed-off-by: Sage Weil <sage@redhat.com>
src/msg/async/Event.cc
src/msg/async/Event.h

index 469ba4b0d90cce2b8c1286a959b1018bc19cc0da..0a34cfe2cbab50edbb9ed39e69a68ff7bbf3bcbd 100644 (file)
@@ -229,7 +229,20 @@ uint64_t EventCenter::create_time_event(uint64_t microseconds, EventCallbackRef
 
   ldout(cct, 10) << __func__ << " id=" << id << " trigger after " << microseconds << "us"<< dendl;
   EventCenter::TimeEvent event;
-  clock_type::time_point expire = clock_type::now() + std::chrono::microseconds(microseconds);
+  utime_t expire;
+  struct timeval tv;
+
+  if (microseconds < 5) {
+    tv.tv_sec = 0;
+    tv.tv_usec = microseconds;
+  } else {
+    expire = ceph_clock_now(cct);
+    expire.copy_to_timeval(&tv);
+    tv.tv_sec += microseconds / 1000000;
+    tv.tv_usec += microseconds % 1000000;
+  }
+  expire.set_from_timeval(&tv);
+
   event.id = id;
   event.time_cb = ctxt;
   time_events[expire].push_back(event);
@@ -247,7 +260,8 @@ void EventCenter::delete_time_event(uint64_t id)
   if (id >= time_event_next_id)
     return ;
 
-  for (auto it = time_events.begin(); it != time_events.end(); ++it) {
+  for (map<utime_t, list<TimeEvent> >::iterator it = time_events.begin();
+       it != time_events.end(); ++it) {
     for (list<TimeEvent>::iterator j = it->second.begin();
          j != it->second.end(); ++j) {
       if (j->id == id) {
@@ -276,8 +290,9 @@ void EventCenter::wakeup()
 int EventCenter::process_time_events()
 {
   int processed = 0;
-  clock_type::time_point now = clock_type::now();
-  ldout(cct, 10) << __func__ << " cur time is " << now << dendl;
+  time_t now = time(NULL);
+  utime_t cur = ceph_clock_now(cct);
+  ldout(cct, 10) << __func__ << " cur time is " << cur << dendl;
 
   time_lock.Lock();
   /* If the system clock is moved to the future, and then set back to the
@@ -288,14 +303,18 @@ int EventCenter::process_time_events()
    * events to be processed ASAP when this happens: the idea is that
    * processing events earlier is less dangerous than delaying them
    * indefinitely, and practice suggests it is. */
-  bool clock_skewed = now < last_time;
+  bool clock_skewed = false;
+  if (now < last_time) {
+    clock_skewed = true;
+  }
   last_time = now;
 
-  map<clock_type::time_point, list<TimeEvent> >::iterator prev;
+  map<utime_t, list<TimeEvent> >::iterator prev;
   list<TimeEvent> need_process;
-  for (auto it = time_events.begin(); it != time_events.end(); ) {
+  for (map<utime_t, list<TimeEvent> >::iterator it = time_events.begin();
+       it != time_events.end(); ) {
     prev = it;
-    if (now >= it->first || clock_skewed) {
+    if (cur >= it->first || clock_skewed) {
       need_process.splice(need_process.end(), it->second);
       ++it;
       time_events.erase(prev);
@@ -322,33 +341,39 @@ int EventCenter::process_events(int timeout_microseconds)
   struct timeval tv;
   int numevents;
   bool trigger_time = false;
-  auto now = clock_type::now();
 
+  utime_t now = ceph_clock_now(cct);;
   // If exists external events, don't block
   if (external_num_events.read()) {
     tv.tv_sec = 0;
     tv.tv_usec = 0;
     next_time = now;
   } else {
-    clock_type::time_point shortest;
-    shortest = now + std::chrono::microseconds(timeout_microseconds); 
+    utime_t period, shortest;
+    now.copy_to_timeval(&tv);
+    if (timeout_microseconds > 0) {
+      tv.tv_sec += timeout_microseconds / 1000000;
+      tv.tv_usec += timeout_microseconds % 1000000;
+    }
+    shortest.set_from_timeval(&tv);
 
     Mutex::Locker l(time_lock);
-    auto it = time_events.begin();
-    if (it != time_events.end() && shortest > it->first) {
+    map<utime_t, list<TimeEvent> >::iterator it = time_events.begin();
+    if (it != time_events.end() && shortest >= it->first) {
       ldout(cct, 10) << __func__ << " shortest is " << shortest << " it->first is " << it->first << dendl;
       shortest = it->first;
       trigger_time = true;
       if (shortest > now) {
-        timeout_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(
-            shortest - now).count();
+        period = shortest - now;
+        period.copy_to_timeval(&tv);
       } else {
-        shortest = now;
-        timeout_microseconds = 0;
+        tv.tv_sec = 0;
+        tv.tv_usec = 0;
       }
+    } else {
+      tv.tv_sec = timeout_microseconds / 1000000;
+      tv.tv_usec = timeout_microseconds % 1000000;
     }
-    tv.tv_sec = timeout_microseconds / 1000000;
-    tv.tv_usec = timeout_microseconds % 1000000;
     next_time = shortest;
   }
 
index 4618c156b0d927b3dc95df502fe376b5f3000e58..126a36c3120bec2f0ef863623954cbc4148dc020 100644 (file)
@@ -42,7 +42,6 @@
 #include "include/atomic.h"
 #include "include/Context.h"
 #include "include/unordered_map.h"
-#include "common/ceph_time.h"
 #include "common/WorkQueue.h"
 #include "net_handler.h"
 
@@ -86,7 +85,6 @@ class EventDriver {
  * EventCenter maintain a set of file descriptor and handle registered events.
  */
 class EventCenter {
-  using clock_type = ceph::coarse_mono_clock;
   struct FileEvent {
     int mask;
     EventCallbackRef read_cb;
@@ -109,10 +107,10 @@ class EventCenter {
   deque<EventCallbackRef> external_events;
   vector<FileEvent> file_events;
   EventDriver *driver;
-  map<clock_type::time_point, list<TimeEvent> > time_events;
+  map<utime_t, list<TimeEvent> > time_events;
   uint64_t time_event_next_id;
-  clock_type::time_point last_time; // last time process time event
-  clock_type::time_point next_time; // next wake up time
+  time_t last_time; // last time process time event
+  utime_t next_time; // next wake up time
   int notify_receive_fd;
   int notify_send_fd;
   NetHandler net;
@@ -138,7 +136,7 @@ class EventCenter {
     notify_receive_fd(-1), notify_send_fd(-1), net(c), owner(0),
     notify_handler(NULL),
     already_wakeup(0) {
-    last_time = clock_type::now();
+    last_time = time(NULL);
   }
   ~EventCenter();
   ostream& _event_prefix(std::ostream *_dout);