gbp: Consider data-plane learnt source better than control-plane
[vpp.git] / src / vlib / main.c
index 4dcf63e..3c0e754 100644 (file)
@@ -680,13 +680,16 @@ vlib_node_runtime_update_stats (vlib_main_t * vm,
   return r;
 }
 
-static inline void
-vlib_node_runtime_perf_counter (vlib_main_t * vm, u64 * pmc0, u64 * pmc1)
+always_inline void
+vlib_node_runtime_perf_counter (vlib_main_t * vm, u64 * pmc0, u64 * pmc1,
+                               vlib_node_runtime_t * node,
+                               vlib_frame_t * frame, int before_or_after)
 {
   *pmc0 = 0;
   *pmc1 = 0;
-  if (PREDICT_FALSE (vm->vlib_node_runtime_perf_counter_cb != 0))
-    (*vm->vlib_node_runtime_perf_counter_cb) (vm, pmc0, pmc1);
+  if (PREDICT_FALSE (vec_len (vm->vlib_node_runtime_perf_counter_cbs) != 0))
+    clib_call_callbacks (vm->vlib_node_runtime_perf_counter_cbs, vm, pmc0,
+                        pmc1, node, frame, before_or_after);
 }
 
 always_inline void
@@ -1016,8 +1019,8 @@ format_buffer_metadata (u8 * s, va_list * args)
              (u32) (b->error), (u32) (b->ref_count),
              (u32) (b->buffer_pool_index));
   s = format (s,
-             "trace_index: %d, len_not_first_buf: %d\n",
-             b->trace_index, b->total_length_not_including_first_buffer);
+             "trace_handle: 0x%x, len_not_first_buf: %d\n",
+             b->trace_handle, b->total_length_not_including_first_buffer);
   return s;
 }
 
@@ -1088,7 +1091,8 @@ dispatch_pcap_trace (vlib_main_t * vm,
          if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
            {
              vlib_trace_header_t **h
-               = pool_elt_at_index (tm->trace_buffer_pool, b->trace_index);
+               = pool_elt_at_index (tm->trace_buffer_pool,
+                                    vlib_buffer_get_trace_index (b));
 
              vm->pcap_buffer = format (vm->pcap_buffer, "%U%c",
                                        format_vlib_trace, vm, h[0], 0);
@@ -1181,7 +1185,8 @@ dispatch_node (vlib_main_t * vm,
                             last_time_stamp, frame ? frame->n_vectors : 0,
                             /* is_after */ 0);
 
-  vlib_node_runtime_perf_counter (vm, &pmc_before[0], &pmc_before[1]);
+  vlib_node_runtime_perf_counter (vm, &pmc_before[0], &pmc_before[1],
+                                 node, frame, 0 /* before */ );
 
   /*
    * Turn this on if you run into
@@ -1215,7 +1220,8 @@ dispatch_node (vlib_main_t * vm,
    * To validate accounting: pmc_delta = t - pmc_before;
    * perf ticks should equal clocks/pkt...
    */
-  vlib_node_runtime_perf_counter (vm, &pmc_after[0], &pmc_after[1]);
+  vlib_node_runtime_perf_counter (vm, &pmc_after[0], &pmc_after[1], node,
+                                 frame, 1 /* after */ );
 
   pmc_delta[0] = pmc_after[0] - pmc_before[0];
   pmc_delta[1] = pmc_after[1] - pmc_before[1];
@@ -1679,6 +1685,7 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
   u64 cpu_time_now;
   vlib_frame_queue_main_t *fqm;
   u32 *last_node_runtime_indices = 0;
+  u32 frame_queue_check_counter = 0;
 
   /* Initialize pending node vector. */
   if (is_main)
@@ -1715,6 +1722,14 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
   if (is_main)
     {
       uword i;
+
+      /*
+       * Perform an initial barrier sync. Pays no attention to
+       * the barrier sync hold-down timer scheme, which won't work
+       * at this point in time.
+       */
+      vlib_worker_thread_initial_barrier_sync_and_release (vm);
+
       nm->current_process_index = ~0;
       for (i = 0; i < vec_len (nm->processes); i++)
        cpu_time_now = dispatch_process (vm, nm->processes[i], /* frame */ 0,
@@ -1734,11 +1749,28 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
       if (!is_main)
        {
          vlib_worker_thread_barrier_check ();
-         vec_foreach (fqm, tm->frame_queue_mains)
-           vlib_frame_queue_dequeue (vm, fqm);
-         if (PREDICT_FALSE (vm->worker_thread_main_loop_callback != 0))
-           ((void (*)(vlib_main_t *)) vm->worker_thread_main_loop_callback)
-             (vm);
+         if (PREDICT_FALSE (vm->check_frame_queues +
+                            frame_queue_check_counter))
+           {
+             u32 processed = 0;
+
+             if (vm->check_frame_queues)
+               {
+                 frame_queue_check_counter = 100;
+                 vm->check_frame_queues = 0;
+               }
+
+             vec_foreach (fqm, tm->frame_queue_mains)
+               processed += vlib_frame_queue_dequeue (vm, fqm);
+
+             /* No handoff queue work found? */
+             if (processed)
+               frame_queue_check_counter = 100;
+             else
+               frame_queue_check_counter--;
+           }
+         if (PREDICT_FALSE (vec_len (vm->worker_thread_main_loop_callbacks)))
+           clib_call_callbacks (vm->worker_thread_main_loop_callbacks, vm);
        }
 
       /* Process pre-input nodes. */
@@ -2064,6 +2096,20 @@ vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
   vec_validate (vm->processing_rpc_requests, 0);
   _vec_len (vm->processing_rpc_requests) = 0;
 
+  if ((error = vlib_call_all_config_functions (vm, input, 0 /* is_early */ )))
+    goto done;
+
+  /* Sort per-thread init functions before we start threads */
+  vlib_sort_init_exit_functions (&vm->worker_init_function_registrations);
+
+  /* Call all main loop enter functions. */
+  {
+    clib_error_t *sub_error;
+    sub_error = vlib_call_all_main_loop_enter_functions (vm);
+    if (sub_error)
+      clib_error_report (sub_error);
+  }
+
   switch (clib_setjmp (&vm->main_loop_exit, VLIB_MAIN_LOOP_EXIT_NONE))
     {
     case VLIB_MAIN_LOOP_EXIT_NONE:
@@ -2078,17 +2124,6 @@ vlib_main (vlib_main_t * volatile vm, unformat_input_t * input)
       goto done;
     }
 
-  if ((error = vlib_call_all_config_functions (vm, input, 0 /* is_early */ )))
-    goto done;
-
-  /* Call all main loop enter functions. */
-  {
-    clib_error_t *sub_error;
-    sub_error = vlib_call_all_main_loop_enter_functions (vm);
-    if (sub_error)
-      clib_error_report (sub_error);
-  }
-
   vlib_main_loop (vm);
 
 done: