From 26fb5d8449f3b17317d2b7b5c54979f576d5f95b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 20 Mar 2018 19:06:52 +0100 Subject: [PATCH] BUG/MEDIUM: fd/threads: ensure the fdcache_mask always reflects the cache contents Commit 4815c8c ("MAJOR: fd/threads: Make the fdcache mostly lockless.") made the fd cache lockless, but after a few iterations, a subtle part was lost, consisting in setting the bit on the fd_cache_mask immediately when adding an event. Now it was done only when the cache started to process events, but the problem it causes is that fd_cache_mask isn't reliable anymore as an indicator of presence of events to be processed with no delay outside of fd_process_cached_events(). This results in some spurious delays when processing inter-thread wakeups between tasks. Just restoring the flag when the event is added is enough to fix the problem. Kudos to Christopher for spotting this one! No backport is needed as this is only in the development version. --- include/proto/fd.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/proto/fd.h b/include/proto/fd.h index b9811fe43..0f59df661 100644 --- a/include/proto/fd.h +++ b/include/proto/fd.h @@ -117,6 +117,7 @@ static inline void updt_fd_polling(const int fd) */ static inline void fd_alloc_cache_entry(const int fd) { + HA_ATOMIC_OR(&fd_cache_mask, fdtab[fd].thread_mask); if (!(fdtab[fd].thread_mask & (fdtab[fd].thread_mask - 1))) fd_add_to_fd_list(&fd_cache_local[my_ffsl(fdtab[fd].thread_mask) - 1], fd); else