From: Haomai Wang Date: Sat, 20 Sep 2014 08:09:19 +0000 (+0800) Subject: Event: Change time precision from millisecond to microsecond X-Git-Tag: v0.88~37^2~4^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=19a9d9531fab4627cafbb2915566c512c41077a8;p=ceph.git Event: Change time precision from millisecond to microsecond Signed-off-by: Haomai Wang --- diff --git a/src/msg/AsyncConnection.cc b/src/msg/AsyncConnection.cc index a9fc8f2b6f81..730eb57fe911 100644 --- a/src/msg/AsyncConnection.cc +++ b/src/msg/AsyncConnection.cc @@ -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() diff --git a/src/msg/AsyncMessenger.cc b/src/msg/AsyncMessenger.cc index f5c5ddfeb609..0a7f82b80688 100644 --- a/src/msg/AsyncMessenger.cc +++ b/src/msg/AsyncMessenger.cc @@ -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; diff --git a/src/msg/Event.cc b/src/msg/Event.cc index c98021944afe..4fa714e9ec51 100644 --- a/src/msg/Event.cc +++ b/src/msg/Event.cc @@ -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::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; diff --git a/src/msg/Event.h b/src/msg/Event.h index d761ea874e51..b956298c75e8 100644 --- a/src/msg/Event.h +++ b/src/msg/Event.h @@ -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