mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-11 01:26:58 +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;
|
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 */
|
#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 */
|
/* now let's wait for polled events */
|
||||||
wait_time = compute_poll_timeout(exp);
|
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);
|
status = epoll_wait(epoll_fd[tid], epoll_events, global.tune.maxpollevents, wait_time);
|
||||||
tv_update_date(wait_time, status);
|
tv_leaving_poll(wait_time, status);
|
||||||
measure_idle();
|
|
||||||
|
|
||||||
thread_harmless_end();
|
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_sec = (delta_ms / 1000);
|
||||||
timeout.tv_nsec = (delta_ms % 1000) * 1000000;
|
timeout.tv_nsec = (delta_ms % 1000) * 1000000;
|
||||||
fd = global.tune.maxpollevents;
|
fd = global.tune.maxpollevents;
|
||||||
gettimeofday(&before_poll, NULL);
|
tv_entering_poll();
|
||||||
status = kevent(kqueue_fd[tid], // int kq
|
status = kevent(kqueue_fd[tid], // int kq
|
||||||
NULL, // const struct kevent *changelist
|
NULL, // const struct kevent *changelist
|
||||||
0, // int nchanges
|
0, // int nchanges
|
||||||
kev, // struct kevent *eventlist
|
kev, // struct kevent *eventlist
|
||||||
fd, // int nevents
|
fd, // int nevents
|
||||||
&timeout); // const struct timespec *timeout
|
&timeout); // const struct timespec *timeout
|
||||||
tv_update_date(delta_ms, status);
|
tv_leaving_poll(delta_ms, status);
|
||||||
measure_idle();
|
|
||||||
|
|
||||||
thread_harmless_end();
|
thread_harmless_end();
|
||||||
|
|
||||||
|
@ -194,10 +194,9 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
|
|
||||||
/* now let's wait for events */
|
/* now let's wait for events */
|
||||||
wait_time = compute_poll_timeout(exp);
|
wait_time = compute_poll_timeout(exp);
|
||||||
gettimeofday(&before_poll, NULL);
|
tv_entering_poll();
|
||||||
status = poll(poll_events, nbfd, wait_time);
|
status = poll(poll_events, nbfd, wait_time);
|
||||||
tv_update_date(wait_time, status);
|
tv_leaving_poll(wait_time, status);
|
||||||
measure_idle();
|
|
||||||
|
|
||||||
thread_harmless_end();
|
thread_harmless_end();
|
||||||
|
|
||||||
|
@ -164,15 +164,13 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
delta_ms = compute_poll_timeout(exp);
|
delta_ms = compute_poll_timeout(exp);
|
||||||
delta.tv_sec = (delta_ms / 1000);
|
delta.tv_sec = (delta_ms / 1000);
|
||||||
delta.tv_usec = (delta_ms % 1000) * 1000;
|
delta.tv_usec = (delta_ms % 1000) * 1000;
|
||||||
gettimeofday(&before_poll, NULL);
|
tv_entering_poll();
|
||||||
status = select(maxfd,
|
status = select(maxfd,
|
||||||
readnotnull ? tmp_evts[DIR_RD] : NULL,
|
readnotnull ? tmp_evts[DIR_RD] : NULL,
|
||||||
writenotnull ? tmp_evts[DIR_WR] : NULL,
|
writenotnull ? tmp_evts[DIR_WR] : NULL,
|
||||||
NULL,
|
NULL,
|
||||||
&delta);
|
&delta);
|
||||||
|
tv_leaving_poll(delta_ms, status);
|
||||||
tv_update_date(delta_ms, status);
|
|
||||||
measure_idle();
|
|
||||||
|
|
||||||
thread_harmless_end();
|
thread_harmless_end();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user