configurable per-dispatch-cycle sleep 62/13062/5
authorDave Barach <dave@barachs.net>
Thu, 14 Jun 2018 22:52:46 +0000 (18:52 -0400)
committerDamjan Marion <dmarion@me.com>
Thu, 21 Jun 2018 14:57:02 +0000 (14:57 +0000)
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>
src/plugins/dpdk/device/dpdk.h
src/plugins/dpdk/device/init.c
src/plugins/dpdk/device/node.c
src/vlib/unix/input.c
src/vlib/unix/main.c
src/vlib/unix/unix.h

index d88e294..8fa8035 100644 (file)
@@ -433,9 +433,6 @@ typedef struct
   f64 link_state_poll_interval;
   f64 stat_poll_interval;
 
-  /* Sleep for this many usec after each device poll */
-  u32 poll_sleep_usec;
-
   /* convenience */
   vlib_main_t *vlib_main;
   vnet_main_t *vnet_main;
index 6105777..0ab339b 100644 (file)
@@ -1005,7 +1005,6 @@ static clib_error_t *
 dpdk_config (vlib_main_t * vm, unformat_input_t * input)
 {
   clib_error_t *error = 0;
-  dpdk_main_t *dm = &dpdk_main;
   dpdk_config_main_t *conf = &dpdk_config_main;
   vlib_thread_main_t *tm = vlib_get_thread_main ();
   dpdk_device_config_t *devconf;
@@ -1097,8 +1096,6 @@ dpdk_config (vlib_main_t * vm, unformat_input_t * input)
          tmp = format (0, "--no-pci%c", 0);
          vec_add1 (conf->eal_init_args, tmp);
        }
-      else if (unformat (input, "poll-sleep %d", &dm->poll_sleep_usec))
-       ;
 
 #define _(a)                                    \
       else if (unformat(input, #a))             \
index bdd0bd0..8fc8f41 100644 (file)
@@ -156,24 +156,6 @@ dpdk_prefetch_buffer_data_x4 (struct rte_mbuf *mb[])
   CLIB_PREFETCH (b->data, CLIB_CACHE_LINE_BYTES, LOAD);
 }
 
-static inline void
-poll_rate_limit (dpdk_main_t * dm)
-{
-  /* Limit the poll rate by sleeping for N msec between polls */
-  if (PREDICT_FALSE (dm->poll_sleep_usec != 0))
-    {
-      struct timespec ts, tsrem;
-
-      ts.tv_sec = 0;
-      ts.tv_nsec = 1000 * dm->poll_sleep_usec;
-
-      while (nanosleep (&ts, &tsrem) < 0)
-       {
-         ts = tsrem;
-       }
-    }
-}
-
 /** \brief Main DPDK input node
     @node dpdk-input
 
@@ -659,9 +641,6 @@ VLIB_NODE_FN (dpdk_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
                                         dq->queue_id);
     }
   /* *INDENT-ON* */
-
-  poll_rate_limit (dm);
-
   return n_rx_packets;
 }
 
index 321e443..0a61c05 100644 (file)
@@ -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);
index 786addf..f812b08 100644 (file)
@@ -344,6 +344,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
        um->cli_no_banner = 1;
       else if (unformat (input, "cli-no-pager"))
        um->cli_no_pager = 1;
+      else if (unformat (input, "poll-sleep-usec %d", &um->poll_sleep_usec))
+       ;
       else if (unformat (input, "cli-pager-buffer-limit %d",
                         &um->cli_pager_buffer_limit))
        ;
index 4c8566b..7856e5b 100644 (file)
@@ -102,6 +102,9 @@ typedef struct
   /* Store the original state of stdin when it's a tty */
   struct termios tio_stdin;
   int tio_isset;
+
+  u32 poll_sleep_usec;
+
 } unix_main_t;
 
 /* Global main structure. */