diff options
-rw-r--r-- | src/vlib/buffer.c | 46 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment.c | 24 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment.h | 14 |
3 files changed, 45 insertions, 39 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c index 091799b3f12..7581d9cdd48 100644 --- a/src/vlib/buffer.c +++ b/src/vlib/buffer.c @@ -725,26 +725,22 @@ buffer_get_cached (vlib_buffer_pool_t * bp) } static vlib_buffer_pool_t * -buffer_get_by_name (vlib_buffer_main_t * bm, char *name) +buffer_get_by_index (vlib_buffer_main_t * bm, u32 index) { vlib_buffer_pool_t *bp; - vec_foreach (bp, bm->buffer_pools) - { - if (!strcmp ((char *) bp->name, name)) - return bp; - } - - return 0; + if (!bm->buffer_pools || vec_len (bm->buffer_pools) < index) + return 0; + bp = vec_elt_at_index (bm->buffer_pools, index); + if (!bp) + return 0; + return bp; } static void -buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e) +buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e, u32 index) { vlib_main_t *vm = vlib_get_main (); - vlib_buffer_pool_t *bp; - - bp = buffer_get_by_name (vm->buffer_main, - &e->name[sizeof ("/buffer/used/") - 1]); + vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index); if (!bp) return; @@ -752,13 +748,11 @@ buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e) } static void -buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e) +buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e, + u32 index) { vlib_main_t *vm = vlib_get_main (); - vlib_buffer_pool_t *bp; - - bp = buffer_get_by_name (vm->buffer_main, - &e->name[sizeof ("/buffer/available/") - 1]); + vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index); if (!bp) return; @@ -766,13 +760,10 @@ buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e) } static void -buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e) +buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e, u32 index) { vlib_main_t *vm = vlib_get_main (); - vlib_buffer_pool_t *bp; - - bp = buffer_get_by_name (vm->buffer_main, - &e->name[sizeof ("/buffer/cached/") - 1]); + vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index); if (!bp) return; @@ -818,13 +809,16 @@ vlib_buffer_main_init (struct vlib_main_t * vm) vec_foreach (bp, bm->buffer_pools) { name = format (0, "/buffer/cached/%s%c", bp->name, 0); - stat_segment_register_gauge (name, buffer_gauges_update_cached_fn); + stat_segment_register_gauge (name, buffer_gauges_update_cached_fn, + bp - bm->buffer_pools); vec_free (name); name = format (0, "/buffer/used/%s%c", bp->name, 0); - stat_segment_register_gauge (name, buffer_gauges_update_used_fn); + stat_segment_register_gauge (name, buffer_gauges_update_used_fn, + bp - bm->buffer_pools); vec_free (name); name = format (0, "/buffer/available/%s%c", bp->name, 0); - stat_segment_register_gauge (name, buffer_gauges_update_available_fn); + stat_segment_register_gauge (name, buffer_gauges_update_available_fn, + bp - bm->buffer_pools); vec_free (name); } diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index 2d6c8c67901..ca78a103522 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -275,7 +275,6 @@ vlib_map_stat_segment_init (void) /* Save the vector offset in the shared segment, for clients */ shared_header->directory_offset = stat_segment_offset (shared_header, sm->directory_vector); - sm->gauges_fns = 0; clib_mem_set_heap (oldheap); @@ -508,11 +507,13 @@ do_stat_segment_updates (stat_segment_main_t * sm) if (sm->node_counters_enabled) update_node_counters (sm); - for (i = 0; i < vec_len (sm->gauges_fns); i++) - { - if (sm->gauges_fns[i]) - sm->gauges_fns[i] (&sm->directory_vector[i]); - } + /* *INDENT-OFF* */ + stat_segment_gauges_pool_t *g; + 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 */ sm->directory_vector[STAT_COUNTER_HEARTBEAT].value++; @@ -619,13 +620,15 @@ statseg_init (vlib_main_t * vm) } clib_error_t * -stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn) +stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn, + u32 caller_index) { stat_segment_main_t *sm = &stat_segment_main; stat_segment_shared_header_t *shared_header = sm->shared_header; void *oldheap; stat_segment_directory_entry_t e; u32 index; + stat_segment_gauges_pool_t *gauge; ASSERT (shared_header); @@ -645,8 +648,11 @@ stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn) vlib_stat_segment_unlock (); clib_mem_set_heap (oldheap); - vec_validate (sm->gauges_fns, index); - sm->gauges_fns[index] = update_fn; + /* Back on our own heap */ + pool_get (sm->gauges, gauge); + gauge->fn = update_fn; + gauge->caller_index = caller_index; + gauge->directory_index = index; return NULL; } diff --git a/src/vpp/stats/stat_segment.h b/src/vpp/stats/stat_segment.h index f3ea50c9d99..fb450f38f53 100644 --- a/src/vpp/stats/stat_segment.h +++ b/src/vpp/stats/stat_segment.h @@ -85,12 +85,18 @@ stat_segment_pointer (void *start, uint64_t offset) return ((char *) start + offset); } -typedef void (*stat_segment_update_fn)(stat_segment_directory_entry_t * e); +typedef void (*stat_segment_update_fn)(stat_segment_directory_entry_t * e, u32 i); + +typedef struct { + u32 directory_index; + stat_segment_update_fn fn; + u32 caller_index; +} stat_segment_gauges_pool_t; typedef struct { /* internal, does not point to shared memory */ - stat_segment_update_fn *gauges_fns; + stat_segment_gauges_pool_t *gauges; /* statistics segment */ uword *directory_vector_by_name; @@ -104,12 +110,12 @@ typedef struct stat_segment_shared_header_t *shared_header; /* pointer to shared memory segment */ int memfd; - u64 last_input_packets; + u64 last_input_packets; // OLE REMOVE? } stat_segment_main_t; extern stat_segment_main_t stat_segment_main; clib_error_t * -stat_segment_register_gauge (u8 *names, stat_segment_update_fn update_fn); +stat_segment_register_gauge (u8 *names, stat_segment_update_fn update_fn, u32 index); #endif |