]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/perf/util/event.h
UBUNTU: Ubuntu-5.11.0-22.23
[mirror_ubuntu-hirsute-kernel.git] / tools / perf / util / event.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
cdd6c482
IM
2#ifndef __PERF_RECORD_H
3#define __PERF_RECORD_H
4cb3c6d5
ACM
4/*
5 * The linux/stddef.h isn't need here, but is needed for __always_inline used
6 * in files included from uapi/linux/perf_event.h such as
7 * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
8 * detected in at least musl libc, used in Alpine Linux. -acme
9 */
482ad897 10#include <stdio.h>
4cb3c6d5 11#include <linux/stddef.h>
1345e2ee 12#include <perf/event.h>
4cb3c6d5 13#include <linux/types.h>
4a58e611 14
0c4e774f 15#include "perf_regs.h"
1fe2c106 16
4cb3c6d5
ACM
17struct dso;
18struct machine;
19struct perf_event_attr;
20
1345e2ee
JO
21#ifdef __LP64__
22/*
23 * /usr/include/inttypes.h uses just 'lu' for PRIu64, but we end up defining
24 * __u64 as long long unsigned int, and then -Werror=format= kicks in and
25 * complains of the mismatched types, so use these two special extra PRI
26 * macros to overcome that.
27 */
28#define PRI_lu64 "l" PRIu64
29#define PRI_lx64 "l" PRIx64
fecb4100 30#define PRI_ld64 "l" PRId64
1345e2ee
JO
31#else
32#define PRI_lu64 PRIu64
33#define PRI_lx64 PRIx64
fecb4100 34#define PRI_ld64 PRId64
1345e2ee 35#endif
1fe2c106 36
a2854124
FW
37#define PERF_SAMPLE_MASK \
38 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
39 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
40 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
75562573
AH
41 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
42 PERF_SAMPLE_IDENTIFIER)
a2854124 43
a65cb4b9
JO
44/* perf sample has 16 bits size limit */
45#define PERF_SAMPLE_MAX_SIZE (1 << 16)
46
0f6a3015 47struct regs_dump {
5b95a4a3 48 u64 abi;
352ea45a 49 u64 mask;
0f6a3015 50 u64 *regs;
0c4e774f
JO
51
52 /* Cached values/mask filled by first register access. */
53 u64 cache_regs[PERF_REGS_MAX];
54 u64 cache_mask;
0f6a3015
JO
55};
56
57struct stack_dump {
58 u16 offset;
59 u64 size;
60 char *data;
61};
62
9ede473c
JO
63struct sample_read_value {
64 u64 value;
65 u64 id;
66};
67
68struct sample_read {
69 u64 time_enabled;
70 u64 time_running;
71 union {
72 struct {
73 u64 nr;
74 struct sample_read_value *values;
75 } group;
76 struct sample_read_value one;
77 };
78};
79
0776eb59
JO
80struct ip_callchain {
81 u64 nr;
6549a8c0 82 u64 ips[];
0776eb59
JO
83};
84
f1a397f3 85struct branch_stack;
0776eb59 86
00447ccd
AH
87enum {
88 PERF_IP_FLAG_BRANCH = 1ULL << 0,
89 PERF_IP_FLAG_CALL = 1ULL << 1,
90 PERF_IP_FLAG_RETURN = 1ULL << 2,
91 PERF_IP_FLAG_CONDITIONAL = 1ULL << 3,
92 PERF_IP_FLAG_SYSCALLRET = 1ULL << 4,
93 PERF_IP_FLAG_ASYNC = 1ULL << 5,
94 PERF_IP_FLAG_INTERRUPT = 1ULL << 6,
95 PERF_IP_FLAG_TX_ABORT = 1ULL << 7,
96 PERF_IP_FLAG_TRACE_BEGIN = 1ULL << 8,
97 PERF_IP_FLAG_TRACE_END = 1ULL << 9,
98 PERF_IP_FLAG_IN_TX = 1ULL << 10,
99};
100
400ea6d3
AH
101#define PERF_IP_FLAG_CHARS "bcrosyiABEx"
102
00447ccd
AH
103#define PERF_BRANCH_MASK (\
104 PERF_IP_FLAG_BRANCH |\
105 PERF_IP_FLAG_CALL |\
106 PERF_IP_FLAG_RETURN |\
107 PERF_IP_FLAG_CONDITIONAL |\
108 PERF_IP_FLAG_SYSCALLRET |\
109 PERF_IP_FLAG_ASYNC |\
110 PERF_IP_FLAG_INTERRUPT |\
111 PERF_IP_FLAG_TX_ABORT |\
112 PERF_IP_FLAG_TRACE_BEGIN |\
113 PERF_IP_FLAG_TRACE_END)
114
faaa8768
AK
115#define MAX_INSN 16
116
98dcf14d
AH
117struct aux_sample {
118 u64 size;
119 void *data;
120};
121
8d50e5b4 122struct perf_sample {
180f95e2
OH
123 u64 ip;
124 u32 pid, tid;
125 u64 time;
126 u64 addr;
127 u64 id;
128 u64 stream_id;
180f95e2 129 u64 period;
05484298 130 u64 weight;
475eeab9 131 u64 transaction;
61d276f4
AH
132 u64 insn_cnt;
133 u64 cyc_cnt;
eed05fe7 134 u32 cpu;
180f95e2 135 u32 raw_size;
98a3b32c 136 u64 data_src;
3b0a5daa 137 u64 phys_addr;
542b88fd 138 u64 data_page_size;
ba78c1c5 139 u64 cgroup;
bf493902
AH
140 u32 flags;
141 u16 insn_len;
473398a2 142 u8 cpumode;
28a0b398 143 u16 misc;
42bbabed 144 bool no_hw_idx; /* No hw_idx collected in branch_stack */
faaa8768 145 char insn[MAX_INSN];
180f95e2 146 void *raw_data;
eed05fe7 147 struct ip_callchain *callchain;
b5387528 148 struct branch_stack *branch_stack;
0f6a3015 149 struct regs_dump user_regs;
6a21c0b5 150 struct regs_dump intr_regs;
0f6a3015 151 struct stack_dump user_stack;
9ede473c 152 struct sample_read read;
98dcf14d 153 struct aux_sample aux_sample;
180f95e2
OH
154};
155
98a3b32c
SE
156#define PERF_MEM_DATA_SRC_NONE \
157 (PERF_MEM_S(OP, NA) |\
158 PERF_MEM_S(LVL, NA) |\
159 PERF_MEM_S(SNOOP, NA) |\
160 PERF_MEM_S(LOCK, NA) |\
161 PERF_MEM_S(TLB, NA))
162
1405720d
AH
163/* Attribute type for custom synthesized events */
164#define PERF_TYPE_SYNTH (INT_MAX + 1U)
165
65c5e18f
AH
166/* Attribute config for custom synthesized events */
167enum perf_synth_id {
168 PERF_SYNTH_INTEL_PTWRITE,
169 PERF_SYNTH_INTEL_MWAIT,
170 PERF_SYNTH_INTEL_PWRE,
171 PERF_SYNTH_INTEL_EXSTOP,
172 PERF_SYNTH_INTEL_PWRX,
173 PERF_SYNTH_INTEL_CBR,
174};
175
176/*
177 * Raw data formats for synthesized events. Note that 4 bytes of padding are
178 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
179 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
180 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
181 * structure sizes are 4 bytes bigger than the raw_size, refer
182 * perf_synth__raw_size().
183 */
184
185struct perf_synth_intel_ptwrite {
186 u32 padding;
187 union {
188 struct {
189 u32 ip : 1,
190 reserved : 31;
191 };
192 u32 flags;
193 };
194 u64 payload;
195};
196
197struct perf_synth_intel_mwait {
198 u32 padding;
199 u32 reserved;
200 union {
201 struct {
202 u64 hints : 8,
203 reserved1 : 24,
204 extensions : 2,
205 reserved2 : 30;
206 };
207 u64 payload;
208 };
209};
210
211struct perf_synth_intel_pwre {
212 u32 padding;
213 u32 reserved;
214 union {
215 struct {
216 u64 reserved1 : 7,
217 hw : 1,
218 subcstate : 4,
219 cstate : 4,
220 reserved2 : 48;
221 };
222 u64 payload;
223 };
224};
225
226struct perf_synth_intel_exstop {
227 u32 padding;
228 union {
229 struct {
230 u32 ip : 1,
231 reserved : 31;
232 };
233 u32 flags;
234 };
235};
236
237struct perf_synth_intel_pwrx {
238 u32 padding;
239 u32 reserved;
240 union {
241 struct {
242 u64 deepest_cstate : 4,
243 last_cstate : 4,
244 wake_reason : 4,
245 reserved1 : 52;
246 };
247 u64 payload;
248 };
249};
250
251struct perf_synth_intel_cbr {
252 u32 padding;
253 union {
254 struct {
255 u32 cbr : 8,
256 reserved1 : 8,
257 max_nonturbo : 8,
258 reserved2 : 8;
259 };
260 u32 flags;
261 };
262 u32 freq;
263 u32 reserved3;
264};
265
266/*
267 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
268 * 8-byte alignment.
269 */
270static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
271{
272 return sample->raw_data - 4;
273}
274
275static inline void *perf_synth__raw_data(void *p)
276{
277 return p + 4;
278}
279
280#define perf_synth__raw_size(d) (sizeof(d) - 4)
281
282#define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
283
2d8f0f18
JO
284enum {
285 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
286 PERF_STAT_ROUND_TYPE__FINAL = 1,
287};
288
8115d60c 289void perf_event__print_totals(void);
62daacb5 290
f854839b 291struct perf_cpu_map;
ea49e01c 292struct perf_record_stat_config;
67424342 293struct perf_stat_config;
ea49e01c 294struct perf_tool;
cf553114 295
8e381596 296void perf_event__read_stat_config(struct perf_stat_config *config,
72932371 297 struct perf_record_stat_config *event);
8115d60c 298
45694aa7 299int perf_event__process_comm(struct perf_tool *tool,
d20deb64
ACM
300 union perf_event *event,
301 struct perf_sample *sample,
743eb868 302 struct machine *machine);
45694aa7 303int perf_event__process_lost(struct perf_tool *tool,
d20deb64
ACM
304 union perf_event *event,
305 struct perf_sample *sample,
743eb868 306 struct machine *machine);
c4937a91
KL
307int perf_event__process_lost_samples(struct perf_tool *tool,
308 union perf_event *event,
309 struct perf_sample *sample,
310 struct machine *machine);
4a96f7a0
AH
311int perf_event__process_aux(struct perf_tool *tool,
312 union perf_event *event,
313 struct perf_sample *sample,
314 struct machine *machine);
0ad21f68
AH
315int perf_event__process_itrace_start(struct perf_tool *tool,
316 union perf_event *event,
317 struct perf_sample *sample,
318 struct machine *machine);
0286039f
AH
319int perf_event__process_switch(struct perf_tool *tool,
320 union perf_event *event,
321 struct perf_sample *sample,
322 struct machine *machine);
f3b3614a
HB
323int perf_event__process_namespaces(struct perf_tool *tool,
324 union perf_event *event,
325 struct perf_sample *sample,
326 struct machine *machine);
ba78c1c5
NK
327int perf_event__process_cgroup(struct perf_tool *tool,
328 union perf_event *event,
329 struct perf_sample *sample,
330 struct machine *machine);
45694aa7 331int perf_event__process_mmap(struct perf_tool *tool,
d20deb64
ACM
332 union perf_event *event,
333 struct perf_sample *sample,
743eb868 334 struct machine *machine);
5c5e854b
SE
335int perf_event__process_mmap2(struct perf_tool *tool,
336 union perf_event *event,
337 struct perf_sample *sample,
338 struct machine *machine);
f62d3f0f
ACM
339int perf_event__process_fork(struct perf_tool *tool,
340 union perf_event *event,
341 struct perf_sample *sample,
342 struct machine *machine);
343int perf_event__process_exit(struct perf_tool *tool,
d20deb64
ACM
344 union perf_event *event,
345 struct perf_sample *sample,
743eb868 346 struct machine *machine);
9aa0bfa3
SL
347int perf_event__process_ksymbol(struct perf_tool *tool,
348 union perf_event *event,
349 struct perf_sample *sample,
350 struct machine *machine);
3f604b5f
ACM
351int perf_event__process_bpf(struct perf_tool *tool,
352 union perf_event *event,
353 struct perf_sample *sample,
354 struct machine *machine);
246eba8e
AH
355int perf_event__process_text_poke(struct perf_tool *tool,
356 union perf_event *event,
357 struct perf_sample *sample,
358 struct machine *machine);
45694aa7 359int perf_event__process(struct perf_tool *tool,
d20deb64
ACM
360 union perf_event *event,
361 struct perf_sample *sample,
743eb868 362 struct machine *machine);
62daacb5 363
1ed091c4 364struct addr_location;
316c7136 365
bb3eb566
ACM
366int machine__resolve(struct machine *machine, struct addr_location *al,
367 struct perf_sample *sample);
1ed091c4 368
b91fc39f
ACM
369void addr_location__put(struct addr_location *al);
370
9b0d2d87
AH
371struct thread;
372
373bool is_bts_event(struct perf_event_attr *attr);
374bool sample_addr_correlates_sym(struct perf_event_attr *attr);
c2740a87
ACM
375void thread__resolve(struct thread *thread, struct addr_location *al,
376 struct perf_sample *sample);
9b0d2d87 377
8115d60c 378const char *perf_event__name(unsigned int id);
c8446b9b 379
482ad897
ACM
380size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
381size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
5c5e854b 382size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
482ad897 383size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
4a96f7a0 384size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
0ad21f68 385size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
0286039f 386size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
ec7fa596 387size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
eb12a1af 388size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
f3b3614a 389size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
ba78c1c5 390size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
9aa0bfa3 391size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
3f604b5f 392size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
7eeb9855
AH
393size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
394size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
482ad897 395
b843f62a
ACM
396int kallsyms__get_function_start(const char *kallsyms_filename,
397 const char *symbol_name, u64 *addr);
29b596b5 398
f854839b 399void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max);
72932371 400void cpu_map_data__synthesize(struct perf_record_cpu_map_data *data, struct perf_cpu_map *map,
6c872901 401 u16 type, int max);
5ab8c689
ACM
402
403void event_attr_init(struct perf_event_attr *attr);
404
405int perf_event_paranoid(void);
c22e150e 406bool perf_event_paranoid_check(int max_level);
5ab8c689
ACM
407
408extern int sysctl_perf_event_max_stack;
409extern int sysctl_perf_event_max_contexts_per_stack;
3fcb10e4 410extern unsigned int proc_map_timeout;
5ab8c689 411
6b9bae63
KL
412#define PAGE_SIZE_NAME_LEN 32
413char *get_page_size_name(u64 size, char *str);
414
8b40f521 415#endif /* __PERF_RECORD_H */