2 * perfmon.h - performance monitor
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __included_perfmon_h__
18 #define __included_perfmon_h__
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/ethernet/ethernet.h>
25 #include <vppinfra/hash.h>
26 #include <vppinfra/error.h>
28 #include <linux/perf_event.h>
29 #include <perfmon/perfmon_intel.h>
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, \
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, \
42 _(PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_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")
57 } perfmon_event_config_t;
61 PERFMON_STATE_OFF = 0,
62 PERFMON_STATE_RUNNING,
67 u8 *thread_and_node_name;
70 u64 *vectors_this_counter;
87 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
89 /* Current counters */
92 /* Current perf_event file descriptors, per thread */
95 /* mmap base of mapped struct perf_event_mmap_page */
96 u8 *perf_event_pages[2];
100 /* vector of counters by node index */
101 perfmon_counters_t *counters;
107 /* API message ID base */
110 /* on/off switch for the periodic function */
113 /* capture pool, hash table */
114 perfmon_capture_t *capture_pool;
115 uword *capture_by_thread_and_node_name;
117 /* vector of registered perfmon tables */
118 perfmon_intel_pmc_registration_t *perfmon_tables;
121 perfmon_intel_pmc_event_t *perfmon_table;
123 uword *pmc_event_by_name;
125 /* vector of single events to collect */
126 perfmon_event_config_t *single_events_to_collect;
128 /* vector of paired events to collect */
129 perfmon_event_config_t *paired_events_to_collect;
131 /* Base indices of synthetic event tuples */
133 u32 mispredict_event_index;
135 /* Length of time to capture a single event */
136 f64 timeout_interval;
138 /* Current event (index) being collected */
141 /* mmap size of (mapped) struct perf_event_mmap_page */
145 uword *thread_bitmap;
147 /* per-thread data */
148 perfmon_thread_t **threads;
151 vlib_log_class_t log_class;
154 vlib_main_t *vlib_main;
155 vnet_main_t *vnet_main;
156 ethernet_main_t *ethernet_main;
159 extern perfmon_main_t perfmon_main;
161 extern vlib_node_registration_t perfmon_periodic_node;
162 uword *perfmon_parse_table (perfmon_main_t * pm, char *path, char *filename);
164 uword unformat_processor_event (unformat_input_t * input, va_list * args);
166 /* Periodic function events */
167 #define PERFMON_START 1
169 #endif /* __included_perfmon_h__ */
172 * fd.io coding-style-patch-verification: ON
175 * eval: (c-set-style "gnu")