X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ffib%2Ffib_walk.c;h=a09e34df3ba7eca7552fa789e82bda734b55ee32;hb=282872127bbeee6ae59ab3f885c09bad601ee0cc;hp=701801370b19bec4494b81b66487a09c2ce878ed;hpb=8c4611b39162da9753caaf654741faa115eaf612;p=vpp.git diff --git a/src/vnet/fib/fib_walk.c b/src/vnet/fib/fib_walk.c index 701801370b1..a09e34df3ba 100644 --- a/src/vnet/fib/fib_walk.c +++ b/src/vnet/fib/fib_walk.c @@ -16,6 +16,8 @@ #include #include +vlib_log_class_t fib_walk_logger; + /** * The flags on a walk */ @@ -85,7 +87,7 @@ typedef struct fib_walk_t_ /** * The reasons this walk is occuring. * This is a vector ordered in time. The reasons and the front were started - * first, and so should be acted first when a node is visisted. + * first, and so should be acted first when a node is visited. */ fib_node_back_walk_ctx_t *fw_ctx; } fib_walk_t; @@ -125,7 +127,7 @@ static const char * const fib_walk_queue_stats_names[] = FIB_WALK_QUEUE_STATS; static const char * const fib_node_bw_reason_names[] = FIB_NODE_BW_REASONS; /** - * A represenation of one queue of walk + * A representation of one queue of walk */ typedef struct fib_walk_queue_t_ { @@ -159,7 +161,7 @@ static fib_walk_queues_t fib_walk_queues; static const char * const fib_walk_priority_names[] = FIB_WALK_PRIORITIES; /** - * @brief Histogram stats on the lenths of each walk in elemenets visisted. + * @brief Histogram stats on the lenths of each walk in elemenets visited. * Store upto 1<<23 elements in increments of 1<<10 */ #define HISTOGRAM_VISITS_PER_WALK_MAX (1<<23) @@ -184,19 +186,30 @@ typedef struct fib_walk_history_t_ { } fib_walk_history_t; static fib_walk_history_t fib_walk_history[HISTORY_N_WALKS]; +static u8* format_fib_walk (u8* s, va_list *ap); + +#define FIB_WALK_DBG(_walk, _fmt, _args...) \ +{ \ + vlib_log_debug(fib_walk_logger, \ + "[%U]:" _fmt, \ + format_fib_walk, \ + fib_walk_get_index(_walk), \ + ##_args); \ +} + u8* -format_fib_walk_priority (u8 *s, va_list ap) +format_fib_walk_priority (u8 *s, va_list *ap) { - fib_walk_priority_t prio = va_arg(ap, fib_walk_priority_t); + fib_walk_priority_t prio = va_arg(*ap, fib_walk_priority_t); ASSERT(prio < FIB_WALK_PRIORITY_NUM); return (format(s, "%s", fib_walk_priority_names[prio])); } static u8* -format_fib_walk_queue_stats (u8 *s, va_list ap) +format_fib_walk_queue_stats (u8 *s, va_list *ap) { - fib_walk_queue_stats_t wqs = va_arg(ap, fib_walk_queue_stats_t); + fib_walk_queue_stats_t wqs = va_arg(*ap, fib_walk_queue_stats_t); ASSERT(wqs < FIB_WALK_QUEUE_STATS_NUM); @@ -350,7 +363,9 @@ fib_walk_advance (fib_node_index_t fwi) while (ii < n_ctxs) { - wrc = fib_node_back_walk_one(&sibling, &fwalk->fw_ctx[ii]); + fib_node_back_walk_ctx_t ctx = fwalk->fw_ctx[ii]; + + wrc = fib_node_back_walk_one(&sibling, &ctx); ii++; fwalk = fib_walk_get(fwi); @@ -399,7 +414,17 @@ typedef enum fib_walk_sleep_type_t_ * @brief Durations for the sleep types */ static f64 fib_walk_sleep_duration[] = { - [FIB_WALK_LONG_SLEEP] = 1e-3, + /** + * Long sleep when there is no more work, i.e. the queues are empty. + * This is a sleep (as opposed to a wait for event) just to be sure we + * are not missing events by sleeping forever. + */ + [FIB_WALK_LONG_SLEEP] = 2, + + /** + * Short sleep. There is work left in the queues. We are yielding the CPU + * momentarily. + */ [FIB_WALK_SHORT_SLEEP] = 1e-8, }; @@ -420,7 +445,7 @@ static u64 fib_walk_work_time_taken[N_TIME_BUCKETS]; * Histogram on the number of nodes visted in each quota */ #define N_ELTS_BUCKETS 128 -static u32 fib_walk_work_nodes_visisted_incr = 2; +static u32 fib_walk_work_nodes_visited_incr = 2; static u64 fib_walk_work_nodes_visited[N_ELTS_BUCKETS]; /** @@ -499,12 +524,12 @@ that_will_do_for_now: /* * collect the stats: - * - for the number of nodes visisted we store 128 increments + * - for the number of nodes visited we store 128 increments * - for the time consumed we store quota/TIME_INCREMENTS increments. */ - bucket = ((n_elts/fib_walk_work_nodes_visisted_incr) > N_ELTS_BUCKETS ? + bucket = ((n_elts/fib_walk_work_nodes_visited_incr) > N_ELTS_BUCKETS ? N_ELTS_BUCKETS-1 : - n_elts/fib_walk_work_nodes_visisted_incr); + n_elts/fib_walk_work_nodes_visited_incr); ++fib_walk_work_nodes_visited[bucket]; bucket = (consumed_time - quota) / (quota / TIME_INCREMENTS); @@ -704,13 +729,16 @@ fib_walk_async (fib_node_type_t parent_type, fib_walk_get_index(fwalk)); fwalk->fw_prio_sibling = fib_walk_prio_queue_enquue(prio, fwalk); + + FIB_WALK_DBG(fwalk, "async-start: %U", + format_fib_node_bw_reason, ctx->fnbw_reason); } /** * @brief Back walk all the children of a FIB node. * * note this is a synchronous depth first walk. Children visited may propagate - * the walk to thier children. Other children node types may not propagate, + * the walk to their children. Other children node types may not propagate, * synchronously but instead queue the walk for later async completion. */ void @@ -749,6 +777,8 @@ fib_walk_sync (fib_node_type_t parent_type, FIB_NODE_TYPE_WALK, fib_walk_get_index(fwalk)); fwi = fib_walk_get_index(fwalk); + FIB_WALK_DBG(fwalk, "sync-start: %U", + format_fib_node_bw_reason, ctx->fnbw_reason); while (1) { @@ -802,6 +832,10 @@ fib_walk_sync (fib_node_type_t parent_type, * continue with it now, but let the stack unwind and along the * appropriate frame to read the depth count and bail. */ + FIB_WALK_DBG(fwalk, "sync-stop: %U", + format_fib_node_bw_reason, + ctx->fnbw_reason); + fwalk = NULL; break; } @@ -817,6 +851,9 @@ fib_walk_sync (fib_node_type_t parent_type, if (NULL != fwalk) { + FIB_WALK_DBG(fwalk, "sync-stop: %U", + format_fib_node_bw_reason, + ctx->fnbw_reason); fib_walk_destroy(fwi); } } @@ -914,23 +951,38 @@ fib_walk_module_init (void) } fib_node_register_type(FIB_NODE_TYPE_WALK, &fib_walk_vft); + fib_walk_logger = vlib_log_register_class("fib", "walk"); } static u8* -format_fib_walk (u8* s, va_list ap) +format_fib_walk (u8* s, va_list *ap) { - fib_node_index_t fwi = va_arg(ap, fib_node_index_t); + fib_node_index_t fwi = va_arg(*ap, fib_node_index_t); fib_walk_t *fwalk; fwalk = fib_walk_get(fwi); - return (format(s, " parent:{%s:%d} visits:%d flags:%d", + return (format(s, "[@%d] parent:{%s:%d} visits:%d flags:%d", fwi, fib_node_type_get_name(fwalk->fw_parent.fnp_type), fwalk->fw_parent.fnp_index, fwalk->fw_n_visits, fwalk->fw_flags)); } +u8 * +format_fib_node_bw_reason (u8 *s, va_list *args) +{ + fib_node_bw_reason_flag_t flag = va_arg (*args, int); + fib_node_back_walk_reason_t reason; + + FOR_EACH_FIB_NODE_BW_REASON(reason) { + if ((1<