blob: c8782023597d7744cdeaaeedcc1e121a94dcbe4e [file] [log] [blame]
Dave Barach4d1a8662018-09-10 12:31:15 -04001/*
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>
Damjan Marion47d165e2019-01-28 13:27:31 +010029#include <perfmon/perfmon_intel.h>
Dave Barach4d1a8662018-09-10 12:31:15 -040030
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
52typedef struct
53{
54 char *name;
55 int pe_type;
56 int pe_config;
57} perfmon_event_config_t;
58
59typedef enum
60{
61 PERFMON_STATE_OFF = 0,
62 PERFMON_STATE_RUNNING,
63} perfmon_state_t;
64
65typedef struct
66{
67 u8 *thread_and_node_name;
68 u8 **counter_names;
69 u64 *counter_values;
70 u64 *vectors_this_counter;
71} perfmon_capture_t;
72
73typedef struct
74{
Dave Barach4d1a8662018-09-10 12:31:15 -040075 u8 *name;
76 u8 *value;
77} name_value_pair_t;
78
79typedef struct
80{
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +000081 u64 ticks[2];
82 u64 vectors;
83} perfmon_counters_t;
84
85typedef 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 */
101 perfmon_counters_t *counters;
102
103} perfmon_thread_t;
104
105typedef struct
106{
Dave Barach4d1a8662018-09-10 12:31:15 -0400107 /* API message ID base */
108 u16 msg_id_base;
109
110 /* on/off switch for the periodic function */
111 volatile u8 state;
112
113 /* capture pool, hash table */
114 perfmon_capture_t *capture_pool;
115 uword *capture_by_thread_and_node_name;
116
Damjan Marion47d165e2019-01-28 13:27:31 +0100117 /* vector of registered perfmon tables */
118 perfmon_intel_pmc_registration_t *perfmon_tables;
119
120 /* active table */
121 perfmon_intel_pmc_event_t *perfmon_table;
122
123 uword *pmc_event_by_name;
Dave Barach4d1a8662018-09-10 12:31:15 -0400124
Dave Barachec595ef2019-01-24 10:34:24 -0500125 /* vector of single events to collect */
126 perfmon_event_config_t *single_events_to_collect;
127
128 /* vector of paired events to collect */
129 perfmon_event_config_t *paired_events_to_collect;
Dave Barach4d1a8662018-09-10 12:31:15 -0400130
131 /* Base indices of synthetic event tuples */
132 u32 ipc_event_index;
133 u32 mispredict_event_index;
134
135 /* Length of time to capture a single event */
136 f64 timeout_interval;
137
138 /* Current event (index) being collected */
139 u32 current_event;
Dave Barachec595ef2019-01-24 10:34:24 -0500140 int n_active;
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000141 /* mmap size of (mapped) struct perf_event_mmap_page */
Dave Barach4d1a8662018-09-10 12:31:15 -0400142 u32 page_size;
143
Dave Barach53fe4a72019-01-26 09:50:26 -0500144 /* thread bitmap */
145 uword *thread_bitmap;
146
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000147 /* per-thread data */
148 perfmon_thread_t **threads;
149
Dave Barach4d1a8662018-09-10 12:31:15 -0400150 /* Logging */
151 vlib_log_class_t log_class;
152
153 /* convenience */
154 vlib_main_t *vlib_main;
155 vnet_main_t *vnet_main;
156 ethernet_main_t *ethernet_main;
157} perfmon_main_t;
158
159extern perfmon_main_t perfmon_main;
160
161extern vlib_node_registration_t perfmon_periodic_node;
162uword *perfmon_parse_table (perfmon_main_t * pm, char *path, char *filename);
163
Tom Seidenberg6c81f5a2020-07-10 15:49:03 +0000164uword unformat_processor_event (unformat_input_t * input, va_list * args);
165
Dave Barach4d1a8662018-09-10 12:31:15 -0400166/* 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 */