From 511ce2572a9710835c6722a09a93b4dd80ab7fae Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Thu, 2 May 2019 15:48:15 -0400 Subject: Clean up multi-thread barrier-sync hold-down timer Main thread: don't bother with the barrier sync hold-down timer if none of the worker threads are busy. Worker threads: avoid epoll_pwait (10ms timeout) when the control-plane has been active in the last half-second. Cherry-pick a recent dangling reference fix: pool_elt_at_index after e.g. rx callback is required, in case the unix file pool expands. Manual feature backport to 18.07 Change-Id: I745fbb8a12aeda34b0ec7b6dcda66c0e25c3eee1 Signed-off-by: Dave Barach --- src/vlib/unix/input.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src/vlib/unix/input.c') diff --git a/src/vlib/unix/input.c b/src/vlib/unix/input.c index 8be0770bfd3..20a98f7a31e 100644 --- a/src/vlib/unix/input.c +++ b/src/vlib/unix/input.c @@ -145,9 +145,13 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_node_main_t *nm = &vm->node_main; u32 ticks_until_expiration; f64 timeout; + f64 now; int timeout_ms = 0, max_timeout_ms = 10; f64 vector_rate = vlib_last_vectors_per_main_loop (vm); + if (is_main == 0) + now = vlib_time_now (vm); + /* * If we've been asked for a fixed-sleep between main loop polls, * do so right away. @@ -194,8 +198,9 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } node->input_main_loops_per_call = 0; } - else if (is_main == 0 && vector_rate < 2 && - nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0) + else if (is_main == 0 && vector_rate < 2 + && (vlib_global_main.time_last_barrier_release + 0.5 < now) + && nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0) { timeout = 10e-3; timeout_ms = max_timeout_ms; @@ -223,12 +228,32 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, em->epoll_events, vec_len (em->epoll_events), timeout_ms); } + } else { + /* + * Worker thread, no epoll fd's, sleep for 100us at a time + * and check for a barrier sync request + */ if (timeout_ms) - usleep (timeout_ms * 1000); - return 0; + { + struct timespec ts, tsrem; + f64 limit = now + (f64) timeout_ms * 1e-3; + + while (vlib_time_now (vm) < limit) + { + /* Sleep for 100us at a time */ + ts.tv_sec = 0; + ts.tv_nsec = 1000 * 100; + + while (nanosleep (&ts, &tsrem) < 0) + ts = tsrem; + if (*vlib_worker_threads->wait_at_barrier) + goto done; + } + } + goto done; } } @@ -238,7 +263,7 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_panic_with_error (vm, clib_error_return_unix (0, "epoll_wait")); /* non fatal error (e.g. EINTR). */ - return 0; + goto done; } em->epoll_waits += 1; @@ -314,6 +339,7 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } } +done: return 0; } -- cgit 1.2.3-korg