mirror of
https://github.com/ceph/ceph
synced 2025-02-22 10:37:15 +00:00
Event: Change time precision from millisecond to microsecond
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
This commit is contained in:
parent
b9c86a31a5
commit
19a9d9531f
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user