X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fcounter.h;h=04ab83769cce163eacb860e858f9317731594749;hb=80f0b88fc388c82627dafef19c01f4c4536bbfa2;hp=60e2055d232a30d1b7513d3d38d8fe4943ce2a97;hpb=586afd762bfa149f5ca167bd5fd5a0cd59ce94fe;p=vpp.git diff --git a/src/vlib/counter.h b/src/vlib/counter.h index 60e2055d232..04ab83769cc 100644 --- a/src/vlib/counter.h +++ b/src/vlib/counter.h @@ -40,6 +40,8 @@ #ifndef included_vlib_counter_h #define included_vlib_counter_h +#include + /** \file Optimized thread-safe counters. @@ -50,9 +52,6 @@ The idea is to drastically eliminate atomic operations. */ -/** 64bit counters */ -typedef u64 counter_t; - /** A collection of simple counters */ typedef struct @@ -63,6 +62,7 @@ typedef struct serialized incrementally. */ char *name; /**< The counter collection's name. */ + char *stat_segment_name; /**< Name in stat segment directory */ } vlib_simple_counter_main_t; /** The number of counters (not the number of per-thread counters) */ @@ -84,6 +84,41 @@ vlib_increment_simple_counter (vlib_simple_counter_main_t * cm, my_counters[index] += increment; } +/** Decrement a simple counter + @param cm - (vlib_simple_counter_main_t *) simple counter main pointer + @param thread_index - (u32) the current cpu index + @param index - (u32) index of the counter to increment + @param increment - (u64) quantitiy remove from the counter value +*/ +always_inline void +vlib_decrement_simple_counter (vlib_simple_counter_main_t * cm, + u32 thread_index, u32 index, u64 decrement) +{ + counter_t *my_counters; + + my_counters = cm->counters[thread_index]; + + ASSERT (my_counters[index] >= decrement); + + my_counters[index] -= decrement; +} + +/** Set a simple counter + @param cm - (vlib_simple_counter_main_t *) simple counter main pointer + @param thread_index - (u32) the current cpu index + @param index - (u32) index of the counter to increment + @param value - (u64) quantitiy to set to the counter +*/ +always_inline void +vlib_set_simple_counter (vlib_simple_counter_main_t * cm, + u32 thread_index, u32 index, u64 value) +{ + counter_t *my_counters; + + my_counters = cm->counters[thread_index]; + my_counters[index] = value; +} + /** Get the value of a simple counter Scrapes the entire set of per-thread counters. Innacurate unless worker threads which might increment the counter are @@ -134,14 +169,6 @@ vlib_zero_simple_counter (vlib_simple_counter_main_t * cm, u32 index) } } -/** Combined counter to hold both packets and byte differences. - */ -typedef struct -{ - counter_t packets; /**< packet counter */ - counter_t bytes; /**< byte counter */ -} vlib_counter_t; - /** Add two combined counters, results in the first counter @param [in,out] a - (vlib_counter_t *) dst counter @param b - (vlib_counter_t *) src counter @@ -183,6 +210,7 @@ typedef struct vlib_counter_t *value_at_last_serialize; /**< Counter values as of last serialize. */ u32 last_incremental_serialize_index; /**< Last counter index serialized incrementally. */ char *name; /**< The counter collection's name. */ + char *stat_segment_name; /**< Name in stat segment directory */ } vlib_combined_counter_main_t; /** The number of counters (not the number of per-thread counters) */ @@ -295,6 +323,8 @@ vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, u32 index) void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index); +void vlib_free_simple_counter (vlib_simple_counter_main_t * cm); + /** validate a combined counter @param cm - (vlib_combined_counter_main_t *) pointer to the counter collection @@ -303,6 +333,10 @@ void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index); +int vlib_validate_combined_counter_will_expand + (vlib_combined_counter_main_t * cm, u32 index); + +void vlib_free_combined_counter (vlib_combined_counter_main_t * cm); /** Obtain the number of simple or combined counters allocated. A macro which reduces to to vec_len(cm->maxi), the answer in either @@ -314,11 +348,6 @@ void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, */ #define vlib_counter_len(cm) vec_len((cm)->maxi) -serialize_function_t serialize_vlib_simple_counter_main, - unserialize_vlib_simple_counter_main; -serialize_function_t serialize_vlib_combined_counter_main, - unserialize_vlib_combined_counter_main; - #endif /* included_vlib_counter_h */ /*