xref: /openbmc/linux/tools/perf/util/auxtrace.h (revision d63670d2)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * auxtrace.h: AUX area trace support
4  * Copyright (c) 2013-2015, Intel Corporation.
5  */
6 
7 #ifndef __PERF_AUXTRACE_H
8 #define __PERF_AUXTRACE_H
9 
10 #include <sys/types.h>
11 #include <errno.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <stdio.h> // FILE
15 #include <linux/list.h>
16 #include <linux/perf_event.h>
17 #include <linux/types.h>
18 #include <internal/cpumap.h>
19 #include <asm/bitsperlong.h>
20 #include <asm/barrier.h>
21 
22 union perf_event;
23 struct perf_session;
24 struct evlist;
25 struct evsel;
26 struct perf_tool;
27 struct mmap;
28 struct perf_sample;
29 struct option;
30 struct record_opts;
31 struct perf_record_auxtrace_error;
32 struct perf_record_auxtrace_info;
33 struct events_stats;
34 struct perf_pmu;
35 
36 enum auxtrace_error_type {
37        PERF_AUXTRACE_ERROR_ITRACE  = 1,
38        PERF_AUXTRACE_ERROR_MAX
39 };
40 
41 /* Auxtrace records must have the same alignment as perf event records */
42 #define PERF_AUXTRACE_RECORD_ALIGNMENT 8
43 
44 enum auxtrace_type {
45 	PERF_AUXTRACE_UNKNOWN,
46 	PERF_AUXTRACE_INTEL_PT,
47 	PERF_AUXTRACE_INTEL_BTS,
48 	PERF_AUXTRACE_CS_ETM,
49 	PERF_AUXTRACE_ARM_SPE,
50 	PERF_AUXTRACE_S390_CPUMSF,
51 };
52 
53 enum itrace_period_type {
54 	PERF_ITRACE_PERIOD_INSTRUCTIONS,
55 	PERF_ITRACE_PERIOD_TICKS,
56 	PERF_ITRACE_PERIOD_NANOSECS,
57 };
58 
59 #define AUXTRACE_ERR_FLG_OVERFLOW	(1 << ('o' - 'a'))
60 #define AUXTRACE_ERR_FLG_DATA_LOST	(1 << ('l' - 'a'))
61 
62 #define AUXTRACE_LOG_FLG_ALL_PERF_EVTS	(1 << ('a' - 'a'))
63 #define AUXTRACE_LOG_FLG_USE_STDOUT	(1 << ('o' - 'a'))
64 
65 /**
66  * struct itrace_synth_opts - AUX area tracing synthesis options.
67  * @set: indicates whether or not options have been set
68  * @default_no_sample: Default to no sampling.
69  * @inject: indicates the event (not just the sample) must be fully synthesized
70  *          because 'perf inject' will write it out
71  * @instructions: whether to synthesize 'instructions' events
72  * @branches: whether to synthesize 'branches' events
73  *            (branch misses only for Arm SPE)
74  * @transactions: whether to synthesize events for transactions
75  * @ptwrites: whether to synthesize events for ptwrites
76  * @pwr_events: whether to synthesize power events
77  * @other_events: whether to synthesize other events recorded due to the use of
78  *                aux_output
79  * @intr_events: whether to synthesize interrupt events
80  * @errors: whether to synthesize decoder error events
81  * @dont_decode: whether to skip decoding entirely
82  * @log: write a decoding log
83  * @calls: limit branch samples to calls (can be combined with @returns)
84  * @returns: limit branch samples to returns (can be combined with @calls)
85  * @callchain: add callchain to 'instructions' events
86  * @add_callchain: add callchain to existing event records
87  * @thread_stack: feed branches to the thread_stack
88  * @last_branch: add branch context to 'instruction' events
89  * @add_last_branch: add branch context to existing event records
90  * @approx_ipc: approximate IPC
91  * @flc: whether to synthesize first level cache events
92  * @llc: whether to synthesize last level cache events
93  * @tlb: whether to synthesize TLB events
94  * @remote_access: whether to synthesize remote access events
95  * @mem: whether to synthesize memory events
96  * @timeless_decoding: prefer "timeless" decoding i.e. ignore timestamps
97  * @vm_time_correlation: perform VM Time Correlation
98  * @vm_tm_corr_dry_run: VM Time Correlation dry-run
99  * @vm_tm_corr_args:  VM Time Correlation implementation-specific arguments
100  * @callchain_sz: maximum callchain size
101  * @last_branch_sz: branch context size
102  * @period: 'instructions' events period
103  * @period_type: 'instructions' events period type
104  * @initial_skip: skip N events at the beginning.
105  * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
106  * @ptime_range: time intervals to trace or NULL
107  * @range_num: number of time intervals to trace
108  * @error_plus_flags: flags to affect what errors are reported
109  * @error_minus_flags: flags to affect what errors are reported
110  * @log_plus_flags: flags to affect what is logged
111  * @log_minus_flags: flags to affect what is logged
112  * @quick: quicker (less detailed) decoding
113  */
114 struct itrace_synth_opts {
115 	bool			set;
116 	bool			default_no_sample;
117 	bool			inject;
118 	bool			instructions;
119 	bool			branches;
120 	bool			transactions;
121 	bool			ptwrites;
122 	bool			pwr_events;
123 	bool			other_events;
124 	bool			intr_events;
125 	bool			errors;
126 	bool			dont_decode;
127 	bool			log;
128 	bool			calls;
129 	bool			returns;
130 	bool			callchain;
131 	bool			add_callchain;
132 	bool			thread_stack;
133 	bool			last_branch;
134 	bool			add_last_branch;
135 	bool			approx_ipc;
136 	bool			flc;
137 	bool			llc;
138 	bool			tlb;
139 	bool			remote_access;
140 	bool			mem;
141 	bool			timeless_decoding;
142 	bool			vm_time_correlation;
143 	bool			vm_tm_corr_dry_run;
144 	char			*vm_tm_corr_args;
145 	unsigned int		callchain_sz;
146 	unsigned int		last_branch_sz;
147 	unsigned long long	period;
148 	enum itrace_period_type	period_type;
149 	unsigned long		initial_skip;
150 	unsigned long		*cpu_bitmap;
151 	struct perf_time_interval *ptime_range;
152 	int			range_num;
153 	unsigned int		error_plus_flags;
154 	unsigned int		error_minus_flags;
155 	unsigned int		log_plus_flags;
156 	unsigned int		log_minus_flags;
157 	unsigned int		quick;
158 };
159 
160 /**
161  * struct auxtrace_index_entry - indexes a AUX area tracing event within a
162  *                               perf.data file.
163  * @file_offset: offset within the perf.data file
164  * @sz: size of the event
165  */
166 struct auxtrace_index_entry {
167 	u64			file_offset;
168 	u64			sz;
169 };
170 
171 #define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
172 
173 /**
174  * struct auxtrace_index - index of AUX area tracing events within a perf.data
175  *                         file.
176  * @list: linking a number of arrays of entries
177  * @nr: number of entries
178  * @entries: array of entries
179  */
180 struct auxtrace_index {
181 	struct list_head	list;
182 	size_t			nr;
183 	struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
184 };
185 
186 /**
187  * struct auxtrace - session callbacks to allow AUX area data decoding.
188  * @process_event: lets the decoder see all session events
189  * @process_auxtrace_event: process a PERF_RECORD_AUXTRACE event
190  * @queue_data: queue an AUX sample or PERF_RECORD_AUXTRACE event for later
191  *              processing
192  * @dump_auxtrace_sample: dump AUX area sample data
193  * @flush_events: process any remaining data
194  * @free_events: free resources associated with event processing
195  * @free: free resources associated with the session
196  */
197 struct auxtrace {
198 	int (*process_event)(struct perf_session *session,
199 			     union perf_event *event,
200 			     struct perf_sample *sample,
201 			     struct perf_tool *tool);
202 	int (*process_auxtrace_event)(struct perf_session *session,
203 				      union perf_event *event,
204 				      struct perf_tool *tool);
205 	int (*queue_data)(struct perf_session *session,
206 			  struct perf_sample *sample, union perf_event *event,
207 			  u64 data_offset);
208 	void (*dump_auxtrace_sample)(struct perf_session *session,
209 				     struct perf_sample *sample);
210 	int (*flush_events)(struct perf_session *session,
211 			    struct perf_tool *tool);
212 	void (*free_events)(struct perf_session *session);
213 	void (*free)(struct perf_session *session);
214 	bool (*evsel_is_auxtrace)(struct perf_session *session,
215 				  struct evsel *evsel);
216 };
217 
218 /**
219  * struct auxtrace_buffer - a buffer containing AUX area tracing data.
220  * @list: buffers are queued in a list held by struct auxtrace_queue
221  * @size: size of the buffer in bytes
222  * @pid: in per-thread mode, the pid this buffer is associated with
223  * @tid: in per-thread mode, the tid this buffer is associated with
224  * @cpu: in per-cpu mode, the cpu this buffer is associated with
225  * @data: actual buffer data (can be null if the data has not been loaded)
226  * @data_offset: file offset at which the buffer can be read
227  * @mmap_addr: mmap address at which the buffer can be read
228  * @mmap_size: size of the mmap at @mmap_addr
229  * @data_needs_freeing: @data was malloc'd so free it when it is no longer
230  *                      needed
231  * @consecutive: the original data was split up and this buffer is consecutive
232  *               to the previous buffer
233  * @offset: offset as determined by aux_head / aux_tail members of struct
234  *          perf_event_mmap_page
235  * @reference: an implementation-specific reference determined when the data is
236  *             recorded
237  * @buffer_nr: used to number each buffer
238  * @use_size: implementation actually only uses this number of bytes
239  * @use_data: implementation actually only uses data starting at this address
240  */
241 struct auxtrace_buffer {
242 	struct list_head	list;
243 	size_t			size;
244 	pid_t			pid;
245 	pid_t			tid;
246 	struct perf_cpu		cpu;
247 	void			*data;
248 	off_t			data_offset;
249 	void			*mmap_addr;
250 	size_t			mmap_size;
251 	bool			data_needs_freeing;
252 	bool			consecutive;
253 	u64			offset;
254 	u64			reference;
255 	u64			buffer_nr;
256 	size_t			use_size;
257 	void			*use_data;
258 };
259 
260 /**
261  * struct auxtrace_queue - a queue of AUX area tracing data buffers.
262  * @head: head of buffer list
263  * @tid: in per-thread mode, the tid this queue is associated with
264  * @cpu: in per-cpu mode, the cpu this queue is associated with
265  * @set: %true once this queue has been dedicated to a specific thread or cpu
266  * @priv: implementation-specific data
267  */
268 struct auxtrace_queue {
269 	struct list_head	head;
270 	pid_t			tid;
271 	int			cpu;
272 	bool			set;
273 	void			*priv;
274 };
275 
276 /**
277  * struct auxtrace_queues - an array of AUX area tracing queues.
278  * @queue_array: array of queues
279  * @nr_queues: number of queues
280  * @new_data: set whenever new data is queued
281  * @populated: queues have been fully populated using the auxtrace_index
282  * @next_buffer_nr: used to number each buffer
283  */
284 struct auxtrace_queues {
285 	struct auxtrace_queue	*queue_array;
286 	unsigned int		nr_queues;
287 	bool			new_data;
288 	bool			populated;
289 	u64			next_buffer_nr;
290 };
291 
292 /**
293  * struct auxtrace_heap_item - element of struct auxtrace_heap.
294  * @queue_nr: queue number
295  * @ordinal: value used for sorting (lowest ordinal is top of the heap) expected
296  *           to be a timestamp
297  */
298 struct auxtrace_heap_item {
299 	unsigned int		queue_nr;
300 	u64			ordinal;
301 };
302 
303 /**
304  * struct auxtrace_heap - a heap suitable for sorting AUX area tracing queues.
305  * @heap_array: the heap
306  * @heap_cnt: the number of elements in the heap
307  * @heap_sz: maximum number of elements (grows as needed)
308  */
309 struct auxtrace_heap {
310 	struct auxtrace_heap_item	*heap_array;
311 	unsigned int		heap_cnt;
312 	unsigned int		heap_sz;
313 };
314 
315 /**
316  * struct auxtrace_mmap - records an mmap of the auxtrace buffer.
317  * @base: address of mapped area
318  * @userpg: pointer to buffer's perf_event_mmap_page
319  * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
320  * @len: size of mapped area
321  * @prev: previous aux_head
322  * @idx: index of this mmap
323  * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
324  *       mmap) otherwise %0
325  * @cpu: cpu number for a per-cpu mmap otherwise %-1
326  */
327 struct auxtrace_mmap {
328 	void		*base;
329 	void		*userpg;
330 	size_t		mask;
331 	size_t		len;
332 	u64		prev;
333 	int		idx;
334 	pid_t		tid;
335 	int		cpu;
336 };
337 
338 /**
339  * struct auxtrace_mmap_params - parameters to set up struct auxtrace_mmap.
340  * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
341  * @offset: file offset of mapped area
342  * @len: size of mapped area
343  * @prot: mmap memory protection
344  * @idx: index of this mmap
345  * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
346  *       mmap) otherwise %0
347  * @cpu: cpu number for a per-cpu mmap otherwise %-1
348  */
349 struct auxtrace_mmap_params {
350 	size_t		mask;
351 	off_t		offset;
352 	size_t		len;
353 	int		prot;
354 	int		idx;
355 	pid_t		tid;
356 	struct perf_cpu	cpu;
357 };
358 
359 /**
360  * struct auxtrace_record - callbacks for recording AUX area data.
361  * @recording_options: validate and process recording options
362  * @info_priv_size: return the size of the private data in auxtrace_info_event
363  * @info_fill: fill-in the private data in auxtrace_info_event
364  * @free: free this auxtrace record structure
365  * @snapshot_start: starting a snapshot
366  * @snapshot_finish: finishing a snapshot
367  * @find_snapshot: find data to snapshot within auxtrace mmap
368  * @parse_snapshot_options: parse snapshot options
369  * @reference: provide a 64-bit reference number for auxtrace_event
370  * @read_finish: called after reading from an auxtrace mmap
371  * @alignment: alignment (if any) for AUX area data
372  * @default_aux_sample_size: default sample size for --aux sample option
373  * @pmu: associated pmu
374  * @evlist: selected events list
375  */
376 struct auxtrace_record {
377 	int (*recording_options)(struct auxtrace_record *itr,
378 				 struct evlist *evlist,
379 				 struct record_opts *opts);
380 	size_t (*info_priv_size)(struct auxtrace_record *itr,
381 				 struct evlist *evlist);
382 	int (*info_fill)(struct auxtrace_record *itr,
383 			 struct perf_session *session,
384 			 struct perf_record_auxtrace_info *auxtrace_info,
385 			 size_t priv_size);
386 	void (*free)(struct auxtrace_record *itr);
387 	int (*snapshot_start)(struct auxtrace_record *itr);
388 	int (*snapshot_finish)(struct auxtrace_record *itr);
389 	int (*find_snapshot)(struct auxtrace_record *itr, int idx,
390 			     struct auxtrace_mmap *mm, unsigned char *data,
391 			     u64 *head, u64 *old);
392 	int (*parse_snapshot_options)(struct auxtrace_record *itr,
393 				      struct record_opts *opts,
394 				      const char *str);
395 	u64 (*reference)(struct auxtrace_record *itr);
396 	int (*read_finish)(struct auxtrace_record *itr, int idx);
397 	unsigned int alignment;
398 	unsigned int default_aux_sample_size;
399 	struct perf_pmu *pmu;
400 	struct evlist *evlist;
401 };
402 
403 /**
404  * struct addr_filter - address filter.
405  * @list: list node
406  * @range: true if it is a range filter
407  * @start: true if action is 'filter' or 'start'
408  * @action: 'filter', 'start' or 'stop' ('tracestop' is accepted but converted
409  *          to 'stop')
410  * @sym_from: symbol name for the filter address
411  * @sym_to: symbol name that determines the filter size
412  * @sym_from_idx: selects n'th from symbols with the same name (0 means global
413  *                and less than 0 means symbol must be unique)
414  * @sym_to_idx: same as @sym_from_idx but for @sym_to
415  * @addr: filter address
416  * @size: filter region size (for range filters)
417  * @filename: DSO file name or NULL for the kernel
418  * @str: allocated string that contains the other string members
419  */
420 struct addr_filter {
421 	struct list_head	list;
422 	bool			range;
423 	bool			start;
424 	const char		*action;
425 	const char		*sym_from;
426 	const char		*sym_to;
427 	int			sym_from_idx;
428 	int			sym_to_idx;
429 	u64			addr;
430 	u64			size;
431 	const char		*filename;
432 	char			*str;
433 };
434 
435 /**
436  * struct addr_filters - list of address filters.
437  * @head: list of address filters
438  * @cnt: number of address filters
439  */
440 struct addr_filters {
441 	struct list_head	head;
442 	int			cnt;
443 };
444 
445 struct auxtrace_cache;
446 
447 #ifdef HAVE_AUXTRACE_SUPPORT
448 
449 u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm);
450 int compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail);
451 
452 static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm,
453 					   int kernel_is_64_bit __maybe_unused)
454 {
455 	struct perf_event_mmap_page *pc = mm->userpg;
456 	u64 head;
457 
458 #if BITS_PER_LONG == 32
459 	if (kernel_is_64_bit)
460 		return compat_auxtrace_mmap__read_head(mm);
461 #endif
462 	head = READ_ONCE(pc->aux_head);
463 
464 	/* Ensure all reads are done after we read the head */
465 	smp_rmb();
466 	return head;
467 }
468 
469 static inline int auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail,
470 					    int kernel_is_64_bit __maybe_unused)
471 {
472 	struct perf_event_mmap_page *pc = mm->userpg;
473 
474 #if BITS_PER_LONG == 32
475 	if (kernel_is_64_bit)
476 		return compat_auxtrace_mmap__write_tail(mm, tail);
477 #endif
478 	/* Ensure all reads are done before we write the tail out */
479 	smp_mb();
480 	WRITE_ONCE(pc->aux_tail, tail);
481 	return 0;
482 }
483 
484 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
485 			struct auxtrace_mmap_params *mp,
486 			void *userpg, int fd);
487 void auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
488 void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
489 				off_t auxtrace_offset,
490 				unsigned int auxtrace_pages,
491 				bool auxtrace_overwrite);
492 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
493 				   struct evlist *evlist, int idx,
494 				   bool per_cpu);
495 
496 typedef int (*process_auxtrace_t)(struct perf_tool *tool,
497 				  struct mmap *map,
498 				  union perf_event *event, void *data1,
499 				  size_t len1, void *data2, size_t len2);
500 
501 int auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
502 			struct perf_tool *tool, process_auxtrace_t fn);
503 
504 int auxtrace_mmap__read_snapshot(struct mmap *map,
505 				 struct auxtrace_record *itr,
506 				 struct perf_tool *tool, process_auxtrace_t fn,
507 				 size_t snapshot_size);
508 
509 int auxtrace_queues__init(struct auxtrace_queues *queues);
510 int auxtrace_queues__add_event(struct auxtrace_queues *queues,
511 			       struct perf_session *session,
512 			       union perf_event *event, off_t data_offset,
513 			       struct auxtrace_buffer **buffer_ptr);
514 struct auxtrace_queue *
515 auxtrace_queues__sample_queue(struct auxtrace_queues *queues,
516 			      struct perf_sample *sample,
517 			      struct perf_session *session);
518 int auxtrace_queues__add_sample(struct auxtrace_queues *queues,
519 				struct perf_session *session,
520 				struct perf_sample *sample, u64 data_offset,
521 				u64 reference);
522 void auxtrace_queues__free(struct auxtrace_queues *queues);
523 int auxtrace_queues__process_index(struct auxtrace_queues *queues,
524 				   struct perf_session *session);
525 int auxtrace_queue_data(struct perf_session *session, bool samples,
526 			bool events);
527 struct auxtrace_buffer *auxtrace_buffer__next(struct auxtrace_queue *queue,
528 					      struct auxtrace_buffer *buffer);
529 void *auxtrace_buffer__get_data_rw(struct auxtrace_buffer *buffer, int fd, bool rw);
530 static inline void *auxtrace_buffer__get_data(struct auxtrace_buffer *buffer, int fd)
531 {
532 	return auxtrace_buffer__get_data_rw(buffer, fd, false);
533 }
534 void auxtrace_buffer__put_data(struct auxtrace_buffer *buffer);
535 void auxtrace_buffer__drop_data(struct auxtrace_buffer *buffer);
536 void auxtrace_buffer__free(struct auxtrace_buffer *buffer);
537 
538 int auxtrace_heap__add(struct auxtrace_heap *heap, unsigned int queue_nr,
539 		       u64 ordinal);
540 void auxtrace_heap__pop(struct auxtrace_heap *heap);
541 void auxtrace_heap__free(struct auxtrace_heap *heap);
542 
543 struct auxtrace_cache_entry {
544 	struct hlist_node hash;
545 	u32 key;
546 };
547 
548 struct auxtrace_cache *auxtrace_cache__new(unsigned int bits, size_t entry_size,
549 					   unsigned int limit_percent);
550 void auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache);
551 void *auxtrace_cache__alloc_entry(struct auxtrace_cache *c);
552 void auxtrace_cache__free_entry(struct auxtrace_cache *c, void *entry);
553 int auxtrace_cache__add(struct auxtrace_cache *c, u32 key,
554 			struct auxtrace_cache_entry *entry);
555 void auxtrace_cache__remove(struct auxtrace_cache *c, u32 key);
556 void *auxtrace_cache__lookup(struct auxtrace_cache *c, u32 key);
557 
558 struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
559 					      int *err);
560 
561 int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
562 				    struct record_opts *opts,
563 				    const char *str);
564 int auxtrace_parse_sample_options(struct auxtrace_record *itr,
565 				  struct evlist *evlist,
566 				  struct record_opts *opts, const char *str);
567 void auxtrace_regroup_aux_output(struct evlist *evlist);
568 int auxtrace_record__options(struct auxtrace_record *itr,
569 			     struct evlist *evlist,
570 			     struct record_opts *opts);
571 size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr,
572 				       struct evlist *evlist);
573 int auxtrace_record__info_fill(struct auxtrace_record *itr,
574 			       struct perf_session *session,
575 			       struct perf_record_auxtrace_info *auxtrace_info,
576 			       size_t priv_size);
577 void auxtrace_record__free(struct auxtrace_record *itr);
578 int auxtrace_record__snapshot_start(struct auxtrace_record *itr);
579 int auxtrace_record__snapshot_finish(struct auxtrace_record *itr, bool on_exit);
580 int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
581 				   struct auxtrace_mmap *mm,
582 				   unsigned char *data, u64 *head, u64 *old);
583 u64 auxtrace_record__reference(struct auxtrace_record *itr);
584 int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
585 
586 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
587 				   off_t file_offset);
588 int auxtrace_index__write(int fd, struct list_head *head);
589 int auxtrace_index__process(int fd, u64 size, struct perf_session *session,
590 			    bool needs_swap);
591 void auxtrace_index__free(struct list_head *head);
592 
593 void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type,
594 			  int code, int cpu, pid_t pid, pid_t tid, u64 ip,
595 			  const char *msg, u64 timestamp);
596 
597 int perf_event__process_auxtrace_info(struct perf_session *session,
598 				      union perf_event *event);
599 s64 perf_event__process_auxtrace(struct perf_session *session,
600 				 union perf_event *event);
601 int perf_event__process_auxtrace_error(struct perf_session *session,
602 				       union perf_event *event);
603 int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
604 			       const char *str, int unset);
605 int itrace_parse_synth_opts(const struct option *opt, const char *str,
606 			    int unset);
607 void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
608 				    bool no_sample);
609 
610 size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp);
611 void perf_session__auxtrace_error_inc(struct perf_session *session,
612 				      union perf_event *event);
613 void events_stats__auxtrace_error_warn(const struct events_stats *stats);
614 
615 void addr_filters__init(struct addr_filters *filts);
616 void addr_filters__exit(struct addr_filters *filts);
617 int addr_filters__parse_bare_filter(struct addr_filters *filts,
618 				    const char *filter);
619 int auxtrace_parse_filters(struct evlist *evlist);
620 
621 int auxtrace__process_event(struct perf_session *session, union perf_event *event,
622 			    struct perf_sample *sample, struct perf_tool *tool);
623 void auxtrace__dump_auxtrace_sample(struct perf_session *session,
624 				    struct perf_sample *sample);
625 int auxtrace__flush_events(struct perf_session *session, struct perf_tool *tool);
626 void auxtrace__free_events(struct perf_session *session);
627 void auxtrace__free(struct perf_session *session);
628 bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
629 				 struct evsel *evsel);
630 
631 #define ITRACE_HELP \
632 "				i[period]:    		synthesize instructions events\n" \
633 "				b:	    		synthesize branches events (branch misses for Arm SPE)\n" \
634 "				c:	    		synthesize branches events (calls only)\n"	\
635 "				r:	    		synthesize branches events (returns only)\n" \
636 "				x:	    		synthesize transactions events\n"		\
637 "				w:	    		synthesize ptwrite events\n"		\
638 "				p:	    		synthesize power events\n"			\
639 "				o:			synthesize other events recorded due to the use\n" \
640 "							of aux-output (refer to perf record)\n"	\
641 "				I:			synthesize interrupt or similar (asynchronous) events\n" \
642 "							(e.g. Intel PT Event Trace)\n" \
643 "				e[flags]:		synthesize error events\n" \
644 "							each flag must be preceded by + or -\n" \
645 "							error flags are: o (overflow)\n" \
646 "									 l (data lost)\n" \
647 "				d[flags]:		create a debug log\n" \
648 "							each flag must be preceded by + or -\n" \
649 "							log flags are: a (all perf events)\n" \
650 "							               o (output to stdout)\n" \
651 "				f:	    		synthesize first level cache events\n" \
652 "				m:	    		synthesize last level cache events\n" \
653 "				t:	    		synthesize TLB events\n" \
654 "				a:	    		synthesize remote access events\n" \
655 "				g[len]:     		synthesize a call chain (use with i or x)\n" \
656 "				G[len]:			synthesize a call chain on existing event records\n" \
657 "				l[len]:     		synthesize last branch entries (use with i or x)\n" \
658 "				L[len]:			synthesize last branch entries on existing event records\n" \
659 "				sNUMBER:    		skip initial number of events\n"		\
660 "				q:			quicker (less detailed) decoding\n" \
661 "				A:			approximate IPC\n" \
662 "				Z:			prefer to ignore timestamps (so-called \"timeless\" decoding)\n" \
663 "				PERIOD[ns|us|ms|i|t]:   specify period to sample stream\n" \
664 "				concatenate multiple options. Default is ibxwpe or cewp\n"
665 
666 static inline
667 void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts,
668 				       struct perf_time_interval *ptime_range,
669 				       int range_num)
670 {
671 	opts->ptime_range = ptime_range;
672 	opts->range_num = range_num;
673 }
674 
675 static inline
676 void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
677 {
678 	opts->ptime_range = NULL;
679 	opts->range_num = 0;
680 }
681 
682 #else
683 #include "debug.h"
684 
685 static inline struct auxtrace_record *
686 auxtrace_record__init(struct evlist *evlist __maybe_unused,
687 		      int *err)
688 {
689 	*err = 0;
690 	return NULL;
691 }
692 
693 static inline
694 void auxtrace_record__free(struct auxtrace_record *itr __maybe_unused)
695 {
696 }
697 
698 static inline
699 int auxtrace_record__options(struct auxtrace_record *itr __maybe_unused,
700 			     struct evlist *evlist __maybe_unused,
701 			     struct record_opts *opts __maybe_unused)
702 {
703 	return 0;
704 }
705 
706 static inline
707 int perf_event__process_auxtrace_info(struct perf_session *session __maybe_unused,
708 				      union perf_event *event __maybe_unused)
709 {
710 	return 0;
711 }
712 
713 static inline
714 s64 perf_event__process_auxtrace(struct perf_session *session __maybe_unused,
715 				 union perf_event *event __maybe_unused)
716 {
717 	return 0;
718 }
719 
720 static inline
721 int perf_event__process_auxtrace_error(struct perf_session *session __maybe_unused,
722 				       union perf_event *event __maybe_unused)
723 {
724 	return 0;
725 }
726 
727 static inline
728 void perf_session__auxtrace_error_inc(struct perf_session *session
729 				      __maybe_unused,
730 				      union perf_event *event
731 				      __maybe_unused)
732 {
733 }
734 
735 static inline
736 void events_stats__auxtrace_error_warn(const struct events_stats *stats
737 				       __maybe_unused)
738 {
739 }
740 
741 static inline
742 int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts __maybe_unused,
743 			       const char *str __maybe_unused, int unset __maybe_unused)
744 {
745 	pr_err("AUX area tracing not supported\n");
746 	return -EINVAL;
747 }
748 
749 static inline
750 int itrace_parse_synth_opts(const struct option *opt __maybe_unused,
751 			    const char *str __maybe_unused,
752 			    int unset __maybe_unused)
753 {
754 	pr_err("AUX area tracing not supported\n");
755 	return -EINVAL;
756 }
757 
758 static inline
759 int auxtrace_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
760 				    struct record_opts *opts __maybe_unused,
761 				    const char *str)
762 {
763 	if (!str)
764 		return 0;
765 	pr_err("AUX area tracing not supported\n");
766 	return -EINVAL;
767 }
768 
769 static inline
770 int auxtrace_parse_sample_options(struct auxtrace_record *itr __maybe_unused,
771 				  struct evlist *evlist __maybe_unused,
772 				  struct record_opts *opts __maybe_unused,
773 				  const char *str)
774 {
775 	if (!str)
776 		return 0;
777 	pr_err("AUX area tracing not supported\n");
778 	return -EINVAL;
779 }
780 
781 static inline
782 void auxtrace_regroup_aux_output(struct evlist *evlist __maybe_unused)
783 {
784 }
785 
786 static inline
787 int auxtrace__process_event(struct perf_session *session __maybe_unused,
788 			    union perf_event *event __maybe_unused,
789 			    struct perf_sample *sample __maybe_unused,
790 			    struct perf_tool *tool __maybe_unused)
791 {
792 	return 0;
793 }
794 
795 static inline
796 void auxtrace__dump_auxtrace_sample(struct perf_session *session __maybe_unused,
797 				    struct perf_sample *sample __maybe_unused)
798 {
799 }
800 
801 static inline
802 int auxtrace__flush_events(struct perf_session *session __maybe_unused,
803 			   struct perf_tool *tool __maybe_unused)
804 {
805 	return 0;
806 }
807 
808 static inline
809 void auxtrace__free_events(struct perf_session *session __maybe_unused)
810 {
811 }
812 
813 static inline
814 void auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache __maybe_unused)
815 {
816 }
817 
818 static inline
819 void auxtrace__free(struct perf_session *session __maybe_unused)
820 {
821 }
822 
823 static inline
824 int auxtrace_index__write(int fd __maybe_unused,
825 			  struct list_head *head __maybe_unused)
826 {
827 	return -EINVAL;
828 }
829 
830 static inline
831 int auxtrace_index__process(int fd __maybe_unused,
832 			    u64 size __maybe_unused,
833 			    struct perf_session *session __maybe_unused,
834 			    bool needs_swap __maybe_unused)
835 {
836 	return -EINVAL;
837 }
838 
839 static inline
840 void auxtrace_index__free(struct list_head *head __maybe_unused)
841 {
842 }
843 
844 static inline
845 bool auxtrace__evsel_is_auxtrace(struct perf_session *session __maybe_unused,
846 				 struct evsel *evsel __maybe_unused)
847 {
848 	return false;
849 }
850 
851 static inline
852 int auxtrace_parse_filters(struct evlist *evlist __maybe_unused)
853 {
854 	return 0;
855 }
856 
857 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
858 			struct auxtrace_mmap_params *mp,
859 			void *userpg, int fd);
860 void auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
861 void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
862 				off_t auxtrace_offset,
863 				unsigned int auxtrace_pages,
864 				bool auxtrace_overwrite);
865 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
866 				   struct evlist *evlist, int idx,
867 				   bool per_cpu);
868 
869 #define ITRACE_HELP ""
870 
871 static inline
872 void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts
873 				       __maybe_unused,
874 				       struct perf_time_interval *ptime_range
875 				       __maybe_unused,
876 				       int range_num __maybe_unused)
877 {
878 }
879 
880 static inline
881 void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts
882 					 __maybe_unused)
883 {
884 }
885 
886 #endif
887 
888 #endif
889