vlib: introduce vlib_get_main_by_index(), vlib_get_n_threads()
[vpp.git] / src / vnet / interface / runtime.c
index f4c09be..20ac51f 100644 (file)
@@ -63,7 +63,8 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
   vnet_hw_if_rx_queue_t *rxq;
   vnet_hw_if_rxq_poll_vector_t *pv, **d = 0;
   vlib_node_state_t *per_thread_node_state = 0;
-  u32 n_threads = vec_len (vlib_mains);
+  u32 n_threads = vlib_get_n_threads ();
+  u16 *per_thread_node_adaptive = 0;
   int something_changed = 0;
   clib_bitmap_t *pending_int = 0;
   int last_int = -1;
@@ -74,6 +75,7 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
   vec_validate (d, n_threads - 1);
   vec_validate_init_empty (per_thread_node_state, n_threads - 1,
                           VLIB_NODE_STATE_DISABLED);
+  vec_validate_init_empty (per_thread_node_adaptive, n_threads - 1, 0);
 
   /* find out desired node state on each thread */
   pool_foreach (rxq, im->hw_if_rx_queues)
@@ -89,7 +91,10 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
        continue;
 
       if (rxq->mode == VNET_HW_IF_RX_MODE_POLLING)
-       per_thread_node_state[ti] = VLIB_NODE_STATE_POLLING;
+       {
+         per_thread_node_state[ti] = VLIB_NODE_STATE_POLLING;
+         per_thread_node_adaptive[ti] = 0;
+       }
 
       if (per_thread_node_state[ti] == VLIB_NODE_STATE_POLLING)
        continue;
@@ -97,26 +102,21 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
       if (rxq->mode == VNET_HW_IF_RX_MODE_INTERRUPT ||
          rxq->mode == VNET_HW_IF_RX_MODE_ADAPTIVE)
        per_thread_node_state[ti] = VLIB_NODE_STATE_INTERRUPT;
+
+      if (rxq->mode == VNET_HW_IF_RX_MODE_ADAPTIVE)
+       per_thread_node_adaptive[ti] = 1;
     }
 
   /* construct per-thread polling vectors */
   pool_foreach (rxq, im->hw_if_rx_queues)
     {
       u32 ti = rxq->thread_index;
-      uword flags;
 
       hi = vnet_get_hw_interface (vnm, rxq->hw_if_index);
 
       if (hi->input_node_index != node_index)
        continue;
 
-      flags = vnet_sw_interface_get_flags (vnm, hi->sw_if_index);
-      if ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0)
-       {
-         log_debug ("skip interface %v (admin down)", hi->name);
-         continue;
-       }
-
       if (rxq->mode == VNET_HW_IF_RX_MODE_INTERRUPT ||
          rxq->mode == VNET_HW_IF_RX_MODE_ADAPTIVE)
        last_int = clib_max (last_int, rxq - im->hw_if_rx_queues);
@@ -133,10 +133,11 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
    * unnecesary barrier */
   for (int i = 0; i < n_threads; i++)
     {
+      vlib_main_t *ovm = vlib_get_main_by_index (i);
       vlib_node_state_t old_state;
       vec_sort_with_function (d[i], poll_data_sort);
 
-      old_state = vlib_node_get_state (vlib_mains[i], node_index);
+      old_state = vlib_node_get_state (ovm, node_index);
       if (per_thread_node_state[i] != old_state)
        {
          something_changed = 1;
@@ -150,7 +151,7 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
       if (something_changed == 0)
        {
          vnet_hw_if_rx_node_runtime_t *rt;
-         rt = vlib_node_get_runtime_data (vlib_mains[i], node_index);
+         rt = vlib_node_get_runtime_data (ovm, node_index);
          if (vec_len (rt->rxq_poll_vector) != vec_len (d[i]))
            something_changed = 1;
          else if (memcmp (d[i], rt->rxq_poll_vector,
@@ -178,7 +179,7 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
 
       for (int i = 0; i < n_threads; i++)
        {
-         vlib_main_t *vm = vlib_mains[i];
+         vlib_main_t *vm = vlib_get_main_by_index (i);
          vnet_hw_if_rx_node_runtime_t *rt;
          rt = vlib_node_get_runtime_data (vm, node_index);
          pv = rt->rxq_poll_vector;
@@ -198,6 +199,8 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
            }
 
          vlib_node_set_state (vm, node_index, per_thread_node_state[i]);
+         vlib_node_set_flag (vm, node_index, VLIB_NODE_FLAG_ADAPTIVE_MODE,
+                             per_thread_node_adaptive[i]);
 
          if (last_int >= 0)
            clib_interrupt_resize (&rt->rxq_interrupts, last_int + 1);
@@ -227,4 +230,5 @@ vnet_hw_if_update_runtime_data (vnet_main_t *vnm, u32 hw_if_index)
 
   vec_free (d);
   vec_free (per_thread_node_state);
+  vec_free (per_thread_node_adaptive);
 }