papi: Use CMSG_SPACE for sizing ancillary buffer space
[vpp.git] / src / vlib / counter.h
index 7c90947..f9da576 100644 (file)
 typedef struct
 {
   counter_t **counters;         /**< Per-thread u64 non-atomic counters */
-  counter_t *value_at_last_serialize;  /**< 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 */
+  u32 stats_entry_index;
 } vlib_simple_counter_main_t;
 
 /** The number of counters (not the number of per-thread counters) */
 u32 vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm);
 
+/** Pre-fetch a per-thread simple counter for the given object index */
+always_inline void
+vlib_prefetch_simple_counter (const vlib_simple_counter_main_t *cm,
+                             u32 thread_index, u32 index)
+{
+  counter_t *my_counters;
+
+  /*
+   * This CPU's index is assumed to already be in cache
+   */
+  my_counters = cm->counters[thread_index];
+  clib_prefetch_store (my_counters + index);
+}
+
 /** Increment a simple counter
     @param cm - (vlib_simple_counter_main_t *) simple counter main pointer
     @param thread_index - (u32) the current cpu index
@@ -84,6 +95,25 @@ 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
@@ -188,10 +218,9 @@ vlib_counter_zero (vlib_counter_t * a)
 typedef struct
 {
   vlib_counter_t **counters;   /**< Per-thread u64 non-atomic counter pairs */
-  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 */
+  u32 stats_entry_index;
 } vlib_combined_counter_main_t;
 
 /** The number of counters (not the number of per-thread counters) */
@@ -241,7 +270,7 @@ vlib_prefetch_combined_counter (const vlib_combined_counter_main_t * cm,
    * This CPU's index is assumed to already be in cache
    */
   cpu_counters = cm->counters[thread_index];
-  CLIB_PREFETCH (cpu_counters + index, CLIB_CACHE_LINE_BYTES, STORE);
+  clib_prefetch_store (cpu_counters + index);
 }
 
 
@@ -314,6 +343,9 @@ void vlib_free_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.