MINOR: pollers: move polled_mask outside of struct fdtab.

The polled_mask is only used in the pollers, and removing it from the
struct fdtab makes it fit in one 64B cacheline again, on a 64bits machine,
so make it a separate array.
This commit is contained in:
Olivier Houchard 2018-04-26 14:23:07 +02:00 committed by Willy Tarreau
parent 6b96f7289c
commit cb92f5cae4
7 changed files with 25 additions and 18 deletions

View File

@ -38,6 +38,8 @@ extern volatile struct fdlist fd_cache_local[MAX_THREADS];
extern volatile struct fdlist update_list; extern volatile struct fdlist update_list;
extern unsigned long *polled_mask;
extern unsigned long fd_cache_mask; // Mask of threads with 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_updt; // FD updates list

View File

@ -114,7 +114,6 @@ struct fdlist {
struct fdtab { struct fdtab {
__decl_hathreads(HA_SPINLOCK_T lock); __decl_hathreads(HA_SPINLOCK_T lock);
unsigned long thread_mask; /* mask of thread IDs authorized to process the task */ unsigned long thread_mask; /* mask of thread IDs authorized to process the task */
unsigned long polled_mask; /* mask of thread IDs currently polling this fd */
unsigned long update_mask; /* mask of thread IDs having an update for fd */ unsigned long update_mask; /* mask of thread IDs having an update for fd */
struct fdlist_entry cache; /* Entry in the fdcache */ struct fdlist_entry cache; /* Entry in the fdcache */
struct fdlist_entry update; /* Entry in the global update list */ struct fdlist_entry update; /* Entry in the global update list */

View File

@ -50,7 +50,7 @@ static THREAD_LOCAL struct epoll_event ev;
REGPRM1 static void __fd_clo(int fd) REGPRM1 static void __fd_clo(int fd)
{ {
if (unlikely(fdtab[fd].cloned)) { if (unlikely(fdtab[fd].cloned)) {
unsigned long m = fdtab[fd].polled_mask; unsigned long m = polled_mask[fd];
int i; int i;
for (i = global.nbthread - 1; i >= 0; i--) for (i = global.nbthread - 1; i >= 0; i--)
@ -65,11 +65,11 @@ static void _update_fd(int fd)
en = fdtab[fd].state; en = fdtab[fd].state;
if (fdtab[fd].polled_mask & tid_bit) { if (polled_mask[fd] & tid_bit) {
if (!(fdtab[fd].thread_mask & tid_bit) || !(en & FD_EV_POLLED_RW)) { if (!(fdtab[fd].thread_mask & tid_bit) || !(en & FD_EV_POLLED_RW)) {
/* fd removed from poll list */ /* fd removed from poll list */
opcode = EPOLL_CTL_DEL; opcode = EPOLL_CTL_DEL;
HA_ATOMIC_AND(&fdtab[fd].polled_mask, ~tid_bit); HA_ATOMIC_AND(&polled_mask[fd], ~tid_bit);
} }
else { else {
/* fd status changed */ /* fd status changed */
@ -79,7 +79,7 @@ static void _update_fd(int fd)
else if ((fdtab[fd].thread_mask & tid_bit) && (en & FD_EV_POLLED_RW)) { else if ((fdtab[fd].thread_mask & tid_bit) && (en & FD_EV_POLLED_RW)) {
/* new fd in the poll list */ /* new fd in the poll list */
opcode = EPOLL_CTL_ADD; opcode = EPOLL_CTL_ADD;
HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); HA_ATOMIC_OR(&polled_mask[fd], tid_bit);
} }
else { else {
return; return;
@ -177,7 +177,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
/* FD has been migrated */ /* FD has been migrated */
activity[tid].poll_skip++; activity[tid].poll_skip++;
epoll_ctl(epoll_fd[tid], EPOLL_CTL_DEL, fd, &ev); epoll_ctl(epoll_fd[tid], EPOLL_CTL_DEL, fd, &ev);
HA_ATOMIC_AND(&fdtab[fd].polled_mask, ~tid_bit); HA_ATOMIC_AND(&polled_mask[fd], ~tid_bit);
continue; continue;
} }

View File

@ -41,29 +41,29 @@ static int _update_fd(int fd)
en = fdtab[fd].state; en = fdtab[fd].state;
if (!(fdtab[fd].thread_mask & tid_bit) || !(en & FD_EV_POLLED_RW)) { if (!(fdtab[fd].thread_mask & tid_bit) || !(en & FD_EV_POLLED_RW)) {
if (!(fdtab[fd].polled_mask & tid_bit)) { if (!(polled_mask[fd] & tid_bit)) {
/* fd was not watched, it's still not */ /* fd was not watched, it's still not */
return 0; return 0;
} }
/* fd totally removed from poll list */ /* fd totally removed from poll list */
EV_SET(&kev[changes++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
HA_ATOMIC_AND(&fdtab[fd].polled_mask, ~tid_bit); HA_ATOMIC_AND(&polled_mask[fd], ~tid_bit);
} }
else { else {
/* OK fd has to be monitored, it was either added or changed */ /* OK fd has to be monitored, it was either added or changed */
if (en & FD_EV_POLLED_R) if (en & FD_EV_POLLED_R)
EV_SET(&kev[changes++], fd, EVFILT_READ, EV_ADD, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_READ, EV_ADD, 0, 0, NULL);
else if (fdtab[fd].polled_mask & tid_bit) else if (polled_mask[fd] & tid_bit)
EV_SET(&kev[changes++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
if (en & FD_EV_POLLED_W) if (en & FD_EV_POLLED_W)
EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_ADD, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_ADD, 0, 0, NULL);
else if (fdtab[fd].polled_mask & tid_bit) else if (polled_mask[fd] & tid_bit)
EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL); EV_SET(&kev[changes++], fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); HA_ATOMIC_OR(&polled_mask[fd], tid_bit);
} }
return changes; return changes;
} }

View File

@ -56,14 +56,14 @@ static void _update_fd(int fd, int *max_add_fd)
* takes it for every other one. * takes it for every other one.
*/ */
if (!(en & FD_EV_POLLED_RW)) { if (!(en & FD_EV_POLLED_RW)) {
if (!fdtab[fd].polled_mask) { if (!polled_mask[fd]) {
/* fd was not watched, it's still not */ /* fd was not watched, it's still not */
return; return;
} }
/* fd totally removed from poll list */ /* fd totally removed from poll list */
hap_fd_clr(fd, fd_evts[DIR_RD]); hap_fd_clr(fd, fd_evts[DIR_RD]);
hap_fd_clr(fd, fd_evts[DIR_WR]); hap_fd_clr(fd, fd_evts[DIR_WR]);
HA_ATOMIC_AND(&fdtab[fd].polled_mask, 0); HA_ATOMIC_AND(&polled_mask[fd], 0);
} }
else { else {
/* OK fd has to be monitored, it was either added or changed */ /* OK fd has to be monitored, it was either added or changed */
@ -77,7 +77,7 @@ static void _update_fd(int fd, int *max_add_fd)
else else
hap_fd_set(fd, fd_evts[DIR_WR]); hap_fd_set(fd, fd_evts[DIR_WR]);
HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); HA_ATOMIC_OR(&polled_mask[fd], tid_bit);
if (fd > *max_add_fd) if (fd > *max_add_fd)
*max_add_fd = fd; *max_add_fd = fd;
} }

View File

@ -47,14 +47,14 @@ static void _update_fd(int fd, int *max_add_fd)
* takes it for every other one. * takes it for every other one.
*/ */
if (!(en & FD_EV_POLLED_RW)) { if (!(en & FD_EV_POLLED_RW)) {
if (!fdtab[fd].polled_mask) { if (!polled_mask[fd]) {
/* fd was not watched, it's still not */ /* fd was not watched, it's still not */
return; return;
} }
/* fd totally removed from poll list */ /* fd totally removed from poll list */
hap_fd_clr(fd, fd_evts[DIR_RD]); hap_fd_clr(fd, fd_evts[DIR_RD]);
hap_fd_clr(fd, fd_evts[DIR_WR]); hap_fd_clr(fd, fd_evts[DIR_WR]);
HA_ATOMIC_AND(&fdtab[fd].polled_mask, 0); HA_ATOMIC_AND(&polled_mask[fd], 0);
} }
else { else {
/* OK fd has to be monitored, it was either added or changed */ /* OK fd has to be monitored, it was either added or changed */
@ -68,7 +68,7 @@ static void _update_fd(int fd, int *max_add_fd)
else else
hap_fd_set(fd, fd_evts[DIR_WR]); hap_fd_set(fd, fd_evts[DIR_WR]);
HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); HA_ATOMIC_OR(&polled_mask[fd], tid_bit);
if (fd > *max_add_fd) if (fd > *max_add_fd)
*max_add_fd = fd; *max_add_fd = fd;
} }

View File

@ -159,6 +159,7 @@
#include <proto/port_range.h> #include <proto/port_range.h>
struct fdtab *fdtab = NULL; /* array of all the file descriptors */ struct fdtab *fdtab = NULL; /* array of all the file descriptors */
unsigned long *polled_mask = NULL; /* Array for the polled_mask of each fd */
struct fdinfo *fdinfo = NULL; /* less-often used infos for file descriptors */ struct fdinfo *fdinfo = NULL; /* less-often used infos for file descriptors */
int totalconn; /* total # of terminated sessions */ int totalconn; /* total # of terminated sessions */
int actconn; /* # of active sessions */ int actconn; /* # of active sessions */
@ -373,7 +374,7 @@ static void fd_dodelete(int fd, int do_close)
fdtab[fd].update_mask &= ~tid_bit; fdtab[fd].update_mask &= ~tid_bit;
fdtab[fd].thread_mask = 0; fdtab[fd].thread_mask = 0;
if (do_close) { if (do_close) {
fdtab[fd].polled_mask = 0; polled_mask[fd] = 0;
close(fd); close(fd);
} }
HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock); HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock);
@ -488,6 +489,8 @@ int init_pollers()
if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL) if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL)
goto fail_tab; goto fail_tab;
if ((polled_mask = calloc(global.maxsock, sizeof(unsigned long))) == NULL)
goto fail_polledmask;
if ((fdinfo = calloc(global.maxsock, sizeof(struct fdinfo))) == NULL) if ((fdinfo = calloc(global.maxsock, sizeof(struct fdinfo))) == NULL)
goto fail_info; goto fail_info;
@ -526,6 +529,8 @@ int init_pollers()
fail_info: fail_info:
free(fdtab); free(fdtab);
fail_tab: fail_tab:
free(polled_mask);
fail_polledmask:
return 0; return 0;
} }
@ -549,6 +554,7 @@ void deinit_pollers() {
free(fdinfo); fdinfo = NULL; free(fdinfo); fdinfo = NULL;
free(fdtab); fdtab = NULL; free(fdtab); fdtab = NULL;
free(polled_mask); polled_mask = NULL;
} }
/* /*