]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: threads/fd: Use a bitfield to know if there are FDs for a thread in the FD...
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 15 Jan 2018 10:57:03 +0000 (11:57 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Jan 2018 14:39:10 +0000 (15:39 +0100)
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]

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

index 8cc191f75da2b4096e53d834492a5d05b6346a5d..44370e768bef58ea171c1588b16ac7413efb819e 100644 (file)
@@ -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:
index 148b4d27ed4713838e941bc0123abd85ed43eab2..8411bcfb90f02ac3caf0a5168214813b0476b762 100644 (file)
--- 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;