]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: poller: move time and date computation out of the pollers
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Oct 2018 12:31:19 +0000 (14:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 17 Oct 2018 17:59:43 +0000 (19:59 +0200)
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.

include/common/time.h
src/ev_epoll.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c

index f3dd3ba1d8f76a65041760fc773ca9fdaf7f24f0..aeb19860d2c85c2cc9dea5fe23d8cd78b7c5eaa3 100644 (file)
@@ -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 */
 
 /*
index b9980dbed316546dcfe13a203671ebc71146c4ac..9d111ce6531a9200f64cd35ac495f4fe45d865f3 100644 (file)
@@ -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();
 
index 3d21cb0349aea7a96707f0449b06217055dc7f31..c1c3e1164582f1fc6017e65b50589b8a92ce227b 100644 (file)
@@ -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();
 
index 0b51e8d01a66c59bf32bd05c566fe1b65998d968..b08274ccce7f70b496469717418c753e6041e4b8 100644 (file)
@@ -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();
 
index 0f9b87ee311bb65d7d2f54241f594c70aa05d761..464635b0f4e52da418f4ad8945ff3f45282cae3d 100644 (file)
@@ -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();