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