From cb92f5cae4491f7e7c5b2ec8d83003f2d32cf46e Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 26 Apr 2018 14:23:07 +0200 Subject: [PATCH] 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. --- include/proto/fd.h | 2 ++ include/types/fd.h | 1 - src/ev_epoll.c | 10 +++++----- src/ev_kqueue.c | 10 +++++----- src/ev_poll.c | 6 +++--- src/ev_select.c | 6 +++--- src/fd.c | 8 +++++++- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/proto/fd.h b/include/proto/fd.h index da09731d4..c5a03f775 100644 --- a/include/proto/fd.h +++ b/include/proto/fd.h @@ -38,6 +38,8 @@ extern volatile struct fdlist fd_cache_local[MAX_THREADS]; 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 THREAD_LOCAL int *fd_updt; // FD updates list diff --git a/include/types/fd.h b/include/types/fd.h index aa18ebefc..5947bafc3 100644 --- a/include/types/fd.h +++ b/include/types/fd.h @@ -114,7 +114,6 @@ struct fdlist { struct fdtab { __decl_hathreads(HA_SPINLOCK_T lock); 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 */ struct fdlist_entry cache; /* Entry in the fdcache */ struct fdlist_entry update; /* Entry in the global update list */ diff --git a/src/ev_epoll.c b/src/ev_epoll.c index 584bf64c9..abc22ba76 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -50,7 +50,7 @@ static THREAD_LOCAL struct epoll_event ev; REGPRM1 static void __fd_clo(int fd) { if (unlikely(fdtab[fd].cloned)) { - unsigned long m = fdtab[fd].polled_mask; + unsigned long m = polled_mask[fd]; int i; for (i = global.nbthread - 1; i >= 0; i--) @@ -65,11 +65,11 @@ static void _update_fd(int fd) 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)) { /* fd removed from poll list */ opcode = EPOLL_CTL_DEL; - HA_ATOMIC_AND(&fdtab[fd].polled_mask, ~tid_bit); + HA_ATOMIC_AND(&polled_mask[fd], ~tid_bit); } else { /* 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)) { /* new fd in the poll list */ opcode = EPOLL_CTL_ADD; - HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); + HA_ATOMIC_OR(&polled_mask[fd], tid_bit); } else { return; @@ -177,7 +177,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp) /* FD has been migrated */ activity[tid].poll_skip++; 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; } diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index 926f77c74..ac5b7c512 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -41,29 +41,29 @@ static int _update_fd(int fd) en = fdtab[fd].state; 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 */ return 0; } /* fd totally removed from poll list */ EV_SET(&kev[changes++], fd, EVFILT_READ, 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 { /* OK fd has to be monitored, it was either added or changed */ if (en & FD_EV_POLLED_R) 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); if (en & FD_EV_POLLED_W) 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); - HA_ATOMIC_OR(&fdtab[fd].polled_mask, tid_bit); + HA_ATOMIC_OR(&polled_mask[fd], tid_bit); } return changes; } diff --git a/src/ev_poll.c b/src/ev_poll.c index 155ac821d..a2e8798e4 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -56,14 +56,14 @@ static void _update_fd(int fd, int *max_add_fd) * takes it for every other one. */ if (!(en & FD_EV_POLLED_RW)) { - if (!fdtab[fd].polled_mask) { + if (!polled_mask[fd]) { /* fd was not watched, it's still not */ return; } /* fd totally removed from poll list */ hap_fd_clr(fd, fd_evts[DIR_RD]); hap_fd_clr(fd, fd_evts[DIR_WR]); - HA_ATOMIC_AND(&fdtab[fd].polled_mask, 0); + HA_ATOMIC_AND(&polled_mask[fd], 0); } else { /* 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 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) *max_add_fd = fd; } diff --git a/src/ev_select.c b/src/ev_select.c index ac4a36064..4890c49de 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -47,14 +47,14 @@ static void _update_fd(int fd, int *max_add_fd) * takes it for every other one. */ if (!(en & FD_EV_POLLED_RW)) { - if (!fdtab[fd].polled_mask) { + if (!polled_mask[fd]) { /* fd was not watched, it's still not */ return; } /* fd totally removed from poll list */ hap_fd_clr(fd, fd_evts[DIR_RD]); hap_fd_clr(fd, fd_evts[DIR_WR]); - HA_ATOMIC_AND(&fdtab[fd].polled_mask, 0); + HA_ATOMIC_AND(&polled_mask[fd], 0); } else { /* 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 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) *max_add_fd = fd; } diff --git a/src/fd.c b/src/fd.c index 4e88d308f..aaba1767e 100644 --- a/src/fd.c +++ b/src/fd.c @@ -159,6 +159,7 @@ #include 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 */ int totalconn; /* total # of terminated 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].thread_mask = 0; if (do_close) { - fdtab[fd].polled_mask = 0; + polled_mask[fd] = 0; close(fd); } HA_SPIN_UNLOCK(FD_LOCK, &fdtab[fd].lock); @@ -488,6 +489,8 @@ int init_pollers() if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL) 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) goto fail_info; @@ -526,6 +529,8 @@ int init_pollers() fail_info: free(fdtab); fail_tab: + free(polled_mask); + fail_polledmask: return 0; } @@ -549,6 +554,7 @@ void deinit_pollers() { free(fdinfo); fdinfo = NULL; free(fdtab); fdtab = NULL; + free(polled_mask); polled_mask = NULL; } /*