From 0138f51f933d8268677f4ea09adb971b83a45e7d Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 15 Oct 2020 20:08:55 +0200 Subject: [PATCH] CLEANUP: fd: finally get rid of fd_done_recv() fd_done_recv() used to be useful with the FD cache because it used to allow to keep a file descriptor active in the poller without being marked as ready in the cache, saving it from ringing immediately, without incurring any system call. It was a way to make it yield to wait for new events leaving a bit of time for others. The only user left was the connection accepter (listen_accept()). We used to suspect that with the FD cache removal it had become totally useless since changing its readiness or not wouldn't change its status regarding the poller itself, which would be the only one deciding to report it again. Careful tests showed that it indeed has exactly zero effect nowadays, the syscall numbers are exactly the same with and without, including when enabling edge-triggered polling. Given that there's no more API available to manipulate it and that it was directly called as an optimization from listener_accept(), it's about time to remove it. --- doc/internals/polling-states.fig | 21 ++++++++------------- include/haproxy/fd.h | 13 ------------- src/listener.c | 2 -- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/doc/internals/polling-states.fig b/doc/internals/polling-states.fig index 064e6bb8c8..df5be18292 100644 --- a/doc/internals/polling-states.fig +++ b/doc/internals/polling-states.fig @@ -1,4 +1,4 @@ -#FIG 3.2 Produced by xfig version 2.1 +#FIG 3.2 Produced by xfig version 3.2.7b Portrait Center Metric @@ -7,17 +7,6 @@ A4 Single -2 1200 2 -6 2520 990 4725 3645 -4 0 0 50 -1 16 10 0.0000 4 150 855 2520 1125 R=ready flag\001 -4 0 0 50 -1 16 10 0.0000 4 150 885 2520 1290 A=active flag\001 -4 0 0 50 -1 16 10 0.0000 4 150 1365 2520 2475 fd_want sets A flag\001 -4 0 0 50 -1 16 10 0.0000 4 150 1440 2520 2640 fd_stop clears A flag\001 -4 0 0 50 -1 16 10 0.0000 4 150 1995 2520 3465 fd_done does what's best to\001 -4 0 0 50 -1 16 10 0.0000 4 120 2025 2700 3630 minimize the amount of work.\001 -4 0 0 50 -1 16 10 0.0000 4 150 1905 2520 3300 update() updates the poller.\001 -4 0 0 50 -1 16 10 0.0000 4 150 2190 2520 2970 fd_cant clears R flag (EAGAIN)\001 -4 0 0 50 -1 16 10 0.0000 4 150 2115 2520 3135 fd_rdy sets R flag (poll return)\001 --6 2 1 0 1 0 7 50 -1 -1 0.000 1 0 -1 1 0 2 1 1 1.00 90.00 180.00 1125 1350 1125 1800 @@ -61,4 +50,10 @@ Single 4 1 0 50 -1 16 8 0.0000 4 120 240 1350 3060 !R,A\001 4 1 0 50 -1 16 8 0.0000 4 120 270 1350 3960 !R,!A\001 4 0 0 50 -1 16 8 0.0000 4 120 255 1665 1710 stop\001 -4 2 0 50 -1 16 8 0.0000 4 105 285 1035 2610 done\001 +4 0 0 50 -1 16 10 0.0000 4 150 855 2520 1125 R=ready flag\001 +4 0 0 50 -1 16 10 0.0000 4 150 885 2520 1290 A=active flag\001 +4 0 0 50 -1 16 10 0.0000 4 150 1365 2520 2475 fd_want sets A flag\001 +4 0 0 50 -1 16 10 0.0000 4 150 1440 2520 2640 fd_stop clears A flag\001 +4 0 0 50 -1 16 10 0.0000 4 150 1905 2520 3300 update() updates the poller.\001 +4 0 0 50 -1 16 10 0.0000 4 150 2190 2520 2970 fd_cant clears R flag (EAGAIN)\001 +4 0 0 50 -1 16 10 0.0000 4 150 2115 2520 3135 fd_rdy sets R flag (poll return)\001 diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 6f0401e02c..5300fd4dc5 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -261,19 +261,6 @@ static inline void fd_may_both(const int fd) HA_ATOMIC_OR(&fdtab[fd].state, FD_EV_READY_RW); } -/* Disable readiness when active. This is useful to interrupt reading when it - * is suspected that the end of data might have been reached (eg: short read). - * This can only be done using level-triggered pollers, so if any edge-triggered - * is ever implemented, a test will have to be added here. - */ -static inline void fd_done_recv(const int fd) -{ - /* removing ready never changes polled status */ - if ((fdtab[fd].state & (FD_EV_ACTIVE_R|FD_EV_READY_R)) != (FD_EV_ACTIVE_R|FD_EV_READY_R) || - !HA_ATOMIC_BTR(&fdtab[fd].state, FD_EV_READY_R_BIT)) - return; -} - /* Report that FD cannot send anymore without polling (EAGAIN detected). */ static inline void fd_cant_send(const int fd) { diff --git a/src/listener.c b/src/listener.c index 2289449839..5a375db683 100644 --- a/src/listener.c +++ b/src/listener.c @@ -1145,8 +1145,6 @@ void listener_accept(int fd) if (l->state == LI_READY) { if (max_accept > 0) fd_cant_recv(fd); - else - fd_done_recv(fd); } else if (l->state > LI_ASSIGNED) { fd_stop_recv(l->rx.fd); }