mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-24 20:08:01 +00:00
MEDIUM: fd: use atomic ops for hap_fd_{clr,set} and remove poll_lock
Now that we can use atomic ops to set/clear an fd occurrence in an fd_set, we don't need the poll_lock anymore. Let's remove it.
This commit is contained in:
parent
d51a507dbd
commit
82b37d74d2
@ -205,7 +205,6 @@ enum lock_label {
|
|||||||
THREAD_SYNC_LOCK = 0,
|
THREAD_SYNC_LOCK = 0,
|
||||||
FDCACHE_LOCK,
|
FDCACHE_LOCK,
|
||||||
FD_LOCK,
|
FD_LOCK,
|
||||||
POLL_LOCK,
|
|
||||||
TASK_RQ_LOCK,
|
TASK_RQ_LOCK,
|
||||||
TASK_WQ_LOCK,
|
TASK_WQ_LOCK,
|
||||||
POOL_LOCK,
|
POOL_LOCK,
|
||||||
|
@ -41,7 +41,6 @@ extern THREAD_LOCAL int *fd_updt; // FD updates list
|
|||||||
extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list
|
extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list
|
||||||
|
|
||||||
__decl_hathreads(extern HA_RWLOCK_T __attribute__((aligned(64))) fdcache_lock); /* global lock to protect fd_cache array */
|
__decl_hathreads(extern HA_RWLOCK_T __attribute__((aligned(64))) fdcache_lock); /* global lock to protect fd_cache array */
|
||||||
__decl_hathreads(extern HA_SPINLOCK_T __attribute__((aligned(64))) poll_lock); /* global lock to protect poll info */
|
|
||||||
|
|
||||||
/* Deletes an FD from the fdsets.
|
/* Deletes an FD from the fdsets.
|
||||||
* The file descriptor is also closed.
|
* The file descriptor is also closed.
|
||||||
@ -412,12 +411,12 @@ static inline void fd_insert(int fd, unsigned long thread_mask)
|
|||||||
/* These are replacements for FD_SET, FD_CLR, FD_ISSET, working on uints */
|
/* These are replacements for FD_SET, FD_CLR, FD_ISSET, working on uints */
|
||||||
static inline void hap_fd_set(int fd, unsigned int *evts)
|
static inline void hap_fd_set(int fd, unsigned int *evts)
|
||||||
{
|
{
|
||||||
evts[fd / (8*sizeof(*evts))] |= 1U << (fd & (8*sizeof(*evts) - 1));
|
HA_ATOMIC_OR(&evts[fd / (8*sizeof(*evts))], 1U << (fd & (8*sizeof(*evts) - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void hap_fd_clr(int fd, unsigned int *evts)
|
static inline void hap_fd_clr(int fd, unsigned int *evts)
|
||||||
{
|
{
|
||||||
evts[fd / (8*sizeof(*evts))] &= ~(1U << (fd & (8*sizeof(*evts) - 1)));
|
HA_ATOMIC_AND(&evts[fd / (8*sizeof(*evts))], ~(1U << (fd & (8*sizeof(*evts) - 1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int hap_fd_isset(int fd, unsigned int *evts)
|
static inline unsigned int hap_fd_isset(int fd, unsigned int *evts)
|
||||||
|
@ -41,10 +41,8 @@ static THREAD_LOCAL struct pollfd *poll_events = NULL;
|
|||||||
|
|
||||||
REGPRM1 static void __fd_clo(int fd)
|
REGPRM1 static void __fd_clo(int fd)
|
||||||
{
|
{
|
||||||
HA_SPIN_LOCK(POLL_LOCK, &poll_lock);
|
|
||||||
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_SPIN_UNLOCK(POLL_LOCK, &poll_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -81,7 +79,6 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
|
|
||||||
if ((eo ^ en) & FD_EV_POLLED_RW) {
|
if ((eo ^ en) & FD_EV_POLLED_RW) {
|
||||||
/* poll status changed, update the lists */
|
/* poll status changed, update the lists */
|
||||||
HA_SPIN_LOCK(POLL_LOCK, &poll_lock);
|
|
||||||
if ((eo & ~en) & FD_EV_POLLED_R)
|
if ((eo & ~en) & FD_EV_POLLED_R)
|
||||||
hap_fd_clr(fd, fd_evts[DIR_RD]);
|
hap_fd_clr(fd, fd_evts[DIR_RD]);
|
||||||
else if ((en & ~eo) & FD_EV_POLLED_R) {
|
else if ((en & ~eo) & FD_EV_POLLED_R) {
|
||||||
@ -97,8 +94,6 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
if (fd > max_add_fd)
|
if (fd > max_add_fd)
|
||||||
max_add_fd = fd;
|
max_add_fd = fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
HA_SPIN_UNLOCK(POLL_LOCK, &poll_lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +32,8 @@ static THREAD_LOCAL fd_set *tmp_evts[2];
|
|||||||
/* Immediately remove the entry upon close() */
|
/* Immediately remove the entry upon close() */
|
||||||
REGPRM1 static void __fd_clo(int fd)
|
REGPRM1 static void __fd_clo(int fd)
|
||||||
{
|
{
|
||||||
HA_SPIN_LOCK(POLL_LOCK, &poll_lock);
|
|
||||||
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_SPIN_UNLOCK(POLL_LOCK, &poll_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -73,7 +71,6 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
|
|
||||||
if ((eo ^ en) & FD_EV_POLLED_RW) {
|
if ((eo ^ en) & FD_EV_POLLED_RW) {
|
||||||
/* poll status changed, update the lists */
|
/* poll status changed, update the lists */
|
||||||
HA_SPIN_LOCK(POLL_LOCK, &poll_lock);
|
|
||||||
if ((eo & ~en) & FD_EV_POLLED_R)
|
if ((eo & ~en) & FD_EV_POLLED_R)
|
||||||
hap_fd_clr(fd, fd_evts[DIR_RD]);
|
hap_fd_clr(fd, fd_evts[DIR_RD]);
|
||||||
else if ((en & ~eo) & FD_EV_POLLED_R) {
|
else if ((en & ~eo) & FD_EV_POLLED_R) {
|
||||||
@ -89,7 +86,6 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
if (fd > max_add_fd)
|
if (fd > max_add_fd)
|
||||||
max_add_fd = fd;
|
max_add_fd = fd;
|
||||||
}
|
}
|
||||||
HA_SPIN_UNLOCK(POLL_LOCK, &poll_lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
src/fd.c
3
src/fd.c
@ -175,7 +175,6 @@ THREAD_LOCAL int *fd_updt = NULL; // FD updates list
|
|||||||
THREAD_LOCAL int fd_nbupdt = 0; // number of updates in the list
|
THREAD_LOCAL int fd_nbupdt = 0; // number of updates in the list
|
||||||
|
|
||||||
__decl_hathreads(HA_RWLOCK_T fdcache_lock); /* global lock to protect fd_cache array */
|
__decl_hathreads(HA_RWLOCK_T fdcache_lock); /* global lock to protect fd_cache array */
|
||||||
__decl_hathreads(HA_SPINLOCK_T poll_lock); /* global lock to protect poll info */
|
|
||||||
|
|
||||||
/* Deletes an FD from the fdsets.
|
/* Deletes an FD from the fdsets.
|
||||||
* The file descriptor is also closed.
|
* The file descriptor is also closed.
|
||||||
@ -331,7 +330,6 @@ int init_pollers()
|
|||||||
HA_SPIN_INIT(&fdtab[p].lock);
|
HA_SPIN_INIT(&fdtab[p].lock);
|
||||||
|
|
||||||
HA_RWLOCK_INIT(&fdcache_lock);
|
HA_RWLOCK_INIT(&fdcache_lock);
|
||||||
HA_SPIN_INIT(&poll_lock);
|
|
||||||
do {
|
do {
|
||||||
bp = NULL;
|
bp = NULL;
|
||||||
for (p = 0; p < nbpollers; p++)
|
for (p = 0; p < nbpollers; p++)
|
||||||
@ -379,7 +377,6 @@ void deinit_pollers() {
|
|||||||
free(fdtab); fdtab = NULL;
|
free(fdtab); fdtab = NULL;
|
||||||
|
|
||||||
HA_RWLOCK_DESTROY(&fdcache_lock);
|
HA_RWLOCK_DESTROY(&fdcache_lock);
|
||||||
HA_SPIN_DESTROY(&poll_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user