FD.io VPP  v16.09
Vector Packet Processing
counter.h File Reference

Optimized thread-safe counters. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vlib_simple_counter_main_t
 A collection of simple counters. More...
 
struct  vlib_counter_t
 Combined counter to hold both packets and byte differences. More...
 
struct  vlib_mini_counter_t
 Mini combined counter. More...
 
struct  vlib_combined_counter_main_t
 A collection of combined counters. More...
 

Macros

#define vlib_counter_len(cm)   vec_len((cm)->maxi)
 Obtain the number of simple or combined counters allocated. More...
 

Functions

static void vlib_increment_simple_counter (vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u32 increment)
 Increment a simple counter. More...
 
static u64 vlib_get_simple_counter (vlib_simple_counter_main_t *cm, u32 index)
 Get the value of a simple counter Scrapes the entire set of mini counters. More...
 
static void vlib_zero_simple_counter (vlib_simple_counter_main_t *cm, u32 index)
 Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter. More...
 
static void vlib_counter_add (vlib_counter_t *a, vlib_counter_t *b)
 Add two combined counters, results in the first counter. More...
 
static void vlib_counter_sub (vlib_counter_t *a, vlib_counter_t *b)
 Subtract combined counters, results in the first counter. More...
 
static void vlib_counter_zero (vlib_counter_t *a)
 Clear a combined counter. More...
 
void vlib_clear_simple_counters (vlib_simple_counter_main_t *cm)
 Clear a collection of simple counters. More...
 
void vlib_clear_combined_counters (vlib_combined_counter_main_t *cm)
 Clear a collection of combined counters. More...
 
