]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: polling: rename "spec_e" to "state"
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2014 10:02:59 +0000 (11:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 25 Jan 2014 23:42:28 +0000 (00:42 +0100)
We're completely changing the way FDs will be polled. First, let's fix
a few field names which become confusing. "spec_e" was used to store a
speculative I/O event state. Now we'll store the whole R/W states for
the FD there.

include/proto/fd.h
include/types/fd.h
src/dumpstats.c
src/ev_epoll.c
src/ev_kqueue.c
src/ev_poll.c
src/ev_select.c
src/fd.c

index 7fe616e381b3787216aac45e19147130b9838a42..a67a3203d6cbc139ff4f981b7421dc0eb1cc122c 100644 (file)
@@ -131,7 +131,7 @@ static inline void release_spec_entry(int fd)
  */
 static inline int fd_ev_is_set(const int fd, int dir)
 {
-       return ((unsigned)fdtab[fd].spec_e >> dir) & FD_EV_STATUS;
+       return ((unsigned)fdtab[fd].state >> dir) & FD_EV_STATUS;
 }
 
 /* Disable processing of events on fd <fd> for direction <dir>. Note: this
@@ -139,10 +139,10 @@ static inline int fd_ev_is_set(const int fd, int dir)
  */
 static inline void fd_ev_clr(const int fd, int dir)
 {
-       unsigned int i = ((unsigned int)fdtab[fd].spec_e) & (FD_EV_STATUS << dir);
+       unsigned int i = ((unsigned int)fdtab[fd].state) & (FD_EV_STATUS << dir);
        if (i == 0)
                return; /* already disabled */
-       fdtab[fd].spec_e ^= i;
+       fdtab[fd].state ^= i;
        updt_fd(fd); /* need an update entry to change the state */
 }
 
@@ -151,10 +151,10 @@ static inline void fd_ev_clr(const int fd, int dir)
  */
 static inline void fd_ev_wai(const int fd, int dir)
 {
-       unsigned int i = ((unsigned int)fdtab[fd].spec_e) & (FD_EV_STATUS << dir);
+       unsigned int i = ((unsigned int)fdtab[fd].state) & (FD_EV_STATUS << dir);
        if (i == (FD_EV_POLLED << dir))
                return; /* already in desired state */
-       fdtab[fd].spec_e ^= i ^ (FD_EV_POLLED << dir);
+       fdtab[fd].state ^= i ^ (FD_EV_POLLED << dir);
        updt_fd(fd); /* need an update entry to change the state */
 }
 
@@ -163,7 +163,7 @@ static inline void fd_ev_wai(const int fd, int dir)
  */
 static inline void fd_ev_set(int fd, int dir)
 {
-       unsigned int i = ((unsigned int)fdtab[fd].spec_e) & (FD_EV_STATUS << dir);
+       unsigned int i = ((unsigned int)fdtab[fd].state) & (FD_EV_STATUS << dir);
 
        /* note that we don't care about disabling the polled state when
         * enabling the active state, since it brings no benefit but costs
@@ -171,17 +171,17 @@ static inline void fd_ev_set(int fd, int dir)
         */
        if (i & (FD_EV_ACTIVE << dir))
                return; /* already in desired state */
-       fdtab[fd].spec_e |= (FD_EV_ACTIVE << dir);
+       fdtab[fd].state |= (FD_EV_ACTIVE << dir);
        updt_fd(fd); /* need an update entry to change the state */
 }
 
 /* Disable processing of events on fd <fd> for both directions. */
 static inline void fd_ev_rem(const int fd)
 {
-       unsigned int i = ((unsigned int)fdtab[fd].spec_e) & FD_EV_CURR_MASK;
+       unsigned int i = ((unsigned int)fdtab[fd].state) & FD_EV_CURR_MASK;
        if (i == 0)
                return; /* already disabled */
-       fdtab[fd].spec_e ^= i;
+       fdtab[fd].state ^= i;
        updt_fd(fd); /* need an update entry to change the state */
 }
 
index 701edfc59aa3e1fc197733bcb4712e134a59640c..23550cbfcebcf0f55a21c3589f63d5291579018a 100644 (file)
@@ -46,7 +46,7 @@ enum {
 #define FD_POLL_STICKY  (FD_POLL_ERR | FD_POLL_HUP)
 
 /* Event state for an FD in each direction, as found in the 4 lower bits of
- * fdtab[].spec_e, and in the 4 next bits.
+ * fdtab[].state, and in the 4 next bits.
  */
 #define FD_EV_ACTIVE    1U
 #define FD_EV_POLLED    4U
@@ -70,7 +70,7 @@ struct fdtab {
        int (*iocb)(int fd);                 /* I/O handler, returns FD_WAIT_* */
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        unsigned int  spec_p;                /* speculative polling: position in spec list+1. 0=not in list. */
-       unsigned char spec_e;                /* speculative polling: read and write events status. 4 bits */
+       unsigned char state;                 /* FD state for read and write directions */
        unsigned char ev;                    /* event seen in return of poll() : FD_POLL_* */
        unsigned char new:1;                 /* 1 if this fd has just been created */
        unsigned char updated:1;             /* 1 if this fd is already in the update list */
index 219b81fd715c2798a7cc01414c7559ecca0a0881..f861650d57bea52695c98867ebfb185346002619 100644 (file)
@@ -4528,7 +4528,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct se
                                      "      flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
                                      conn->flags,
                                      conn->t.sock.fd,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0,
+                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
                                      conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0,
                                      conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
                }
@@ -4556,7 +4556,7 @@ static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct se
                                      "      flags=0x%08x fd=%d fd_spec_e=%02x fd_spec_p=%d updt=%d\n",
                                      conn->flags,
                                      conn->t.sock.fd,
-                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_e : 0,
+                                     conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0,
                                      conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].spec_p : 0,
                                      conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0);
                }
