MINOR: poller: centralize poll return handling
authorWilly Tarreau <w@1wt.eu>
Wed, 22 Jun 2022 13:21:34 +0000 (15:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
When returning from the polling syscall, all pollers have a certain
dance to follow, made of wall clock updates, thread harmless updates,
idle time management and sleeping mask updates. Let's have a centralized
function to deal with all of this boring stuff: fd_leaving_poll(), and
make all the pollers use it.

include/haproxy/fd.h
src/ev_epoll.c
src/ev_evports.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c
src/fd.c

index 010fdac..fa24240 100644 (file)
@@ -79,6 +79,7 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t
 void my_closefrom(int start);
 
 int compute_poll_timeout(int next);
+void fd_leaving_poll(int wait_time, int status);
 
 /* disable the specified poller */
 void disable_poller(const char *poller_name);
index 5832062..fd49d92 100644 (file)
@@ -208,13 +208,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                        break;
        } while (1);
 
-       clock_leaving_poll(wait_time, status);
-
-       thread_harmless_end();
-       thread_idle_end();
-
-       if (sleeping_thread_mask & tid_bit)
-               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+       fd_leaving_poll(wait_time, status);
 
        /* process polled events */
 
index 4d61154..301e86e 100644 (file)
@@ -202,13 +202,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                        break;
        } while(1);
 
-       clock_leaving_poll(wait_time, nevlist);
-
-       thread_harmless_end();
-       thread_idle_end();
-
-       if (sleeping_thread_mask & tid_bit)
-               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+       fd_leaving_poll(wait_time, nevlist);
 
        if (nevlist > 0)
                activity[tid].poll_io++;
index 3bc7121..43643fb 100644 (file)
@@ -174,13 +174,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                        break;
        } while (1);
 
-       clock_leaving_poll(wait_time, status);
-
-       thread_harmless_end();
-       thread_idle_end();
-
-       if (sleeping_thread_mask & tid_bit)
-               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+       fd_leaving_poll(wait_time, status);
 
        for (count = 0; count < status; count++) {
                unsigned int n = 0;
index 5f52262..92e45a6 100644 (file)
@@ -205,13 +205,8 @@ static void _do_poll(struct poller *p, int exp, int wake)
        clock_entering_poll();
        status = poll(poll_events, nbfd, wait_time);
        clock_update_date(wait_time, status);
-       clock_leaving_poll(wait_time, status);
 
-       thread_harmless_end();
-       thread_idle_end();
-
-       if (sleeping_thread_mask & tid_bit)
-               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+       fd_leaving_poll(wait_time, status);
 
        if (status > 0)
                activity[tid].poll_io++;
index 3880d0d..b3e1b40 100644 (file)
@@ -180,13 +180,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                        NULL,
                        &delta);
        clock_update_date(delta_ms, status);
-       clock_leaving_poll(delta_ms, status);
-
-       thread_harmless_end();
-       thread_idle_end();
-
-       if (sleeping_thread_mask & tid_bit)
-               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+       fd_leaving_poll(delta_ms, status);
 
        if (status <= 0)
                return;
index 99c8c4e..5dd648e 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -759,6 +759,21 @@ int compute_poll_timeout(int next)
        return wait_time;
 }
 
+/* Handle the return of the poller, which consists in calculating the idle
+ * time, saving a few clocks, marking the thread harmful again etc. All that
+ * is some boring stuff that all pollers have to do anyway.
+ */
+void fd_leaving_poll(int wait_time, int status)
+{
+       clock_leaving_poll(wait_time, status);
+
+       thread_harmless_end();
+       thread_idle_end();
+
+       if (sleeping_thread_mask & tid_bit)
+               _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit);
+}
+
 /* disable the specified poller */
 void disable_poller(const char *poller_name)
 {