static void vlib_increment_combined_counter (vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
 Increment a combined counter. More...
 
static void vlib_get_combined_counter (vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
 Get the value of a combined counter, never called in the speed path Scrapes the entire set of mini counters. More...
 
static void vlib_zero_combined_counter (vlib_combined_counter_main_t *cm, u32 index)
 Clear a combined counter Clears the set of per-thread u16 counters, and the shared vlib_counter_t. More...
 
void vlib_validate_simple_counter (vlib_simple_counter_main_t *cm, u32 index)
 validate a simple counter More...
 
void vlib_validate_combined_counter (vlib_combined_counter_main_t *cm, u32 index)
 validate a combined counter More...
 

Variables

serialize_function_t serialize_vlib_simple_counter_main
 
serialize_function_t unserialize_vlib_simple_counter_main
 
serialize_function_t serialize_vlib_combined_counter_main
 
serialize_function_t unserialize_vlib_combined_counter_main
 

Detailed Description

Optimized thread-safe counters.

Each vlib_[simple|combined]_counter_main_t consists of a single vector of thread-safe / atomically-updated u64 counters [the "maxi" vector], and a (u16 **) per-thread vector [the "minis" vector] of narrow, per-thread counters.

The idea is to drastically reduce the number of atomic operations. In the case of packet counts, we divide the number of atomic ops by 2**16, etc.

Definition in file counter.h.

Macro Definition Documentation

#define vlib_counter_len (   cm)    vec_len((cm)->maxi)

Obtain the number of simple or combined counters allocated.

A macro which reduces to to vec_len(cm->maxi), the answer in either case.

Parameters
cm- (vlib_simple_counter_main_t) or (vlib_combined_counter_main_t) the counter collection to interrogate
Returns
vec_len(cm->maxi)

Definition at line 364 of file counter.h.

Function Documentation

void vlib_clear_combined_counters ( vlib_combined_counter_main_t cm)

Clear a collection of combined counters.

Parameters
cm- (vlib_combined_counter_main_t *) collection to clear

Definition at line 67 of file counter.c.

+ Here is the caller graph for this function:

void vlib_clear_simple_counters ( vlib_simple_counter_main_t cm)

Clear a collection of simple counters.

Parameters
cm- (vlib_simple_counter_main_t *) collection to clear

Definition at line 43 of file counter.c.

+ Here is the caller graph for this function:

static void vlib_counter_add ( vlib_counter_t a,
vlib_counter_t b 
)
inlinestatic

Add two combined counters, results in the first counter.

Parameters
[in,out]a- (vlib_counter_t *) dst counter
b- (vlib_counter_t *) src counter

Definition at line 176 of file counter.h.

+ Here is the caller graph for this function:

static void vlib_counter_sub ( vlib_counter_t a,
vlib_counter_t b 
)
inlinestatic

Subtract combined counters, results in the first counter.

Parameters
[in,out]a- (vlib_counter_t *) dst counter
b- (vlib_counter_t *) src counter

Definition at line 187 of file counter.h.

+ Here is the caller graph for this function:

static void vlib_counter_zero ( vlib_counter_t a)
inlinestatic

Clear a combined counter.

Parameters
a- (vlib_counter_t *) counter to clear

Definition at line 199 of file counter.h.

+ Here is the caller graph for this function:

static void vlib_get_combined_counter ( vlib_combined_counter_main_t cm,
u32  index,
vlib_counter_t result 
)
inlinestatic

Get the value of a combined counter, never called in the speed path Scrapes the entire set of mini counters.

Innacurate unless worker threads which might increment the counter are barrier-synchronized

Parameters
cm- (vlib_combined_counter_main_t *) combined counter main pointer
index- (u32) index of the combined counter to fetch
result[out] - (vlib_counter_t *) result stored here

Definition at line 287 of file counter.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static u64 vlib_get_simple_counter ( vlib_simple_counter_main_t cm,
u32  index 
)
inlinestatic

Get the value of a simple counter Scrapes the entire set of mini counters.

Innacurate unless worker threads which might increment the counter are barrier-synchronized

Parameters
cm- (vlib_simple_counter_main_t *) simple counter main pointer
index- (u32) index of the counter to fetch
Returns
- (u64) current counter value

Definition at line 108 of file counter.h.

+ Here is the caller graph for this function:

static void vlib_increment_combined_counter ( vlib_combined_counter_main_t cm,
u32  cpu_index,
u32  index,
u32  packet_increment,
u32  byte_increment 
)
inlinestatic

Increment a combined counter.

Parameters
cm- (vlib_combined_counter_main_t *) comined counter main pointer
cpu_index- (u32) the current cpu index
index- (u32) index of the counter to increment
packet_increment- (u32) number of packets to add to the counter
byte_increment- (u32) number of bytes to add to the counter

Definition at line 241 of file counter.h.

+ Here is the caller graph for this function:

static void vlib_increment_simple_counter ( vlib_simple_counter_main_t cm,
u32  cpu_index,
u32  index,
u32  increment 
)
inlinestatic

Increment a simple counter.

Parameters
cm- (vlib_simple_counter_main_t *) simple counter main pointer
cpu_index- (u32) the current cpu index
index- (u32) index of the counter to increment
increment- (u32) quantitiy to add to the counter

Definition at line 78 of file counter.h.

+ Here is the caller graph for this function:

void vlib_validate_combined_counter ( vlib_combined_counter_main_t cm,
u32  index 
)

validate a combined counter

Parameters
cm- (vlib_combined_counter_main_t *) pointer to the counter collection
index- (u32) index of the counter to validate

Definition at line 110 of file counter.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void vlib_validate_simple_counter ( vlib_simple_counter_main_t cm,
u32  index 
)

validate a simple counter

Parameters
cm- (vlib_simple_counter_main_t *) pointer to the counter collection
index- (u32) index of the counter to validate

Definition at line 98 of file counter.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void vlib_zero_combined_counter ( vlib_combined_counter_main_t cm,
u32  index 
)
inlinestatic

Clear a combined counter Clears the set of per-thread u16 counters, and the shared vlib_counter_t.

Parameters
cm- (vlib_combined_counter_main_t *) combined counter main pointer
index- (u32) index of the counter to clear

Definition at line 321 of file counter.h.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void vlib_zero_simple_counter ( vlib_simple_counter_main_t cm,
u32  index 
)
inlinestatic

Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.

Parameters
cm- (vlib_simple_counter_main_t *) simple counter main pointer
index- (u32) index of the counter to clear

Definition at line 143 of file counter.h.

+ Here is the caller graph for this function:

Variable Documentation

serialize_function_t serialize_vlib_combined_counter_main

Definition at line 368 of file counter.h.

serialize_function_t serialize_vlib_simple_counter_main

Definition at line 366 of file counter.h.

serialize_function_t unserialize_vlib_combined_counter_main

Definition at line 368 of file counter.h.

serialize_function_t unserialize_vlib_simple_counter_main

Definition at line 366 of file counter.h.