diff options
author | 2021-05-06 11:02:37 +0200 | |
---|---|---|
committer | 2021-05-06 18:10:13 +0000 | |
commit | 3b51f28a6fd480cc397dac90b8f0c1152c186d4d (patch) | |
tree | 21a6712a70e92ac51e62addfcf0505a543e74fdb /src/vpp | |
parent | 8f12698f836a94c2aa45a76045d97ca5d9d53e8a (diff) |
stats: move vector_rate counters into provider
Type: improvement
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Iae1fb59a6dc9679c0fa0b87fa5232d551a7995a5
Diffstat (limited to 'src/vpp')
-rw-r--r-- | src/vpp/stats/stat_segment.c | 54 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment.h | 31 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment_provider.c | 77 |
3 files changed, 96 insertions, 66 deletions
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index efbc2e42ffc..24ab3e62ff9 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -359,16 +359,6 @@ stat_validate_counter_vector (stat_segment_directory_entry_t *ep, u32 max) stat_validate_counter_vector2 (ep, tm->n_vlib_mains, max); } -always_inline void -stat_set_simple_counter (stat_segment_directory_entry_t * ep, - u32 thread_index, u32 index, u64 value) -{ - ASSERT (ep->data); - counter_t **counters = ep->data; - counter_t *cb = counters[thread_index]; - cb[index] = value; -} - void vlib_stats_pop_heap2 (u64 * error_vector, u32 thread_index, void *oldheap, int lock) @@ -751,11 +741,8 @@ update_node_counters (stat_segment_main_t * sm) static void do_stat_segment_updates (vlib_main_t *vm, stat_segment_main_t *sm) { - f64 vector_rate; u64 input_packets; f64 dt, now; - vlib_main_t *this_vlib_main; - int i; static int num_worker_threads_set; /* @@ -765,46 +752,15 @@ do_stat_segment_updates (vlib_main_t *vm, stat_segment_main_t *sm) */ if (PREDICT_FALSE (num_worker_threads_set == 0)) { - void *oldheap = clib_mem_set_heap (sm->heap); - vlib_stat_segment_lock (); - - stat_validate_counter_vector (&sm->directory_vector - [STAT_COUNTER_VECTOR_RATE_PER_WORKER], 0); + vlib_thread_main_t *tm = vlib_get_thread_main (); + ASSERT (tm->n_vlib_mains > 0); + stat_provider_register_vector_rate (tm->n_vlib_mains - 1); + sm->directory_vector[STAT_COUNTER_NUM_WORKER_THREADS].value = + tm->n_vlib_mains - 1; num_worker_threads_set = 1; - vlib_stat_segment_unlock (); - clib_mem_set_heap (oldheap); } /* - * Compute per-worker vector rates, and the average vector rate - * across all workers - */ - vector_rate = 0.0; - - for (i = 0; i < vlib_get_n_threads (); i++) - { - - f64 this_vector_rate; - - 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); - - vector_rate += this_vector_rate; - - /* Set the per-worker rate */ - stat_set_simple_counter (&sm->directory_vector - [STAT_COUNTER_VECTOR_RATE_PER_WORKER], i, 0, - this_vector_rate); - } - - /* And set the system average rate */ - vector_rate /= (f64) (i > 1 ? i - 1 : 1); - - sm->directory_vector[STAT_COUNTER_VECTOR_RATE].value = vector_rate; - - /* * Compute the aggregate input rate */ now = vlib_time_now (vm); diff --git a/src/vpp/stats/stat_segment.h b/src/vpp/stats/stat_segment.h index c6056b1fade..f5862a684e4 100644 --- a/src/vpp/stats/stat_segment.h +++ b/src/vpp/stats/stat_segment.h @@ -22,20 +22,18 @@ typedef enum { - STAT_COUNTER_VECTOR_RATE = 0, - STAT_COUNTER_NUM_WORKER_THREADS, - STAT_COUNTER_VECTOR_RATE_PER_WORKER, - STAT_COUNTER_INPUT_RATE, - STAT_COUNTER_LAST_UPDATE, - STAT_COUNTER_LAST_STATS_CLEAR, - STAT_COUNTER_HEARTBEAT, - STAT_COUNTER_NODE_CLOCKS, - STAT_COUNTER_NODE_VECTORS, - STAT_COUNTER_NODE_CALLS, - STAT_COUNTER_NODE_SUSPENDS, - STAT_COUNTER_INTERFACE_NAMES, - STAT_COUNTER_NODE_NAMES, - STAT_COUNTERS + STAT_COUNTER_NUM_WORKER_THREADS = 0, + STAT_COUNTER_INPUT_RATE, + STAT_COUNTER_LAST_UPDATE, + STAT_COUNTER_LAST_STATS_CLEAR, + STAT_COUNTER_HEARTBEAT, + STAT_COUNTER_NODE_CLOCKS, + STAT_COUNTER_NODE_VECTORS, + STAT_COUNTER_NODE_CALLS, + STAT_COUNTER_NODE_SUSPENDS, + STAT_COUNTER_INTERFACE_NAMES, + STAT_COUNTER_NODE_NAMES, + STAT_COUNTERS } stat_segment_counter_t; /* clang-format off */ @@ -46,9 +44,6 @@ typedef enum _ (NODE_SUSPENDS, COUNTER_VECTOR_SIMPLE, suspends, /sys/node) #define foreach_stat_segment_counter_name \ - _ (VECTOR_RATE, SCALAR_INDEX, vector_rate, /sys) \ - _ (VECTOR_RATE_PER_WORKER, COUNTER_VECTOR_SIMPLE, vector_rate_per_worker, \ - /sys) \ _ (NUM_WORKER_THREADS, SCALAR_INDEX, num_worker_threads, /sys) \ _ (INPUT_RATE, SCALAR_INDEX, input_rate, /sys) \ _ (LAST_UPDATE, SCALAR_INDEX, last_update, /sys) \ @@ -123,4 +118,6 @@ void vlib_stat_segment_unlock (void); void vlib_stats_register_symlink (void *oldheap, u8 *name, u32 index1, u32 index2, u8 lock); +void stat_provider_register_vector_rate (u32 num_workers); + #endif diff --git a/src/vpp/stats/stat_segment_provider.c b/src/vpp/stats/stat_segment_provider.c index 2212ffe98dd..fc883f7751d 100644 --- a/src/vpp/stats/stat_segment_provider.c +++ b/src/vpp/stats/stat_segment_provider.c @@ -119,3 +119,80 @@ vlib_stats_register_mem_heap (clib_mem_heap_t *heap) stat_segment_poll_add (mem_vector_index, stat_provider_mem_usage_update_fn, heap_index, 10); } + +static void +stat_provider_vector_rate_per_thread_update_fn ( + stat_segment_directory_entry_t *e, u32 index) +{ + vlib_main_t *this_vlib_main; + int i; + ASSERT (e->data); + counter_t **counters = e->data; + + for (i = 0; i < vlib_get_n_threads (); i++) + { + + f64 this_vector_rate; + + 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); + /* Set the per-worker rate */ + counter_t *cb = counters[i]; + cb[0] = this_vector_rate; + } +} + +static void +stat_provider_vector_rate_update_fn (stat_segment_directory_entry_t *e, + u32 index) +{ + vlib_main_t *this_vlib_main; + int i; + f64 vector_rate = 0.0; + for (i = 0; i < vlib_get_n_threads (); i++) + { + + f64 this_vector_rate; + + 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); + + vector_rate += this_vector_rate; + } + + /* And set the system average rate */ + vector_rate /= (f64) (i > 1 ? i - 1 : 1); + e->value = vector_rate; +} + +void +stat_provider_register_vector_rate (u32 num_workers) +{ + int i; + + u8 *s = format (0, "/sys/vector_rate"); + + i = stat_segment_new_entry (s, STAT_DIR_TYPE_SCALAR_INDEX); + if (i == ~0) + ASSERT (0); + vec_free (s); + stat_segment_poll_add (i, stat_provider_vector_rate_update_fn, ~0, 10); + + s = format (0, "/sys/vector_rate_per_worker"); + i = stat_segment_new_entry (s, STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE); + if (i == ~0) + ASSERT (0); + vec_free (s); + stat_segment_poll_add (i, stat_provider_vector_rate_per_thread_update_fn, ~0, + 10); + + stat_segment_main_t *sm = &stat_segment_main; + vlib_stat_segment_lock (); + stat_segment_directory_entry_t *ep = &sm->directory_vector[i]; + ep->data = stat_validate_counter_vector3 (ep->data, num_workers, 0); + vlib_stat_segment_unlock (); +} |