aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib/unix/input.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2018-06-14 18:52:46 -0400
committerDamjan Marion <dmarion@me.com>2018-06-21 14:57:02 +0000
commit85aa49019f4b4b2b7a4fce4313fdc0f2de65c277 (patch)
tree14c2ef301403f64e1dd08f7912c86a2cb1bffed3 /src/vlib/unix/input.c
parentcb3b7052357b57ab927edf178baa1412d7df81d5 (diff)
configurable per-dispatch-cycle sleep
Workaround for lack of driver interrupt support. Also quite handy for home gateway, laptop/vagrant, other use-cases not requiring maximum vectors/second for proper operation. Change-Id: Ifc4b98112450664beef67b89ab8a6940a3bf24b5 Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vlib/unix/input.c')
-rw-r--r--src/vlib/unix/input.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/vlib/unix/input.c b/src/vlib/unix/input.c
index 321e443dee9..0a61c05d471 100644
--- a/src/vlib/unix/input.c
+++ b/src/vlib/unix/input.c
@@ -148,9 +148,27 @@ linux_epoll_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
int timeout_ms = 0, max_timeout_ms = 10;
f64 vector_rate = vlib_last_vectors_per_main_loop (vm);
+ /*
+ * If we've been asked for a fixed-sleep between main loop polls,
+ * do so right away.
+ */
+ if (PREDICT_FALSE (is_main && um->poll_sleep_usec))
+ {
+ struct timespec ts, tsrem;
+ timeout = 0;
+ timeout_ms = 0;
+ node->input_main_loops_per_call = 0;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1000 * um->poll_sleep_usec;
+
+ while (nanosleep (&ts, &tsrem) < 0)
+ {
+ ts = tsrem;
+ }
+ }
/* If we're not working very hard, decide how long to sleep */
- if (is_main && vector_rate < 2 && vm->api_queue_nonempty == 0
- && nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0)
+ else if (is_main && vector_rate < 2 && vm->api_queue_nonempty == 0
+ && nm->input_node_counts_by_state[VLIB_NODE_STATE_POLLING] == 0)
{
ticks_until_expiration = TW (tw_timer_first_expires_in_ticks)
((TWT (tw_timer_wheel) *) nm->timing_wheel);