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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __perfmon_perfmon_h
17 #define __perfmon_perfmon_h
19 #include <linux/perf_event.h>
20 #include <vppinfra/clib.h>
21 #include <vppinfra/format.h>
22 #include <vppinfra/error.h>
23 #include <vlib/vlib.h>
25 #define PERF_MAX_EVENTS 7 /* 3 fixed and 4 programmable */
29 PERFMON_BUNDLE_TYPE_UNKNOWN,
30 PERFMON_BUNDLE_TYPE_NODE,
31 PERFMON_BUNDLE_TYPE_THREAD,
32 PERFMON_BUNDLE_TYPE_SYSTEM,
33 } perfmon_bundle_type_t;
37 u32 type_from_instance : 1;
38 u32 exclude_kernel : 1;
60 perfmon_instance_t *instances;
61 } perfmon_instance_type_t;
63 struct perfmon_source;
64 vlib_node_function_t perfmon_dispatch_wrapper;
66 typedef clib_error_t *(perfmon_source_init_fn_t) (vlib_main_t *vm,
67 struct perfmon_source *);
68 typedef struct perfmon_source
72 struct perfmon_source *next;
73 perfmon_event_t *events;
75 perfmon_instance_type_t *instances_by_type;
76 format_function_t *format_config;
77 perfmon_source_init_fn_t *init_fn;
80 struct perfmon_bundle;
81 typedef clib_error_t *(perfmon_bundle_init_fn_t) (vlib_main_t *vm,
82 struct perfmon_bundle *);
83 typedef struct perfmon_bundle
89 perfmon_bundle_type_t type;
90 u32 events[PERF_MAX_EVENTS];
93 perfmon_bundle_init_fn_t *init_fn;
95 char **column_headers;
96 format_function_t *format_fn;
98 /* do not set manually */
99 perfmon_source_t *src;
100 struct perfmon_bundle *next;
108 u64 value[PERF_MAX_EVENTS];
113 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
116 u64 value[PERF_MAX_EVENTS];
117 } perfmon_node_stats_t;
123 perfmon_node_stats_t *node_stats;
124 struct perf_event_mmap_page *mmap_pages[PERF_MAX_EVENTS];
125 } perfmon_thread_runtime_t;
129 perfmon_thread_runtime_t *thread_runtimes;
130 perfmon_bundle_t *bundles;
131 uword *bundle_by_name;
132 perfmon_source_t *sources;
133 uword *source_by_name;
134 perfmon_bundle_t *active_bundle;
138 perfmon_instance_type_t *default_instance_type;
139 perfmon_instance_type_t *active_instance_type;
142 extern perfmon_main_t perfmon_main;
144 #define PERFMON_REGISTER_SOURCE(x) \
145 perfmon_source_t __perfmon_source_##x; \
146 static void __clib_constructor __perfmon_source_registration_##x (void) \
148 perfmon_main_t *pm = &perfmon_main; \
149 __perfmon_source_##x.next = pm->sources; \
150 pm->sources = &__perfmon_source_##x; \
152 perfmon_source_t __perfmon_source_##x
154 #define PERFMON_REGISTER_BUNDLE(x) \
155 perfmon_bundle_t __perfmon_bundle_##x; \
156 static void __clib_constructor __perfmon_bundle_registration_##x (void) \
158 perfmon_main_t *pm = &perfmon_main; \
159 __perfmon_bundle_##x.next = pm->bundles; \
160 pm->bundles = &__perfmon_bundle_##x; \
162 perfmon_bundle_t __perfmon_bundle_##x
164 void perfmon_reset (vlib_main_t *vm);
165 clib_error_t *perfmon_set (vlib_main_t *vm, perfmon_bundle_t *);
166 clib_error_t *perfmon_start (vlib_main_t *vm);
167 clib_error_t *perfmon_stop (vlib_main_t *vm);
169 #define PERFMON_STRINGS(...) \
170 (char *[]) { __VA_ARGS__, 0 }