]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: fd: add a counter of takeovers of an FD since it was last opened
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Jan 2025 14:59:11 +0000 (15:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Jan 2025 18:45:34 +0000 (19:45 +0100)
That's essentially in order to help with debugging strange cases like
the occasional epoll issues/races, by keeping a counter of how many
times an FD was taken over since last inserted. The room is available
so let's use it. If it's needed later, this patch can easily be reverted.
The counter is also reported in "show fd" as "tkov".

include/haproxy/fd-t.h
include/haproxy/fd.h
src/cli.c
src/fd.c

index c5e94cbec7da9b5fd56283cb488b4f192f7cd6f5..c2b2aee2067c7ed8bf13659f39d59ff7798b29ad 100644 (file)
@@ -193,6 +193,11 @@ struct fdtab {
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        unsigned int state;                  /* FD state for read and write directions (FD_EV_*) + FD_POLL_* */
        unsigned int refc_tgid;              /* refcounted tgid, updated atomically */
+       /* the info below are mainly used for epoll debugging/strengthening.
+        * they're filling the rest of the cache line but may easily be dropped
+        * if the room is needed for more important stuff.
+        */
+       unsigned int nb_takeover;            /* number of times this FD was taken over since inserted (used for debugging) */
 #ifdef DEBUG_FD
        unsigned int event_count;            /* number of events reported */
 #endif
index faaeaa64566964620dd9ca937be362cc468142e3..a83539e4817fd54305dc2f267c1b9ea0d033d567 100644 (file)
@@ -500,6 +500,10 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), int tgid
        fdtab[fd].iocb = iocb;
        fdtab[fd].state = newstate;
        fdtab[fd].thread_mask = thread_mask;
+
+       /* just for debugging: how many times taken over since last fd_insert() */
+       fdtab[fd].nb_takeover = 0;
+
        fd_drop_tgid(fd);
 
 #ifdef DEBUG_FD
index d5cc3449976c9d8f956e6e827429fe06366df6ed..d00b5b2410a465c22b57069d8750de7396d20ad3 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1415,7 +1415,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                        suspicious = 1;
 
                chunk_printf(&trash,
-                            "  %5d : st=0x%06x(%c%c %c%c%c%c%c W:%c%c%c R:%c%c%c) ref=%#x gid=%d tmask=0x%lx umask=0x%lx prmsk=0x%lx pwmsk=0x%lx owner=%p iocb=%p(",
+                            "  %5d : st=0x%06x(%c%c %c%c%c%c%c W:%c%c%c R:%c%c%c) ref=%#x gid=%d tmask=0x%lx umask=0x%lx prmsk=0x%lx pwmsk=0x%lx owner=%p tkov=%u iocb=%p(",
                             fd,
                             fdt.state,
                             (fdt.state & FD_CLONED) ? 'C' : 'c',
@@ -1437,6 +1437,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                             polled_mask[fd].poll_recv,
                             polled_mask[fd].poll_send,
                             fdt.owner,
+                            fdt.nb_takeover,
                             fdt.iocb);
                resolve_sym_name(&trash, NULL, fdt.iocb);
 
index cf77884b1efc0066050fc710c72b8bebb148a44e..bf4241ba2131600039576e1787b01f01a4835635 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -542,6 +542,9 @@ int fd_takeover(int fd, void *expected_owner)
         */
        fd_stop_recv(fd);
 
+       /* essentially for debugging */
+       fdtab[fd].nb_takeover++;
+
        /* we're done with it */
        HA_ATOMIC_AND(&fdtab[fd].running_mask, ~ti->ltid_bit);