From: Christopher Faulet Date: Mon, 15 Jan 2018 10:57:03 +0000 (+0100) Subject: MINOR: threads/fd: Use a bitfield to know if there are FDs for a thread in the FD... X-Git-Tag: v1.9-dev1~507 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69553fe62c5c69753d1862a3e74740a1ff6c4d8d;p=thirdparty%2Fhaproxy.git MINOR: threads/fd: Use a bitfield to know if there are FDs for a thread in the FD cache A bitfield has been added to know if there are some FDs processable by a specific thread in the FD cache. When a FD is inserted in the FD cache, the bits corresponding to its thread_mask are set. On each thread, the bitfield is updated when the FD cache is processed. If there is no FD processed, the thread is removed from the bitfield by unsetting its tid_bit. Note that this bitfield is updated but not checked in fd_process_cached_events. So, when this function is called, the FDs cache is always processed. [wt: should be backported to 1.8 as it will help fix a design limitation] --- diff --git a/include/proto/fd.h b/include/proto/fd.h index 8cc191f75d..44370e768b 100644 --- a/include/proto/fd.h +++ b/include/proto/fd.h @@ -35,6 +35,7 @@ extern unsigned int *fd_cache; // FD events cache extern int fd_cache_num; // number of events in the cache +extern unsigned long fd_cache_mask; // Mask of threads with events in the cache extern THREAD_LOCAL int *fd_updt; // FD updates list extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list @@ -115,6 +116,7 @@ static inline void fd_alloc_cache_entry(const int fd) if (fdtab[fd].cache) goto end; fd_cache_num++; + fd_cache_mask |= fdtab[fd].thread_mask; fdtab[fd].cache = fd_cache_num; fd_cache[fd_cache_num-1] = fd; end: diff --git a/src/fd.c b/src/fd.c index 148b4d27ed..8411bcfb90 100644 --- a/src/fd.c +++ b/src/fd.c @@ -170,6 +170,7 @@ int nbpollers = 0; unsigned int *fd_cache = NULL; // FD events cache int fd_cache_num = 0; // number of events in the cache +unsigned long fd_cache_mask = 0; // Mask of threads with events in the cache THREAD_LOCAL int *fd_updt = NULL; // FD updates list THREAD_LOCAL int fd_nbupdt = 0; // number of updates in the list @@ -236,10 +237,8 @@ void fd_process_cached_events() { int fd, entry, e; - if (!fd_cache_num) - return; - HA_RWLOCK_RDLOCK(FDCACHE_LOCK, &fdcache_lock); + fd_cache_mask &= ~tid_bit; for (entry = 0; entry < fd_cache_num; ) { fd = fd_cache[entry]; @@ -247,6 +246,8 @@ void fd_process_cached_events() activity[tid].fd_skip++; goto next; } + + fd_cache_mask |= tid_bit; if (HA_SPIN_TRYLOCK(FD_LOCK, &fdtab[fd].lock)) { activity[tid].fd_lock++; goto next;