2006-06-25 20:48:02 -04:00
|
|
|
/*
|
2009-10-18 01:25:52 -04:00
|
|
|
* include/types/fd.h
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
* File descriptors states - check src/fd.c for explanations.
|
2009-10-18 01:25:52 -04:00
|
|
|
*
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
* Copyright (C) 2000-2014 Willy Tarreau - w@1wt.eu
|
2009-10-18 01:25:52 -04:00
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation, version 2.1
|
|
|
|
|
* exclusively.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*/
|
2006-06-25 20:48:02 -04:00
|
|
|
|
|
|
|
|
#ifndef _TYPES_FD_H
|
|
|
|
|
#define _TYPES_FD_H
|
|
|
|
|
|
2006-06-29 11:53:05 -04:00
|
|
|
#include <common/config.h>
|
MAJOR: threads/fd: Make fd stuffs thread-safe
Many changes have been made to do so. First, the fd_updt array, where all
pending FDs for polling are stored, is now a thread-local array. Then 3 locks
have been added to protect, respectively, the fdtab array, the fd_cache array
and poll information. In addition, a lock for each entry in the fdtab array has
been added to protect all accesses to a specific FD or its information.
For pollers, according to the poller, the way to manage the concurrency is
different. There is a poller loop on each thread. So the set of monitored FDs
may need to be protected. epoll and kqueue are thread-safe per-se, so there few
things to do to protect these pollers. This is not possible with select and
poll, so there is no sharing between the threads. The poller on each thread is
independant from others.
Finally, per-thread init/deinit functions are used for each pollers and for FD
part for manage thread-local ressources.
Now, you must be carefull when a FD is created during the HAProxy startup. All
update on the FD state must be made in the threads context and never before
their creation. This is mandatory because fd_updt array is thread-local and
initialized only for threads. Because there is no pollers for the main one, this
array remains uninitialized in this context. For this reason, listeners are now
enabled in run_thread_poll_loop function, just like the worker pipe.
2017-05-29 04:40:41 -04:00
|
|
|
#include <common/hathreads.h>
|
2012-09-02 16:34:23 -04:00
|
|
|
#include <types/port_range.h>
|
2006-06-25 20:48:02 -04:00
|
|
|
|
2012-11-11 09:02:54 -05:00
|
|
|
/* Direction for each FD event update */
|
2006-07-29 10:59:06 -04:00
|
|
|
enum {
|
|
|
|
|
DIR_RD=0,
|
|
|
|
|
DIR_WR=1,
|
|
|
|
|
};
|
2006-06-25 20:48:02 -04:00
|
|
|
|
2012-11-11 09:02:54 -05:00
|
|
|
/* Polling status flags returned in fdtab[].ev :
|
2008-01-18 11:20:13 -05:00
|
|
|
* FD_POLL_IN remains set as long as some data is pending for read.
|
|
|
|
|
* FD_POLL_OUT remains set as long as the fd accepts to write data.
|
|
|
|
|
* FD_POLL_ERR and FD_POLL_ERR remain set forever (until processed).
|
|
|
|
|
*/
|
2007-04-15 05:31:05 -04:00
|
|
|
#define FD_POLL_IN 0x01
|
|
|
|
|
#define FD_POLL_PRI 0x02
|
|
|
|
|
#define FD_POLL_OUT 0x04
|
|
|
|
|
#define FD_POLL_ERR 0x08
|
|
|
|
|
#define FD_POLL_HUP 0x10
|
|
|
|
|
|
2008-01-18 11:20:13 -05:00
|
|
|
#define FD_POLL_DATA (FD_POLL_IN | FD_POLL_OUT)
|
|
|
|
|
#define FD_POLL_STICKY (FD_POLL_ERR | FD_POLL_HUP)
|
2007-04-15 05:31:05 -04:00
|
|
|
|
2012-11-11 09:02:54 -05:00
|
|
|
#define FD_EV_ACTIVE 1U
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
#define FD_EV_READY 2U
|
2012-11-11 09:02:54 -05:00
|
|
|
#define FD_EV_POLLED 4U
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
|
|
|
|
|
#define FD_EV_STATUS (FD_EV_ACTIVE | FD_EV_POLLED | FD_EV_READY)
|
2012-11-11 09:02:54 -05:00
|
|
|
#define FD_EV_STATUS_R (FD_EV_STATUS)
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
#define FD_EV_STATUS_W (FD_EV_STATUS << 4)
|
2012-11-11 09:02:54 -05:00
|
|
|
|
|
|
|
|
#define FD_EV_POLLED_R (FD_EV_POLLED)
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
#define FD_EV_POLLED_W (FD_EV_POLLED << 4)
|
2012-11-11 09:02:54 -05:00
|
|
|
#define FD_EV_POLLED_RW (FD_EV_POLLED_R | FD_EV_POLLED_W)
|
|
|
|
|
|
|
|
|
|
#define FD_EV_ACTIVE_R (FD_EV_ACTIVE)
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
#define FD_EV_ACTIVE_W (FD_EV_ACTIVE << 4)
|
2012-11-11 09:02:54 -05:00
|
|
|
#define FD_EV_ACTIVE_RW (FD_EV_ACTIVE_R | FD_EV_ACTIVE_W)
|
|
|
|
|
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
#define FD_EV_READY_R (FD_EV_READY)
|
|
|
|
|
#define FD_EV_READY_W (FD_EV_READY << 4)
|
|
|
|
|
#define FD_EV_READY_RW (FD_EV_READY_R | FD_EV_READY_W)
|
|
|
|
|
|
|
|
|
|
enum fd_states {
|
|
|
|
|
FD_ST_DISABLED = 0,
|
|
|
|
|
FD_ST_MUSTPOLL,
|
|
|
|
|
FD_ST_STOPPED,
|
|
|
|
|
FD_ST_ACTIVE,
|
|
|
|
|
FD_ST_ABORT,
|
|
|
|
|
FD_ST_POLLED,
|
|
|
|
|
FD_ST_PAUSED,
|
|
|
|
|
FD_ST_READY
|
|
|
|
|
};
|
2012-11-11 09:02:54 -05:00
|
|
|
|
2016-11-17 08:22:52 -05:00
|
|
|
|
|
|
|
|
/* This is the value used to mark a file descriptor as dead. This value is
|
|
|
|
|
* negative, this is important so that tests on fd < 0 properly match. It
|
|
|
|
|
* also has the nice property of being highly negative but not overflowing
|
|
|
|
|
* nor changing sign on 32-bit machines when multipled by sizeof(fdtab).
|
|
|
|
|
* This ensures that any unexpected dereference of such an uninitialized
|
|
|
|
|
* file descriptor will lead to so large a dereference that it will crash
|
|
|
|
|
* the process at the exact location of the bug with a clean stack trace
|
|
|
|
|
* instead of causing silent manipulation of other FDs. And it's readable
|
|
|
|
|
* when found in a dump.
|
|
|
|
|
*/
|
|
|
|
|
#define DEAD_FD_MAGIC 0xFDDEADFD
|
|
|
|
|
|
MEDIUM: fd/threads: Make sure we don't miss a fd cache entry.
An fd cache entry might be removed and added at the end of the list, while
another thread is parsing it, if that happens, we may miss fd cache entries,
to avoid that, add a new field in the struct fdtab, "added_mask", which
contains a mask for potentially affected threads, if it is set, the
corresponding thread will set its bit in fd_cache_mask, to avoid waiting in
poll while it may have more work to do.
2018-01-31 12:07:29 -05:00
|
|
|
/* fdlist_entry: entry used by the fd cache.
|
|
|
|
|
* >= 0 means we're in the cache and gives the FD of the next in the cache,
|
|
|
|
|
* -1 means we're in the cache and the last element,
|
|
|
|
|
* -2 means the entry is locked,
|
|
|
|
|
* <= -3 means not in the cache, and next element is -4-fd
|
|
|
|
|
*
|
|
|
|
|
* It must remain 8-aligned so that aligned CAS operations may be done on both
|
|
|
|
|
* entries at once.
|
|
|
|
|
*/
|
2018-01-24 12:17:56 -05:00
|
|
|
struct fdlist_entry {
|
MEDIUM: fd/threads: Make sure we don't miss a fd cache entry.
An fd cache entry might be removed and added at the end of the list, while
another thread is parsing it, if that happens, we may miss fd cache entries,
to avoid that, add a new field in the struct fdtab, "added_mask", which
contains a mask for potentially affected threads, if it is set, the
corresponding thread will set its bit in fd_cache_mask, to avoid waiting in
poll while it may have more work to do.
2018-01-31 12:07:29 -05:00
|
|
|
int next;
|
|
|
|
|
int prev;
|
2018-01-24 12:17:56 -05:00
|
|
|
} __attribute__ ((aligned(8)));
|
|
|
|
|
|
MEDIUM: fd/threads: Make sure we don't miss a fd cache entry.
An fd cache entry might be removed and added at the end of the list, while
another thread is parsing it, if that happens, we may miss fd cache entries,
to avoid that, add a new field in the struct fdtab, "added_mask", which
contains a mask for potentially affected threads, if it is set, the
corresponding thread will set its bit in fd_cache_mask, to avoid waiting in
poll while it may have more work to do.
2018-01-31 12:07:29 -05:00
|
|
|
/* head of the fd cache */
|
2018-01-24 12:17:56 -05:00
|
|
|
struct fdlist {
|
MEDIUM: fd/threads: Make sure we don't miss a fd cache entry.
An fd cache entry might be removed and added at the end of the list, while
another thread is parsing it, if that happens, we may miss fd cache entries,
to avoid that, add a new field in the struct fdtab, "added_mask", which
contains a mask for potentially affected threads, if it is set, the
corresponding thread will set its bit in fd_cache_mask, to avoid waiting in
poll while it may have more work to do.
2018-01-31 12:07:29 -05:00
|
|
|
int first;
|
|
|
|
|
int last;
|
2018-01-24 12:17:56 -05:00
|
|
|
} __attribute__ ((aligned(8)));
|
|
|
|
|
|
2006-06-25 20:48:02 -04:00
|
|
|
/* info about one given fd */
|
|
|
|
|
struct fdtab {
|
2017-11-26 04:41:47 -05:00
|
|
|
__decl_hathreads(HA_SPINLOCK_T lock);
|
|
|
|
|
unsigned long thread_mask; /* mask of thread IDs authorized to process the task */
|
2018-01-20 17:53:50 -05:00
|
|
|
unsigned long update_mask; /* mask of thread IDs having an update for fd */
|
MEDIUM: fd/threads: Make sure we don't miss a fd cache entry.
An fd cache entry might be removed and added at the end of the list, while
another thread is parsing it, if that happens, we may miss fd cache entries,
to avoid that, add a new field in the struct fdtab, "added_mask", which
contains a mask for potentially affected threads, if it is set, the
corresponding thread will set its bit in fd_cache_mask, to avoid waiting in
poll while it may have more work to do.
2018-01-31 12:07:29 -05:00
|
|
|
struct fdlist_entry cache; /* Entry in the fdcache */
|
2018-04-25 10:58:25 -04:00
|
|
|
struct fdlist_entry update; /* Entry in the global update list */
|
2016-04-14 05:13:20 -04:00
|
|
|
void (*iocb)(int fd); /* I/O handler */
|
2012-07-06 08:54:49 -04:00
|
|
|
void *owner; /* the connection or listener associated with this fd, NULL if closed */
|
MAJOR: polling: rework the whole polling system
This commit heavily changes the polling system in order to definitely
fix the frequent breakage of SSL which needs to remember the last
EAGAIN before deciding whether to poll or not. Now we have a state per
direction for each FD, as opposed to a previous and current state
previously. An FD can have up to 8 different states for each direction,
each of which being the result of a 3-bit combination. These 3 bits
indicate a wish to access the FD, the readiness of the FD and the
subscription of the FD to the polling system.
This means that it will now be possible to remember the state of a
file descriptor across disable/enable sequences that generally happen
during forwarding, where enabling reading on a previously disabled FD
would result in forgetting the EAGAIN flag it met last time.
Several new state manipulation functions have been introduced or
adapted :
- fd_want_{recv,send} : enable receiving/sending on the FD regardless
of its state (sets the ACTIVE flag) ;
- fd_stop_{recv,send} : stop receiving/sending on the FD regardless
of its state (clears the ACTIVE flag) ;
- fd_cant_{recv,send} : report a failure to receive/send on the FD
corresponding to EAGAIN (clears the READY flag) ;
- fd_may_{recv,send} : report the ability to receive/send on the FD
as reported by poll() (sets the READY flag) ;
Some functions are used to report the current FD status :
- fd_{recv,send}_active
- fd_{recv,send}_ready
- fd_{recv,send}_polled
Some functions were removed :
- fd_ev_clr(), fd_ev_set(), fd_ev_rem(), fd_ev_wai()
The POLLHUP/POLLERR flags are now reported as ready so that the I/O layers
knows it can try to access the file descriptor to get this information.
In order to simplify the conditions to add/remove cache entries, a new
function fd_alloc_or_release_cache_entry() was created to be used from
pollers while scanning for updates.
The following pollers have been updated :
ev_select() : done, built, tested on Linux 3.10
ev_poll() : done, built, tested on Linux 3.10
ev_epoll() : done, built, tested on Linux 3.10 & 3.13
ev_kqueue() : done, built, tested on OpenBSD 5.2
2014-01-10 10:58:45 -05:00
|
|
|
unsigned char state; /* FD state for read and write directions (2*3 bits) */
|
2007-04-15 05:31:05 -04:00
|
|
|
unsigned char ev; /* event seen in return of poll() : FD_POLL_* */
|
2013-12-15 08:19:38 -05:00
|
|
|
unsigned char linger_risk:1; /* 1 if we must kill lingering before closing */
|
2014-05-20 08:28:24 -04:00
|
|
|
unsigned char cloned:1; /* 1 if a cloned socket, requires EPOLL_CTL_DEL on close */
|
2009-10-18 01:25:52 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* less often used information */
|
|
|
|
|
struct fdinfo {
|
2009-06-10 05:09:37 -04:00
|
|
|
struct port_range *port_range; /* optional port range to bind to */
|
2009-10-18 01:25:52 -04:00
|
|
|
int local_port; /* optional local port */
|
2006-06-25 20:48:02 -04:00
|
|
|
};
|
|
|
|
|
|
2007-04-08 10:39:58 -04:00
|
|
|
/*
|
|
|
|
|
* Poller descriptors.
|
|
|
|
|
* - <name> is initialized by the poller's register() function, and should not
|
|
|
|
|
* be allocated, just linked to.
|
|
|
|
|
* - <pref> is initialized by the poller's register() function. It is set to 0
|
|
|
|
|
* by default, meaning the poller is disabled. init() should set it to 0 in
|
|
|
|
|
* case of failure. term() must set it to 0. A generic unoptimized select()
|
|
|
|
|
* poller should set it to 100.
|
|
|
|
|
* - <private> is initialized by the poller's init() function, and cleaned by
|
|
|
|
|
* the term() function.
|
2012-11-11 15:02:34 -05:00
|
|
|
* - clo() should be used to do indicate the poller that fd will be closed.
|
2007-05-12 16:35:00 -04:00
|
|
|
* - poll() calls the poller, expiring at <exp>
|
2017-03-13 06:38:28 -04:00
|
|
|
* - flags indicate what the poller supports (HAP_POLL_F_*)
|
2007-04-08 10:39:58 -04:00
|
|
|
*/
|
2017-03-13 06:38:28 -04:00
|
|
|
|
|
|
|
|
#define HAP_POLL_F_RDHUP 0x00000001 /* the poller notifies of HUP with reads */
|
|
|
|
|
|
2007-04-08 10:39:58 -04:00
|
|
|
struct poller {
|
|
|
|
|
void *private; /* any private data for the poller */
|
2012-11-11 15:02:34 -05:00
|
|
|
void REGPRM1 (*clo)(const int fd); /* mark <fd> as closed */
|
2008-07-06 18:09:58 -04:00
|
|
|
void REGPRM2 (*poll)(struct poller *p, int exp); /* the poller itself */
|
2007-04-15 19:33:26 -04:00
|
|
|
int REGPRM1 (*init)(struct poller *p); /* poller initialization */
|
|
|
|
|
void REGPRM1 (*term)(struct poller *p); /* termination of this poller */
|
|
|
|
|
int REGPRM1 (*test)(struct poller *p); /* pre-init check of the poller */
|
|
|
|
|
int REGPRM1 (*fork)(struct poller *p); /* post-fork re-opening */
|
2007-04-08 10:39:58 -04:00
|
|
|
const char *name; /* poller name */
|
2017-03-13 06:38:28 -04:00
|
|
|
unsigned int flags; /* HAP_POLL_F_* */
|
2007-04-08 10:39:58 -04:00
|
|
|
int pref; /* try pollers with higher preference first */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern struct poller cur_poller; /* the current poller */
|
|
|
|
|
extern int nbpollers;
|
|
|
|
|
#define MAX_POLLERS 10
|
|
|
|
|
extern struct poller pollers[MAX_POLLERS]; /* all registered pollers */
|
|
|
|
|
|
2006-06-25 20:48:02 -04:00
|
|
|
extern struct fdtab *fdtab; /* array of all the file descriptors */
|
2009-10-18 01:25:52 -04:00
|
|
|
extern struct fdinfo *fdinfo; /* less-often used infos for file descriptors */
|
2006-06-25 20:48:02 -04:00
|
|
|
extern int totalconn; /* total # of terminated sessions */
|
|
|
|
|
extern int actconn; /* # of active sessions */
|
|
|
|
|
|
|
|
|
|
#endif /* _TYPES_FD_H */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Local variables:
|
|
|
|
|
* c-indent-level: 8
|
|
|
|
|
* c-basic-offset: 8
|
|
|
|
|
* End:
|
|
|
|
|
*/
|