X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvlib%2Fcounter.h;h=3aacc9b375fd5ee90fb0b9f12d3eb8aa58956a76;hb=58492a83722caf1c49977d73abf931418ce1f8f2;hp=17a8521776bda1cac46ac3cd773b363ca22cd066;hpb=1bd01099a6512b6119bbf337b36222a6f0770d49;p=vpp.git diff --git a/src/vlib/counter.h b/src/vlib/counter.h index 17a8521776b..3aacc9b375f 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) */ @@ -70,17 +70,17 @@ u32 vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm); /** Increment a simple counter @param cm - (vlib_simple_counter_main_t *) simple counter main pointer - @param cpu_index - (u32) the current cpu index + @param thread_index - (u32) the current cpu index @param index - (u32) index of the counter to increment @param increment - (u64) quantitiy to add to the counter */ always_inline void vlib_increment_simple_counter (vlib_simple_counter_main_t * cm, - u32 cpu_index, u32 index, u64 increment) + u32 thread_index, u32 index, u64 increment) { counter_t *my_counters; - my_counters = cm->counters[cpu_index]; + my_counters = cm->counters[thread_index]; my_counters[index] += increment; } @@ -134,14 +134,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 +175,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) */ @@ -201,7 +194,7 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm); /** Increment a combined counter @param cm - (vlib_combined_counter_main_t *) comined counter main pointer - @param cpu_index - (u32) the current cpu index + @param thread_index - (u32) the current cpu index @param index - (u32) index of the counter to increment @param packet_increment - (u64) number of packets to add to the counter @param byte_increment - (u64) number of bytes to add to the counter @@ -209,13 +202,13 @@ void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm); always_inline void vlib_increment_combined_counter (vlib_combined_counter_main_t * cm, - u32 cpu_index, + u32 thread_index, u32 index, u64 n_packets, u64 n_bytes) { vlib_counter_t *my_counters; /* Use this CPU's counter array */ - my_counters = cm->counters[cpu_index]; + my_counters = cm->counters[thread_index]; my_counters[index].packets += n_packets; my_counters[index].bytes += n_bytes; @@ -224,14 +217,14 @@ vlib_increment_combined_counter (vlib_combined_counter_main_t * cm, /** Pre-fetch a per-thread combined counter for the given object index */ always_inline void vlib_prefetch_combined_counter (const vlib_combined_counter_main_t * cm, - u32 cpu_index, u32 index) + u32 thread_index, u32 index) { vlib_counter_t *cpu_counters; /* * This CPU's index is assumed to already be in cache */ - cpu_counters = cm->counters[cpu_index]; + cpu_counters = cm->counters[thread_index]; CLIB_PREFETCH (cpu_counters + index, CLIB_CACHE_LINE_BYTES, STORE); }