mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-29 14:50:59 +01:00
CLEANUP: poll: move the conditions for waiting out of the poll functions
The poll() functions have become a bit dirty because they now check the size of the signal queue, the FD cache and the number of tasks. It's not their job, this must be moved to the caller. In the end it simplifies the code because the expiration date is now set to now_ms if we must not wait, and this achieves in exactly the same result and is cleaner. The change looks large due to the change of indent for blocks which were inside an "if" block.
This commit is contained in:
parent
108b1dd69d
commit
10146c9c51
@ -25,9 +25,6 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/signal.h>
|
|
||||||
#include <proto/task.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* private data */
|
/* private data */
|
||||||
@ -112,25 +109,14 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
fd_nbupdt = 0;
|
fd_nbupdt = 0;
|
||||||
|
|
||||||
/* compute the epoll_wait() timeout */
|
/* compute the epoll_wait() timeout */
|
||||||
|
if (!exp)
|
||||||
if (fd_cache_num || run_queue || signal_queue_len) {
|
wait_time = MAX_DELAY_MS;
|
||||||
/* Maybe we still have events in the spec list, or there are
|
else if (tick_is_expired(exp, now_ms))
|
||||||
* some tasks left pending in the run_queue, so we must not
|
|
||||||
* wait in epoll() otherwise we would delay their delivery by
|
|
||||||
* the next timeout.
|
|
||||||
*/
|
|
||||||
wait_time = 0;
|
wait_time = 0;
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (!exp)
|
wait_time = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
|
||||||
|
if (wait_time > MAX_DELAY_MS)
|
||||||
wait_time = MAX_DELAY_MS;
|
wait_time = MAX_DELAY_MS;
|
||||||
else if (tick_is_expired(exp, now_ms))
|
|
||||||
wait_time = 0;
|
|
||||||
else {
|
|
||||||
wait_time = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
|
|
||||||
if (wait_time > MAX_DELAY_MS)
|
|
||||||
wait_time = MAX_DELAY_MS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now let's wait for polled events */
|
/* now let's wait for polled events */
|
||||||
|
|||||||
@ -26,8 +26,7 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/signal.h>
|
|
||||||
#include <proto/task.h>
|
|
||||||
|
|
||||||
/* private data */
|
/* private data */
|
||||||
static int kqueue_fd;
|
static int kqueue_fd;
|
||||||
@ -93,19 +92,17 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
timeout.tv_sec = 0;
|
timeout.tv_sec = 0;
|
||||||
timeout.tv_nsec = 0;
|
timeout.tv_nsec = 0;
|
||||||
|
|
||||||
if (!fd_cache_num && !run_queue && !signal_queue_len) {
|
if (!exp) {
|
||||||
if (!exp) {
|
delta_ms = MAX_DELAY_MS;
|
||||||
delta_ms = MAX_DELAY_MS;
|
timeout.tv_sec = (MAX_DELAY_MS / 1000);
|
||||||
timeout.tv_sec = (MAX_DELAY_MS / 1000);
|
timeout.tv_nsec = (MAX_DELAY_MS % 1000) * 1000000;
|
||||||
timeout.tv_nsec = (MAX_DELAY_MS % 1000) * 1000000;
|
}
|
||||||
}
|
else if (!tick_is_expired(exp, now_ms)) {
|
||||||
else if (!tick_is_expired(exp, now_ms)) {
|
delta_ms = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
|
||||||
delta_ms = TICKS_TO_MS(tick_remain(now_ms, exp)) + 1;
|
if (delta_ms > MAX_DELAY_MS)
|
||||||
if (delta_ms > MAX_DELAY_MS)
|
delta_ms = MAX_DELAY_MS;
|
||||||
delta_ms = MAX_DELAY_MS;
|
timeout.tv_sec = (delta_ms / 1000);
|
||||||
timeout.tv_sec = (delta_ms / 1000);
|
timeout.tv_nsec = (delta_ms % 1000) * 1000000;
|
||||||
timeout.tv_nsec = (delta_ms % 1000) * 1000000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = MIN(maxfd, global.tune.maxpollevents);
|
fd = MIN(maxfd, global.tune.maxpollevents);
|
||||||
|
|||||||
@ -23,8 +23,6 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/signal.h>
|
|
||||||
#include <proto/task.h>
|
|
||||||
|
|
||||||
|
|
||||||
static unsigned int *fd_evts[2];
|
static unsigned int *fd_evts[2];
|
||||||
@ -116,9 +114,7 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* now let's wait for events */
|
/* now let's wait for events */
|
||||||
if (fd_cache_num || run_queue || signal_queue_len)
|
if (!exp)
|
||||||
wait_time = 0;
|
|
||||||
else if (!exp)
|
|
||||||
wait_time = MAX_DELAY_MS;
|
wait_time = MAX_DELAY_MS;
|
||||||
else if (tick_is_expired(exp, now_ms))
|
else if (tick_is_expired(exp, now_ms))
|
||||||
wait_time = 0;
|
wait_time = 0;
|
||||||
|
|||||||
@ -22,8 +22,6 @@
|
|||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#include <proto/fd.h>
|
#include <proto/fd.h>
|
||||||
#include <proto/signal.h>
|
|
||||||
#include <proto/task.h>
|
|
||||||
|
|
||||||
|
|
||||||
static fd_set *fd_evts[2];
|
static fd_set *fd_evts[2];
|
||||||
@ -83,19 +81,17 @@ REGPRM2 static void _do_poll(struct poller *p, int exp)
|
|||||||
delta.tv_sec = 0;
|
delta.tv_sec = 0;
|
||||||
delta.tv_usec = 0;
|
delta.tv_usec = 0;
|
||||||
|
|
||||||
if (!fd_cache_num && !run_queue && !signal_queue_len) {
|
if (!exp) {
|
||||||
if (!exp) {
|
delta_ms = MAX_DELAY_MS;
|
||||||
delta_ms = MAX_DELAY_MS;
|
delta.tv_sec = (MAX_DELAY_MS / 1000);
|
||||||
delta.tv_sec = (MAX_DELAY_MS / 1000);
|
delta.tv_usec = (MAX_DELAY_MS % 1000) * 1000;
|
||||||
delta.tv_usec = (MAX_DELAY_MS % 1000) * 1000;
|
}
|
||||||
}
|
else if (!tick_is_expired(exp, now_ms)) {
|
||||||
else if (!tick_is_expired(exp, now_ms)) {
|
delta_ms = TICKS_TO_MS(tick_remain(now_ms, exp)) + SCHEDULER_RESOLUTION;
|
||||||
delta_ms = TICKS_TO_MS(tick_remain(now_ms, exp)) + SCHEDULER_RESOLUTION;
|
if (delta_ms > MAX_DELAY_MS)
|
||||||
if (delta_ms > MAX_DELAY_MS)
|
delta_ms = MAX_DELAY_MS;
|
||||||
delta_ms = MAX_DELAY_MS;
|
delta.tv_sec = (delta_ms / 1000);
|
||||||
delta.tv_sec = (delta_ms / 1000);
|
delta.tv_usec = (delta_ms % 1000) * 1000;
|
||||||
delta.tv_usec = (delta_ms % 1000) * 1000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* let's restore fdset state */
|
/* let's restore fdset state */
|
||||||
|
|||||||
@ -1486,6 +1486,10 @@ void run_poll_loop()
|
|||||||
if (jobs == 0)
|
if (jobs == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
/* expire immediately if events are pending */
|
||||||
|
if (fd_cache_num || run_queue || signal_queue_len)
|
||||||
|
next = now_ms;
|
||||||
|
|
||||||
/* The poller will ensure it returns around <next> */
|
/* The poller will ensure it returns around <next> */
|
||||||
cur_poller.poll(&cur_poller, next);
|
cur_poller.poll(&cur_poller, next);
|
||||||
fd_process_cached_events();
|
fd_process_cached_events();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user