X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fnode.c;h=805c69e4f8bf0fe63cd18a7ecd4190ea9fc7cd13;hb=c3638fece1a3b96349b7df11261e6661b101ccbe;hp=e6739dc7cf94d52d89fe15aae60a8b688d7fba78;hpb=19e9d954bd9eb4f04d48640d6540198e84ef65d7;p=vpp.git diff --git a/src/vlib/node.c b/src/vlib/node.c index e6739dc7cf9..805c69e4f8b 100644 --- a/src/vlib/node.c +++ b/src/vlib/node.c @@ -324,6 +324,26 @@ register_node (vlib_main_t * vm, vlib_node_registration_t * r) ASSERT (VLIB_NODE_TYPE_INTERNAL == zero.type); } + if (r->node_fn_registrations) + { + vlib_node_fn_registration_t *fnr = r->node_fn_registrations; + int priority = -1; + + /* to avoid confusion, please remove ".function " statiement from + CLIB_NODE_REGISTRATION() if using function function candidates */ + ASSERT (r->function == 0); + + while (fnr) + { + if (fnr->priority > priority) + { + priority = fnr->priority; + r->function = fnr->function; + } + fnr = fnr->next_registration; + } + } + ASSERT (r->function != 0); n = clib_mem_alloc_no_fail (sizeof (n[0])); @@ -543,6 +563,68 @@ vlib_register_all_static_nodes (vlib_main_t * vm) } } +void +vlib_node_get_nodes (vlib_main_t * vm, u32 max_threads, int include_stats, + int barrier_sync, vlib_node_t **** node_dupsp, + vlib_main_t *** stat_vmsp) +{ + vlib_node_main_t *nm = &vm->node_main; + vlib_node_t *n; + vlib_node_t ***node_dups = *node_dupsp; + vlib_node_t **nodes; + vlib_main_t **stat_vms = *stat_vmsp; + vlib_main_t *stat_vm; + uword i, j; + u32 threads_to_serialize; + + if (vec_len (stat_vms) == 0) + { + for (i = 0; i < vec_len (vlib_mains); i++) + { + stat_vm = vlib_mains[i]; + if (stat_vm) + vec_add1 (stat_vms, stat_vm); + } + } + + threads_to_serialize = clib_min (max_threads, vec_len (stat_vms)); + + vec_validate (node_dups, threads_to_serialize - 1); + + /* + * Barrier sync across stats scraping. + * Otherwise, the counts will be grossly inaccurate. + */ + if (barrier_sync) + vlib_worker_thread_barrier_sync (vm); + + for (j = 0; j < threads_to_serialize; j++) + { + stat_vm = stat_vms[j]; + nm = &stat_vm->node_main; + + if (include_stats) + { + for (i = 0; i < vec_len (nm->nodes); i++) + { + n = nm->nodes[i]; + vlib_node_sync_stats (stat_vm, n); + } + } + + nodes = node_dups[j]; + vec_validate (nodes, vec_len (nm->nodes) - 1); + clib_memcpy (nodes, nm->nodes, vec_len (nm->nodes) * sizeof (nodes[0])); + node_dups[j] = nodes; + } + + if (barrier_sync) + vlib_worker_thread_barrier_release (vm); + + *node_dupsp = node_dups; + *stat_vmsp = stat_vms; +} + clib_error_t * vlib_node_main_init (vlib_main_t * vm) {