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]
This commit is contained in:
parent
d80cb4ee13
commit
69553fe62c
@ -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:
|
||||
|
7
src/fd.c
7
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user