FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
perfmon.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef __perfmon_perfmon_h
17 #define __perfmon_perfmon_h
18 
19 #include <linux/perf_event.h>
20 #include <vppinfra/clib.h>
21 #include <vppinfra/format.h>
22 #include <vppinfra/error.h>
23 #include <vppinfra/cpu.h>
24 #include <vlib/vlib.h>
25 
26 #define PERF_MAX_EVENTS 8 /* 4 fixed and 8 programmable on ICX */
27 
28 typedef enum
29 {
36 
37 typedef enum
38 {
43 
44 typedef struct
45 {
48  union
49  {
52  };
54  char *name;
55  char *description;
57 
58 typedef struct
59 {
61  int cpu;
62  pid_t pid;
63  char *name;
65 
66 typedef struct
67 {
68  char *name;
71 
75 
76 #define foreach_permon_offset_type \
77  _ (PERFMON_OFFSET_TYPE_MMAP, perfmon_dispatch_wrapper_mmap) \
78  _ (PERFMON_OFFSET_TYPE_METRICS, perfmon_dispatch_wrapper_metrics)
79 
81  struct perfmon_source *);
82 typedef struct perfmon_source
83 {
84  char *name;
85  char *description;
93 
94 struct perfmon_bundle;
95 
97  struct perfmon_bundle *);
98 
99 typedef struct
100 {
104 
105 typedef struct perfmon_bundle
106 {
107  char *name;
108  char *description;
109  char *source;
110  char *footer;
115 
118 
121 
123 
126 
127  /* do not set manually */
131 
132 typedef struct
133 {
139 
140 typedef struct
141 {
142  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
145  union
146  {
147  struct
148  {
150  } t[2];
152  };
154 
155 typedef struct
156 {
161  struct perf_event_mmap_page *mmap_pages[PERF_MAX_EVENTS];
163 
164 typedef struct
165 {
174  int *group_fds;
179 
181 
184 {
185  perfmon_cpu_supports_t *supports = b->cpu_supports;
186  uword type = 0;
187 
188  /* if nothing specific for this bundle, go with the default */
189  if (!supports)
190  return b->type;
191 
192  /* the last specified type, will always win */
193  for (int i = 0; i < b->n_cpu_supports; ++i)
194  if (supports[i].cpu_supports ())
195  type = supports[i].bundle_type;
196 
197  return type;
198 }
199 
200 #define PERFMON_REGISTER_SOURCE(x) \
201  perfmon_source_t __perfmon_source_##x; \
202  static void __clib_constructor __perfmon_source_registration_##x (void) \
203  { \
204  perfmon_main_t *pm = &perfmon_main; \
205  __perfmon_source_##x.next = pm->sources; \
206  pm->sources = &__perfmon_source_##x; \
207  } \
208  perfmon_source_t __perfmon_source_##x
209 
210 #define PERFMON_REGISTER_BUNDLE(x) \
211  perfmon_bundle_t __perfmon_bundle_##x; \
212  static void __clib_constructor __perfmon_bundle_registration_##x (void) \
213  { \
214  perfmon_main_t *pm = &perfmon_main; \
215  __perfmon_bundle_##x.next = pm->bundles; \
216  __perfmon_bundle_##x.type = \
217  perfmon_cpu_supported_bundle_type (&__perfmon_bundle_##x); \
218  pm->bundles = &__perfmon_bundle_##x; \
219  } \
220  perfmon_bundle_t __perfmon_bundle_##x
221 
225 
226 #define PERFMON_STRINGS(...) \
227  (char *[]) { __VA_ARGS__, 0 }
228 
229 #endif
vlib.h
perfmon_node_stats_t
Definition: perfmon.h:140
PERFMON_OFFSET_TYPE_METRICS
@ PERFMON_OFFSET_TYPE_METRICS
Definition: perfmon.h:40
perfmon_start
clib_error_t * perfmon_start(vlib_main_t *vm, perfmon_bundle_t *)
Definition: perfmon.c:216
perfmon_node_stats_t::n_packets
u64 n_packets
Definition: perfmon.h:144
perfmon_thread_runtime_t::n_events
u8 n_events
Definition: perfmon.h:157
perfmon_bundle_t
struct perfmon_bundle perfmon_bundle_t
perfmon_event_t::config
u64 config
Definition: perfmon.h:53
clib_cpu_supports_func_t
int(* clib_cpu_supports_func_t)()
Definition: cpu.h:182
PERFMON_BUNDLE_TYPE_NODE
@ PERFMON_BUNDLE_TYPE_NODE
Definition: perfmon.h:31
perfmon_instance_type_t::name
char * name
Definition: perfmon.h:68
perfmon_bundle::type
perfmon_bundle_type_t type
Definition: perfmon.h:111
PERFMON_BUNDLE_TYPE_MAX
@ PERFMON_BUNDLE_TYPE_MAX
Definition: perfmon.h:34
perfmon_reading_t
Definition: perfmon.h:132
perfmon_cpu_supports_t::cpu_supports
clib_cpu_supports_func_t cpu_supports
Definition: perfmon.h:101
perfmon_source::events
perfmon_event_t * events
Definition: perfmon.h:87
perfmon_main_t::active_bundle
perfmon_bundle_t * active_bundle
Definition: perfmon.h:171
perfmon_event_t
Definition: perfmon.h:44
CLIB_CACHE_LINE_ALIGN_MARK
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
perfmon_main_t
Definition: perfmon.h:164
perfmon_instance_type_t
Definition: perfmon.h:66
clib.h
perfmon_node_stats_t::n_calls
u64 n_calls
Definition: perfmon.h:143
perfmon_thread_runtime_t::n_nodes
u16 n_nodes
Definition: perfmon.h:158
perfmon_reading_t::time_enabled
u64 time_enabled
Definition: perfmon.h:135
perfmon_bundle::n_metrics
u32 n_metrics
Definition: perfmon.h:117
perfmon_bundle::column_headers
char ** column_headers
Definition: perfmon.h:124
perfmon_main_t::bundles
perfmon_bundle_t * bundles
Definition: perfmon.h:167
PERFMON_BUNDLE_TYPE_UNKNOWN
@ PERFMON_BUNDLE_TYPE_UNKNOWN
Definition: perfmon.h:30
u16
unsigned short u16
Definition: types.h:57
perfmon_bundle
Definition: perfmon.h:105
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
perfmon_source::instances_by_type
perfmon_instance_type_t * instances_by_type
Definition: perfmon.h:89
perfmon_event_t::instance_type
u32 instance_type
Definition: perfmon.h:51
perfmon_source::name
char * name
Definition: perfmon.h:84
perfmon_source::n_events
u32 n_events
Definition: perfmon.h:88
vlib_node_function_t
uword() vlib_node_function_t(struct vlib_main_t *vm, struct vlib_node_runtime_t *node, struct vlib_frame_t *frame)
Definition: node.h:54
perfmon_main_t::active_instance_type
perfmon_instance_type_t * active_instance_type
Definition: perfmon.h:177
perfmon_main_t::thread_runtimes
perfmon_thread_runtime_t * thread_runtimes
Definition: perfmon.h:166
perfmon_main_t::source_by_name
uword * source_by_name
Definition: perfmon.h:170
perfmon_source::init_fn
perfmon_source_init_fn_t * init_fn
Definition: perfmon.h:91
perfmon_source::next
struct perfmon_source * next
Definition: perfmon.h:86
perfmon_cpu_supported_bundle_type
static uword perfmon_cpu_supported_bundle_type(perfmon_bundle_t *b)
Definition: perfmon.h:183
perfmon_instance_t::type
u32 type
Definition: perfmon.h:60
perfmon_main_t::sources
perfmon_source_t * sources
Definition: perfmon.h:169
perfmon_bundle::cpu_supports
perfmon_cpu_supports_t * cpu_supports
Definition: perfmon.h:119
perfmon_event_t::type
u32 type
Definition: perfmon.h:50
error.h
perfmon_source
Definition: perfmon.h:82
PERFMON_BUNDLE_TYPE_THREAD
@ PERFMON_BUNDLE_TYPE_THREAD
Definition: perfmon.h:32
perfmon_source_t
struct perfmon_source perfmon_source_t
perfmon_main_t::sample_time
f64 sample_time
Definition: perfmon.h:173
perfmon_bundle::footer
char * footer
Definition: perfmon.h:110
perfmon_bundle::description
char * description
Definition: perfmon.h:108
uword
u64 uword
Definition: types.h:112
perfmon_bundle::offset_type
perfmon_offset_type_t offset_type
Definition: perfmon.h:112
perfmon_thread_runtime_t::bundle
perfmon_bundle_t * bundle
Definition: perfmon.h:160
perfmon_main
perfmon_main_t perfmon_main
Definition: perfmon.c:27
perfmon_offset_type_t
perfmon_offset_type_t
Definition: perfmon.h:37
PERFMON_BUNDLE_TYPE_SYSTEM
@ PERFMON_BUNDLE_TYPE_SYSTEM
Definition: perfmon.h:33
perfmon_cpu_supports_t
Definition: perfmon.h:99
perfmon_main_t::fds_to_close
int * fds_to_close
Definition: perfmon.h:175
f64
double f64
Definition: types.h:142
format.h
PERFMON_OFFSET_TYPE_MMAP
@ PERFMON_OFFSET_TYPE_MMAP
Definition: perfmon.h:39
perfmon_source::format_config
format_function_t * format_config
Definition: perfmon.h:90
perfmon_dispatch_wrapper_metrics
vlib_node_function_t perfmon_dispatch_wrapper_metrics
Definition: perfmon.h:74
cpu.h
perfmon_bundle::source
char * source
Definition: perfmon.h:109
perfmon_bundle::metrics
u32 metrics[PERF_MAX_EVENTS]
Definition: perfmon.h:116
perfmon_event_t::exclude_kernel
u32 exclude_kernel
Definition: perfmon.h:47
perfmon_instance_t
Definition: perfmon.h:58
perfmon_reset
void perfmon_reset(vlib_main_t *vm)
Definition: perfmon.c:45
perfmon_bundle::init_fn
perfmon_bundle_init_fn_t * init_fn
Definition: perfmon.h:122
PERFMON_OFFSET_TYPE_MAX
@ PERFMON_OFFSET_TYPE_MAX
Definition: perfmon.h:41
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
PERF_MAX_EVENTS
#define PERF_MAX_EVENTS
Definition: perfmon.h:26
perfmon_main_t::group_fds
int * group_fds
Definition: perfmon.h:174
u64
unsigned long u64
Definition: types.h:89
perfmon_bundle::events
u32 events[PERF_MAX_EVENTS]
Definition: perfmon.h:113
perfmon_main_t::bundle_by_name
uword * bundle_by_name
Definition: perfmon.h:168
perfmon_bundle_init_fn_t
clib_error_t *() perfmon_bundle_init_fn_t(vlib_main_t *vm, struct perfmon_bundle *)
Definition: perfmon.h:96
u32
unsigned int u32
Definition: types.h:88
perfmon_instance_type_t::instances
perfmon_instance_t * instances
Definition: perfmon.h:69
perfmon_stop
clib_error_t * perfmon_stop(vlib_main_t *vm)
Definition: perfmon.c:262
perfmon_main_t::default_instance_type
perfmon_instance_type_t * default_instance_type
Definition: perfmon.h:176
perfmon_bundle::name
char * name
Definition: perfmon.h:107
perfmon_instance_t::pid
pid_t pid
Definition: perfmon.h:62
perfmon_reading_t::nr
u64 nr
Definition: perfmon.h:134
perfmon_main_t::is_running
int is_running
Definition: perfmon.h:172
perfmon_instance_t::name
char * name
Definition: perfmon.h:63
perfmon_event_t::name
char * name
Definition: perfmon.h:54
perfmon_event_t::type_from_instance
u32 type_from_instance
Definition: perfmon.h:46
perfmon_bundle::src
perfmon_source_t * src
Definition: perfmon.h:128
value
u8 value
Definition: qos.api:54
perfmon_thread_runtime_t
Definition: perfmon.h:155
perfmon_instance_t::cpu
int cpu
Definition: perfmon.h:61
perfmon_bundle::n_cpu_supports
u32 n_cpu_supports
Definition: perfmon.h:120
vlib_main_t
Definition: main.h:102
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
perfmon_bundle::n_events
u32 n_events
Definition: perfmon.h:114
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
perfmon_thread_runtime_t::node_stats
perfmon_node_stats_t * node_stats
Definition: perfmon.h:159
perfmon_event_t::description
char * description
Definition: perfmon.h:55
i
int i
Definition: flowhash_template.h:376
perfmon_source_init_fn_t
clib_error_t *() perfmon_source_init_fn_t(vlib_main_t *vm, struct perfmon_source *)
Definition: perfmon.h:80
perfmon_bundle::format_fn
format_function_t * format_fn
Definition: perfmon.h:125
perfmon_dispatch_wrapper_mmap
vlib_node_function_t perfmon_dispatch_wrapper_mmap
Definition: perfmon.h:72
perfmon_source::description
char * description
Definition: perfmon.h:85
perfmon_bundle_type_t
perfmon_bundle_type_t
Definition: perfmon.h:28
perfmon_bundle::next
struct perfmon_bundle * next
Definition: perfmon.h:129
perfmon_cpu_supports_t::bundle_type
perfmon_bundle_type_t bundle_type
Definition: perfmon.h:102
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
perfmon_reading_t::time_running
u64 time_running
Definition: perfmon.h:136