MEDIUM: poller: program the update in fd_update_events() for a migrated FD

When an FD is migrated, all pollers program an update. That's useless
code duplication, and when thread groups will be supported, this will
require an extra round of locking just to verify the update_mask on
return. Let's just program the update direction from fd_update_events()
as it already does for closed FDs, this becomes more logical.
This commit is contained in:
Willy Tarreau 2022-07-09 18:55:37 +02:00
parent 1b927eb3c3
commit b1093c6ba2
5 changed files with 10 additions and 29 deletions

View File

@ -214,7 +214,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
for (count = 0; count < status; count++) { for (count = 0; count < status; count++) {
unsigned int n, e; unsigned int n, e;
int ret;
e = epoll_events[count].events; e = epoll_events[count].events;
fd = epoll_events[count].data.fd; fd = epoll_events[count].data.fd;
@ -231,13 +230,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
((e & EPOLLHUP) ? FD_EV_SHUT_RW : 0) | ((e & EPOLLHUP) ? FD_EV_SHUT_RW : 0) |
((e & EPOLLERR) ? FD_EV_ERR_RW : 0); ((e & EPOLLERR) ? FD_EV_ERR_RW : 0);
ret = fd_update_events(fd, n); fd_update_events(fd, n);
if (ret == FD_UPDT_MIGRATED) {
/* FD has been migrated */
if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
fd_updt[fd_nbupdt++] = fd;
}
} }
/* the caller will take care of cached events */ /* the caller will take care of cached events */
} }

View File

@ -244,12 +244,9 @@ static void _do_poll(struct poller *p, int exp, int wake)
*/ */
ret = fd_update_events(fd, n); ret = fd_update_events(fd, n);
/* disable polling on this instance if the FD was migrated */ /* polling will be on this instance if the FD was migrated */
if (ret == FD_UPDT_MIGRATED) { if (ret == FD_UPDT_MIGRATED)
if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
fd_updt[fd_nbupdt++] = fd;
continue; continue;
}
/* /*
* This file descriptor was closed during the processing of * This file descriptor was closed during the processing of

View File

@ -178,7 +178,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
for (count = 0; count < status; count++) { for (count = 0; count < status; count++) {
unsigned int n = 0; unsigned int n = 0;
int ret;
fd = kev[count].ident; fd = kev[count].ident;
@ -197,13 +196,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
n |= FD_EV_ERR_RW; n |= FD_EV_ERR_RW;
} }
ret = fd_update_events(fd, n); fd_update_events(fd, n);
if (ret == FD_UPDT_MIGRATED) {
/* FD was migrated, let's stop polling it */
if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
fd_updt[fd_nbupdt++] = fd;
}
} }
} }

View File

@ -213,8 +213,8 @@ static void _do_poll(struct poller *p, int exp, int wake)
for (count = 0; status > 0 && count < nbfd; count++) { for (count = 0; status > 0 && count < nbfd; count++) {
unsigned int n; unsigned int n;
int ret;
int e = poll_events[count].revents; int e = poll_events[count].revents;
fd = poll_events[count].fd; fd = poll_events[count].fd;
if ((e & POLLRDHUP) && !(cur_poller.flags & HAP_POLL_F_RDHUP)) if ((e & POLLRDHUP) && !(cur_poller.flags & HAP_POLL_F_RDHUP))
@ -235,13 +235,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
((e & POLLHUP) ? FD_EV_SHUT_RW : 0) | ((e & POLLHUP) ? FD_EV_SHUT_RW : 0) |
((e & POLLERR) ? FD_EV_ERR_RW : 0); ((e & POLLERR) ? FD_EV_ERR_RW : 0);
ret = fd_update_events(fd, n); fd_update_events(fd, n);
if (ret == FD_UPDT_MIGRATED) {
/* FD was migrated, let's stop polling it */
if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
fd_updt[fd_nbupdt++] = fd;
}
} }
} }

View File

@ -483,6 +483,10 @@ int fd_update_events(int fd, uint evts)
if (!(tmask & tid_bit)) { if (!(tmask & tid_bit)) {
/* a takeover has started */ /* a takeover has started */
activity[tid].poll_skip_fd++; activity[tid].poll_skip_fd++;
/* Let the poller know this FD was lost */
if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
fd_updt[fd_nbupdt++] = fd;
return FD_UPDT_MIGRATED; return FD_UPDT_MIGRATED;
} }
} while (!HA_ATOMIC_CAS(&fdtab[fd].running_mask, &rmask, rmask | tid_bit)); } while (!HA_ATOMIC_CAS(&fdtab[fd].running_mask, &rmask, rmask | tid_bit));