]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: add a bitmask to indicate that an FD is known by the poller
authorWilly Tarreau <w@1wt.eu>
Wed, 17 Jan 2018 17:44:46 +0000 (18:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Jan 2018 14:42:57 +0000 (15:42 +0100)
Some pollers like epoll() need to know if the fd is already known or
not in order to compute the operation to perform (add, mod, del). For
now this is performed based on the difference between the previous FD
state and the new state but this will not be usable anymore once threads
become responsible for their own polling.

Here we come with a different approach : a bitmask is stored with the
fd to indicate which pollers already know it, and the pollers will be
able to simply perform the add/mod/del operations based on this bit
combined with the new state.

This patch only adds the bitmask declaration and initialization, it
is it not yet used. It will be needed by the next two fixes and will
need to be backported to 1.8.

include/proto/fd.h
include/types/fd.h
src/fd.c

index d6b591d192541b152d7cf516f020793e777f48da..cc559ac32f82f0f2a32c855b0430740fd83dc3c8 100644 (file)
@@ -405,6 +405,9 @@ static inline void fd_insert(int fd, unsigned long thread_mask)
        fdtab[fd].cloned = 0;
        fdtab[fd].cache = 0;
        fdtab[fd].thread_mask = thread_mask;
+       /* note: do not reset polled_mask here as it indicates which poller
+        * still knows this FD from a possible previous round.
+        */
        HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
 
        HA_SPIN_LOCK(FDTAB_LOCK, &fdtab_lock);
index 54192e478b3e5e2318e46c0bece7a64d9b4befa4..9f2c5feea73cd94b3cc7df79e107acfec19f70c1 100644 (file)
@@ -94,6 +94,7 @@ enum fd_states {
 struct fdtab {
        __decl_hathreads(HA_SPINLOCK_T lock);
        unsigned long thread_mask;           /* mask of thread IDs authorized to process the task */
+       unsigned long polled_mask;           /* mask of thread IDs currently polling this fd */
        unsigned long update_mask;           /* mask of thread IDs having an update for fd */
        void (*iocb)(int fd);                /* I/O handler */
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
index 112806bbb4691ff9c351985147fe4ff80725ff16..b64130ed0a1e5c4c1e44670c2cab28ea3cde9a35 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -202,8 +202,10 @@ static void fd_dodelete(int fd, int do_close)
        fdtab[fd].update_mask &= ~tid_bit;
        fdtab[fd].new = 0;
        fdtab[fd].thread_mask = 0;
-       if (do_close)
+       if (do_close) {
+               fdtab[fd].polled_mask = 0;
                close(fd);
+       }
        HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
 
        HA_SPIN_LOCK(FDTAB_LOCK, &fdtab_lock);