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