X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fstats%2Fstat_segment.c;h=c8445ba5814c8e7c8fbbeb56fb7da9bc5775d20f;hb=db0238090;hp=b96e667783a58368dc71b5e80da38ad2e196b6cc;hpb=72e31bc2d9b910147c09e1c329713fccc873a018;p=vpp.git diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index b96e667783a..c8445ba5814 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -19,10 +19,7 @@ #include "stat_segment.h" #include #include /* vnet_get_aggregate_rx_packets */ -#undef HAVE_MEMFD_CREATE -#include #include -#include stat_segment_main_t stat_segment_main; @@ -148,6 +145,40 @@ vlib_stats_delete_counter (u32 index, void *oldheap) e->type = STAT_DIR_TYPE_EMPTY; } +/* + * Called from main heap + */ +void +vlib_stats_delete_cm (void *cm_arg) +{ + vlib_simple_counter_main_t *cm = (vlib_simple_counter_main_t *) cm_arg; + stat_segment_main_t *sm = &stat_segment_main; + stat_segment_directory_entry_t *e; + + /* Not all counters have names / hash-table entries */ + if (!cm->name && !cm->stat_segment_name) + { + return; + } + vlib_stat_segment_lock (); + + /* Lookup hash-table is on the main heap */ + char *stat_segment_name = + cm->stat_segment_name ? cm->stat_segment_name : cm->name; + u32 index = lookup_hash_index ((u8 *) stat_segment_name); + + e = &sm->directory_vector[index]; + hash_unset (sm->directory_vector_by_name, &e->name); + + void *oldheap = clib_mem_set_heap (sm->heap); /* Enter stats segment */ + clib_mem_set_heap (oldheap); /* Exit stats segment */ + + memset (e, 0, sizeof (*e)); + e->type = STAT_DIR_TYPE_EMPTY; + + vlib_stat_segment_unlock (); +} + void vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex, stat_directory_type_t type) @@ -172,6 +203,7 @@ vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex, /* Lookup hash-table is on the main heap */ stat_segment_name = cm->stat_segment_name ? cm->stat_segment_name : cm->name; + clib_mem_set_heap (oldheap); /* Exit stats segment */ u32 vector_index = lookup_hash_index ((u8 *) stat_segment_name); /* Back to stats segment */ @@ -187,35 +219,87 @@ vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex, } stat_segment_directory_entry_t *ep = &sm->directory_vector[vector_index]; - ep->offset = stat_segment_offset (shared_header, cm->counters); /* Vector of threads of vectors of counters */ - u64 *offset_vector = - ep->offset_vector ? stat_segment_pointer (shared_header, - ep->offset_vector) : 0; + ep->data = cm->counters; + + /* Reset the client hash table pointer, since it WILL change! */ + shared_header->directory_vector = sm->directory_vector; - /* Update the 2nd dimension offset vector */ + vlib_stat_segment_unlock (); + clib_mem_set_heap (oldheap); +} + +u8 * +format_vlib_stats_symlink (u8 *s, va_list *args) +{ + char *input = va_arg (*args, char *); + char *modified_input = vec_dup (input); int i; - vec_validate (offset_vector, vec_len (cm->counters) - 1); + u8 *result; + + for (i = 0; i < strlen (modified_input); i++) + if (modified_input[i] == '/') + modified_input[i] = '_'; + + result = format (s, "%s", modified_input); + vec_free (modified_input); + return result; +} + +void +vlib_stats_register_symlink (void *oldheap, u8 *name, u32 index1, u32 index2, + u8 lock) +{ + stat_segment_main_t *sm = &stat_segment_main; + stat_segment_shared_header_t *shared_header = sm->shared_header; + stat_segment_directory_entry_t e; + + ASSERT (shared_header); - if (sm->last != offset_vector) + if (lock) + vlib_stat_segment_lock (); + clib_mem_set_heap (oldheap); /* Exit stats segment */ + u32 vector_index = lookup_hash_index (name); + /* Back to stats segment */ + clib_mem_set_heap (sm->heap); /* Re-enter stat segment */ + + if (vector_index == STAT_SEGMENT_INDEX_INVALID) { - for (i = 0; i < vec_len (cm->counters); i++) - offset_vector[i] = - stat_segment_offset (shared_header, cm->counters[i]); + memcpy (e.name, name, vec_len (name)); + e.name[vec_len (name)] = '\0'; + e.type = STAT_DIR_TYPE_SYMLINK; + e.index1 = index1; + e.index2 = index2; + vector_index = vlib_stats_create_counter (&e, oldheap); + + /* Warn clients to refresh any pointers they might be holding */ + shared_header->directory_vector = sm->directory_vector; } - else - offset_vector[cindex] = - stat_segment_offset (shared_header, cm->counters[cindex]); - ep->offset_vector = stat_segment_offset (shared_header, offset_vector); - sm->directory_vector[vector_index].offset = - stat_segment_offset (shared_header, cm->counters); + if (lock) + vlib_stat_segment_unlock (); +} + +void +vlib_stats_rename_symlink (void *oldheap, u64 index, u8 *new_name) +{ + stat_segment_main_t *sm = &stat_segment_main; + stat_segment_directory_entry_t *e; - /* Reset the client hash table pointer, since it WILL change! */ - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + ASSERT (clib_mem_get_heap () == sm->heap); - vlib_stat_segment_unlock (); + if (index > vec_len (sm->directory_vector)) + return; + + e = &sm->directory_vector[index]; + + clib_mem_set_heap (oldheap); + hash_unset (sm->directory_vector_by_name, &e->name); + clib_mem_set_heap (sm->heap); + + strncpy (e->name, (char *) new_name, 128 - 1); clib_mem_set_heap (oldheap); + hash_set (sm->directory_vector_by_name, &e->name, index); + clib_mem_set_heap (sm->heap); } void @@ -239,13 +323,11 @@ vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec, memcpy (e.name, name, vec_len (name)); e.name[vec_len (name)] = '\0'; e.type = STAT_DIR_TYPE_ERROR_INDEX; - e.offset = index; - e.offset_vector = 0; + e.index = index; vector_index = vlib_stats_create_counter (&e, oldheap); /* Warn clients to refresh any pointers they might be holding */ - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + shared_header->directory_vector = sm->directory_vector; } vlib_stat_segment_unlock (); @@ -254,37 +336,25 @@ vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec, static void stat_validate_counter_vector (stat_segment_directory_entry_t * ep, u32 max) { - stat_segment_main_t *sm = &stat_segment_main; - stat_segment_shared_header_t *shared_header = sm->shared_header; - counter_t **counters = 0; + counter_t **counters = ep->data; vlib_thread_main_t *tm = vlib_get_thread_main (); int i; - u64 *offset_vector = 0; vec_validate_aligned (counters, tm->n_vlib_mains - 1, CLIB_CACHE_LINE_BYTES); for (i = 0; i < tm->n_vlib_mains; i++) - { - vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES); - vec_add1 (offset_vector, - stat_segment_offset (shared_header, counters[i])); - } - ep->offset = stat_segment_offset (shared_header, counters); - ep->offset_vector = stat_segment_offset (shared_header, offset_vector); + vec_validate_aligned (counters[i], max, CLIB_CACHE_LINE_BYTES); + + ep->data = counters; } always_inline void stat_set_simple_counter (stat_segment_directory_entry_t * ep, u32 thread_index, u32 index, u64 value) { - stat_segment_main_t *sm = &stat_segment_main; - stat_segment_shared_header_t *shared_header = sm->shared_header; - - ASSERT (shared_header); - counter_t *offset_vector = - stat_segment_pointer (sm->shared_header, ep->offset_vector); - counter_t *cb = - stat_segment_pointer (sm->shared_header, offset_vector[thread_index]); + ASSERT (ep->data); + counter_t **counters = ep->data; + counter_t *cb = counters[thread_index]; cb[index] = value; } @@ -302,13 +372,10 @@ vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap, /* Reset the client hash table pointer, since it WILL change! */ vec_validate (sm->error_vector, thread_index); - sm->error_vector[thread_index] = - stat_segment_offset (shared_header, error_vector); + sm->error_vector[thread_index] = error_vector; - shared_header->error_offset = - stat_segment_offset (shared_header, sm->error_vector); - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + shared_header->error_vector = sm->error_vector; + shared_header->directory_vector = sm->directory_vector; if (lock) vlib_stat_segment_unlock (); @@ -321,41 +388,40 @@ vlib_map_stat_segment_init (void) stat_segment_main_t *sm = &stat_segment_main; stat_segment_shared_header_t *shared_header; void *oldheap; - ssize_t memory_size; + uword memory_size, sys_page_sz; int mfd; - char *mem_name = "stat_segment_test"; - void *memaddr; + char *mem_name = "stat segment"; + void *heap, *memaddr; memory_size = sm->memory_size; if (memory_size == 0) memory_size = STAT_SEGMENT_DEFAULT_SIZE; - /* Create shared memory segment */ - if ((mfd = memfd_create (mem_name, 0)) < 0) - return clib_error_return (0, "stat segment memfd_create failure"); + if (sm->log2_page_sz == CLIB_MEM_PAGE_SZ_UNKNOWN) + sm->log2_page_sz = CLIB_MEM_PAGE_SZ_DEFAULT; + + mfd = clib_mem_vm_create_fd (sm->log2_page_sz, mem_name); + if (mfd == -1) + return clib_error_return (0, "stat segment memory fd failure: %U", + format_clib_error, clib_mem_get_last_error ()); /* Set size */ if ((ftruncate (mfd, memory_size)) == -1) - return clib_error_return (0, "stat segment ftruncate failure"); + { + close (mfd); + return clib_error_return (0, "stat segment ftruncate failure"); + } - if ((memaddr = - mmap (NULL, memory_size, PROT_READ | PROT_WRITE, MAP_SHARED, mfd, - 0)) == MAP_FAILED) + memaddr = clib_mem_vm_map_shared (0, memory_size, mfd, 0, mem_name); + + if (memaddr == CLIB_MEM_VM_MAP_FAILED) return clib_error_return (0, "stat segment mmap failure"); - void *heap; -#if USE_DLMALLOC == 0 - heap = mheap_alloc_with_flags (((u8 *) memaddr) + getpagesize (), - memory_size - getpagesize (), - MHEAP_FLAG_DISABLE_VM | - MHEAP_FLAG_THREAD_SAFE); -#else - heap = - create_mspace_with_base (((u8 *) memaddr) + getpagesize (), - memory_size - getpagesize (), 1 /* locked */ ); - mspace_disable_expand (heap); -#endif + sys_page_sz = clib_mem_get_page_size (); + heap = clib_mem_create_heap (((u8 *) memaddr) + sys_page_sz, memory_size + - sys_page_sz, 1 /* locked */ , + "stat segment"); sm->heap = heap; sm->memfd = mfd; @@ -363,6 +429,7 @@ vlib_map_stat_segment_init (void) sm->shared_header = shared_header = memaddr; shared_header->version = STAT_SEGMENT_VERSION; + shared_header->base = memaddr; sm->stat_segment_lockp = clib_mem_alloc (sizeof (clib_spinlock_t)); clib_spinlock_init (sm->stat_segment_lockp); @@ -381,15 +448,14 @@ vlib_map_stat_segment_init (void) sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t; foreach_stat_segment_counter_name #undef _ - /* Save the vector offset in the shared segment, for clients */ - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + /* Save the vector in the shared segment, for clients */ + shared_header->directory_vector = sm->directory_vector; clib_mem_set_heap (oldheap); /* Total shared memory size */ clib_mem_usage_t usage; - mheap_usage (sm->heap, &usage); + clib_mem_get_heap_usage (sm->heap, &usage); sm->directory_vector[STAT_COUNTER_MEM_STATSEG_TOTAL].value = usage.bytes_total; @@ -443,7 +509,7 @@ format_stat_dir_entry (u8 * s, va_list * args) break; } - return format (s, format_string, ep->name, type_name, ep->offset); + return format (s, format_string, ep->name, type_name, 0); } static clib_error_t * @@ -483,7 +549,8 @@ show_stat_segment_command_fn (vlib_main_t * vm, if (verbose) { ASSERT (sm->heap); - vlib_cli_output (vm, "%U", format_mheap, sm->heap, 0 /* verbose */ ); + vlib_cli_output (vm, "%U", format_clib_mem_heap, sm->heap, + 0 /* verbose */ ); } return 0; @@ -512,16 +579,14 @@ update_node_counters (stat_segment_main_t * sm) vlib_main_t **stat_vms = 0; vlib_node_t ***node_dups = 0; int i, j; - stat_segment_shared_header_t *shared_header = sm->shared_header; static u32 no_max_nodes = 0; - vlib_node_get_nodes (0 /* vm, for barrier sync */ , - (u32) ~ 0 /* all threads */ , - 1 /* include stats */ , - 0 /* barrier sync */ , - &node_dups, &stat_vms); + vlib_node_get_nodes (0 /* vm, for barrier sync */, + (u32) ~0 /* all threads */, 1 /* include stats */, + 0 /* barrier sync */, &node_dups, &stat_vms); u32 l = vec_len (node_dups[0]); + u8 *symlink_name = 0; /* * Extend performance nodes if necessary @@ -531,28 +596,23 @@ update_node_counters (stat_segment_main_t * sm) void *oldheap = clib_mem_set_heap (sm->heap); vlib_stat_segment_lock (); - stat_validate_counter_vector (&sm->directory_vector - [STAT_COUNTER_NODE_CLOCKS], l - 1); - stat_validate_counter_vector (&sm->directory_vector - [STAT_COUNTER_NODE_VECTORS], l - 1); - stat_validate_counter_vector (&sm->directory_vector - [STAT_COUNTER_NODE_CALLS], l - 1); - stat_validate_counter_vector (&sm->directory_vector - [STAT_COUNTER_NODE_SUSPENDS], l - 1); + stat_validate_counter_vector ( + &sm->directory_vector[STAT_COUNTER_NODE_CLOCKS], l - 1); + stat_validate_counter_vector ( + &sm->directory_vector[STAT_COUNTER_NODE_VECTORS], l - 1); + stat_validate_counter_vector ( + &sm->directory_vector[STAT_COUNTER_NODE_CALLS], l - 1); + stat_validate_counter_vector ( + &sm->directory_vector[STAT_COUNTER_NODE_SUSPENDS], l - 1); vec_validate (sm->nodes, l - 1); stat_segment_directory_entry_t *ep; ep = &sm->directory_vector[STAT_COUNTER_NODE_NAMES]; - ep->offset = stat_segment_offset (shared_header, sm->nodes); + ep->data = sm->nodes; - int i; - u64 *offset_vector = - ep->offset_vector ? stat_segment_pointer (shared_header, - ep->offset_vector) : 0; /* Update names dictionary */ - vec_validate (offset_vector, l - 1); vlib_node_t **nodes = node_dups[0]; - + int i; for (i = 0; i < vec_len (nodes); i++) { vlib_node_t *n = nodes[i]; @@ -561,13 +621,17 @@ update_node_counters (stat_segment_main_t * sm) if (sm->nodes[n->index]) vec_free (sm->nodes[n->index]); sm->nodes[n->index] = s; - offset_vector[i] = - sm->nodes[i] ? stat_segment_offset (shared_header, - sm->nodes[i]) : 0; +#define _(E, t, name, p) \ + vec_reset_length (symlink_name); \ + symlink_name = format (symlink_name, "/nodes/%U/" #name "%c", \ + format_vlib_stats_symlink, s, 0); \ + vlib_stats_register_symlink (oldheap, symlink_name, STAT_COUNTER_##E, \ + n->index, 0 /* don't lock */); + foreach_stat_segment_node_counter_name +#undef _ } - ep->offset_vector = stat_segment_offset (shared_header, offset_vector); - + vec_free (symlink_name); vlib_stat_segment_unlock (); clib_mem_set_heap (oldheap); no_max_nodes = l; @@ -583,34 +647,54 @@ update_node_counters (stat_segment_main_t * sm) counter_t *c; vlib_node_t *n = nodes[i]; - counters = - stat_segment_pointer (shared_header, - sm->directory_vector - [STAT_COUNTER_NODE_CLOCKS].offset); + if (j == 0) + { + if (strncmp ((char *) sm->nodes[n->index], (char *) n->name, + strlen ((char *) sm->nodes[n->index]))) + { + u8 *s = 0; + u32 vector_index; + u8 *symlink_new_name = 0; + void *oldheap = clib_mem_set_heap (sm->heap); + vlib_stat_segment_lock (); + s = format (s, "%v%c", n->name, 0); +#define _(E, t, name, p) \ + vec_reset_length (symlink_name); \ + symlink_name = format (symlink_name, "/nodes/%U/" #name "%c", \ + format_vlib_stats_symlink, sm->nodes[n->index], 0); \ + clib_mem_set_heap (oldheap); /* Exit stats segment */ \ + vector_index = lookup_hash_index ((u8 *) symlink_name); \ + clib_mem_set_heap (sm->heap); /* Re-enter stat segment */ \ + vec_reset_length (symlink_new_name); \ + symlink_new_name = format (symlink_new_name, "/nodes/%U/" #name "%c", \ + format_vlib_stats_symlink, s, 0); \ + vlib_stats_rename_symlink (oldheap, vector_index, symlink_new_name); + foreach_stat_segment_node_counter_name +#undef _ + vec_free (symlink_name); + vec_free (symlink_new_name); + vec_free (sm->nodes[n->index]); + sm->nodes[n->index] = s; + vlib_stat_segment_unlock (); + clib_mem_set_heap (oldheap); + } + } + + counters = sm->directory_vector[STAT_COUNTER_NODE_CLOCKS].data; c = counters[j]; c[n->index] = n->stats_total.clocks - n->stats_last_clear.clocks; - counters = - stat_segment_pointer (shared_header, - sm->directory_vector - [STAT_COUNTER_NODE_VECTORS].offset); + counters = sm->directory_vector[STAT_COUNTER_NODE_VECTORS].data; c = counters[j]; c[n->index] = n->stats_total.vectors - n->stats_last_clear.vectors; - counters = - stat_segment_pointer (shared_header, - sm->directory_vector - [STAT_COUNTER_NODE_CALLS].offset); + counters = sm->directory_vector[STAT_COUNTER_NODE_CALLS].data; c = counters[j]; c[n->index] = n->stats_total.calls - n->stats_last_clear.calls; - counters = - stat_segment_pointer (shared_header, - sm->directory_vector - [STAT_COUNTER_NODE_SUSPENDS].offset); + counters = sm->directory_vector[STAT_COUNTER_NODE_SUSPENDS].data; c = counters[j]; - c[n->index] = - n->stats_total.suspends - n->stats_last_clear.suspends; + c[n->index] = n->stats_total.suspends - n->stats_last_clear.suspends; } vec_free (node_dups[j]); } @@ -619,9 +703,8 @@ update_node_counters (stat_segment_main_t * sm) } static void -do_stat_segment_updates (stat_segment_main_t * sm) +do_stat_segment_updates (vlib_main_t *vm, stat_segment_main_t *sm) { - vlib_main_t *vm = vlib_mains[0]; f64 vector_rate; u64 input_packets; f64 dt, now; @@ -652,12 +735,12 @@ do_stat_segment_updates (stat_segment_main_t * sm) */ vector_rate = 0.0; - for (i = 0; i < vec_len (vlib_mains); i++) + for (i = 0; i < vlib_get_n_threads (); i++) { f64 this_vector_rate; - this_vlib_main = vlib_mains[i]; + this_vlib_main = vlib_get_main_by_index (i); this_vector_rate = vlib_internal_node_vector_rate (this_vlib_main); vlib_clear_internal_node_vector_rate (this_vlib_main); @@ -690,7 +773,7 @@ do_stat_segment_updates (stat_segment_main_t * sm) /* Stats segment memory heap counter */ clib_mem_usage_t usage; - mheap_usage (sm->heap, &usage); + clib_mem_get_heap_usage (sm->heap, &usage); sm->directory_vector[STAT_COUNTER_MEM_STATSEG_USED].value = usage.bytes_used; @@ -699,10 +782,10 @@ do_stat_segment_updates (stat_segment_main_t * sm) /* *INDENT-OFF* */ stat_segment_gauges_pool_t *g; - pool_foreach(g, sm->gauges, - ({ + pool_foreach (g, sm->gauges) + { g->fn(&sm->directory_vector[g->directory_index], g->caller_index); - })); + } /* *INDENT-ON* */ /* Heartbeat, so clients detect we're still here */ @@ -790,7 +873,7 @@ stat_segment_collector_process (vlib_main_t * vm, vlib_node_runtime_t * rt, while (1) { - do_stat_segment_updates (sm); + do_stat_segment_updates (vm, sm); vlib_process_suspend (vm, sm->update_interval); } return 0; /* or not */ @@ -840,8 +923,7 @@ stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn, vlib_stat_segment_lock (); vector_index = vlib_stats_create_counter (&e, oldheap); - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + shared_header->directory_vector = sm->directory_vector; vlib_stat_segment_unlock (); clib_mem_set_heap (oldheap); @@ -880,8 +962,7 @@ stat_segment_register_state_counter (u8 * name, u32 * index) vector_index = vlib_stats_create_counter (&e, oldheap); - shared_header->directory_offset = - stat_segment_offset (shared_header, sm->directory_vector); + shared_header->directory_vector = sm->directory_vector; vlib_stat_segment_unlock (); clib_mem_set_heap (oldheap); @@ -943,6 +1024,9 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input) else if (unformat (input, "size %U", unformat_memory_size, &sm->memory_size)) ; + else if (unformat (input, "page-size %U", + unformat_log2_page_size, &sm->log2_page_sz)) + ; else if (unformat (input, "per-node-counters on")) sm->node_counters_enabled = 1; else if (unformat (input, "per-node-counters off")) @@ -970,63 +1054,67 @@ static clib_error_t * statseg_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) { stat_segment_main_t *sm = &stat_segment_main; - stat_segment_shared_header_t *shared_header = sm->shared_header; + vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); + vnet_sw_interface_t *si_sup = + vnet_get_sup_sw_interface (vnm, si->sw_if_index); + vnet_hw_interface_t *hi_sup; + u8 *s = 0; + u8 *symlink_name = 0; + u32 vector_index; void *oldheap = vlib_stats_push_heap (sm->interfaces); vlib_stat_segment_lock (); vec_validate (sm->interfaces, sw_if_index); + + ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); + hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); + + s = format (s, "%v", hi_sup->name); + if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) + s = format (s, ".%d", si->sub.id); + s = format (s, "%c", 0); + if (is_add) { - vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); - vnet_sw_interface_t *si_sup = - vnet_get_sup_sw_interface (vnm, si->sw_if_index); - vnet_hw_interface_t *hi_sup; - - ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); - hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); - - u8 *s = 0; - s = format (s, "%v", hi_sup->name); - if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) - s = format (s, ".%d", si->sub.id); - s = format (s, "%c", 0); sm->interfaces[sw_if_index] = s; +#define _(E, n, p) \ + clib_mem_set_heap (oldheap); /* Exit stats segment */ \ + vector_index = lookup_hash_index ((u8 *) "/" #p "/" #n); \ + clib_mem_set_heap (sm->heap); /* Re-enter stat segment */ \ + vec_reset_length (symlink_name); \ + symlink_name = format (symlink_name, "/interfaces/%U/" #n "%c", \ + format_vlib_stats_symlink, s, 0); \ + vlib_stats_register_symlink (oldheap, symlink_name, vector_index, \ + sw_if_index, 0 /* don't lock */); + foreach_simple_interface_counter_name + foreach_combined_interface_counter_name +#undef _ + + vec_free (symlink_name); } else { vec_free (sm->interfaces[sw_if_index]); sm->interfaces[sw_if_index] = 0; +#define _(E, n, p) \ + vec_reset_length (symlink_name); \ + symlink_name = format (symlink_name, "/interfaces/%U/" #n "%c", \ + format_vlib_stats_symlink, s, 0); \ + clib_mem_set_heap (oldheap); /* Exit stats segment */ \ + vector_index = lookup_hash_index ((u8 *) symlink_name); \ + clib_mem_set_heap (sm->heap); /* Re-enter stat segment */ \ + vlib_stats_delete_counter (vector_index, oldheap); + foreach_simple_interface_counter_name + foreach_combined_interface_counter_name +#undef _ + + vec_free (symlink_name); } stat_segment_directory_entry_t *ep; ep = &sm->directory_vector[STAT_COUNTER_INTERFACE_NAMES]; - ep->offset = stat_segment_offset (shared_header, sm->interfaces); - - int i; - u64 *offset_vector = - ep->offset_vector ? stat_segment_pointer (shared_header, - ep->offset_vector) : 0; - - vec_validate (offset_vector, vec_len (sm->interfaces) - 1); - - if (sm->last != sm->interfaces) - { - /* the interface vector moved, so need to recalulate the offset array */ - for (i = 0; i < vec_len (sm->interfaces); i++) - { - offset_vector[i] = - sm->interfaces[i] ? stat_segment_offset (shared_header, - sm->interfaces[i]) : 0; - } - } - else - { - offset_vector[sw_if_index] = - sm->interfaces[sw_if_index] ? - stat_segment_offset (shared_header, sm->interfaces[sw_if_index]) : 0; - } - ep->offset_vector = stat_segment_offset (shared_header, offset_vector); + ep->data = sm->interfaces; vlib_stat_segment_unlock (); clib_mem_set_heap (oldheap);