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