18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * auxtrace.h: AUX area trace support
48c2ecf20Sopenharmony_ci * Copyright (c) 2013-2015, Intel Corporation.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef __PERF_AUXTRACE_H
88c2ecf20Sopenharmony_ci#define __PERF_AUXTRACE_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <sys/types.h>
118c2ecf20Sopenharmony_ci#include <errno.h>
128c2ecf20Sopenharmony_ci#include <stdbool.h>
138c2ecf20Sopenharmony_ci#include <stddef.h>
148c2ecf20Sopenharmony_ci#include <stdio.h> // FILE
158c2ecf20Sopenharmony_ci#include <linux/list.h>
168c2ecf20Sopenharmony_ci#include <linux/perf_event.h>
178c2ecf20Sopenharmony_ci#include <linux/types.h>
188c2ecf20Sopenharmony_ci#include <asm/bitsperlong.h>
198c2ecf20Sopenharmony_ci#include <asm/barrier.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ciunion perf_event;
228c2ecf20Sopenharmony_cistruct perf_session;
238c2ecf20Sopenharmony_cistruct evlist;
248c2ecf20Sopenharmony_cistruct evsel;
258c2ecf20Sopenharmony_cistruct perf_tool;
268c2ecf20Sopenharmony_cistruct mmap;
278c2ecf20Sopenharmony_cistruct perf_sample;
288c2ecf20Sopenharmony_cistruct option;
298c2ecf20Sopenharmony_cistruct record_opts;
308c2ecf20Sopenharmony_cistruct perf_record_auxtrace_error;
318c2ecf20Sopenharmony_cistruct perf_record_auxtrace_info;
328c2ecf20Sopenharmony_cistruct events_stats;
338c2ecf20Sopenharmony_cistruct perf_pmu;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cienum auxtrace_error_type {
368c2ecf20Sopenharmony_ci       PERF_AUXTRACE_ERROR_ITRACE  = 1,
378c2ecf20Sopenharmony_ci       PERF_AUXTRACE_ERROR_MAX
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* Auxtrace records must have the same alignment as perf event records */
418c2ecf20Sopenharmony_ci#define PERF_AUXTRACE_RECORD_ALIGNMENT 8
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cienum auxtrace_type {
448c2ecf20Sopenharmony_ci	PERF_AUXTRACE_UNKNOWN,
458c2ecf20Sopenharmony_ci	PERF_AUXTRACE_INTEL_PT,
468c2ecf20Sopenharmony_ci	PERF_AUXTRACE_INTEL_BTS,
478c2ecf20Sopenharmony_ci	PERF_AUXTRACE_CS_ETM,
488c2ecf20Sopenharmony_ci	PERF_AUXTRACE_ARM_SPE,
498c2ecf20Sopenharmony_ci	PERF_AUXTRACE_S390_CPUMSF,
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cienum itrace_period_type {
538c2ecf20Sopenharmony_ci	PERF_ITRACE_PERIOD_INSTRUCTIONS,
548c2ecf20Sopenharmony_ci	PERF_ITRACE_PERIOD_TICKS,
558c2ecf20Sopenharmony_ci	PERF_ITRACE_PERIOD_NANOSECS,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define AUXTRACE_ERR_FLG_OVERFLOW	(1 << ('o' - 'a'))
598c2ecf20Sopenharmony_ci#define AUXTRACE_ERR_FLG_DATA_LOST	(1 << ('l' - 'a'))
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define AUXTRACE_LOG_FLG_ALL_PERF_EVTS	(1 << ('a' - 'a'))
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/**
648c2ecf20Sopenharmony_ci * struct itrace_synth_opts - AUX area tracing synthesis options.
658c2ecf20Sopenharmony_ci * @set: indicates whether or not options have been set
668c2ecf20Sopenharmony_ci * @default_no_sample: Default to no sampling.
678c2ecf20Sopenharmony_ci * @inject: indicates the event (not just the sample) must be fully synthesized
688c2ecf20Sopenharmony_ci *          because 'perf inject' will write it out
698c2ecf20Sopenharmony_ci * @instructions: whether to synthesize 'instructions' events
708c2ecf20Sopenharmony_ci * @branches: whether to synthesize 'branches' events
718c2ecf20Sopenharmony_ci *            (branch misses only for Arm SPE)
728c2ecf20Sopenharmony_ci * @transactions: whether to synthesize events for transactions
738c2ecf20Sopenharmony_ci * @ptwrites: whether to synthesize events for ptwrites
748c2ecf20Sopenharmony_ci * @pwr_events: whether to synthesize power events
758c2ecf20Sopenharmony_ci * @other_events: whether to synthesize other events recorded due to the use of
768c2ecf20Sopenharmony_ci *                aux_output
778c2ecf20Sopenharmony_ci * @errors: whether to synthesize decoder error events
788c2ecf20Sopenharmony_ci * @dont_decode: whether to skip decoding entirely
798c2ecf20Sopenharmony_ci * @log: write a decoding log
808c2ecf20Sopenharmony_ci * @calls: limit branch samples to calls (can be combined with @returns)
818c2ecf20Sopenharmony_ci * @returns: limit branch samples to returns (can be combined with @calls)
828c2ecf20Sopenharmony_ci * @callchain: add callchain to 'instructions' events
838c2ecf20Sopenharmony_ci * @add_callchain: add callchain to existing event records
848c2ecf20Sopenharmony_ci * @thread_stack: feed branches to the thread_stack
858c2ecf20Sopenharmony_ci * @last_branch: add branch context to 'instruction' events
868c2ecf20Sopenharmony_ci * @add_last_branch: add branch context to existing event records
878c2ecf20Sopenharmony_ci * @flc: whether to synthesize first level cache events
888c2ecf20Sopenharmony_ci * @llc: whether to synthesize last level cache events
898c2ecf20Sopenharmony_ci * @tlb: whether to synthesize TLB events
908c2ecf20Sopenharmony_ci * @remote_access: whether to synthesize remote access events
918c2ecf20Sopenharmony_ci * @callchain_sz: maximum callchain size
928c2ecf20Sopenharmony_ci * @last_branch_sz: branch context size
938c2ecf20Sopenharmony_ci * @period: 'instructions' events period
948c2ecf20Sopenharmony_ci * @period_type: 'instructions' events period type
958c2ecf20Sopenharmony_ci * @initial_skip: skip N events at the beginning.
968c2ecf20Sopenharmony_ci * @cpu_bitmap: CPUs for which to synthesize events, or NULL for all
978c2ecf20Sopenharmony_ci * @ptime_range: time intervals to trace or NULL
988c2ecf20Sopenharmony_ci * @range_num: number of time intervals to trace
998c2ecf20Sopenharmony_ci * @error_plus_flags: flags to affect what errors are reported
1008c2ecf20Sopenharmony_ci * @error_minus_flags: flags to affect what errors are reported
1018c2ecf20Sopenharmony_ci * @log_plus_flags: flags to affect what is logged
1028c2ecf20Sopenharmony_ci * @log_minus_flags: flags to affect what is logged
1038c2ecf20Sopenharmony_ci * @quick: quicker (less detailed) decoding
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_cistruct itrace_synth_opts {
1068c2ecf20Sopenharmony_ci	bool			set;
1078c2ecf20Sopenharmony_ci	bool			default_no_sample;
1088c2ecf20Sopenharmony_ci	bool			inject;
1098c2ecf20Sopenharmony_ci	bool			instructions;
1108c2ecf20Sopenharmony_ci	bool			branches;
1118c2ecf20Sopenharmony_ci	bool			transactions;
1128c2ecf20Sopenharmony_ci	bool			ptwrites;
1138c2ecf20Sopenharmony_ci	bool			pwr_events;
1148c2ecf20Sopenharmony_ci	bool			other_events;
1158c2ecf20Sopenharmony_ci	bool			errors;
1168c2ecf20Sopenharmony_ci	bool			dont_decode;
1178c2ecf20Sopenharmony_ci	bool			log;
1188c2ecf20Sopenharmony_ci	bool			calls;
1198c2ecf20Sopenharmony_ci	bool			returns;
1208c2ecf20Sopenharmony_ci	bool			callchain;
1218c2ecf20Sopenharmony_ci	bool			add_callchain;
1228c2ecf20Sopenharmony_ci	bool			thread_stack;
1238c2ecf20Sopenharmony_ci	bool			last_branch;
1248c2ecf20Sopenharmony_ci	bool			add_last_branch;
1258c2ecf20Sopenharmony_ci	bool			flc;
1268c2ecf20Sopenharmony_ci	bool			llc;
1278c2ecf20Sopenharmony_ci	bool			tlb;
1288c2ecf20Sopenharmony_ci	bool			remote_access;
1298c2ecf20Sopenharmony_ci	unsigned int		callchain_sz;
1308c2ecf20Sopenharmony_ci	unsigned int		last_branch_sz;
1318c2ecf20Sopenharmony_ci	unsigned long long	period;
1328c2ecf20Sopenharmony_ci	enum itrace_period_type	period_type;
1338c2ecf20Sopenharmony_ci	unsigned long		initial_skip;
1348c2ecf20Sopenharmony_ci	unsigned long		*cpu_bitmap;
1358c2ecf20Sopenharmony_ci	struct perf_time_interval *ptime_range;
1368c2ecf20Sopenharmony_ci	int			range_num;
1378c2ecf20Sopenharmony_ci	unsigned int		error_plus_flags;
1388c2ecf20Sopenharmony_ci	unsigned int		error_minus_flags;
1398c2ecf20Sopenharmony_ci	unsigned int		log_plus_flags;
1408c2ecf20Sopenharmony_ci	unsigned int		log_minus_flags;
1418c2ecf20Sopenharmony_ci	unsigned int		quick;
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/**
1458c2ecf20Sopenharmony_ci * struct auxtrace_index_entry - indexes a AUX area tracing event within a
1468c2ecf20Sopenharmony_ci *                               perf.data file.
1478c2ecf20Sopenharmony_ci * @file_offset: offset within the perf.data file
1488c2ecf20Sopenharmony_ci * @sz: size of the event
1498c2ecf20Sopenharmony_ci */
1508c2ecf20Sopenharmony_cistruct auxtrace_index_entry {
1518c2ecf20Sopenharmony_ci	u64			file_offset;
1528c2ecf20Sopenharmony_ci	u64			sz;
1538c2ecf20Sopenharmony_ci};
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define PERF_AUXTRACE_INDEX_ENTRY_COUNT 256
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/**
1588c2ecf20Sopenharmony_ci * struct auxtrace_index - index of AUX area tracing events within a perf.data
1598c2ecf20Sopenharmony_ci *                         file.
1608c2ecf20Sopenharmony_ci * @list: linking a number of arrays of entries
1618c2ecf20Sopenharmony_ci * @nr: number of entries
1628c2ecf20Sopenharmony_ci * @entries: array of entries
1638c2ecf20Sopenharmony_ci */
1648c2ecf20Sopenharmony_cistruct auxtrace_index {
1658c2ecf20Sopenharmony_ci	struct list_head	list;
1668c2ecf20Sopenharmony_ci	size_t			nr;
1678c2ecf20Sopenharmony_ci	struct auxtrace_index_entry entries[PERF_AUXTRACE_INDEX_ENTRY_COUNT];
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/**
1718c2ecf20Sopenharmony_ci * struct auxtrace - session callbacks to allow AUX area data decoding.
1728c2ecf20Sopenharmony_ci * @process_event: lets the decoder see all session events
1738c2ecf20Sopenharmony_ci * @process_auxtrace_event: process a PERF_RECORD_AUXTRACE event
1748c2ecf20Sopenharmony_ci * @queue_data: queue an AUX sample or PERF_RECORD_AUXTRACE event for later
1758c2ecf20Sopenharmony_ci *              processing
1768c2ecf20Sopenharmony_ci * @dump_auxtrace_sample: dump AUX area sample data
1778c2ecf20Sopenharmony_ci * @flush_events: process any remaining data
1788c2ecf20Sopenharmony_ci * @free_events: free resources associated with event processing
1798c2ecf20Sopenharmony_ci * @free: free resources associated with the session
1808c2ecf20Sopenharmony_ci */
1818c2ecf20Sopenharmony_cistruct auxtrace {
1828c2ecf20Sopenharmony_ci	int (*process_event)(struct perf_session *session,
1838c2ecf20Sopenharmony_ci			     union perf_event *event,
1848c2ecf20Sopenharmony_ci			     struct perf_sample *sample,
1858c2ecf20Sopenharmony_ci			     struct perf_tool *tool);
1868c2ecf20Sopenharmony_ci	int (*process_auxtrace_event)(struct perf_session *session,
1878c2ecf20Sopenharmony_ci				      union perf_event *event,
1888c2ecf20Sopenharmony_ci				      struct perf_tool *tool);
1898c2ecf20Sopenharmony_ci	int (*queue_data)(struct perf_session *session,
1908c2ecf20Sopenharmony_ci			  struct perf_sample *sample, union perf_event *event,
1918c2ecf20Sopenharmony_ci			  u64 data_offset);
1928c2ecf20Sopenharmony_ci	void (*dump_auxtrace_sample)(struct perf_session *session,
1938c2ecf20Sopenharmony_ci				     struct perf_sample *sample);
1948c2ecf20Sopenharmony_ci	int (*flush_events)(struct perf_session *session,
1958c2ecf20Sopenharmony_ci			    struct perf_tool *tool);
1968c2ecf20Sopenharmony_ci	void (*free_events)(struct perf_session *session);
1978c2ecf20Sopenharmony_ci	void (*free)(struct perf_session *session);
1988c2ecf20Sopenharmony_ci	bool (*evsel_is_auxtrace)(struct perf_session *session,
1998c2ecf20Sopenharmony_ci				  struct evsel *evsel);
2008c2ecf20Sopenharmony_ci};
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci/**
2038c2ecf20Sopenharmony_ci * struct auxtrace_buffer - a buffer containing AUX area tracing data.
2048c2ecf20Sopenharmony_ci * @list: buffers are queued in a list held by struct auxtrace_queue
2058c2ecf20Sopenharmony_ci * @size: size of the buffer in bytes
2068c2ecf20Sopenharmony_ci * @pid: in per-thread mode, the pid this buffer is associated with
2078c2ecf20Sopenharmony_ci * @tid: in per-thread mode, the tid this buffer is associated with
2088c2ecf20Sopenharmony_ci * @cpu: in per-cpu mode, the cpu this buffer is associated with
2098c2ecf20Sopenharmony_ci * @data: actual buffer data (can be null if the data has not been loaded)
2108c2ecf20Sopenharmony_ci * @data_offset: file offset at which the buffer can be read
2118c2ecf20Sopenharmony_ci * @mmap_addr: mmap address at which the buffer can be read
2128c2ecf20Sopenharmony_ci * @mmap_size: size of the mmap at @mmap_addr
2138c2ecf20Sopenharmony_ci * @data_needs_freeing: @data was malloc'd so free it when it is no longer
2148c2ecf20Sopenharmony_ci *                      needed
2158c2ecf20Sopenharmony_ci * @consecutive: the original data was split up and this buffer is consecutive
2168c2ecf20Sopenharmony_ci *               to the previous buffer
2178c2ecf20Sopenharmony_ci * @offset: offset as determined by aux_head / aux_tail members of struct
2188c2ecf20Sopenharmony_ci *          perf_event_mmap_page
2198c2ecf20Sopenharmony_ci * @reference: an implementation-specific reference determined when the data is
2208c2ecf20Sopenharmony_ci *             recorded
2218c2ecf20Sopenharmony_ci * @buffer_nr: used to number each buffer
2228c2ecf20Sopenharmony_ci * @use_size: implementation actually only uses this number of bytes
2238c2ecf20Sopenharmony_ci * @use_data: implementation actually only uses data starting at this address
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cistruct auxtrace_buffer {
2268c2ecf20Sopenharmony_ci	struct list_head	list;
2278c2ecf20Sopenharmony_ci	size_t			size;
2288c2ecf20Sopenharmony_ci	pid_t			pid;
2298c2ecf20Sopenharmony_ci	pid_t			tid;
2308c2ecf20Sopenharmony_ci	int			cpu;
2318c2ecf20Sopenharmony_ci	void			*data;
2328c2ecf20Sopenharmony_ci	off_t			data_offset;
2338c2ecf20Sopenharmony_ci	void			*mmap_addr;
2348c2ecf20Sopenharmony_ci	size_t			mmap_size;
2358c2ecf20Sopenharmony_ci	bool			data_needs_freeing;
2368c2ecf20Sopenharmony_ci	bool			consecutive;
2378c2ecf20Sopenharmony_ci	u64			offset;
2388c2ecf20Sopenharmony_ci	u64			reference;
2398c2ecf20Sopenharmony_ci	u64			buffer_nr;
2408c2ecf20Sopenharmony_ci	size_t			use_size;
2418c2ecf20Sopenharmony_ci	void			*use_data;
2428c2ecf20Sopenharmony_ci};
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ci/**
2458c2ecf20Sopenharmony_ci * struct auxtrace_queue - a queue of AUX area tracing data buffers.
2468c2ecf20Sopenharmony_ci * @head: head of buffer list
2478c2ecf20Sopenharmony_ci * @tid: in per-thread mode, the tid this queue is associated with
2488c2ecf20Sopenharmony_ci * @cpu: in per-cpu mode, the cpu this queue is associated with
2498c2ecf20Sopenharmony_ci * @set: %true once this queue has been dedicated to a specific thread or cpu
2508c2ecf20Sopenharmony_ci * @priv: implementation-specific data
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_cistruct auxtrace_queue {
2538c2ecf20Sopenharmony_ci	struct list_head	head;
2548c2ecf20Sopenharmony_ci	pid_t			tid;
2558c2ecf20Sopenharmony_ci	int			cpu;
2568c2ecf20Sopenharmony_ci	bool			set;
2578c2ecf20Sopenharmony_ci	void			*priv;
2588c2ecf20Sopenharmony_ci};
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci/**
2618c2ecf20Sopenharmony_ci * struct auxtrace_queues - an array of AUX area tracing queues.
2628c2ecf20Sopenharmony_ci * @queue_array: array of queues
2638c2ecf20Sopenharmony_ci * @nr_queues: number of queues
2648c2ecf20Sopenharmony_ci * @new_data: set whenever new data is queued
2658c2ecf20Sopenharmony_ci * @populated: queues have been fully populated using the auxtrace_index
2668c2ecf20Sopenharmony_ci * @next_buffer_nr: used to number each buffer
2678c2ecf20Sopenharmony_ci */
2688c2ecf20Sopenharmony_cistruct auxtrace_queues {
2698c2ecf20Sopenharmony_ci	struct auxtrace_queue	*queue_array;
2708c2ecf20Sopenharmony_ci	unsigned int		nr_queues;
2718c2ecf20Sopenharmony_ci	bool			new_data;
2728c2ecf20Sopenharmony_ci	bool			populated;
2738c2ecf20Sopenharmony_ci	u64			next_buffer_nr;
2748c2ecf20Sopenharmony_ci};
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci/**
2778c2ecf20Sopenharmony_ci * struct auxtrace_heap_item - element of struct auxtrace_heap.
2788c2ecf20Sopenharmony_ci * @queue_nr: queue number
2798c2ecf20Sopenharmony_ci * @ordinal: value used for sorting (lowest ordinal is top of the heap) expected
2808c2ecf20Sopenharmony_ci *           to be a timestamp
2818c2ecf20Sopenharmony_ci */
2828c2ecf20Sopenharmony_cistruct auxtrace_heap_item {
2838c2ecf20Sopenharmony_ci	unsigned int		queue_nr;
2848c2ecf20Sopenharmony_ci	u64			ordinal;
2858c2ecf20Sopenharmony_ci};
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/**
2888c2ecf20Sopenharmony_ci * struct auxtrace_heap - a heap suitable for sorting AUX area tracing queues.
2898c2ecf20Sopenharmony_ci * @heap_array: the heap
2908c2ecf20Sopenharmony_ci * @heap_cnt: the number of elements in the heap
2918c2ecf20Sopenharmony_ci * @heap_sz: maximum number of elements (grows as needed)
2928c2ecf20Sopenharmony_ci */
2938c2ecf20Sopenharmony_cistruct auxtrace_heap {
2948c2ecf20Sopenharmony_ci	struct auxtrace_heap_item	*heap_array;
2958c2ecf20Sopenharmony_ci	unsigned int		heap_cnt;
2968c2ecf20Sopenharmony_ci	unsigned int		heap_sz;
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci/**
3008c2ecf20Sopenharmony_ci * struct auxtrace_mmap - records an mmap of the auxtrace buffer.
3018c2ecf20Sopenharmony_ci * @base: address of mapped area
3028c2ecf20Sopenharmony_ci * @userpg: pointer to buffer's perf_event_mmap_page
3038c2ecf20Sopenharmony_ci * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
3048c2ecf20Sopenharmony_ci * @len: size of mapped area
3058c2ecf20Sopenharmony_ci * @prev: previous aux_head
3068c2ecf20Sopenharmony_ci * @idx: index of this mmap
3078c2ecf20Sopenharmony_ci * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
3088c2ecf20Sopenharmony_ci *       mmap) otherwise %0
3098c2ecf20Sopenharmony_ci * @cpu: cpu number for a per-cpu mmap otherwise %-1
3108c2ecf20Sopenharmony_ci */
3118c2ecf20Sopenharmony_cistruct auxtrace_mmap {
3128c2ecf20Sopenharmony_ci	void		*base;
3138c2ecf20Sopenharmony_ci	void		*userpg;
3148c2ecf20Sopenharmony_ci	size_t		mask;
3158c2ecf20Sopenharmony_ci	size_t		len;
3168c2ecf20Sopenharmony_ci	u64		prev;
3178c2ecf20Sopenharmony_ci	int		idx;
3188c2ecf20Sopenharmony_ci	pid_t		tid;
3198c2ecf20Sopenharmony_ci	int		cpu;
3208c2ecf20Sopenharmony_ci};
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci/**
3238c2ecf20Sopenharmony_ci * struct auxtrace_mmap_params - parameters to set up struct auxtrace_mmap.
3248c2ecf20Sopenharmony_ci * @mask: %0 if @len is not a power of two, otherwise (@len - %1)
3258c2ecf20Sopenharmony_ci * @offset: file offset of mapped area
3268c2ecf20Sopenharmony_ci * @len: size of mapped area
3278c2ecf20Sopenharmony_ci * @prot: mmap memory protection
3288c2ecf20Sopenharmony_ci * @idx: index of this mmap
3298c2ecf20Sopenharmony_ci * @tid: tid for a per-thread mmap (also set if there is only 1 tid on a per-cpu
3308c2ecf20Sopenharmony_ci *       mmap) otherwise %0
3318c2ecf20Sopenharmony_ci * @cpu: cpu number for a per-cpu mmap otherwise %-1
3328c2ecf20Sopenharmony_ci */
3338c2ecf20Sopenharmony_cistruct auxtrace_mmap_params {
3348c2ecf20Sopenharmony_ci	size_t		mask;
3358c2ecf20Sopenharmony_ci	off_t		offset;
3368c2ecf20Sopenharmony_ci	size_t		len;
3378c2ecf20Sopenharmony_ci	int		prot;
3388c2ecf20Sopenharmony_ci	int		idx;
3398c2ecf20Sopenharmony_ci	pid_t		tid;
3408c2ecf20Sopenharmony_ci	int		cpu;
3418c2ecf20Sopenharmony_ci};
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci/**
3448c2ecf20Sopenharmony_ci * struct auxtrace_record - callbacks for recording AUX area data.
3458c2ecf20Sopenharmony_ci * @recording_options: validate and process recording options
3468c2ecf20Sopenharmony_ci * @info_priv_size: return the size of the private data in auxtrace_info_event
3478c2ecf20Sopenharmony_ci * @info_fill: fill-in the private data in auxtrace_info_event
3488c2ecf20Sopenharmony_ci * @free: free this auxtrace record structure
3498c2ecf20Sopenharmony_ci * @snapshot_start: starting a snapshot
3508c2ecf20Sopenharmony_ci * @snapshot_finish: finishing a snapshot
3518c2ecf20Sopenharmony_ci * @find_snapshot: find data to snapshot within auxtrace mmap
3528c2ecf20Sopenharmony_ci * @parse_snapshot_options: parse snapshot options
3538c2ecf20Sopenharmony_ci * @reference: provide a 64-bit reference number for auxtrace_event
3548c2ecf20Sopenharmony_ci * @read_finish: called after reading from an auxtrace mmap
3558c2ecf20Sopenharmony_ci * @alignment: alignment (if any) for AUX area data
3568c2ecf20Sopenharmony_ci * @default_aux_sample_size: default sample size for --aux sample option
3578c2ecf20Sopenharmony_ci * @pmu: associated pmu
3588c2ecf20Sopenharmony_ci * @evlist: selected events list
3598c2ecf20Sopenharmony_ci */
3608c2ecf20Sopenharmony_cistruct auxtrace_record {
3618c2ecf20Sopenharmony_ci	int (*recording_options)(struct auxtrace_record *itr,
3628c2ecf20Sopenharmony_ci				 struct evlist *evlist,
3638c2ecf20Sopenharmony_ci				 struct record_opts *opts);
3648c2ecf20Sopenharmony_ci	size_t (*info_priv_size)(struct auxtrace_record *itr,
3658c2ecf20Sopenharmony_ci				 struct evlist *evlist);
3668c2ecf20Sopenharmony_ci	int (*info_fill)(struct auxtrace_record *itr,
3678c2ecf20Sopenharmony_ci			 struct perf_session *session,
3688c2ecf20Sopenharmony_ci			 struct perf_record_auxtrace_info *auxtrace_info,
3698c2ecf20Sopenharmony_ci			 size_t priv_size);
3708c2ecf20Sopenharmony_ci	void (*free)(struct auxtrace_record *itr);
3718c2ecf20Sopenharmony_ci	int (*snapshot_start)(struct auxtrace_record *itr);
3728c2ecf20Sopenharmony_ci	int (*snapshot_finish)(struct auxtrace_record *itr);
3738c2ecf20Sopenharmony_ci	int (*find_snapshot)(struct auxtrace_record *itr, int idx,
3748c2ecf20Sopenharmony_ci			     struct auxtrace_mmap *mm, unsigned char *data,
3758c2ecf20Sopenharmony_ci			     u64 *head, u64 *old);
3768c2ecf20Sopenharmony_ci	int (*parse_snapshot_options)(struct auxtrace_record *itr,
3778c2ecf20Sopenharmony_ci				      struct record_opts *opts,
3788c2ecf20Sopenharmony_ci				      const char *str);
3798c2ecf20Sopenharmony_ci	u64 (*reference)(struct auxtrace_record *itr);
3808c2ecf20Sopenharmony_ci	int (*read_finish)(struct auxtrace_record *itr, int idx);
3818c2ecf20Sopenharmony_ci	unsigned int alignment;
3828c2ecf20Sopenharmony_ci	unsigned int default_aux_sample_size;
3838c2ecf20Sopenharmony_ci	struct perf_pmu *pmu;
3848c2ecf20Sopenharmony_ci	struct evlist *evlist;
3858c2ecf20Sopenharmony_ci};
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci/**
3888c2ecf20Sopenharmony_ci * struct addr_filter - address filter.
3898c2ecf20Sopenharmony_ci * @list: list node
3908c2ecf20Sopenharmony_ci * @range: true if it is a range filter
3918c2ecf20Sopenharmony_ci * @start: true if action is 'filter' or 'start'
3928c2ecf20Sopenharmony_ci * @action: 'filter', 'start' or 'stop' ('tracestop' is accepted but converted
3938c2ecf20Sopenharmony_ci *          to 'stop')
3948c2ecf20Sopenharmony_ci * @sym_from: symbol name for the filter address
3958c2ecf20Sopenharmony_ci * @sym_to: symbol name that determines the filter size
3968c2ecf20Sopenharmony_ci * @sym_from_idx: selects n'th from symbols with the same name (0 means global
3978c2ecf20Sopenharmony_ci *                and less than 0 means symbol must be unique)
3988c2ecf20Sopenharmony_ci * @sym_to_idx: same as @sym_from_idx but for @sym_to
3998c2ecf20Sopenharmony_ci * @addr: filter address
4008c2ecf20Sopenharmony_ci * @size: filter region size (for range filters)
4018c2ecf20Sopenharmony_ci * @filename: DSO file name or NULL for the kernel
4028c2ecf20Sopenharmony_ci * @str: allocated string that contains the other string members
4038c2ecf20Sopenharmony_ci */
4048c2ecf20Sopenharmony_cistruct addr_filter {
4058c2ecf20Sopenharmony_ci	struct list_head	list;
4068c2ecf20Sopenharmony_ci	bool			range;
4078c2ecf20Sopenharmony_ci	bool			start;
4088c2ecf20Sopenharmony_ci	const char		*action;
4098c2ecf20Sopenharmony_ci	const char		*sym_from;
4108c2ecf20Sopenharmony_ci	const char		*sym_to;
4118c2ecf20Sopenharmony_ci	int			sym_from_idx;
4128c2ecf20Sopenharmony_ci	int			sym_to_idx;
4138c2ecf20Sopenharmony_ci	u64			addr;
4148c2ecf20Sopenharmony_ci	u64			size;
4158c2ecf20Sopenharmony_ci	const char		*filename;
4168c2ecf20Sopenharmony_ci	char			*str;
4178c2ecf20Sopenharmony_ci};
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/**
4208c2ecf20Sopenharmony_ci * struct addr_filters - list of address filters.
4218c2ecf20Sopenharmony_ci * @head: list of address filters
4228c2ecf20Sopenharmony_ci * @cnt: number of address filters
4238c2ecf20Sopenharmony_ci */
4248c2ecf20Sopenharmony_cistruct addr_filters {
4258c2ecf20Sopenharmony_ci	struct list_head	head;
4268c2ecf20Sopenharmony_ci	int			cnt;
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_cistruct auxtrace_cache;
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci#ifdef HAVE_AUXTRACE_SUPPORT
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci/*
4348c2ecf20Sopenharmony_ci * In snapshot mode the mmapped page is read-only which makes using
4358c2ecf20Sopenharmony_ci * __sync_val_compare_and_swap() problematic.  However, snapshot mode expects
4368c2ecf20Sopenharmony_ci * the buffer is not updated while the snapshot is made (e.g. Intel PT disables
4378c2ecf20Sopenharmony_ci * the event) so there is not a race anyway.
4388c2ecf20Sopenharmony_ci */
4398c2ecf20Sopenharmony_cistatic inline u64 auxtrace_mmap__read_snapshot_head(struct auxtrace_mmap *mm)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	struct perf_event_mmap_page *pc = mm->userpg;
4428c2ecf20Sopenharmony_ci	u64 head = READ_ONCE(pc->aux_head);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci	/* Ensure all reads are done after we read the head */
4458c2ecf20Sopenharmony_ci	rmb();
4468c2ecf20Sopenharmony_ci	return head;
4478c2ecf20Sopenharmony_ci}
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_cistatic inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm)
4508c2ecf20Sopenharmony_ci{
4518c2ecf20Sopenharmony_ci	struct perf_event_mmap_page *pc = mm->userpg;
4528c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
4538c2ecf20Sopenharmony_ci	u64 head = READ_ONCE(pc->aux_head);
4548c2ecf20Sopenharmony_ci#else
4558c2ecf20Sopenharmony_ci	u64 head = __sync_val_compare_and_swap(&pc->aux_head, 0, 0);
4568c2ecf20Sopenharmony_ci#endif
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	/* Ensure all reads are done after we read the head */
4598c2ecf20Sopenharmony_ci	rmb();
4608c2ecf20Sopenharmony_ci	return head;
4618c2ecf20Sopenharmony_ci}
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_cistatic inline void auxtrace_mmap__write_tail(struct auxtrace_mmap *mm, u64 tail)
4648c2ecf20Sopenharmony_ci{
4658c2ecf20Sopenharmony_ci	struct perf_event_mmap_page *pc = mm->userpg;
4668c2ecf20Sopenharmony_ci#if BITS_PER_LONG != 64 && defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
4678c2ecf20Sopenharmony_ci	u64 old_tail;
4688c2ecf20Sopenharmony_ci#endif
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci	/* Ensure all reads are done before we write the tail out */
4718c2ecf20Sopenharmony_ci	mb();
4728c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 64 || !defined(HAVE_SYNC_COMPARE_AND_SWAP_SUPPORT)
4738c2ecf20Sopenharmony_ci	pc->aux_tail = tail;
4748c2ecf20Sopenharmony_ci#else
4758c2ecf20Sopenharmony_ci	do {
4768c2ecf20Sopenharmony_ci		old_tail = __sync_val_compare_and_swap(&pc->aux_tail, 0, 0);
4778c2ecf20Sopenharmony_ci	} while (!__sync_bool_compare_and_swap(&pc->aux_tail, old_tail, tail));
4788c2ecf20Sopenharmony_ci#endif
4798c2ecf20Sopenharmony_ci}
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ciint auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
4828c2ecf20Sopenharmony_ci			struct auxtrace_mmap_params *mp,
4838c2ecf20Sopenharmony_ci			void *userpg, int fd);
4848c2ecf20Sopenharmony_civoid auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
4858c2ecf20Sopenharmony_civoid auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
4868c2ecf20Sopenharmony_ci				off_t auxtrace_offset,
4878c2ecf20Sopenharmony_ci				unsigned int auxtrace_pages,
4888c2ecf20Sopenharmony_ci				bool auxtrace_overwrite);
4898c2ecf20Sopenharmony_civoid auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
4908c2ecf20Sopenharmony_ci				   struct evlist *evlist, int idx,
4918c2ecf20Sopenharmony_ci				   bool per_cpu);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_citypedef int (*process_auxtrace_t)(struct perf_tool *tool,
4948c2ecf20Sopenharmony_ci				  struct mmap *map,
4958c2ecf20Sopenharmony_ci				  union perf_event *event, void *data1,
4968c2ecf20Sopenharmony_ci				  size_t len1, void *data2, size_t len2);
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ciint auxtrace_mmap__read(struct mmap *map, struct auxtrace_record *itr,
4998c2ecf20Sopenharmony_ci			struct perf_tool *tool, process_auxtrace_t fn);
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ciint auxtrace_mmap__read_snapshot(struct mmap *map,
5028c2ecf20Sopenharmony_ci				 struct auxtrace_record *itr,
5038c2ecf20Sopenharmony_ci				 struct perf_tool *tool, process_auxtrace_t fn,
5048c2ecf20Sopenharmony_ci				 size_t snapshot_size);
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ciint auxtrace_queues__init(struct auxtrace_queues *queues);
5078c2ecf20Sopenharmony_ciint auxtrace_queues__add_event(struct auxtrace_queues *queues,
5088c2ecf20Sopenharmony_ci			       struct perf_session *session,
5098c2ecf20Sopenharmony_ci			       union perf_event *event, off_t data_offset,
5108c2ecf20Sopenharmony_ci			       struct auxtrace_buffer **buffer_ptr);
5118c2ecf20Sopenharmony_cistruct auxtrace_queue *
5128c2ecf20Sopenharmony_ciauxtrace_queues__sample_queue(struct auxtrace_queues *queues,
5138c2ecf20Sopenharmony_ci			      struct perf_sample *sample,
5148c2ecf20Sopenharmony_ci			      struct perf_session *session);
5158c2ecf20Sopenharmony_ciint auxtrace_queues__add_sample(struct auxtrace_queues *queues,
5168c2ecf20Sopenharmony_ci				struct perf_session *session,
5178c2ecf20Sopenharmony_ci				struct perf_sample *sample, u64 data_offset,
5188c2ecf20Sopenharmony_ci				u64 reference);
5198c2ecf20Sopenharmony_civoid auxtrace_queues__free(struct auxtrace_queues *queues);
5208c2ecf20Sopenharmony_ciint auxtrace_queues__process_index(struct auxtrace_queues *queues,
5218c2ecf20Sopenharmony_ci				   struct perf_session *session);
5228c2ecf20Sopenharmony_ciint auxtrace_queue_data(struct perf_session *session, bool samples,
5238c2ecf20Sopenharmony_ci			bool events);
5248c2ecf20Sopenharmony_cistruct auxtrace_buffer *auxtrace_buffer__next(struct auxtrace_queue *queue,
5258c2ecf20Sopenharmony_ci					      struct auxtrace_buffer *buffer);
5268c2ecf20Sopenharmony_civoid *auxtrace_buffer__get_data(struct auxtrace_buffer *buffer, int fd);
5278c2ecf20Sopenharmony_civoid auxtrace_buffer__put_data(struct auxtrace_buffer *buffer);
5288c2ecf20Sopenharmony_civoid auxtrace_buffer__drop_data(struct auxtrace_buffer *buffer);
5298c2ecf20Sopenharmony_civoid auxtrace_buffer__free(struct auxtrace_buffer *buffer);
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ciint auxtrace_heap__add(struct auxtrace_heap *heap, unsigned int queue_nr,
5328c2ecf20Sopenharmony_ci		       u64 ordinal);
5338c2ecf20Sopenharmony_civoid auxtrace_heap__pop(struct auxtrace_heap *heap);
5348c2ecf20Sopenharmony_civoid auxtrace_heap__free(struct auxtrace_heap *heap);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_cistruct auxtrace_cache_entry {
5378c2ecf20Sopenharmony_ci	struct hlist_node hash;
5388c2ecf20Sopenharmony_ci	u32 key;
5398c2ecf20Sopenharmony_ci};
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_cistruct auxtrace_cache *auxtrace_cache__new(unsigned int bits, size_t entry_size,
5428c2ecf20Sopenharmony_ci					   unsigned int limit_percent);
5438c2ecf20Sopenharmony_civoid auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache);
5448c2ecf20Sopenharmony_civoid *auxtrace_cache__alloc_entry(struct auxtrace_cache *c);
5458c2ecf20Sopenharmony_civoid auxtrace_cache__free_entry(struct auxtrace_cache *c, void *entry);
5468c2ecf20Sopenharmony_ciint auxtrace_cache__add(struct auxtrace_cache *c, u32 key,
5478c2ecf20Sopenharmony_ci			struct auxtrace_cache_entry *entry);
5488c2ecf20Sopenharmony_civoid auxtrace_cache__remove(struct auxtrace_cache *c, u32 key);
5498c2ecf20Sopenharmony_civoid *auxtrace_cache__lookup(struct auxtrace_cache *c, u32 key);
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_cistruct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
5528c2ecf20Sopenharmony_ci					      int *err);
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ciint auxtrace_parse_snapshot_options(struct auxtrace_record *itr,
5558c2ecf20Sopenharmony_ci				    struct record_opts *opts,
5568c2ecf20Sopenharmony_ci				    const char *str);
5578c2ecf20Sopenharmony_ciint auxtrace_parse_sample_options(struct auxtrace_record *itr,
5588c2ecf20Sopenharmony_ci				  struct evlist *evlist,
5598c2ecf20Sopenharmony_ci				  struct record_opts *opts, const char *str);
5608c2ecf20Sopenharmony_ciint auxtrace_record__options(struct auxtrace_record *itr,
5618c2ecf20Sopenharmony_ci			     struct evlist *evlist,
5628c2ecf20Sopenharmony_ci			     struct record_opts *opts);
5638c2ecf20Sopenharmony_cisize_t auxtrace_record__info_priv_size(struct auxtrace_record *itr,
5648c2ecf20Sopenharmony_ci				       struct evlist *evlist);
5658c2ecf20Sopenharmony_ciint auxtrace_record__info_fill(struct auxtrace_record *itr,
5668c2ecf20Sopenharmony_ci			       struct perf_session *session,
5678c2ecf20Sopenharmony_ci			       struct perf_record_auxtrace_info *auxtrace_info,
5688c2ecf20Sopenharmony_ci			       size_t priv_size);
5698c2ecf20Sopenharmony_civoid auxtrace_record__free(struct auxtrace_record *itr);
5708c2ecf20Sopenharmony_ciint auxtrace_record__snapshot_start(struct auxtrace_record *itr);
5718c2ecf20Sopenharmony_ciint auxtrace_record__snapshot_finish(struct auxtrace_record *itr, bool on_exit);
5728c2ecf20Sopenharmony_ciint auxtrace_record__find_snapshot(struct auxtrace_record *itr, int idx,
5738c2ecf20Sopenharmony_ci				   struct auxtrace_mmap *mm,
5748c2ecf20Sopenharmony_ci				   unsigned char *data, u64 *head, u64 *old);
5758c2ecf20Sopenharmony_ciu64 auxtrace_record__reference(struct auxtrace_record *itr);
5768c2ecf20Sopenharmony_ciint auxtrace_record__read_finish(struct auxtrace_record *itr, int idx);
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ciint auxtrace_index__auxtrace_event(struct list_head *head, union perf_event *event,
5798c2ecf20Sopenharmony_ci				   off_t file_offset);
5808c2ecf20Sopenharmony_ciint auxtrace_index__write(int fd, struct list_head *head);
5818c2ecf20Sopenharmony_ciint auxtrace_index__process(int fd, u64 size, struct perf_session *session,
5828c2ecf20Sopenharmony_ci			    bool needs_swap);
5838c2ecf20Sopenharmony_civoid auxtrace_index__free(struct list_head *head);
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_civoid auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type,
5868c2ecf20Sopenharmony_ci			  int code, int cpu, pid_t pid, pid_t tid, u64 ip,
5878c2ecf20Sopenharmony_ci			  const char *msg, u64 timestamp);
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ciint perf_event__process_auxtrace_info(struct perf_session *session,
5908c2ecf20Sopenharmony_ci				      union perf_event *event);
5918c2ecf20Sopenharmony_cis64 perf_event__process_auxtrace(struct perf_session *session,
5928c2ecf20Sopenharmony_ci				 union perf_event *event);
5938c2ecf20Sopenharmony_ciint perf_event__process_auxtrace_error(struct perf_session *session,
5948c2ecf20Sopenharmony_ci				       union perf_event *event);
5958c2ecf20Sopenharmony_ciint itrace_parse_synth_opts(const struct option *opt, const char *str,
5968c2ecf20Sopenharmony_ci			    int unset);
5978c2ecf20Sopenharmony_civoid itrace_synth_opts__set_default(struct itrace_synth_opts *synth_opts,
5988c2ecf20Sopenharmony_ci				    bool no_sample);
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_cisize_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp);
6018c2ecf20Sopenharmony_civoid perf_session__auxtrace_error_inc(struct perf_session *session,
6028c2ecf20Sopenharmony_ci				      union perf_event *event);
6038c2ecf20Sopenharmony_civoid events_stats__auxtrace_error_warn(const struct events_stats *stats);
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_civoid addr_filters__init(struct addr_filters *filts);
6068c2ecf20Sopenharmony_civoid addr_filters__exit(struct addr_filters *filts);
6078c2ecf20Sopenharmony_ciint addr_filters__parse_bare_filter(struct addr_filters *filts,
6088c2ecf20Sopenharmony_ci				    const char *filter);
6098c2ecf20Sopenharmony_ciint auxtrace_parse_filters(struct evlist *evlist);
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ciint auxtrace__process_event(struct perf_session *session, union perf_event *event,
6128c2ecf20Sopenharmony_ci			    struct perf_sample *sample, struct perf_tool *tool);
6138c2ecf20Sopenharmony_civoid auxtrace__dump_auxtrace_sample(struct perf_session *session,
6148c2ecf20Sopenharmony_ci				    struct perf_sample *sample);
6158c2ecf20Sopenharmony_ciint auxtrace__flush_events(struct perf_session *session, struct perf_tool *tool);
6168c2ecf20Sopenharmony_civoid auxtrace__free_events(struct perf_session *session);
6178c2ecf20Sopenharmony_civoid auxtrace__free(struct perf_session *session);
6188c2ecf20Sopenharmony_cibool auxtrace__evsel_is_auxtrace(struct perf_session *session,
6198c2ecf20Sopenharmony_ci				 struct evsel *evsel);
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci#define ITRACE_HELP \
6228c2ecf20Sopenharmony_ci"				i[period]:    		synthesize instructions events\n" \
6238c2ecf20Sopenharmony_ci"				b:	    		synthesize branches events (branch misses for Arm SPE)\n" \
6248c2ecf20Sopenharmony_ci"				c:	    		synthesize branches events (calls only)\n"	\
6258c2ecf20Sopenharmony_ci"				r:	    		synthesize branches events (returns only)\n" \
6268c2ecf20Sopenharmony_ci"				x:	    		synthesize transactions events\n"		\
6278c2ecf20Sopenharmony_ci"				w:	    		synthesize ptwrite events\n"		\
6288c2ecf20Sopenharmony_ci"				p:	    		synthesize power events\n"			\
6298c2ecf20Sopenharmony_ci"				o:			synthesize other events recorded due to the use\n" \
6308c2ecf20Sopenharmony_ci"							of aux-output (refer to perf record)\n"	\
6318c2ecf20Sopenharmony_ci"				e[flags]:		synthesize error events\n" \
6328c2ecf20Sopenharmony_ci"							each flag must be preceded by + or -\n" \
6338c2ecf20Sopenharmony_ci"							error flags are: o (overflow)\n" \
6348c2ecf20Sopenharmony_ci"									 l (data lost)\n" \
6358c2ecf20Sopenharmony_ci"				d[flags]:		create a debug log\n" \
6368c2ecf20Sopenharmony_ci"							each flag must be preceded by + or -\n" \
6378c2ecf20Sopenharmony_ci"							log flags are: a (all perf events)\n" \
6388c2ecf20Sopenharmony_ci"				f:	    		synthesize first level cache events\n" \
6398c2ecf20Sopenharmony_ci"				m:	    		synthesize last level cache events\n" \
6408c2ecf20Sopenharmony_ci"				t:	    		synthesize TLB events\n" \
6418c2ecf20Sopenharmony_ci"				a:	    		synthesize remote access events\n" \
6428c2ecf20Sopenharmony_ci"				g[len]:     		synthesize a call chain (use with i or x)\n" \
6438c2ecf20Sopenharmony_ci"				G[len]:			synthesize a call chain on existing event records\n" \
6448c2ecf20Sopenharmony_ci"				l[len]:     		synthesize last branch entries (use with i or x)\n" \
6458c2ecf20Sopenharmony_ci"				L[len]:			synthesize last branch entries on existing event records\n" \
6468c2ecf20Sopenharmony_ci"				sNUMBER:    		skip initial number of events\n"		\
6478c2ecf20Sopenharmony_ci"				q:			quicker (less detailed) decoding\n" \
6488c2ecf20Sopenharmony_ci"				PERIOD[ns|us|ms|i|t]:   specify period to sample stream\n" \
6498c2ecf20Sopenharmony_ci"				concatenate multiple options. Default is ibxwpe or cewp\n"
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_cistatic inline
6528c2ecf20Sopenharmony_civoid itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts,
6538c2ecf20Sopenharmony_ci				       struct perf_time_interval *ptime_range,
6548c2ecf20Sopenharmony_ci				       int range_num)
6558c2ecf20Sopenharmony_ci{
6568c2ecf20Sopenharmony_ci	opts->ptime_range = ptime_range;
6578c2ecf20Sopenharmony_ci	opts->range_num = range_num;
6588c2ecf20Sopenharmony_ci}
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_cistatic inline
6618c2ecf20Sopenharmony_civoid itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts)
6628c2ecf20Sopenharmony_ci{
6638c2ecf20Sopenharmony_ci	opts->ptime_range = NULL;
6648c2ecf20Sopenharmony_ci	opts->range_num = 0;
6658c2ecf20Sopenharmony_ci}
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci#else
6688c2ecf20Sopenharmony_ci#include "debug.h"
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_cistatic inline struct auxtrace_record *
6718c2ecf20Sopenharmony_ciauxtrace_record__init(struct evlist *evlist __maybe_unused,
6728c2ecf20Sopenharmony_ci		      int *err)
6738c2ecf20Sopenharmony_ci{
6748c2ecf20Sopenharmony_ci	*err = 0;
6758c2ecf20Sopenharmony_ci	return NULL;
6768c2ecf20Sopenharmony_ci}
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_cistatic inline
6798c2ecf20Sopenharmony_civoid auxtrace_record__free(struct auxtrace_record *itr __maybe_unused)
6808c2ecf20Sopenharmony_ci{
6818c2ecf20Sopenharmony_ci}
6828c2ecf20Sopenharmony_ci
6838c2ecf20Sopenharmony_cistatic inline
6848c2ecf20Sopenharmony_ciint auxtrace_record__options(struct auxtrace_record *itr __maybe_unused,
6858c2ecf20Sopenharmony_ci			     struct evlist *evlist __maybe_unused,
6868c2ecf20Sopenharmony_ci			     struct record_opts *opts __maybe_unused)
6878c2ecf20Sopenharmony_ci{
6888c2ecf20Sopenharmony_ci	return 0;
6898c2ecf20Sopenharmony_ci}
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci#define perf_event__process_auxtrace_info		0
6928c2ecf20Sopenharmony_ci#define perf_event__process_auxtrace			0
6938c2ecf20Sopenharmony_ci#define perf_event__process_auxtrace_error		0
6948c2ecf20Sopenharmony_ci
6958c2ecf20Sopenharmony_cistatic inline
6968c2ecf20Sopenharmony_civoid perf_session__auxtrace_error_inc(struct perf_session *session
6978c2ecf20Sopenharmony_ci				      __maybe_unused,
6988c2ecf20Sopenharmony_ci				      union perf_event *event
6998c2ecf20Sopenharmony_ci				      __maybe_unused)
7008c2ecf20Sopenharmony_ci{
7018c2ecf20Sopenharmony_ci}
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_cistatic inline
7048c2ecf20Sopenharmony_civoid events_stats__auxtrace_error_warn(const struct events_stats *stats
7058c2ecf20Sopenharmony_ci				       __maybe_unused)
7068c2ecf20Sopenharmony_ci{
7078c2ecf20Sopenharmony_ci}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_cistatic inline
7108c2ecf20Sopenharmony_ciint itrace_parse_synth_opts(const struct option *opt __maybe_unused,
7118c2ecf20Sopenharmony_ci			    const char *str __maybe_unused,
7128c2ecf20Sopenharmony_ci			    int unset __maybe_unused)
7138c2ecf20Sopenharmony_ci{
7148c2ecf20Sopenharmony_ci	pr_err("AUX area tracing not supported\n");
7158c2ecf20Sopenharmony_ci	return -EINVAL;
7168c2ecf20Sopenharmony_ci}
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_cistatic inline
7198c2ecf20Sopenharmony_ciint auxtrace_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
7208c2ecf20Sopenharmony_ci				    struct record_opts *opts __maybe_unused,
7218c2ecf20Sopenharmony_ci				    const char *str)
7228c2ecf20Sopenharmony_ci{
7238c2ecf20Sopenharmony_ci	if (!str)
7248c2ecf20Sopenharmony_ci		return 0;
7258c2ecf20Sopenharmony_ci	pr_err("AUX area tracing not supported\n");
7268c2ecf20Sopenharmony_ci	return -EINVAL;
7278c2ecf20Sopenharmony_ci}
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_cistatic inline
7308c2ecf20Sopenharmony_ciint auxtrace_parse_sample_options(struct auxtrace_record *itr __maybe_unused,
7318c2ecf20Sopenharmony_ci				  struct evlist *evlist __maybe_unused,
7328c2ecf20Sopenharmony_ci				  struct record_opts *opts __maybe_unused,
7338c2ecf20Sopenharmony_ci				  const char *str)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	if (!str)
7368c2ecf20Sopenharmony_ci		return 0;
7378c2ecf20Sopenharmony_ci	pr_err("AUX area tracing not supported\n");
7388c2ecf20Sopenharmony_ci	return -EINVAL;
7398c2ecf20Sopenharmony_ci}
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_cistatic inline
7428c2ecf20Sopenharmony_ciint auxtrace__process_event(struct perf_session *session __maybe_unused,
7438c2ecf20Sopenharmony_ci			    union perf_event *event __maybe_unused,
7448c2ecf20Sopenharmony_ci			    struct perf_sample *sample __maybe_unused,
7458c2ecf20Sopenharmony_ci			    struct perf_tool *tool __maybe_unused)
7468c2ecf20Sopenharmony_ci{
7478c2ecf20Sopenharmony_ci	return 0;
7488c2ecf20Sopenharmony_ci}
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_cistatic inline
7518c2ecf20Sopenharmony_civoid auxtrace__dump_auxtrace_sample(struct perf_session *session __maybe_unused,
7528c2ecf20Sopenharmony_ci				    struct perf_sample *sample __maybe_unused)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci}
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_cistatic inline
7578c2ecf20Sopenharmony_ciint auxtrace__flush_events(struct perf_session *session __maybe_unused,
7588c2ecf20Sopenharmony_ci			   struct perf_tool *tool __maybe_unused)
7598c2ecf20Sopenharmony_ci{
7608c2ecf20Sopenharmony_ci	return 0;
7618c2ecf20Sopenharmony_ci}
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_cistatic inline
7648c2ecf20Sopenharmony_civoid auxtrace__free_events(struct perf_session *session __maybe_unused)
7658c2ecf20Sopenharmony_ci{
7668c2ecf20Sopenharmony_ci}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_cistatic inline
7698c2ecf20Sopenharmony_civoid auxtrace_cache__free(struct auxtrace_cache *auxtrace_cache __maybe_unused)
7708c2ecf20Sopenharmony_ci{
7718c2ecf20Sopenharmony_ci}
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_cistatic inline
7748c2ecf20Sopenharmony_civoid auxtrace__free(struct perf_session *session __maybe_unused)
7758c2ecf20Sopenharmony_ci{
7768c2ecf20Sopenharmony_ci}
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_cistatic inline
7798c2ecf20Sopenharmony_ciint auxtrace_index__write(int fd __maybe_unused,
7808c2ecf20Sopenharmony_ci			  struct list_head *head __maybe_unused)
7818c2ecf20Sopenharmony_ci{
7828c2ecf20Sopenharmony_ci	return -EINVAL;
7838c2ecf20Sopenharmony_ci}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_cistatic inline
7868c2ecf20Sopenharmony_ciint auxtrace_index__process(int fd __maybe_unused,
7878c2ecf20Sopenharmony_ci			    u64 size __maybe_unused,
7888c2ecf20Sopenharmony_ci			    struct perf_session *session __maybe_unused,
7898c2ecf20Sopenharmony_ci			    bool needs_swap __maybe_unused)
7908c2ecf20Sopenharmony_ci{
7918c2ecf20Sopenharmony_ci	return -EINVAL;
7928c2ecf20Sopenharmony_ci}
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_cistatic inline
7958c2ecf20Sopenharmony_civoid auxtrace_index__free(struct list_head *head __maybe_unused)
7968c2ecf20Sopenharmony_ci{
7978c2ecf20Sopenharmony_ci}
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_cistatic inline
8008c2ecf20Sopenharmony_cibool auxtrace__evsel_is_auxtrace(struct perf_session *session __maybe_unused,
8018c2ecf20Sopenharmony_ci				 struct evsel *evsel __maybe_unused)
8028c2ecf20Sopenharmony_ci{
8038c2ecf20Sopenharmony_ci	return false;
8048c2ecf20Sopenharmony_ci}
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_cistatic inline
8078c2ecf20Sopenharmony_ciint auxtrace_parse_filters(struct evlist *evlist __maybe_unused)
8088c2ecf20Sopenharmony_ci{
8098c2ecf20Sopenharmony_ci	return 0;
8108c2ecf20Sopenharmony_ci}
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ciint auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
8138c2ecf20Sopenharmony_ci			struct auxtrace_mmap_params *mp,
8148c2ecf20Sopenharmony_ci			void *userpg, int fd);
8158c2ecf20Sopenharmony_civoid auxtrace_mmap__munmap(struct auxtrace_mmap *mm);
8168c2ecf20Sopenharmony_civoid auxtrace_mmap_params__init(struct auxtrace_mmap_params *mp,
8178c2ecf20Sopenharmony_ci				off_t auxtrace_offset,
8188c2ecf20Sopenharmony_ci				unsigned int auxtrace_pages,
8198c2ecf20Sopenharmony_ci				bool auxtrace_overwrite);
8208c2ecf20Sopenharmony_civoid auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
8218c2ecf20Sopenharmony_ci				   struct evlist *evlist, int idx,
8228c2ecf20Sopenharmony_ci				   bool per_cpu);
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci#define ITRACE_HELP ""
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_cistatic inline
8278c2ecf20Sopenharmony_civoid itrace_synth_opts__set_time_range(struct itrace_synth_opts *opts
8288c2ecf20Sopenharmony_ci				       __maybe_unused,
8298c2ecf20Sopenharmony_ci				       struct perf_time_interval *ptime_range
8308c2ecf20Sopenharmony_ci				       __maybe_unused,
8318c2ecf20Sopenharmony_ci				       int range_num __maybe_unused)
8328c2ecf20Sopenharmony_ci{
8338c2ecf20Sopenharmony_ci}
8348c2ecf20Sopenharmony_ci
8358c2ecf20Sopenharmony_cistatic inline
8368c2ecf20Sopenharmony_civoid itrace_synth_opts__clear_time_range(struct itrace_synth_opts *opts
8378c2ecf20Sopenharmony_ci					 __maybe_unused)
8388c2ecf20Sopenharmony_ci{
8398c2ecf20Sopenharmony_ci}
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci#endif
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci#endif
844