mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: poller: move time and date computation out of the pollers
By placing this code into time.h (tv_entering_poll() and tv_leaving_poll()) we can remove the logic from the pollers and prepare for extending this to offer more accurate time measurements.
This commit is contained in:
parent
f37ba94768
commit
7e9c4ae4de
@ -543,6 +543,25 @@ static inline void measure_idle()
|
||||
idle_time = samp_time = 0;
|
||||
}
|
||||
|
||||
/* Collect date and time information before calling poll(). This will be used
|
||||
* to count the run time of the past loop and the sleep time of the next poll.
|
||||
*/
|
||||
static inline void tv_entering_poll()
|
||||
{
|
||||
gettimeofday(&before_poll, NULL);
|
||||
}
|
||||
|
||||
/* Collect date and time information after leaving poll(). <timeout> must be
|
||||
* set to the maximum sleep time passed to poll (in milliseconds), and
|
||||
* <interrupted> must be zero if the poller reached the timeout or non-zero
|
||||
* otherwise, which generally is provided by the poller's return value.
|
||||
*/
|
||||
static inline void tv_leaving_poll(int timeout, int interrupted)
|
||||
{
|
||||
tv_update_date(timeout, interrupted);
|
||||
measure_idle();
|
||||
}
|
||||
|
||||
#endif /* _COMMON_TIME_H */
|
||||
|
||||
/*
|
||||
|
@ -146,10 +146,9 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
|
||||
/* now let's wait for polled events */
|
||||
wait_time = compute_poll_timeout(exp);
|
||||
gettimeofday(&before_poll, NULL);
|
||||
tv_entering_poll();
|
||||
status = epoll_wait(epoll_fd[tid], epoll_events, global.tune.maxpollevents, wait_time);
|
||||
tv_update_date(wait_time, status);
|
||||
measure_idle();
|
||||
tv_leaving_poll(wait_time, status);
|
||||
|
||||
thread_harmless_end();
|
||||
|
||||
|
@ -134,15 +134,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
timeout.tv_sec = (delta_ms / 1000);
|
||||
timeout.tv_nsec = (delta_ms % 1000) * 1000000;
|
||||
fd = global.tune.maxpollevents;
|
||||
gettimeofday(&before_poll, NULL);
|
||||
tv_entering_poll();
|
||||
status = kevent(kqueue_fd[tid], // int kq
|
||||
NULL, // const struct kevent *changelist
|
||||
0, // int nchanges
|
||||
kev, // struct kevent *eventlist
|
||||
fd, // int nevents
|
||||
&timeout); // const struct timespec *timeout
|
||||
tv_update_date(delta_ms, status);
|
||||
measure_idle();
|
||||
tv_leaving_poll(delta_ms, status);
|
||||
|
||||
thread_harmless_end();
|
||||
|
||||
|
@ -194,10 +194,9 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
|
||||
/* now let's wait for events */
|
||||
wait_time = compute_poll_timeout(exp);
|
||||
gettimeofday(&before_poll, NULL);
|
||||
tv_entering_poll();
|
||||
status = poll(poll_events, nbfd, wait_time);
|
||||
tv_update_date(wait_time, status);
|
||||
measure_idle();
|
||||
tv_leaving_poll(wait_time, status);
|
||||
|
||||
thread_harmless_end();
|
||||
|
||||
|
@ -164,15 +164,13 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
||||
delta_ms = compute_poll_timeout(exp);
|
||||
delta.tv_sec = (delta_ms / 1000);
|
||||
delta.tv_usec = (delta_ms % 1000) * 1000;
|
||||
gettimeofday(&before_poll, NULL);
|
||||
tv_entering_poll();
|
||||
status = select(maxfd,
|
||||
readnotnull ? tmp_evts[DIR_RD] : NULL,
|
||||
writenotnull ? tmp_evts[DIR_WR] : NULL,
|
||||
NULL,
|
||||
&delta);
|
||||
|
||||
tv_update_date(delta_ms, status);
|
||||
measure_idle();
|
||||
tv_leaving_poll(delta_ms, status);
|
||||
|
||||
thread_harmless_end();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user