diff options
author | Damjan Marion <damarion@cisco.com> | 2016-02-06 00:54:12 +0100 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2016-02-14 00:02:31 +0000 |
commit | cfb2d804ce4a9262577c63b9c0245d45b2335e64 (patch) | |
tree | 1a2a0724261fc014cb654e80e57d364bd6840959 | |
parent | 161781988918e2403c0fb1e7f6ebe0d3051985b4 (diff) |
Make size of per-thread mini counter vector equal to number of threads
Change-Id: Icfd91cca3cd686e5efa8a988f04483238605e1cb
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | vlib/vlib/counter.c | 26 | ||||
-rw-r--r-- | vlib/vlib/counter.h | 42 |
2 files changed, 30 insertions, 38 deletions
diff --git a/vlib/vlib/counter.c b/vlib/vlib/counter.c index 1b94884e319..9c5e0db8427 100644 --- a/vlib/vlib/counter.c +++ b/vlib/vlib/counter.c @@ -44,7 +44,7 @@ void vlib_clear_simple_counters (vlib_simple_counter_main_t * cm) uword i, j; u16 * my_minis; - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; @@ -67,7 +67,7 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm) uword i, j; vlib_mini_counter_t * my_minis; - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; @@ -92,6 +92,28 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm) } } +void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index) +{ + vlib_thread_main_t * tm = vlib_get_thread_main(); + int i; + + vec_validate (cm->minis, tm->n_vlib_mains - 1); + for (i = 0; i < tm->n_vlib_mains; i++) + vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); + vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); +} + +void vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index) +{ + vlib_thread_main_t * tm = vlib_get_thread_main(); + int i; + + vec_validate (cm->minis, tm->n_vlib_mains - 1); + for (i = 0; i < tm->n_vlib_mains ; i++) + vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); + vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); +} + void serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va) { clib_warning ("unimplemented"); diff --git a/vlib/vlib/counter.h b/vlib/vlib/counter.h index 804757173bb..8db999c3a94 100644 --- a/vlib/vlib/counter.h +++ b/vlib/vlib/counter.h @@ -45,7 +45,6 @@ * the CPU configuration is available, so we have to * preallocate the mini-counter per-cpu vectors */ -#define VLIB_COUNTER_MAX_CPUS 32 typedef struct { /* Compact counters that (rarely) can overflow. */ @@ -101,7 +100,7 @@ vlib_get_simple_counter (vlib_simple_counter_main_t * cm, u32 index) v = 0; - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; mini = vec_elt_at_index (my_minis, index); @@ -127,7 +126,7 @@ vlib_zero_simple_counter (vlib_simple_counter_main_t * cm, u32 index) ASSERT (index < vec_len (cm->maxi)); - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; my_minis[index] = 0; @@ -257,7 +256,7 @@ vlib_get_combined_counter (vlib_combined_counter_main_t * cm, result->packets = 0; result->bytes = 0; - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; @@ -281,7 +280,7 @@ vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, vlib_mini_counter_t * mini, * my_minis; int i; - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) + for (i = 0; i < vec_len(cm->minis); i++) { my_minis = cm->minis[i]; @@ -295,37 +294,8 @@ vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, vlib_counter_zero (&cm->value_at_last_clear[index]); } -/* Initialize/allocate given counter index. - Works for both simple and combined counters. */ -#define vlib_validate_counter_DEPRECATED(cm,index) \ - do { \ - int i; \ - \ - vec_validate ((cm)->minis, VLIB_COUNTER_MAX_CPUS-1); \ - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) \ - vec_validate ((cm)->minis[i], (index)); \ - vec_validate ((cm)->maxi, (index)); \ - } while (0) - -static inline void -vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index) -{ - int i; - vec_validate (cm->minis, VLIB_COUNTER_MAX_CPUS-1); - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) - vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); - vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); -} - -static inline void -vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index) -{ - int i; - vec_validate (cm->minis, VLIB_COUNTER_MAX_CPUS-1); - for (i = 0; i < VLIB_COUNTER_MAX_CPUS; i++) - vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); - vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); -} +void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index); +void vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index); /* Number of simple/combined counters allocated. */ #define vlib_counter_len(cm) vec_len((cm)->maxi) |