Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * auxtrace.h: AUX area trace support
0004  * Copyright (c) 2013-2015, Intel Corporation.
0005  */
0006 
0007 #ifndef __PERF_AUXTRACE_H
0008 #define __PERF_AUXTRACE_H
0009 
0010 #include <sys/types.h>
0011 #include <errno.h>
0012 #include <stdbool.h>
0013 #include <stddef.h>
0014 #include <stdio.h> // FILE
0015 #include <linux/list.h>
0016 #include <linux/perf_event.h>
0017 #include <linux/types.h>
0018 #include <internal/cpumap.h>
0019 #include <asm/bitsperlong.h>
0020 #include <asm/barrier.h>
0021 
0022 union perf_event;
0023 struct perf_session;
0024 struct evlist;
0025 struct evsel;
0026 struct perf_tool;
0027 struct mmap;
0028 struct perf_sample;
0029 struct option;
0030 struct record_opts;
0031 struct perf_record_auxtrace_error;
0032 struct perf_record_auxtrace_info;
0033 struct events_stats;
0034 struct perf_pmu;
0035 
0036 enum auxtrace_error_type {
0037        PERF_AUXTRACE_ERROR_ITRACE  = 1,
0038        PERF_AUXTRACE_ERROR_MAX
0039 };
0040 
0041 /* Auxtrace records must have the same alignment as perf event records */
0042 #define PERF_AUXTRACE_RECORD_ALIGNMENT 8
0043 
0044 enum auxtrace_type {
0045     PERF_AUXTRACE_UNKNOWN,
0046     PERF_AUXTRACE_INTEL_PT,
0047     PERF_AUXTRACE_INTEL_BTS,
0048     PERF_AUXTRACE_CS_ETM,
0049     PERF_AUXTRACE_ARM_SPE,
0050     PERF_AUXTRACE_S390_CPUMSF,
0051 };
0052 
0053 enum itrace_period_type {
0054     PERF_ITRACE_PERIOD_INSTRUCTIONS,
0055     PERF_ITRACE_PERIOD_TICKS,
0056     PERF_ITRACE_PERIOD_NANOSECS,
0057 };
0058 
0059 #define AUXTRACE_ERR_FLG_OVERFLOW   (1 << ('o' - 'a'))
0060 #define AUXTRACE_ERR_FLG_DATA_LOST  (1 << ('l' - 'a'))
0061 
0062 #define AUXTRACE_LOG_FLG_ALL_PERF_EVTS  (1 << ('a' - 'a'))
0063 #define AUXTRACE_LOG_FLG_USE_STDOUT (1 << ('o' - 'a'))
0064 
0065 /**
0066  * struct itrace_synth_opts - AUX area tracing synthesis options.
0067  * @set: indicates whether or not options have been set
0068  * @default_no_sample: Default to no sampling.
0069  * @inject: indicates the event (not just the sample) must be fully synthesized
0070  *          because 'perf inject' will write it out
0071  * @instructions: whether to synthesize 'instructions' events
0072  * @branches: whether to synthesize 'branches' events
0073  *            (branch misses only for Arm SPE)
0074  * @transactions: whether to synthesize events for transactions
0075  * @ptwrites: whether to synthesize events for ptwrites
0076  * @pwr_events: whether to synthesize power events
0077  * @other_events: whether to synthesize other events recorded due to the use of
0078  *                aux_output
0079  * @intr_events: whether to synthesize interrupt events
0080  * @errors: whether to synthesize decoder error events
0081  * @dont_decode: whether to skip decoding entirely
0082  * @log: write a decoding log
0083  * @calls: limit branch samples to calls (can be combined with @returns)
0084  * @returns: limit branch samples to returns (can be combined with @calls)
0085  * @callchain: add callchain to 'instructions' events
0086  * @add_callchain: add callchain to existing event records
0087  * @thread_stack: feed branches to the thread_stack
0088  * @last_branch: add branch context to 'instruction' events
0089  * @add_last_branch: add branch context to existing event records
0090  * @approx_ipc: approximate IPC
0091  * @flc: whether to synthesize first level cache events
0092  * @llc: whether to synthesize last level cache events
0093  * @tlb: whether to synthesize TLB events
0094  * @remote_access: whether to synthesize remote access events
0095  * @mem: whether to synthesize memory events
0096  * @timeless_decoding: prefer "timeless" decoding i.e. ignore timestamps
0097  * @vm_time_correlation: perform VM Time Correlation
0098  * @vm_tm_corr_dry_run: VM Time Correlation dry-run
0099  * @vm_tm_corr_args:  VM Time Correlation implementation-specific arguments
0100  * @callchain_sz: maximum callchain size
0101  * @last_branch_sz: branch context size
0102  * @period: 'instructions' events period
0103  * @period_type: 'instructions' events period type
0104  * @initial_skip: skip N events at the beginning.
0105  * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
0106  * @ptime_range: time intervals to trace or NULL
0107  * @range_num: number of time intervals to trace
0108  * @error_plus_flags: flags to affect what errors are reported
0109  * @error_minus_flags: flags to affect what errors are reported
0110  * @log_plus_flags: flags to affect what is logged
0111  * @log_minus_flags: flags to affect what is logged
0112  * @quick: quicker (less detailed) decoding
0113  */
0114 struct itrace_synth_opts {
0115     bool            set;
0116     bool            default_no_sample;
0117     bool            inject;
0118     bool            instructions;
0119     bool            branches;
0120     bool            transactions;
0121     bool            ptwrites;
0122     bool            pwr_events;
0123     bool            other_events;
0124     bool            intr_events;
0125     bool            errors;
0126     bool            dont_decode;
0127     bool            log;
0128     bool            calls;
0129     bool            returns;
0130     bool            callchain;
0131     bool            add_callchain;
0132     bool            thread_stack;
0133     bool            last_branch;
0134     bool            add_last_branch;
0135     bool            approx_ipc;
0136     bool            flc;
0137     bool            llc;
0138     bool            tlb;
0139     bool            remote_access;
0140     bool            mem;
0141     bool            timeless_decoding;
0142     bool            vm_time_correlation;
0143     bool            vm_tm_corr_dry_run;
0144     char            *vm_tm_corr_args;
0145     unsigned int        callchain_sz;
0146     unsigned int        last_branch_sz;
0147     unsigned long long  period;
0148     enum itrace_period_type period_type;
0149     unsigned long       initial_skip;
0150     unsigned long       *cpu_bitmap;
0151     struct perf_time_interval *ptime_range;
0152     int         range_num;
0153     unsigned int        error_plus_flags;
0154     unsigned int        error_minus_flags;
0155     unsigned int        log_plus_flags;
0156     unsigned int        log_minus_flags;
0157     unsigned int        quick;
0158 };
0159 
0160 /**
0161  * struct auxtrace_index_entry - indexes a AUX area tracing event within a
0162  *                               perf.data file.
0163  * @file_offset: offset within the perf.data file
0164  * @sz: size of the event
0165  */
0166 struct auxtrace_index_entry {
0167     u64         file_offset;
0168     u64         sz;
0169 };
0170 
0171 #define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
0172 
0173 /**
0174  * struct auxtrace_index - index of AUX area tracing events within a perf.data
0175  *                         file.
0176  * @list: linking a number of arrays of entries
0177  * @nr: number of entries
0178  * @entries: array of entries
0179  */
0180 struct auxtrace_index {
0181     struct list_head    list;
0182     size_t          nr;
0183     struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
0184 };
0185 
0186 /**
0187  * struct auxtrace - session callbacks to allow AUX area data decoding.
0188  * @process_event: lets the decoder see all session events
0189  * @process_auxtrace_event: process a PERF_RECORD_AUXTRACE event
0190  * @queue_data: queue an AUX sample or PERF_RECORD_AUXTRACE event for later
0191  *              processing
0192  * @dump_auxtrace_sample: dump AUX area sample data
0193  * @flush_events: process any remaining data
0194  * @free_events: free resources associated with event processing
0195  * @free: free resources associated with the session
0196  */
0197 struct auxtrace {
0198     int (*process_event)(struct perf_session *session,
0199                  union perf_event *event,
0200                  struct perf_sample *sample,
0201                  struct perf_tool *tool);
0202     int (*process_auxtrace_event)(struct perf_session *session,
0203                       union perf_event *event,
0204                       struct perf_tool *tool);
0205     int (*queue_data)(struct perf_session *session,
0206               struct perf_sample *sample, union perf_event *event,
0207               u64 data_offset);
0208     void (*dump_auxtrace_sample)(struct perf_session *session,
0209                      struct perf_sample *sample);
0210     int (*flush_events)(struct perf_session *session,
0211                 struct perf_tool *tool);
0212     void (*free_events)(struct perf_session *session);
0213     void (*free)(struct perf_session *session);
0214     bool (*evsel_is_auxtrace)(struct perf_session *session,
0215                   struct evsel *evsel);
0216 };
0217 
0218 /**
0219  * struct auxtrace_buffer - a buffer containing AUX area tracing data.
0220  * @list: buffers are queued in a list held by struct auxtrace_queue
0221  * @size: size of the buffer in bytes
0222  * @pid: in per-thread mode, the pid this buffer is associated with
0223  * @tid: in per-thread mode, the tid this buffer is associated with
0224  * @cpu: in per-cpu mode, the cpu this buffer is associated with
0225  * @data: actual buffer data (can be null if the data has not been loaded)
0226  * @data_offset: file offset at which the buffer can be read
0227  * @mmap_addr: mmap address at which the buffer can be read
0228  * @mmap_size: size of the mmap at @mmap_addr
0229  * @data_needs_freeing: @data was malloc'd so free it when it is no longer
0230  *                      needed
0231  * @consecutive: the original data was split up and this buffer is consecutive
0232  *               to the previous buffer
0233  * @offset: offset as determined by aux_head / aux_tail members of struct
0234  *          perf_event_mmap_page
0235  * @reference: an implementation-specific reference determined when the data is
0236  *             recorded
0237  * @buffer_nr: used to number each buffer
0238  * @use_size: implementation actually only uses this number of bytes
0239  * @use_data: implementation actually only uses data starting at this address
0240  */
0241 struct auxtrace_buffer {
0242     struct list_head    list;
0243     size_t          size;
0244     pid_t           pid;
0245     pid_t           tid;
0246     struct perf_cpu     cpu;
0247     void            *data;
0248     off_t           data_offset;
0249     void            *mmap_addr;
0250     size_t          mmap_size;
0251     bool            data_needs_freeing;
0252     bool            consecutive;
0253     u64         offset;
0254     u64         reference;
0255     u64         buffer_nr;
0256     size_t          use_size;
0257     void            *use_data;
0258 };
0259 
0260 /**
0261  * struct auxtrace_queue - a queue of AUX area tracing data buffers.
0262  * @head: head of buffer list
0263  * @tid: in per-thread mode, the tid this queue is associated with
0264  * @cpu: in per-cpu mode, the cpu this queue is associated with
0265  * @set: %true once this queue has been dedicated to a specific thread or cpu
0266  * @priv: implementation-specific data
0267  */
0268 struct auxtrace_queue {
0269     struct list_head    head;
0270     pid_t           tid;
0271     int         cpu;
0272     bool            set;
0273     void            *priv;
0274 };
0275 
0276 /**
0277  * struct auxtrace_queues - an array of AUX area tracing queues.
0278  * @queue_array: array of queues
0279  * @nr_queues: number of queues
0280  * @new_data: set whenever new data is queued
0281  * @populated: queues have been fully populated using the auxtrace_index
0282  * @next_buffer_nr: used to number each buffer
0283  */
0284 struct auxtrace_queues {
0285     struct auxtrace_queue   *queue_array;
0286     unsigned int        nr_queues;
0287     bool            new_data;
0288     bool            populated;
0289     u64         next_buffer_nr;
0290 };
0291 
0292 /**
0293  * struct auxtrace_heap_item - element of struct auxtrace_heap.
0294  * @queue_nr: queue number
0295  * @ordinal: value used for sorting (lowest ordinal is top of the heap) expected
0296  *           to be a timestamp
0297  */
0298 struct auxtrace_heap_item {
0299     unsigned int        queue_nr;
0300     u64         ordinal;
0301 };
0302 
0303 /**
0304  * struct auxtrace_heap - a heap suitable for sorting AUX area tracing queues.
0305  * @heap_array: the heap
0306  * @heap_cnt: the number of elements in the heap
0307  * @heap_sz: maximum number of elements (grows as needed)
0308  */
0309 struct auxtrace_heap {
0310     struct auxtrace_heap_item   *heap_array;
0311     unsigned int        heap_cnt;
0312     unsigned int        heap_sz;
0313 };
0314 
0315 /**
0316  * struct auxtrace_mmap - records an mmap of the auxtrace buffer.
0317  * @base: address of mapped area
0318  * @userpg: pointer to buffer's perf_event_mmap_page
0319  * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
0320  * @len: size of mapped area
0321  * @prev: previous aux_head
0322  * @idx: index of this mmap
0323  * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
0324  *       mmap) otherwise %0
0325  * @cpu: cpu number for a per-cpu mmap otherwise %-1
0326  */
0327 struct auxtrace_mmap {
0328     void        *base;
0329     void        *userpg;
0330     size_t      mask;
0331     size_t      len;
0332     u64     prev;
0333     int     idx;
0334     pid_t       tid;
0335     int     cpu;
0336 };
0337 
0338 /**
0339  * struct auxtrace_mmap_params - parameters to set up struct auxtrace_mmap.
0340  * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
0341  * @offset: file offset of mapped area
0342  * @len: size of mapped area
0343  * @prot: mmap memory protection
0344  * @idx: index of this mmap
0345  * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
0346  *       mmap) otherwise %0
0347  * @mmap_needed: set to %false for non-auxtrace events. This is needed because
0348  *               auxtrace mmapping is done in the same code path as non-auxtrace
0349  *               mmapping but not every evsel that needs non-auxtrace mmapping
0350  *               also needs auxtrace mmapping.
0351  * @cpu: cpu number for a per-cpu mmap otherwise %-1
0352  */
0353 struct auxtrace_mmap_params {
0354     size_t      mask;
0355     off_t       offset;
0356     size_t      len;
0357     int     prot;
0358     int     idx;
0359     pid_t       tid;
0360     bool        mmap_needed;
0361     struct perf_cpu cpu;
0362 };
0363 
0364 /**
0365  * struct auxtrace_record - callbacks for recording AUX area data.
0366  * @recording_options: validate and process recording options
0367  * @info_priv_size: return the size of the private data in auxtrace_info_event
0368  * @info_fill: fill-in the private data in auxtrace_info_event
0369  * @free: free this auxtrace record structure
0370  * @snapshot_start: starting a snapshot
0371  * @snapshot_finish: finishing a snapshot
0372  * @find_snapshot: find data to snapshot within auxtrace mmap
0373  * @parse_snapshot_options: parse snapshot options
0374  * @reference: provide a 64-bit reference number for auxtrace_event
0375  * @read_finish: called after reading from an auxtrace mmap
0376  * @alignment: alignment (if any) for AUX area data
0377  * @default_aux_sample_size: default sample size for --aux sample option
0378  * @pmu: associated pmu
0379  * @evlist: selected events list
0380  */
0381 struct auxtrace_record {
0382     int (*recording_options)(struct auxtrace_record *itr,
0383                  struct evlist *evlist,
0384                  struct record_opts *opts);
0385     size_t (*info_priv_size)(struct auxtrace_record *itr,
0386                  struct evlist *evlist);
0387     int (*info_fill)(struct auxtrace_record *itr,
0388              struct perf_session *session,
0389              struct perf_record_auxtrace_info *auxtrace_info,
0390              size_t priv_size);
0391     void (*free)(struct auxtrace_record *itr);
0392     int (*snapshot_start)(struct auxtrace_record *itr);
0393     int (*snapshot_finish)(struct auxtrace_record *itr);
0394     int (*find_snapshot)(struct auxtrace_record *itr, int idx,
0395                  struct auxtrace_mmap *mm, unsigned char *data,
0396                  u64 *head, u64 *old);
0397     int (*parse_snapshot_options)(struct auxtrace_record *itr,
0398                       struct record_opts *opts,
0399                       const char *str);
0400     u64 (*reference)(struct auxtrace_record *itr);
0401     int (*read_finish)(struct auxtrace_record *itr, int idx);
0402     unsigned int alignment;
0403     unsigned int default_aux_sample_size;
0404     struct perf_pmu *pmu;
0405     struct evlist *evlist;
0406 };
0407 
0408 /**
0409  * struct addr_filter - address filter.
0410  * @list: list node
0411  * @range: true if it is a range filter
0412  * @start: true if action is 'filter' or 'start'
0413  * @action: 'filter', 'start' or 'stop' ('tracestop' is accepted but converted
0414  *          to 'stop')
0415  * @sym_from: symbol name for the filter address
0416  * @sym_to: symbol name that determines the filter size
0417  * @sym_from_idx: selects n'th from symbols with the same name (0 means global
0418  *                and less than 0 means symbol must be unique)
0419  * @sym_to_idx: same as @sym_from_idx but for @sym_to
0420  * @addr: filter address
0421  * @size: filter region size (for range filters)
0422  * @filename: DSO file name or NULL for the kernel
0423  * @str: allocated string that contains the other string members
0424  */
0425 struct addr_filter {
0426     struct list_head    list;
0427     bool            range;
0428     bool            start;
0429     const char      *action;
0430     const char      *sym_from;
0431     const char      *sym_to;
0432     int         sym_from_idx;
0433     int         sym_to_idx;
0434     u64         addr;
0435     u64         size;
0436     const char      *filename;
0437     char            *str;
0438 };
0439 
0440 /**
0441  * struct addr_filters - list of address filters.
0442  * @head: list of address filters
0443  * @cnt: number of address filters
0444  */
0445 struct addr_filters {
0446     struct list_head    head;
0447     int         cnt;
0448 };
0449 
0450 struct auxtrace_cache;
0451 
0452 #ifdef HAVE_AUXTRACE_SUPPORT
0453 
0454 u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm);
0455 int compat_auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail);
0456 
0457 static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm,
0458                        int kernel_is_64_bit __maybe_unused)
0459 {
0460     struct perf_event_mmap_page *pc = mm->userpg;
0461     u64 head;
0462 
0463 #if BITS_PER_LONG == 32
0464     if (kernel_is_64_bit)
0465         return compat_auxtrace_mmap__read_head(mm);
0466 #endif
0467     head = READ_ONCE(pc->aux_head);
0468 
0469     /* Ensure all reads are done after we read the head */
0470     smp_rmb();
0471     return head;
0472 }
0473 
0474 static inline int auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail,
0475                         int kernel_is_64_bit __maybe_unused)
0476 {
0477     struct perf_event_mmap_page *pc = mm->userpg;
0478 
0479 #if BITS_PER_LONG == 32
0480     if (kernel_is_64_bit)
0481         return compat_auxtrace_mmap__write_tail(mm, tail);
0482 #endif
0483     /* Ensure all reads are done before we write the tail out */
0484     smp_mb();
0485     WRITE_ONCE(pc->aux_tail, tail);
0486     return 0;
0487 }
0488 
0489 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
0490             struct auxtrace_mmap_params *mp,
0491             void *userpg, int fd);
0492 void auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
0493 void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
0494                 off_t auxtrace_offset,
0495                 unsigned int auxtrace_pages,
0496                 bool auxtrace_overwrite);
0497 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
0498                    struct evlist *evlist,
0499                    struct evsel *evsel, int idx);
0500 
0501 typedef int (*process_auxtrace_t)(struct perf_tool *tool,
0502                   struct mmap *map,
0503                   union perf_event *event, void *data1,
0504                   size_t len1, void *data2, size_t len2);
0505 
0506 int auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
0507             struct perf_tool *tool, process_auxtrace_t fn);
0508 
0509 int auxtrace_mmap__read_snapshot(struct mmap *map,
0510                  struct auxtrace_record *itr,
0511                  struct perf_tool *tool, process_auxtrace_t fn,
0512                  size_t snapshot_size);
0513 
0514 int auxtrace_queues__init(struct auxtrace_queues *queues);
0515 int auxtrace_queues__add_event(struct auxtrace_queues *queues,
0516                    struct perf_session *session,
0517                    union perf_event *event, off_t data_offset,
0518                    struct auxtrace_buffer **buffer_ptr);
0519 struct auxtrace_queue *
0520 auxtrace_queues__sample_queue(struct auxtrace_queues *queues,
0521                   struct perf_sample *sample,
0522                   struct perf_session *session);
0523 int auxtrace_queues__add_sample(struct auxtrace_queues *queues,
0524                 struct perf_session *session,
0525                 struct perf_sample *sample, u64 data_offset,
0526                 u64 reference);
0527 void auxtrace_queues__free(struct auxtrace_queues *queues);
0528 int auxtrace_queues__process_index(struct auxtrace_queues *queues,
0529                    struct perf_session *session);
0530 int auxtrace_queue_data(struct perf_session *session, bool samples,
0531             bool events);
0532 struct auxtrace_buffer *auxtrace_buffer__next(struct auxtrace_queue *queue,
0533                           struct auxtrace_buffer *buffer);
0534 void *auxtrace_buffer__get_data_rw(struct auxtrace_buffer *buffer, int fd, bool rw);
0535 static inline void *auxtrace_buffer__get_data(struct auxtrace_buffer *buffer, int fd)
0536 {
0537     return auxtrace_buffer__get_data_rw(buffer, fd, false);
0538 }
0539 void auxtrace_buffer__put_data(struct auxtrace_buffer *buffer);
0540 void auxtrace_buffer__drop_data(struct auxtrace_buffer *buffer);
0541 void auxtrace_buffer__free(struct auxtrace_buffer *buffer);
0542 
0543 int auxtrace_heap__add(struct auxtrace_heap *heap, unsigned int queue_nr,
0544                u64 ordinal);
0545 void auxtrace_heap__pop(struct auxtrace_heap *heap);
0546 void auxtrace_heap__free(struct auxtrace_heap *heap);
0547 
0548 struct auxtrace_cache_entry {
0549     struct hlist_node hash;
0550     u32 key;
0551 };
0552 
0553 struct auxtrace_cache *auxtrace_cache__new(unsigned int bits, size_t entry_size,
0554                        unsigned int limit_percent);
0555 void auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache);
0556 void *auxtrace_cache__alloc_entry(struct auxtrace_cache *c);
0557 void auxtrace_cache__free_entry(struct auxtrace_cache *c, void *entry);
0558 int auxtrace_cache__add(struct auxtrace_cache *c, u32 key,
0559             struct auxtrace_cache_entry *entry);
0560 void auxtrace_cache__remove(struct auxtrace_cache *c, u32 key);
0561 void *auxtrace_cache__lookup(struct auxtrace_cache *c, u32 key);
0562 
0563 struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
0564                           int *err);
0565 
0566 int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
0567                     struct record_opts *opts,
0568                     const char *str);
0569 int auxtrace_parse_sample_options(struct auxtrace_record *itr,
0570                   struct evlist *evlist,
0571                   struct record_opts *opts, const char *str);
0572 void auxtrace_regroup_aux_output(struct evlist *evlist);
0573 int auxtrace_record__options(struct auxtrace_record *itr,
0574                  struct evlist *evlist,
0575                  struct record_opts *opts);
0576 size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr,
0577                        struct evlist *evlist);
0578 int auxtrace_record__info_fill(struct auxtrace_record *itr,
0579                    struct perf_session *session,
0580                    struct perf_record_auxtrace_info *auxtrace_info,
0581                    size_t priv_size);
0582 void auxtrace_record__free(struct auxtrace_record *itr);
0583 int auxtrace_record__snapshot_start(struct auxtrace_record *itr);
0584 int auxtrace_record__snapshot_finish(struct auxtrace_record *itr, bool on_exit);
0585 int auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
0586                    struct auxtrace_mmap *mm,
0587                    unsigned char *data, u64 *head, u64 *old);
0588 u64 auxtrace_record__reference(struct auxtrace_record *itr);
0589 int auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
0590 
0591 int auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
0592                    off_t file_offset);
0593 int auxtrace_index__write(int fd, struct list_head *head);
0594 int auxtrace_index__process(int fd, u64 size, struct perf_session *session,
0595                 bool needs_swap);
0596 void auxtrace_index__free(struct list_head *head);
0597 
0598 void auxtrace_synth_guest_error(struct perf_record_auxtrace_error *auxtrace_error, int type,
0599                 int code, int cpu, pid_t pid, pid_t tid, u64 ip,
0600                 const char *msg, u64 timestamp,
0601                 pid_t machine_pid, int vcpu);
0602 void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type,
0603               int code, int cpu, pid_t pid, pid_t tid, u64 ip,
0604               const char *msg, u64 timestamp);
0605 
0606 int perf_event__process_auxtrace_info(struct perf_session *session,
0607                       union perf_event *event);
0608 s64 perf_event__process_auxtrace(struct perf_session *session,
0609                  union perf_event *event);
0610 int perf_event__process_auxtrace_error(struct perf_session *session,
0611                        union perf_event *event);
0612 int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts,
0613                    const char *str, int unset);
0614 int itrace_parse_synth_opts(const struct option *opt, const char *str,
0615                 int unset);
0616 void itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
0617                     bool no_sample);
0618 
0619 size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp);
0620 void perf_session__auxtrace_error_inc(struct perf_session *session,
0621                       union perf_event *event);
0622 void events_stats__auxtrace_error_warn(const struct events_stats *stats);
0623 
0624 void addr_filters__init(struct addr_filters *filts);
0625 void addr_filters__exit(struct addr_filters *filts);
0626 int addr_filters__parse_bare_filter(struct addr_filters *filts,
0627                     const char *filter);
0628 int auxtrace_parse_filters(struct evlist *evlist);
0629 
0630 int auxtrace__process_event(struct perf_session *session, union perf_event *event,
0631                 struct perf_sample *sample, struct perf_tool *tool);
0632 void auxtrace__dump_auxtrace_sample(struct perf_session *session,
0633                     struct perf_sample *sample);
0634 int auxtrace__flush_events(struct perf_session *session, struct perf_tool *tool);
0635 void auxtrace__free_events(struct perf_session *session);
0636 void auxtrace__free(struct perf_session *session);
0637 bool auxtrace__evsel_is_auxtrace(struct perf_session *session,
0638                  struct evsel *evsel);
0639 
0640 #define ITRACE_HELP \
0641 "               i[period]:          synthesize instructions events\n" \
0642 "               b:              synthesize branches events (branch misses for Arm SPE)\n" \
0643 "               c:              synthesize branches events (calls only)\n"  \
0644 "               r:              synthesize branches events (returns only)\n" \
0645 "               x:              synthesize transactions events\n"       \
0646 "               w:              synthesize ptwrite events\n"        \
0647 "               p:              synthesize power events\n"          \
0648 "               o:          synthesize other events recorded due to the use\n" \
0649 "                           of aux-output (refer to perf record)\n" \
0650 "               I:          synthesize interrupt or similar (asynchronous) events\n" \
0651 "                           (e.g. Intel PT Event Trace)\n" \
0652 "               e[flags]:       synthesize error events\n" \
0653 "                           each flag must be preceded by + or -\n" \
0654 "                           error flags are: o (overflow)\n" \
0655 "                                    l (data lost)\n" \
0656 "               d[flags]:       create a debug log\n" \
0657 "                           each flag must be preceded by + or -\n" \
0658 "                           log flags are: a (all perf events)\n" \
0659 "                                          o (output to stdout)\n" \
0660 "               f:              synthesize first level cache events\n" \
0661 "               m:              synthesize last level cache events\n" \
0662 "               t:              synthesize TLB events\n" \
0663 "               a:              synthesize remote access events\n" \
0664 "               g[len]:             synthesize a call chain (use with i or x)\n" \
0665 "               G[len]:         synthesize a call chain on existing event records\n" \
0666 "               l[len]:             synthesize last branch entries (use with i or x)\n" \
0667 "               L[len]:         synthesize last branch entries on existing event records\n" \
0668 "               sNUMBER:            skip initial number of events\n"        \
0669 "               q:          quicker (less detailed) decoding\n" \
0670 "               A:          approximate IPC\n" \
0671 "               Z:          prefer to ignore timestamps (so-called \"timeless\" decoding)\n" \
0672 "               PERIOD[ns|us|ms|i|t]:   specify period to sample stream\n" \
0673 "               concatenate multiple options. Default is ibxwpe or cewp\n"
0674 
0675 static inline
0676 void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts,
0677                        struct perf_time_interval *ptime_range,
0678                        int range_num)
0679 {
0680     opts->ptime_range = ptime_range;
0681     opts->range_num = range_num;
0682 }
0683 
0684 static inline
0685 void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
0686 {
0687     opts->ptime_range = NULL;
0688     opts->range_num = 0;
0689 }
0690 
0691 #else
0692 #include "debug.h"
0693 
0694 static inline struct auxtrace_record *
0695 auxtrace_record__init(struct evlist *evlist __maybe_unused,
0696               int *err)
0697 {
0698     *err = 0;
0699     return NULL;
0700 }
0701 
0702 static inline
0703 void auxtrace_record__free(struct auxtrace_record *itr __maybe_unused)
0704 {
0705 }
0706 
0707 static inline
0708 int auxtrace_record__options(struct auxtrace_record *itr __maybe_unused,
0709                  struct evlist *evlist __maybe_unused,
0710                  struct record_opts *opts __maybe_unused)
0711 {
0712     return 0;
0713 }
0714 
0715 static inline
0716 int perf_event__process_auxtrace_info(struct perf_session *session __maybe_unused,
0717                       union perf_event *event __maybe_unused)
0718 {
0719     return 0;
0720 }
0721 
0722 static inline
0723 s64 perf_event__process_auxtrace(struct perf_session *session __maybe_unused,
0724                  union perf_event *event __maybe_unused)
0725 {
0726     return 0;
0727 }
0728 
0729 static inline
0730 int perf_event__process_auxtrace_error(struct perf_session *session __maybe_unused,
0731                        union perf_event *event __maybe_unused)
0732 {
0733     return 0;
0734 }
0735 
0736 static inline
0737 void perf_session__auxtrace_error_inc(struct perf_session *session
0738                       __maybe_unused,
0739                       union perf_event *event
0740                       __maybe_unused)
0741 {
0742 }
0743 
0744 static inline
0745 void events_stats__auxtrace_error_warn(const struct events_stats *stats
0746                        __maybe_unused)
0747 {
0748 }
0749 
0750 static inline
0751 int itrace_do_parse_synth_opts(struct itrace_synth_opts *synth_opts __maybe_unused,
0752                    const char *str __maybe_unused, int unset __maybe_unused)
0753 {
0754     pr_err("AUX area tracing not supported\n");
0755     return -EINVAL;
0756 }
0757 
0758 static inline
0759 int itrace_parse_synth_opts(const struct option *opt __maybe_unused,
0760                 const char *str __maybe_unused,
0761                 int unset __maybe_unused)
0762 {
0763     pr_err("AUX area tracing not supported\n");
0764     return -EINVAL;
0765 }
0766 
0767 static inline
0768 int auxtrace_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
0769                     struct record_opts *opts __maybe_unused,
0770                     const char *str)
0771 {
0772     if (!str)
0773         return 0;
0774     pr_err("AUX area tracing not supported\n");
0775     return -EINVAL;
0776 }
0777 
0778 static inline
0779 int auxtrace_parse_sample_options(struct auxtrace_record *itr __maybe_unused,
0780                   struct evlist *evlist __maybe_unused,
0781                   struct record_opts *opts __maybe_unused,
0782                   const char *str)
0783 {
0784     if (!str)
0785         return 0;
0786     pr_err("AUX area tracing not supported\n");
0787     return -EINVAL;
0788 }
0789 
0790 static inline
0791 void auxtrace_regroup_aux_output(struct evlist *evlist __maybe_unused)
0792 {
0793 }
0794 
0795 static inline
0796 int auxtrace__process_event(struct perf_session *session __maybe_unused,
0797                 union perf_event *event __maybe_unused,
0798                 struct perf_sample *sample __maybe_unused,
0799                 struct perf_tool *tool __maybe_unused)
0800 {
0801     return 0;
0802 }
0803 
0804 static inline
0805 void auxtrace__dump_auxtrace_sample(struct perf_session *session __maybe_unused,
0806                     struct perf_sample *sample __maybe_unused)
0807 {
0808 }
0809 
0810 static inline
0811 int auxtrace__flush_events(struct perf_session *session __maybe_unused,
0812                struct perf_tool *tool __maybe_unused)
0813 {
0814     return 0;
0815 }
0816 
0817 static inline
0818 void auxtrace__free_events(struct perf_session *session __maybe_unused)
0819 {
0820 }
0821 
0822 static inline
0823 void auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache __maybe_unused)
0824 {
0825 }
0826 
0827 static inline
0828 void auxtrace__free(struct perf_session *session __maybe_unused)
0829 {
0830 }
0831 
0832 static inline
0833 int auxtrace_index__write(int fd __maybe_unused,
0834               struct list_head *head __maybe_unused)
0835 {
0836     return -EINVAL;
0837 }
0838 
0839 static inline
0840 int auxtrace_index__process(int fd __maybe_unused,
0841                 u64 size __maybe_unused,
0842                 struct perf_session *session __maybe_unused,
0843                 bool needs_swap __maybe_unused)
0844 {
0845     return -EINVAL;
0846 }
0847 
0848 static inline
0849 void auxtrace_index__free(struct list_head *head __maybe_unused)
0850 {
0851 }
0852 
0853 static inline
0854 bool auxtrace__evsel_is_auxtrace(struct perf_session *session __maybe_unused,
0855                  struct evsel *evsel __maybe_unused)
0856 {
0857     return false;
0858 }
0859 
0860 static inline
0861 int auxtrace_parse_filters(struct evlist *evlist __maybe_unused)
0862 {
0863     return 0;
0864 }
0865 
0866 int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
0867             struct auxtrace_mmap_params *mp,
0868             void *userpg, int fd);
0869 void auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
0870 void auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
0871                 off_t auxtrace_offset,
0872                 unsigned int auxtrace_pages,
0873                 bool auxtrace_overwrite);
0874 void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
0875                    struct evlist *evlist,
0876                    struct evsel *evsel, int idx);
0877 
0878 #define ITRACE_HELP ""
0879 
0880 static inline
0881 void itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts
0882                        __maybe_unused,
0883                        struct perf_time_interval *ptime_range
0884                        __maybe_unused,
0885                        int range_num __maybe_unused)
0886 {
0887 }
0888 
0889 static inline
0890 void itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts
0891                      __maybe_unused)
0892 {
0893 }
0894 
0895 #endif
0896 
0897 #endif