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.
diff --git a/include/proto/fd.h b/include/proto/fd.h
index da09731..c5a03f7 100644
--- a/include/proto/fd.h
+++ b/include/proto/fd.h
@@ -38,6 +38,8 @@
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 aa18ebe..5947baf 100644
--- a/include/types/fd.h
+++ b/include/types/fd.h
@@ -114,7 +114,6 @@
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 584bf64..abc22ba 100644
--- a/src/ev_epoll.c
+++ b/src/ev_epoll.c
@@ -50,7 +50,7 @@
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 @@
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 @@
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 @@
/* 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 926f77c..ac5b7c5 100644
--- a/src/ev_kqueue.c
+++ b/src/ev_kqueue.c
@@ -41,29 +41,29 @@
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 155ac82..a2e8798 100644
--- a/src/ev_poll.c
+++ b/src/ev_poll.c
@@ -56,14 +56,14 @@
* 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 @@
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 ac4a360..4890c49 100644
--- a/src/ev_select.c
+++ b/src/ev_select.c
@@ -47,14 +47,14 @@
* 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 @@
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 4e88d30..aaba176 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -159,6 +159,7 @@
#include <proto/port_range.h>
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 @@
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 @@
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 @@
fail_info:
free(fdtab);
fail_tab:
+ free(polled_mask);
+ fail_polledmask:
return 0;
}
@@ -549,6 +554,7 @@
free(fdinfo); fdinfo = NULL;
free(fdtab); fdtab = NULL;
+ free(polled_mask); polled_mask = NULL;
}
/*