index 18abb107c7c4e7eea670cb036bccdf1c377b83f8..ba0025b20f1b73fa1600b2d84dc85407a951d37c 100644 (file)
@@ -59,8 +59,8 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = fdtab[fd].spec_e & 15;  /* new events */
-               eo = fdtab[fd].spec_e >> 4;  /* previous events */
+               en = fdtab[fd].state & 15;  /* new events */
+               eo = fdtab[fd].state >> 4;  /* previous events */
 
                if (fdtab[fd].owner && (eo ^ en)) {
                        if ((eo ^ en) & FD_EV_POLLED_RW) {
@@ -90,7 +90,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                epoll_ctl(epoll_fd, opcode, fd, &ev);
                        }
 
-                       fdtab[fd].spec_e = (en << 4) + en;  /* save new events */
+                       fdtab[fd].state = (en << 4) + en;  /* save new events */
 
                        if (!(en & FD_EV_ACTIVE_RW)) {
                                /* This fd doesn't use any active entry anymore, we can
@@ -213,10 +213,10 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                fdtab[fd].new = 0;
                                fdtab[fd].ev &= FD_POLL_STICKY;
 
-                               if ((fdtab[fd].spec_e & FD_EV_STATUS_R) == FD_EV_ACTIVE_R)
+                               if ((fdtab[fd].state & FD_EV_STATUS_R) == FD_EV_ACTIVE_R)
                                        fdtab[fd].ev |= FD_POLL_IN;
 
-                               if ((fdtab[fd].spec_e & FD_EV_STATUS_W) == FD_EV_ACTIVE_W)
+                               if ((fdtab[fd].state & FD_EV_STATUS_W) == FD_EV_ACTIVE_W)
                                        fdtab[fd].ev |= FD_POLL_OUT;
 
                                if (fdtab[fd].ev && fdtab[fd].iocb && fdtab[fd].owner)
@@ -225,7 +225,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                /* we can remove this update entry if it's the last one and is
                                 * unused, otherwise we don't touch anything.
                                 */
-                               if (new_updt == fd_nbupdt && fdtab[fd].spec_e == 0) {
+                               if (new_updt == fd_nbupdt && fdtab[fd].state == 0) {
                                        fdtab[fd].updated = 0;
                                        fd_nbupdt--;
                                }
index 2142132e21bea4050480a84422b2312a07bb0626..ca14eeb0ff4e1f65806cf224636be0829ffa9a39 100644 (file)
@@ -51,8 +51,8 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = fdtab[fd].spec_e & 15;  /* new events */
-               eo = fdtab[fd].spec_e >> 4;  /* previous events */
+               en = fdtab[fd].state & 15;  /* new events */
+               eo = fdtab[fd].state >> 4;  /* previous events */
 
                if (fdtab[fd].owner && (eo ^ en)) {
                        if ((eo ^ en) & FD_EV_POLLED_R) {
@@ -79,7 +79,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                }
                        }
 
-                       fdtab[fd].spec_e = (en << 4) + en;  /* save new events */
+                       fdtab[fd].state = (en << 4) + en;  /* save new events */
 
                        if (!(en & FD_EV_ACTIVE_RW)) {
                                /* This fd doesn't use any active entry anymore, we can
@@ -139,11 +139,11 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                fdtab[fd].ev &= FD_POLL_STICKY;
 
                if (kev[count].filter ==  EVFILT_READ) {
-                       if ((fdtab[fd].spec_e & FD_EV_STATUS_R))
+                       if ((fdtab[fd].state & FD_EV_STATUS_R))
                                fdtab[fd].ev |= FD_POLL_IN;
                }
                else if (kev[count].filter ==  EVFILT_WRITE) {
-                       if ((fdtab[fd].spec_e & FD_EV_STATUS_W))
+                       if ((fdtab[fd].state & FD_EV_STATUS_W))
                                fdtab[fd].ev |= FD_POLL_OUT;
                }
 
index 537157fcabb4b253a838fa0c98dff6cc7efe626b..8b3f5959972d3706030e65cc6fb28f771357581a 100644 (file)
@@ -70,8 +70,8 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = fdtab[fd].spec_e & 15;  /* new events */
-               eo = fdtab[fd].spec_e >> 4;  /* previous events */
+               en = fdtab[fd].state & 15;  /* new events */
+               eo = fdtab[fd].state >> 4;  /* previous events */
 
                if (fdtab[fd].owner && (eo ^ en)) {
                        if ((eo ^ en) & FD_EV_POLLED_RW) {
@@ -87,7 +87,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                        hap_fd_set(fd, fd_evts[DIR_WR]);
                        }
 
-                       fdtab[fd].spec_e = (en << 4) + en;  /* save new events */
+                       fdtab[fd].state = (en << 4) + en;  /* save new events */
 
                        if (!(en & FD_EV_ACTIVE_RW)) {
                                /* This fd doesn't use any active entry anymore, we can
index 946fbfdaaa5cdf67c0c06377babeaa29bf003962..300cffa1483c250c49180f61f3b034311f640e91 100644 (file)
@@ -53,8 +53,8 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
        /* first, scan the update list to find changes */
        for (updt_idx = 0; updt_idx < fd_nbupdt; updt_idx++) {
                fd = fd_updt[updt_idx];
-               en = fdtab[fd].spec_e & 15;  /* new events */
-               eo = fdtab[fd].spec_e >> 4;  /* previous events */
+               en = fdtab[fd].state & 15;  /* new events */
+               eo = fdtab[fd].state >> 4;  /* previous events */
 
                if (fdtab[fd].owner && (eo ^ en)) {
                        if ((eo ^ en) & FD_EV_POLLED_RW) {
@@ -70,7 +70,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
                                        FD_SET(fd, fd_evts[DIR_WR]);
                        }
 
-                       fdtab[fd].spec_e = (en << 4) + en;  /* save new events */
+                       fdtab[fd].state = (en << 4) + en;  /* save new events */
 
                        if (!(en & FD_EV_ACTIVE_RW)) {
                                /* This fd doesn't use any active entry anymore, we can
index 12f38f1f6c9242e25239a29b71a0f58e65f22080..ad45f4666817932c39df538bd7564ea9d394a152 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -77,7 +77,7 @@
  * reference is always valid unless the FD if currently being polled and not
  * updated (in which case the reference points to index 0).
  *
- * We store the FD state in the 4 lower bits of fdtab[fd].spec_e, and save the
+ * We store the FD state in the 4 lower bits of fdtab[fd].state, and save the
  * previous state upon changes in the 4 higher bits, so that changes are easy
  * to spot.
  */
@@ -125,7 +125,7 @@ void fd_delete(int fd)
                cur_poller.clo(fd);
 
        release_spec_entry(fd);
-       fdtab[fd].spec_e &= ~(FD_EV_CURR_MASK | FD_EV_PREV_MASK);
+       fdtab[fd].state &= ~(FD_EV_CURR_MASK | FD_EV_PREV_MASK);
 
        port_range_release_port(fdinfo[fd].port_range, fdinfo[fd].local_port);
        fdinfo[fd].port_range = NULL;
@@ -148,7 +148,7 @@ void fd_process_spec_events()
 
        for (spec_idx = 0; spec_idx < fd_nbspec; ) {
                fd = fd_spec[spec_idx];
-               e = fdtab[fd].spec_e;
+               e = fdtab[fd].state;
 
                /*
                 * Process the speculative events.