Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * FD polling functions for Speculative I/O combined with Linux epoll() |
| 3 | * |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 4 | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
Willy Tarreau | f2e8ee2 | 2008-05-25 10:39:02 +0200 | [diff] [blame] | 11 | * |
| 12 | * This code implements "speculative I/O" under Linux. The principle is to |
| 13 | * try to perform expected I/O before registering the events in the poller. |
| 14 | * Each time this succeeds, it saves an expensive epoll_ctl(). It generally |
| 15 | * succeeds for all reads after an accept(), and for writes after a connect(). |
| 16 | * It also improves performance for streaming connections because even if only |
| 17 | * one side is polled, the other one may react accordingly depending on the |
| 18 | * level of the buffer. |
| 19 | * |
| 20 | * It has a presents drawbacks though. If too many events are set for spec I/O, |
| 21 | * those ones can starve the polled events. Experiments show that when polled |
| 22 | * events starve, they quickly turn into spec I/O, making the situation even |
| 23 | * worse. While we can reduce the number of polled events processed at once, |
| 24 | * we cannot do this on speculative events because most of them are new ones |
| 25 | * (avg 2/3 new - 1/3 old from experiments). |
| 26 | * |
| 27 | * The solution against this problem relies on those two factors : |
| 28 | * 1) one FD registered as a spec event cannot be polled at the same time |
| 29 | * 2) even during very high loads, we will almost never be interested in |
| 30 | * simultaneous read and write streaming on the same FD. |
| 31 | * |
| 32 | * The first point implies that during starvation, we will not have more than |
| 33 | * half of our FDs in the poll list, otherwise it means there is less than that |
| 34 | * in the spec list, implying there is no starvation. |
| 35 | * |
| 36 | * The second point implies that we're statically only interested in half of |
| 37 | * the maximum number of file descriptors at once, because we will unlikely |
| 38 | * have simultaneous read and writes for a same buffer during long periods. |
| 39 | * |
| 40 | * So, if we make it possible to drain maxsock/2/2 during peak loads, then we |
| 41 | * can ensure that there will be no starvation effect. This means that we must |
| 42 | * always allocate maxsock/4 events for the poller. |
| 43 | * |
| 44 | * |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 45 | */ |
| 46 | |
| 47 | #include <unistd.h> |
| 48 | #include <sys/time.h> |
| 49 | #include <sys/types.h> |
| 50 | |
| 51 | #include <common/compat.h> |
| 52 | #include <common/config.h> |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 53 | #include <common/debug.h> |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 54 | #include <common/epoll.h> |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 55 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 56 | #include <common/ticks.h> |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 57 | #include <common/time.h> |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 58 | #include <common/tools.h> |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 59 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 60 | #include <types/global.h> |
| 61 | |
| 62 | #include <proto/fd.h> |
Willy Tarreau | 332740d | 2009-05-10 09:57:21 +0200 | [diff] [blame] | 63 | #include <proto/signal.h> |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 64 | #include <proto/task.h> |
| 65 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 66 | /* |
| 67 | * We define 4 states for each direction of a file descriptor, which we store |
| 68 | * as 2 bits : |
| 69 | * |
| 70 | * 00 = IDLE : we're not interested in this event |
| 71 | * 01 = SPEC : perform speculative I/O on this FD |
| 72 | * 10 = WAIT : really wait for an availability event on this FD (poll) |
| 73 | * 11 = STOP : was marked WAIT, but disabled. It can switch back to WAIT if |
| 74 | * the application changes its mind, otherwise disable FD polling |
| 75 | * and switch back to IDLE. |
| 76 | * |
| 77 | * Since we do not want to scan all the FD list to find speculative I/O events, |
| 78 | * we store them in a list consisting in a linear array holding only the FD |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 79 | * indexes right now. Note that a closed FD cannot exist in the spec list, |
| 80 | * because it is closed by fd_delete() which in turn calls __fd_clo() which |
| 81 | * always removes it from the list. |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 82 | * |
| 83 | * The STOP state requires the event to be present in the spec list so that |
| 84 | * it can be detected and flushed upon next scan without having to scan the |
| 85 | * whole FD list. |
| 86 | * |
| 87 | * This translates like this : |
| 88 | * |
| 89 | * EVENT_IN_SPEC_LIST = 01 |
| 90 | * EVENT_IN_POLL_LIST = 10 |
| 91 | * |
| 92 | * IDLE = 0 |
| 93 | * SPEC = (EVENT_IN_SPEC_LIST) |
| 94 | * WAIT = (EVENT_IN_POLL_LIST) |
| 95 | * STOP = (EVENT_IN_SPEC_LIST|EVENT_IN_POLL_LIST) |
| 96 | * |
| 97 | * fd_is_set() just consists in checking that the status is 01 or 10. |
| 98 | * |
| 99 | * For efficiency reasons, we will store the Read and Write bits interlaced to |
| 100 | * form a 4-bit field, so that we can simply shift the value right by 0/1 and |
| 101 | * get what we want : |
| 102 | * 3 2 1 0 |
| 103 | * Wp Rp Ws Rs |
| 104 | * |
| 105 | * The FD array has to hold a back reference to the speculative list. This |
| 106 | * reference is only valid if at least one of the directions is marked SPEC. |
| 107 | * |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 108 | * We store the FD state in the 4 lower bits of fdtab[fd].spec_e, and save the |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 109 | * previous state upon changes in the 4 higher bits, so that changes are easy |
| 110 | * to spot. |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 111 | */ |
| 112 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 113 | #define FD_EV_IN_SL 1U |
| 114 | #define FD_EV_IN_PL 4U |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 115 | |
| 116 | #define FD_EV_IDLE 0 |
| 117 | #define FD_EV_SPEC (FD_EV_IN_SL) |
| 118 | #define FD_EV_WAIT (FD_EV_IN_PL) |
| 119 | #define FD_EV_STOP (FD_EV_IN_SL|FD_EV_IN_PL) |
| 120 | |
| 121 | /* Those match any of R or W for Spec list or Poll list */ |
| 122 | #define FD_EV_RW_SL (FD_EV_IN_SL | (FD_EV_IN_SL << 1)) |
| 123 | #define FD_EV_RW_PL (FD_EV_IN_PL | (FD_EV_IN_PL << 1)) |
| 124 | #define FD_EV_MASK_DIR (FD_EV_IN_SL|FD_EV_IN_PL) |
| 125 | |
| 126 | #define FD_EV_IDLE_R 0 |
| 127 | #define FD_EV_SPEC_R (FD_EV_IN_SL) |
| 128 | #define FD_EV_WAIT_R (FD_EV_IN_PL) |
| 129 | #define FD_EV_STOP_R (FD_EV_IN_SL|FD_EV_IN_PL) |
| 130 | #define FD_EV_MASK_R (FD_EV_IN_SL|FD_EV_IN_PL) |
| 131 | |
| 132 | #define FD_EV_IDLE_W (FD_EV_IDLE_R << 1) |
| 133 | #define FD_EV_SPEC_W (FD_EV_SPEC_R << 1) |
| 134 | #define FD_EV_WAIT_W (FD_EV_WAIT_R << 1) |
| 135 | #define FD_EV_STOP_W (FD_EV_STOP_R << 1) |
| 136 | #define FD_EV_MASK_W (FD_EV_MASK_R << 1) |
| 137 | |
| 138 | #define FD_EV_MASK (FD_EV_MASK_W | FD_EV_MASK_R) |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 139 | #define FD_EV_MASK_OLD (FD_EV_MASK << 4) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 140 | |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 141 | /* This is the minimum number of events successfully processed in speculative |
| 142 | * mode above which we agree to return without checking epoll() (1/2 times). |
| 143 | */ |
| 144 | #define MIN_RETURN_EVENTS 25 |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 145 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 146 | static int nbspec = 0; // current size of the spec list |
Willy Tarreau | f2e8ee2 | 2008-05-25 10:39:02 +0200 | [diff] [blame] | 147 | static int absmaxevents = 0; // absolute maximum amounts of polled events |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 148 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 149 | static unsigned int *spec_list = NULL; // speculative I/O list |
| 150 | |
| 151 | /* private data */ |
| 152 | static struct epoll_event *epoll_events; |
| 153 | static int epoll_fd; |
| 154 | |
| 155 | /* This structure may be used for any purpose. Warning! do not use it in |
| 156 | * recursive functions ! |
| 157 | */ |
| 158 | static struct epoll_event ev; |
| 159 | |
| 160 | |
Willy Tarreau | ff9d5ba | 2009-10-17 21:43:03 +0200 | [diff] [blame] | 161 | REGPRM1 static inline void alloc_spec_entry(const int fd) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 162 | { |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 163 | if (fdtab[fd].spec_p) |
Willy Tarreau | ff9d5ba | 2009-10-17 21:43:03 +0200 | [diff] [blame] | 164 | /* sometimes the entry already exists for the other direction */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 165 | return; |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 166 | fdtab[fd].spec_p = nbspec + 1; |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 167 | spec_list[nbspec] = fd; |
| 168 | nbspec++; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 171 | /* Removes entry used by fd <fd> from the spec list and replaces it with the |
Willy Tarreau | b48b323 | 2009-10-17 22:54:17 +0200 | [diff] [blame] | 172 | * last one. The fdtab.spec is adjusted to match the back reference if needed. |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 173 | * If the fd has no entry assigned, return immediately. |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 174 | */ |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 175 | REGPRM1 static void release_spec_entry(int fd) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 176 | { |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 177 | unsigned int pos; |
| 178 | |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 179 | pos = fdtab[fd].spec_p; |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 180 | if (!pos) |
| 181 | return; |
| 182 | |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 183 | fdtab[fd].spec_p = 0; |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 184 | pos--; |
| 185 | /* we have spec_list[pos]==fd */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 186 | |
| 187 | nbspec--; |
| 188 | if (pos == nbspec) |
| 189 | return; |
| 190 | |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 191 | /* we replace current FD by the highest one, which may sometimes be the same */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 192 | fd = spec_list[nbspec]; |
| 193 | spec_list[pos] = fd; |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 194 | fdtab[fd].spec_p = pos + 1; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Returns non-zero if <fd> is already monitored for events in direction <dir>. |
| 199 | */ |
| 200 | REGPRM2 static int __fd_is_set(const int fd, int dir) |
| 201 | { |
| 202 | int ret; |
| 203 | |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 204 | #if DEBUG_DEV |
Willy Tarreau | db3b326 | 2012-07-05 23:19:22 +0200 | [diff] [blame] | 205 | if (!fdtab[fd].owner) { |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 206 | fprintf(stderr, "sepoll.fd_isset called on closed fd #%d.\n", fd); |
| 207 | ABORT_NOW(); |
| 208 | } |
| 209 | #endif |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 210 | ret = ((unsigned)fdtab[fd].spec_e >> dir) & FD_EV_MASK_DIR; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 211 | return (ret == FD_EV_SPEC || ret == FD_EV_WAIT); |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Don't worry about the strange constructs in __fd_set/__fd_clr, they are |
| 216 | * designed like this in order to reduce the number of jumps (verified). |
| 217 | */ |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 218 | REGPRM2 static void __fd_wai(const int fd, int dir) |
| 219 | { |
| 220 | unsigned int i; |
| 221 | |
| 222 | #if DEBUG_DEV |
| 223 | if (!fdtab[fd].owner) { |
| 224 | fprintf(stderr, "sepoll.fd_wai called on closed fd #%d.\n", fd); |
| 225 | ABORT_NOW(); |
| 226 | } |
| 227 | #endif |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 228 | i = ((unsigned)fdtab[fd].spec_e >> dir) & FD_EV_MASK_DIR; |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 229 | |
| 230 | if (!(i & FD_EV_IN_SL)) { |
| 231 | if (i == FD_EV_WAIT) |
| 232 | return; /* already in desired state */ |
| 233 | alloc_spec_entry(fd); /* need a spec entry */ |
| 234 | } |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 235 | fdtab[fd].spec_e ^= (i ^ (unsigned int)FD_EV_IN_PL) << dir; |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 236 | } |
| 237 | |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 238 | REGPRM2 static void __fd_set(const int fd, int dir) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 239 | { |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 240 | unsigned int i; |
| 241 | |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 242 | #if DEBUG_DEV |
Willy Tarreau | db3b326 | 2012-07-05 23:19:22 +0200 | [diff] [blame] | 243 | if (!fdtab[fd].owner) { |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 244 | fprintf(stderr, "sepoll.fd_set called on closed fd #%d.\n", fd); |
| 245 | ABORT_NOW(); |
| 246 | } |
| 247 | #endif |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 248 | i = ((unsigned)fdtab[fd].spec_e >> dir) & FD_EV_MASK_DIR; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 249 | |
Willy Tarreau | ff9d5ba | 2009-10-17 21:43:03 +0200 | [diff] [blame] | 250 | if (i != FD_EV_STOP) { |
| 251 | if (unlikely(i != FD_EV_IDLE)) |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 252 | return; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 253 | // switch to SPEC state and allocate a SPEC entry. |
| 254 | alloc_spec_entry(fd); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 255 | } |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 256 | fdtab[fd].spec_e ^= (unsigned int)(FD_EV_IN_SL << dir); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 259 | REGPRM2 static void __fd_clr(const int fd, int dir) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 260 | { |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 261 | unsigned int i; |
| 262 | |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 263 | #if DEBUG_DEV |
Willy Tarreau | db3b326 | 2012-07-05 23:19:22 +0200 | [diff] [blame] | 264 | if (!fdtab[fd].owner) { |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 265 | fprintf(stderr, "sepoll.fd_clr called on closed fd #%d.\n", fd); |
| 266 | ABORT_NOW(); |
| 267 | } |
| 268 | #endif |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 269 | i = ((unsigned)fdtab[fd].spec_e >> dir) & FD_EV_MASK_DIR; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 270 | |
Willy Tarreau | ff9d5ba | 2009-10-17 21:43:03 +0200 | [diff] [blame] | 271 | if (i != FD_EV_SPEC) { |
| 272 | if (unlikely(i != FD_EV_WAIT)) |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 273 | return; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 274 | // switch to STOP state |
| 275 | /* We will create a queue entry for this one because we want to |
| 276 | * process it later in order to merge it with other events on |
| 277 | * the same FD. |
| 278 | */ |
| 279 | alloc_spec_entry(fd); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 280 | } |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 281 | fdtab[fd].spec_e ^= (unsigned int)(FD_EV_IN_SL << dir); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 284 | /* normally unused */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 285 | REGPRM1 static void __fd_rem(int fd) |
| 286 | { |
| 287 | __fd_clr(fd, DIR_RD); |
| 288 | __fd_clr(fd, DIR_WR); |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * On valid epoll() implementations, a call to close() automatically removes |
| 293 | * the fds. This means that the FD will appear as previously unset. |
| 294 | */ |
| 295 | REGPRM1 static void __fd_clo(int fd) |
| 296 | { |
Willy Tarreau | 7a52a5c | 2008-08-16 16:06:02 +0200 | [diff] [blame] | 297 | release_spec_entry(fd); |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 298 | fdtab[fd].spec_e &= ~(FD_EV_MASK | FD_EV_MASK_OLD); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Willy Tarreau | dc246a7 | 2007-05-09 21:57:51 +0200 | [diff] [blame] | 301 | /* |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 302 | * speculative epoll() poller |
| 303 | */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 304 | REGPRM2 static void _do_poll(struct poller *p, int exp) |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 305 | { |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 306 | int status, eo, en; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 307 | int fd, opcode; |
| 308 | int count; |
| 309 | int spec_idx; |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 310 | int wait_time; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 311 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 312 | /* first, update the poll list according to what changed in the spec list */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 313 | spec_idx = nbspec; |
| 314 | while (likely(spec_idx > 0)) { |
| 315 | spec_idx--; |
| 316 | fd = spec_list[spec_idx]; |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 317 | en = fdtab[fd].spec_e & 15; /* new events */ |
| 318 | eo = fdtab[fd].spec_e >> 4; /* previous events */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 319 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 320 | /* If an fd with a poll bit is present here, it means that it |
| 321 | * has last requested a poll, or is leaving from a poll. Given |
| 322 | * that an FD is fully in the poll list or in the spec list but |
| 323 | * not in both at once, we'll first ensure that if it is |
| 324 | * already being polled in one direction and requests a spec |
| 325 | * access, then we'll turn that into a polled access in order |
| 326 | * to save a syscall which will likely return EAGAIN. |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 327 | */ |
| 328 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 329 | if ((en & FD_EV_RW_PL) && (en & FD_EV_RW_SL)) { |
| 330 | /* convert SPEC to WAIT if fd already being polled */ |
| 331 | if ((en & FD_EV_MASK_R) == FD_EV_SPEC_R) |
| 332 | en = (en & ~FD_EV_MASK_R) | FD_EV_WAIT_R; |
| 333 | |
| 334 | if ((en & FD_EV_MASK_W) == FD_EV_SPEC_W) |
| 335 | en = (en & ~FD_EV_MASK_W) | FD_EV_WAIT_W; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 336 | } |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 337 | |
| 338 | if ((en & FD_EV_MASK_R) == FD_EV_STOP_R) { |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 339 | /* This FD was being polled and is now being removed. */ |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 340 | en &= ~FD_EV_MASK_R; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 341 | } |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 342 | |
| 343 | if ((en & FD_EV_MASK_W) == FD_EV_STOP_W) { |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 344 | /* This FD was being polled and is now being removed. */ |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 345 | en &= ~FD_EV_MASK_W; |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 346 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 347 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 348 | if ((eo ^ en) & FD_EV_RW_PL) { |
| 349 | /* poll status changed */ |
| 350 | if ((en & FD_EV_RW_PL) == 0) { |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 351 | /* fd removed from poll list */ |
| 352 | opcode = EPOLL_CTL_DEL; |
| 353 | } |
| 354 | else if ((eo & FD_EV_RW_PL) == 0) { |
| 355 | /* new fd in the poll list */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 356 | opcode = EPOLL_CTL_ADD; |
| 357 | } |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 358 | else { |
| 359 | /* fd status changed */ |
| 360 | opcode = EPOLL_CTL_MOD; |
| 361 | } |
| 362 | |
| 363 | /* construct the epoll events based on new state */ |
| 364 | ev.events = 0; |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 365 | if (en & FD_EV_WAIT_R) |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 366 | ev.events |= EPOLLIN; |
| 367 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 368 | if (en & FD_EV_WAIT_W) |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 369 | ev.events |= EPOLLOUT; |
| 370 | |
| 371 | ev.data.fd = fd; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 372 | epoll_ctl(epoll_fd, opcode, fd, &ev); |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 373 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 374 | |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 375 | fdtab[fd].spec_e = (en << 4) + en; /* save new events */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 376 | |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 377 | if (!(fdtab[fd].spec_e & FD_EV_RW_SL)) { |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 378 | /* This fd switched to combinations of either WAIT or |
| 379 | * IDLE. It must be removed from the spec list. |
| 380 | */ |
Willy Tarreau | 4eac209 | 2007-08-31 17:01:18 +0200 | [diff] [blame] | 381 | release_spec_entry(fd); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 385 | /* compute the epoll_wait() timeout */ |
Willy Tarreau | cb65125 | 2008-08-29 13:57:30 +0200 | [diff] [blame] | 386 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 387 | if (nbspec || run_queue || signal_queue_len) { |
| 388 | /* Maybe we still have events in the spec list, or there are |
Willy Tarreau | 3a62811 | 2008-06-13 21:06:56 +0200 | [diff] [blame] | 389 | * some tasks left pending in the run_queue, so we must not |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 390 | * wait in epoll() otherwise we would delay their delivery by |
Willy Tarreau | 6653d17 | 2007-05-13 01:52:05 +0200 | [diff] [blame] | 391 | * the next timeout. |
| 392 | */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 393 | wait_time = 0; |
| 394 | } |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 395 | else { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 396 | if (!exp) |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 397 | wait_time = MAX_DELAY_MS; |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 398 | else if (tick_is_expired(exp, now_ms)) |
Willy Tarreau | bdefc51 | 2007-05-14 02:02:04 +0200 | [diff] [blame] | 399 | wait_time = 0; |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 400 | else { |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 401 | wait_time = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1; |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 402 | if (wait_time > MAX_DELAY_MS) |
| 403 | wait_time = MAX_DELAY_MS; |
| 404 | } |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 405 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 406 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 407 | /* now let's wait for real events */ |
| 408 | fd = MIN(maxfd, global.tune.maxpollevents); |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 409 | gettimeofday(&before_poll, NULL); |
Willy Tarreau | 1db3771 | 2007-06-03 17:16:49 +0200 | [diff] [blame] | 410 | status = epoll_wait(epoll_fd, epoll_events, fd, wait_time); |
Willy Tarreau | b0b37bc | 2008-06-23 14:00:57 +0200 | [diff] [blame] | 411 | tv_update_date(wait_time, status); |
Willy Tarreau | 45a1251 | 2011-09-10 16:56:42 +0200 | [diff] [blame] | 412 | measure_idle(); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 413 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 414 | /* process events */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 415 | for (count = 0; count < status; count++) { |
| 416 | int e = epoll_events[count].events; |
| 417 | fd = epoll_events[count].data.fd; |
| 418 | |
Willy Tarreau | 076be25 | 2012-07-06 16:02:29 +0200 | [diff] [blame] | 419 | if (!fdtab[fd].owner) |
| 420 | continue; |
| 421 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 422 | /* it looks complicated but gcc can optimize it away when constants |
| 423 | * have same values. |
| 424 | */ |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 425 | fdtab[fd].ev &= FD_POLL_STICKY; |
Willy Tarreau | 491c498 | 2012-07-06 11:16:01 +0200 | [diff] [blame] | 426 | fdtab[fd].ev |= |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 427 | ((e & EPOLLIN ) ? FD_POLL_IN : 0) | |
| 428 | ((e & EPOLLPRI) ? FD_POLL_PRI : 0) | |
| 429 | ((e & EPOLLOUT) ? FD_POLL_OUT : 0) | |
| 430 | ((e & EPOLLERR) ? FD_POLL_ERR : 0) | |
| 431 | ((e & EPOLLHUP) ? FD_POLL_HUP : 0); |
Willy Tarreau | 491c498 | 2012-07-06 11:16:01 +0200 | [diff] [blame] | 432 | |
Willy Tarreau | 9845e75 | 2012-07-06 11:44:28 +0200 | [diff] [blame] | 433 | if (fdtab[fd].iocb && fdtab[fd].owner && fdtab[fd].ev) |
| 434 | fdtab[fd].iocb(fd); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 435 | } |
Willy Tarreau | cb65125 | 2008-08-29 13:57:30 +0200 | [diff] [blame] | 436 | |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 437 | /* now process speculative events if any */ |
| 438 | |
| 439 | /* Here we have two options : |
| 440 | * - either walk the list forwards and hope to match more events |
| 441 | * - or walk it backwards to minimize the number of changes and |
| 442 | * to make better use of the cache. |
| 443 | * Tests have shown that walking backwards improves perf by 0.2%. |
| 444 | */ |
| 445 | |
| 446 | spec_idx = nbspec; |
| 447 | while (likely(spec_idx > 0)) { |
| 448 | spec_idx--; |
| 449 | fd = spec_list[spec_idx]; |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 450 | eo = fdtab[fd].spec_e; /* save old events */ |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 451 | |
| 452 | /* |
| 453 | * Process the speculative events. |
| 454 | * |
| 455 | * Principle: events which are marked FD_EV_SPEC are processed |
| 456 | * with their assigned function. If the function returns 0, it |
| 457 | * means there is nothing doable without polling first. We will |
| 458 | * then convert the event to a pollable one by assigning them |
| 459 | * the WAIT status. |
Willy Tarreau | cb65125 | 2008-08-29 13:57:30 +0200 | [diff] [blame] | 460 | */ |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 461 | |
| 462 | fdtab[fd].ev &= FD_POLL_STICKY; |
Willy Tarreau | 076be25 | 2012-07-06 16:02:29 +0200 | [diff] [blame] | 463 | if ((eo & FD_EV_MASK_R) == FD_EV_SPEC_R) |
Willy Tarreau | 5d526b7 | 2012-07-05 23:33:51 +0200 | [diff] [blame] | 464 | fdtab[fd].ev |= FD_POLL_IN; |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 465 | |
Willy Tarreau | 076be25 | 2012-07-06 16:02:29 +0200 | [diff] [blame] | 466 | if ((eo & FD_EV_MASK_W) == FD_EV_SPEC_W) |
Willy Tarreau | 5d526b7 | 2012-07-05 23:33:51 +0200 | [diff] [blame] | 467 | fdtab[fd].ev |= FD_POLL_OUT; |
Willy Tarreau | 9845e75 | 2012-07-06 11:44:28 +0200 | [diff] [blame] | 468 | |
Willy Tarreau | 26f44d1 | 2012-08-17 23:55:05 +0200 | [diff] [blame] | 469 | if (fdtab[fd].iocb && fdtab[fd].owner && fdtab[fd].ev) |
| 470 | fdtab[fd].iocb(fd); |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 471 | |
| 472 | /* one callback might already have closed the fd by itself */ |
Willy Tarreau | db3b326 | 2012-07-05 23:19:22 +0200 | [diff] [blame] | 473 | if (!fdtab[fd].owner) |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 474 | continue; |
| 475 | |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 476 | if (!(fdtab[fd].spec_e & (FD_EV_RW_SL|FD_EV_RW_PL))) { |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 477 | /* This fd switched to IDLE, it can be removed from the spec list. */ |
| 478 | release_spec_entry(fd); |
| 479 | continue; |
| 480 | } |
Willy Tarreau | cb65125 | 2008-08-29 13:57:30 +0200 | [diff] [blame] | 481 | } |
Willy Tarreau | dbcd47e | 2012-05-13 09:42:26 +0200 | [diff] [blame] | 482 | |
| 483 | /* in the end, we have processed status + spec_processed FDs */ |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* |
| 487 | * Initialization of the speculative epoll() poller. |
| 488 | * Returns 0 in case of failure, non-zero in case of success. If it fails, it |
| 489 | * disables the poller by setting its pref to 0. |
| 490 | */ |
| 491 | REGPRM1 static int _do_init(struct poller *p) |
| 492 | { |
Willy Tarreau | b48b323 | 2009-10-17 22:54:17 +0200 | [diff] [blame] | 493 | __label__ fail_spec, fail_ee, fail_fd; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 494 | |
| 495 | p->private = NULL; |
| 496 | |
| 497 | epoll_fd = epoll_create(global.maxsock + 1); |
| 498 | if (epoll_fd < 0) |
| 499 | goto fail_fd; |
| 500 | |
Willy Tarreau | f2e8ee2 | 2008-05-25 10:39:02 +0200 | [diff] [blame] | 501 | /* See comments at the top of the file about this formula. */ |
| 502 | absmaxevents = MAX(global.tune.maxpollevents, global.maxsock/4); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 503 | epoll_events = (struct epoll_event*) |
Willy Tarreau | f2e8ee2 | 2008-05-25 10:39:02 +0200 | [diff] [blame] | 504 | calloc(1, sizeof(struct epoll_event) * absmaxevents); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 505 | |
| 506 | if (epoll_events == NULL) |
| 507 | goto fail_ee; |
| 508 | |
| 509 | if ((spec_list = (uint32_t *)calloc(1, sizeof(uint32_t) * global.maxsock)) == NULL) |
| 510 | goto fail_spec; |
| 511 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 512 | return 1; |
| 513 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 514 | fail_spec: |
| 515 | free(epoll_events); |
| 516 | fail_ee: |
| 517 | close(epoll_fd); |
Willy Tarreau | d79e79b | 2009-05-10 10:18:54 +0200 | [diff] [blame] | 518 | epoll_fd = -1; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 519 | fail_fd: |
| 520 | p->pref = 0; |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /* |
| 525 | * Termination of the speculative epoll() poller. |
| 526 | * Memory is released and the poller is marked as unselectable. |
| 527 | */ |
| 528 | REGPRM1 static void _do_term(struct poller *p) |
| 529 | { |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 530 | free(spec_list); |
| 531 | free(epoll_events); |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 532 | |
Willy Tarreau | d79e79b | 2009-05-10 10:18:54 +0200 | [diff] [blame] | 533 | if (epoll_fd >= 0) { |
| 534 | close(epoll_fd); |
| 535 | epoll_fd = -1; |
| 536 | } |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 537 | |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 538 | spec_list = NULL; |
| 539 | epoll_events = NULL; |
| 540 | |
| 541 | p->private = NULL; |
| 542 | p->pref = 0; |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Check that the poller works. |
| 547 | * Returns 1 if OK, otherwise 0. |
| 548 | */ |
| 549 | REGPRM1 static int _do_test(struct poller *p) |
| 550 | { |
| 551 | int fd; |
| 552 | |
| 553 | fd = epoll_create(global.maxsock + 1); |
| 554 | if (fd < 0) |
| 555 | return 0; |
| 556 | close(fd); |
| 557 | return 1; |
| 558 | } |
| 559 | |
| 560 | /* |
Willy Tarreau | fb8983f | 2007-06-03 16:40:44 +0200 | [diff] [blame] | 561 | * Recreate the epoll file descriptor after a fork(). Returns 1 if OK, |
| 562 | * otherwise 0. It will ensure that all processes will not share their |
| 563 | * epoll_fd. Some side effects were encountered because of this, such |
| 564 | * as epoll_wait() returning an FD which was previously deleted. |
| 565 | */ |
| 566 | REGPRM1 static int _do_fork(struct poller *p) |
| 567 | { |
Willy Tarreau | d79e79b | 2009-05-10 10:18:54 +0200 | [diff] [blame] | 568 | if (epoll_fd >= 0) |
| 569 | close(epoll_fd); |
Willy Tarreau | fb8983f | 2007-06-03 16:40:44 +0200 | [diff] [blame] | 570 | epoll_fd = epoll_create(global.maxsock + 1); |
| 571 | if (epoll_fd < 0) |
| 572 | return 0; |
| 573 | return 1; |
| 574 | } |
| 575 | |
| 576 | /* |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 577 | * It is a constructor, which means that it will automatically be called before |
| 578 | * main(). This is GCC-specific but it works at least since 2.95. |
| 579 | * Special care must be taken so that it does not need any uninitialized data. |
| 580 | */ |
| 581 | __attribute__((constructor)) |
| 582 | static void _do_register(void) |
| 583 | { |
| 584 | struct poller *p; |
| 585 | |
| 586 | if (nbpollers >= MAX_POLLERS) |
| 587 | return; |
Willy Tarreau | d79e79b | 2009-05-10 10:18:54 +0200 | [diff] [blame] | 588 | |
| 589 | epoll_fd = -1; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 590 | p = &pollers[nbpollers++]; |
| 591 | |
| 592 | p->name = "sepoll"; |
| 593 | p->pref = 400; |
| 594 | p->private = NULL; |
| 595 | |
| 596 | p->test = _do_test; |
| 597 | p->init = _do_init; |
| 598 | p->term = _do_term; |
| 599 | p->poll = _do_poll; |
Willy Tarreau | fb8983f | 2007-06-03 16:40:44 +0200 | [diff] [blame] | 600 | p->fork = _do_fork; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 601 | |
| 602 | p->is_set = __fd_is_set; |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 603 | p->set = __fd_set; |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 604 | p->wai = __fd_wai; |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 605 | p->clr = __fd_clr; |
Willy Tarreau | de99e99 | 2007-04-16 00:53:59 +0200 | [diff] [blame] | 606 | p->rem = __fd_rem; |
| 607 | p->clo = __fd_clo; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /* |
| 612 | * Local variables: |
| 613 | * c-indent-level: 8 |
| 614 | * c-basic-offset: 8 |
| 615 | * End: |
| 616 | */ |