FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
perfmon.h
Go to the documentation of this file.
1 /*
2  * perfmon.h - performance monitor
3  *
4  * Copyright (c) 2018 Cisco Systems and/or its affiliates
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef __included_perfmon_h__
18 #define __included_perfmon_h__
19 
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/ethernet/ethernet.h>
23 #include <vlib/log.h>
24 
25 #include <vppinfra/hash.h>
26 #include <vppinfra/error.h>
27 
28 #include <linux/perf_event.h>
29 #include <perfmon/perfmon_intel.h>
30 
31 #define foreach_perfmon_event \
32 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, "cpu-cycles") \
33 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, "instructions") \
34 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES, \
35  "cache-references") \
36 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES, "cache-misses") \
37 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS, "branches") \
38  _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES, "branch-misses") \
39 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES, "bus-cycles") \
40 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND, \
41  "stall-frontend") \
42 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND, \
43  "stall-backend") \
44 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, "ref-cpu-cycles") \
45 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS, "page-faults") \
46 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES, "context-switches") \
47 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS, "cpu-migrations") \
48 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN, "minor-pagefaults") \
49 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ, "major-pagefaults") \
50 _(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS, "emulation-faults")
51 
52 typedef struct
53 {
54  char *name;
55  int pe_type;
56  int pe_config;
58 
59 typedef enum
60 {
64 
65 typedef struct
66 {
72 
73 typedef struct
74 {
75  u8 *name;
78 
79 typedef struct
80 {
81  u64 ticks[2];
84 
85 typedef struct
86 {
87  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
88 
89  /* Current counters */
90  u64 c[2];
91 
92  /* Current perf_event file descriptors, per thread */
93  int pm_fds[2];
94 
95  /* mmap base of mapped struct perf_event_mmap_page */
96  u8 *perf_event_pages[2];
97 
98  u32 rdpmc_indices[2];
99 
100  /* vector of counters by node index */
102 
104 
105 typedef struct
106 {
107  /* API message ID base */
109 
110  /* on/off switch for the periodic function */
111  volatile u8 state;
112 
113  /* capture pool, hash table */
116 
117  /* vector of registered perfmon tables */
119 
120  /* active table */
122 
124 
125  /* vector of single events to collect */
127 
128  /* vector of paired events to collect */
130 
131  /* Base indices of synthetic event tuples */
134 
135  /* Length of time to capture a single event */
137 
138  /* Current event (index) being collected */
140  int n_active;
141  /* mmap size of (mapped) struct perf_event_mmap_page */
143 
144  /* thread bitmap */
146 
147  /* per-thread data */
149 
150  /* Logging */
152 
153  /* convenience */
158 
160 
162 uword *perfmon_parse_table (perfmon_main_t * pm, char *path, char *filename);
163 
164 uword unformat_processor_event (unformat_input_t * input, va_list * args);
165 
166 /* Periodic function events */
167 #define PERFMON_START 1
168 
169 #endif /* __included_perfmon_h__ */
170 
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "gnu")
176  * End:
177  */
perfmon_counters_t
Definition: perfmon.h:79
perfmon_main_t::vnet_main
vnet_main_t * vnet_main
Definition: perfmon.h:155
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vlib_log_class_t
u32 vlib_log_class_t
Definition: vlib.h:52
perfmon_main_t
Definition: perfmon.h:153
perfmon_periodic_node
vlib_node_registration_t perfmon_periodic_node
(constructor) VLIB_REGISTER_NODE (perfmon_periodic_node)
Definition: perfmon_periodic.c:533
perfmon_main_t::ipc_event_index
u32 ipc_event_index
Definition: perfmon.h:132
perfmon_parse_table
uword * perfmon_parse_table(perfmon_main_t *pm, char *path, char *filename)
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
u16
unsigned short u16
Definition: types.h:57
perfmon_capture_t::vectors_this_counter
u64 * vectors_this_counter
Definition: perfmon.h:70
unformat_processor_event
uword unformat_processor_event(unformat_input_t *input, va_list *args)
Definition: perfmon.c:159
perfmon_main_t::capture_pool
perfmon_capture_t * capture_pool
Definition: perfmon.h:114
perfmon_main_t::page_size
u32 page_size
Definition: perfmon.h:142
unformat_input_t
struct _unformat_input_t unformat_input_t
ethernet.h
perfmon_main_t::log_class
vlib_log_class_t log_class
Definition: perfmon.h:151
perfmon_main_t::n_active
int n_active
Definition: perfmon.h:140
name_value_pair_t
Definition: perfmon.h:73
perfmon_event_config_t::name
char * name
Definition: perfmon.h:54
perfmon_main_t::current_event
u32 current_event
Definition: perfmon.h:139
error.h
perfmon_main_t::vlib_main
vlib_main_t * vlib_main
Definition: perfmon.h:154
perfmon_main_t::timeout_interval
f64 timeout_interval
Definition: perfmon.h:136
ethernet_main_t_
Definition: ethernet.h:289
perfmon_main_t::single_events_to_collect
perfmon_event_config_t * single_events_to_collect
Definition: perfmon.h:126
c
svmdb_client_t * c
Definition: vpp_get_metrics.c:48
log.h
name_value_pair_t::value
u8 * value
Definition: perfmon.h:76
uword
u64 uword
Definition: types.h:112
perfmon_main
perfmon_main_t perfmon_main
Definition: perfmon.c:27
perfmon_intel_pmc_event_t
Definition: perfmon_intel.h:24
name_value_pair_t::name
u8 * name
Definition: perfmon.h:75
perfmon_capture_t::thread_and_node_name
u8 * thread_and_node_name
Definition: perfmon.h:67
f64
double f64
Definition: types.h:142
perfmon_main_t::state
volatile u8 state
Definition: perfmon.h:111
perfmon_thread_t
Definition: perfmon.h:85
perfmon_event_config_t::pe_type
int pe_type
Definition: perfmon.h:55
perfmon_capture_t::counter_values
u64 * counter_values
Definition: perfmon.h:69
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
perfmon_counters_t::vectors
u64 vectors
Definition: perfmon.h:82
perfmon_capture_t::counter_names
u8 ** counter_names
Definition: perfmon.h:68
vnet_main_t
Definition: vnet.h:76
perfmon_thread_t::counters
perfmon_counters_t * counters
Definition: perfmon.h:101
perfmon_main_t::ethernet_main
ethernet_main_t * ethernet_main
Definition: perfmon.h:156
u64
unsigned long u64
Definition: types.h:89
perfmon_main_t::msg_id_base
u16 msg_id_base
Definition: perfmon.h:108
perfmon_main_t::capture_by_thread_and_node_name
uword * capture_by_thread_and_node_name
Definition: perfmon.h:115
ip.h
u32
unsigned int u32
Definition: types.h:88
perfmon_intel_pmc_registration_t
Definition: perfmon_intel.h:42
perfmon_event_config_t
Definition: perfmon.h:52
perfmon_capture_t
Definition: perfmon.h:65
vlib_main_t
Definition: main.h:102
perfmon_main_t::perfmon_table
perfmon_intel_pmc_event_t * perfmon_table
Definition: perfmon.h:121
hash.h
u8
unsigned char u8
Definition: types.h:56
perfmon_main_t::perfmon_tables
perfmon_intel_pmc_registration_t * perfmon_tables
Definition: perfmon.h:118
perfmon_main_t::pmc_event_by_name
uword * pmc_event_by_name
Definition: perfmon.h:123
perfmon_main_t::mispredict_event_index
u32 mispredict_event_index
Definition: perfmon.h:133
perfmon_main_t::threads
perfmon_thread_t ** threads
Definition: perfmon.h:148
vnet.h
PERFMON_STATE_RUNNING
@ PERFMON_STATE_RUNNING
Definition: perfmon.h:62
perfmon_main_t::thread_bitmap
uword * thread_bitmap
Definition: perfmon.h:145
perfmon_main_t::paired_events_to_collect
perfmon_event_config_t * paired_events_to_collect
Definition: perfmon.h:129
PERFMON_STATE_OFF
@ PERFMON_STATE_OFF
Definition: perfmon.h:61
perfmon_event_config_t::pe_config
int pe_config
Definition: perfmon.h:56
perfmon_intel.h
perfmon_state_t
perfmon_state_t
Definition: perfmon.h:59