]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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 010fdacf8e05634cb5a6e11aeaa2aae4105d575c..fa24240568cf76557e8d4d60f36a97aa83b97aa6 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 583206232939e99fcc152256d0f19564561d00a3..fd49d92c56e089fda93972c354100d490ebc0b81 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 4d611541cf5bf14121a63fa8243bf7b7efb7f588..301e86eef948901f28eec396f53c9ce1af1209e7 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 3bc7121cbdcaea5fcba71f9caf8430ca09eb5f4c..43643fb38754d46435ae100f2e2c6eb7ac1bdd94 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 5f52262adaed60d749c10da39b1a9ab0161ff76e..92e45a634fb9a92089ad7385137c8da6e1791023 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 3880d0d1437fb13764912ad6aa8f3b8ec248990b..b3e1b40e6e2c989de544e3dff4a111c7dedfd4ab 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 99c8c4e5b34bfa1cc133473ebc17c1b9c8583039..5dd648ef7effd1eb9dc37a7c42502dd9b6cd9706 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)
 {