Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions include/h2o/socket/evloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ typedef struct st_h2o_evloop_t {
struct st_h2o_evloop_socket_t *head;
struct st_h2o_evloop_socket_t **tail_ref;
} _statechanged;
uint64_t _now;
uint64_t _now_millisec;
uint64_t _now_nanosec;
struct timeval _tv_at;
h2o_timerwheel_t *_timeouts;
h2o_sliding_counter_t exec_time_counter;
Expand Down Expand Up @@ -79,7 +80,12 @@ static inline struct timeval h2o_gettimeofday(h2o_evloop_t *loop)

static inline uint64_t h2o_now(h2o_evloop_t *loop)
{
return loop->_now;
return loop->_now_millisec;
}

static inline uint64_t h2o_now_nanosec(h2o_evloop_t *loop)
{
return loop->_now_nanosec;
}

static inline uint64_t h2o_evloop_get_execution_time(h2o_evloop_t *loop)
Expand All @@ -89,7 +95,7 @@ static inline uint64_t h2o_evloop_get_execution_time(h2o_evloop_t *loop)

inline void h2o_timer_link(h2o_evloop_t *loop, uint64_t delay_ticks, h2o_timer_t *timer)
{
h2o_timerwheel_link_abs(loop->_timeouts, timer, loop->_now + delay_ticks);
h2o_timerwheel_link_abs(loop->_timeouts, timer, loop->_now_millisec + delay_ticks);
}

#endif
5 changes: 5 additions & 0 deletions include/h2o/socket/uv-binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ static inline uint64_t h2o_now(h2o_loop_t *loop)
return uv_now(loop);
}

static inline uint64_t h2o_now_nanosec(h2o_loop_t *loop)
{
return uv_now(loop) * 1000000;
}

inline void h2o_timer_init(h2o_timer_t *timer, h2o_timer_cb cb)
{
memset(timer, 0, sizeof(*timer));
Expand Down
13 changes: 7 additions & 6 deletions lib/common/socket/evloop.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,16 @@ h2o_evloop_t *create_evloop(size_t sz)
loop->_statechanged.tail_ref = &loop->_statechanged.head;
update_now(loop);
/* 3 levels * 32-slots => 1 second goes into 2nd, becomes O(N) above approx. 31 seconds */
loop->_timeouts = h2o_timerwheel_create(3, loop->_now);
loop->_timeouts = h2o_timerwheel_create(3, loop->_now_millisec);

return loop;
}

void update_now(h2o_evloop_t *loop)
{
gettimeofday(&loop->_tv_at, NULL);
loop->_now = (uint64_t)loop->_tv_at.tv_sec * 1000 + loop->_tv_at.tv_usec / 1000;
loop->_now_nanosec = ((uint64_t)loop->_tv_at.tv_sec * 1000000 + loop->_tv_at.tv_usec) * 1000;
loop->_now_millisec = loop->_now_nanosec / 1000000;
}

int32_t adjust_max_wait(h2o_evloop_t *loop, int32_t max_wait)
Expand All @@ -484,10 +485,10 @@ int32_t adjust_max_wait(h2o_evloop_t *loop, int32_t max_wait)

update_now(loop);

if (wake_at <= loop->_now) {
if (wake_at <= loop->_now_millisec) {
max_wait = 0;
} else {
uint64_t delta = wake_at - loop->_now;
uint64_t delta = wake_at - loop->_now_millisec;
if (delta < max_wait)
max_wait = (int32_t)delta;
}
Expand Down Expand Up @@ -606,7 +607,7 @@ int h2o_evloop_run(h2o_evloop_t *loop, int32_t max_wait)
while (1) {
h2o_linklist_t expired;
h2o_linklist_init_anchor(&expired);
h2o_timerwheel_get_expired(loop->_timeouts, loop->_now, &expired);
h2o_timerwheel_get_expired(loop->_timeouts, loop->_now_millisec, &expired);
if (h2o_linklist_is_empty(&expired))
break;
do {
Expand All @@ -622,7 +623,7 @@ int h2o_evloop_run(h2o_evloop_t *loop, int32_t max_wait)

if (h2o_sliding_counter_is_running(&loop->exec_time_counter)) {
update_now(loop);
h2o_sliding_counter_stop(&loop->exec_time_counter, loop->_now);
h2o_sliding_counter_stop(&loop->exec_time_counter, loop->_now_millisec);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/common/socket/evloop/epoll.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ int evloop_do_proceed(h2o_evloop_t *_loop, int32_t max_wait)
return -1;

if (nevents != 0)
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now);
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now_millisec);

/* update readable flags, perform writes */
for (i = 0; i != nevents; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/socket/evloop/kqueue.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ int evloop_do_proceed(h2o_evloop_t *_loop, int32_t max_wait)
return -1;

if (nevents != 0)
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now);
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now_millisec);

/* update readable flags, perform writes */
for (i = 0; i != nevents; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion lib/common/socket/evloop/poll.c.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int evloop_do_proceed(h2o_evloop_t *_loop, int32_t max_wait)
/* update readable flags, perform writes */
if (ret > 0) {
size_t i;
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now);
h2o_sliding_counter_start(&loop->super.exec_time_counter, loop->super._now_millisec);
for (i = 0; i != pollfds.size; ++i) {
/* set read_ready flag before calling the write cb, since app. code invoked by the latter may close the socket, clearing
* the former flag */
Expand Down