1247 lines · 35.4 KB · C
RawDownload
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note *//* * Performance events: * *    Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de> *    Copyright (C) 2008-2011, Red Hat, Inc., Ingo Molnar *    Copyright (C) 2008-2011, Red Hat, Inc., Peter Zijlstra * * Data type definitions, declarations, prototypes. * *    Started by: Thomas Gleixner and Ingo Molnar * * For licencing details see kernel-base/COPYING */#ifndef _UAPI_LINUX_PERF_EVENT_H#define _UAPI_LINUX_PERF_EVENT_H #include <linux/types.h>#include <linux/ioctl.h>#include <asm/byteorder.h> /* * User-space ABI bits: */ /* * attr.type */enum perf_type_id {	PERF_TYPE_HARDWARE			= 0,	PERF_TYPE_SOFTWARE			= 1,	PERF_TYPE_TRACEPOINT			= 2,	PERF_TYPE_HW_CACHE			= 3,	PERF_TYPE_RAW				= 4,	PERF_TYPE_BREAKPOINT			= 5, 	PERF_TYPE_MAX,				/* non-ABI */}; /* * Generalized performance event event_id types, used by the * attr.event_id parameter of the sys_perf_event_open() * syscall: */enum perf_hw_id {	/*	 * Common hardware events, generalized by the kernel:	 */	PERF_COUNT_HW_CPU_CYCLES		= 0,	PERF_COUNT_HW_INSTRUCTIONS		= 1,	PERF_COUNT_HW_CACHE_REFERENCES		= 2,	PERF_COUNT_HW_CACHE_MISSES		= 3,	PERF_COUNT_HW_BRANCH_INSTRUCTIONS	= 4,	PERF_COUNT_HW_BRANCH_MISSES		= 5,	PERF_COUNT_HW_BUS_CYCLES		= 6,	PERF_COUNT_HW_STALLED_CYCLES_FRONTEND	= 7,	PERF_COUNT_HW_STALLED_CYCLES_BACKEND	= 8,	PERF_COUNT_HW_REF_CPU_CYCLES		= 9, 	PERF_COUNT_HW_MAX,			/* non-ABI */}; /* * Generalized hardware cache events: * *       { L1-D, L1-I, LLC, ITLB, DTLB, BPU, NODE } x *       { read, write, prefetch } x *       { accesses, misses } */enum perf_hw_cache_id {	PERF_COUNT_HW_CACHE_L1D			= 0,	PERF_COUNT_HW_CACHE_L1I			= 1,	PERF_COUNT_HW_CACHE_LL			= 2,	PERF_COUNT_HW_CACHE_DTLB		= 3,	PERF_COUNT_HW_CACHE_ITLB		= 4,	PERF_COUNT_HW_CACHE_BPU			= 5,	PERF_COUNT_HW_CACHE_NODE		= 6, 	PERF_COUNT_HW_CACHE_MAX,		/* non-ABI */}; enum perf_hw_cache_op_id {	PERF_COUNT_HW_CACHE_OP_READ		= 0,	PERF_COUNT_HW_CACHE_OP_WRITE		= 1,	PERF_COUNT_HW_CACHE_OP_PREFETCH		= 2, 	PERF_COUNT_HW_CACHE_OP_MAX,		/* non-ABI */}; enum perf_hw_cache_op_result_id {	PERF_COUNT_HW_CACHE_RESULT_ACCESS	= 0,	PERF_COUNT_HW_CACHE_RESULT_MISS		= 1, 	PERF_COUNT_HW_CACHE_RESULT_MAX,		/* non-ABI */}; /* * Special "software" events provided by the kernel, even if the hardware * does not support performance events. These events measure various * physical and sw events of the kernel (and allow the profiling of them as * well): */enum perf_sw_ids {	PERF_COUNT_SW_CPU_CLOCK			= 0,	PERF_COUNT_SW_TASK_CLOCK		= 1,	PERF_COUNT_SW_PAGE_FAULTS		= 2,	PERF_COUNT_SW_CONTEXT_SWITCHES		= 3,	PERF_COUNT_SW_CPU_MIGRATIONS		= 4,	PERF_COUNT_SW_PAGE_FAULTS_MIN		= 5,	PERF_COUNT_SW_PAGE_FAULTS_MAJ		= 6,	PERF_COUNT_SW_ALIGNMENT_FAULTS		= 7,	PERF_COUNT_SW_EMULATION_FAULTS		= 8,	PERF_COUNT_SW_DUMMY			= 9,	PERF_COUNT_SW_BPF_OUTPUT		= 10, 	PERF_COUNT_SW_MAX,			/* non-ABI */}; /* * Bits that can be set in attr.sample_type to request information * in the overflow packets. */enum perf_event_sample_format {	PERF_SAMPLE_IP				= 1U << 0,	PERF_SAMPLE_TID				= 1U << 1,	PERF_SAMPLE_TIME			= 1U << 2,	PERF_SAMPLE_ADDR			= 1U << 3,	PERF_SAMPLE_READ			= 1U << 4,	PERF_SAMPLE_CALLCHAIN			= 1U << 5,	PERF_SAMPLE_ID				= 1U << 6,	PERF_SAMPLE_CPU				= 1U << 7,	PERF_SAMPLE_PERIOD			= 1U << 8,	PERF_SAMPLE_STREAM_ID			= 1U << 9,	PERF_SAMPLE_RAW				= 1U << 10,	PERF_SAMPLE_BRANCH_STACK		= 1U << 11,	PERF_SAMPLE_REGS_USER			= 1U << 12,	PERF_SAMPLE_STACK_USER			= 1U << 13,	PERF_SAMPLE_WEIGHT			= 1U << 14,	PERF_SAMPLE_DATA_SRC			= 1U << 15,	PERF_SAMPLE_IDENTIFIER			= 1U << 16,	PERF_SAMPLE_TRANSACTION			= 1U << 17,	PERF_SAMPLE_REGS_INTR			= 1U << 18,	PERF_SAMPLE_PHYS_ADDR			= 1U << 19,	PERF_SAMPLE_AUX				= 1U << 20,	PERF_SAMPLE_CGROUP			= 1U << 21, 	PERF_SAMPLE_MAX = 1U << 22,		/* non-ABI */ 	__PERF_SAMPLE_CALLCHAIN_EARLY		= 1ULL << 63, /* non-ABI; internal use */}; /* * values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set * * If the user does not pass priv level information via branch_sample_type, * the kernel uses the event's priv level. Branch and event priv levels do * not have to match. Branch priv level is checked for permissions. * * The branch types can be combined, however BRANCH_ANY covers all types * of branches and therefore it supersedes all the other types. */enum perf_branch_sample_type_shift {	PERF_SAMPLE_BRANCH_USER_SHIFT		= 0, /* user branches */	PERF_SAMPLE_BRANCH_KERNEL_SHIFT		= 1, /* kernel branches */	PERF_SAMPLE_BRANCH_HV_SHIFT		= 2, /* hypervisor branches */ 	PERF_SAMPLE_BRANCH_ANY_SHIFT		= 3, /* any branch types */	PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT	= 4, /* any call branch */	PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT	= 5, /* any return branch */	PERF_SAMPLE_BRANCH_IND_CALL_SHIFT	= 6, /* indirect calls */	PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT	= 7, /* transaction aborts */	PERF_SAMPLE_BRANCH_IN_TX_SHIFT		= 8, /* in transaction */	PERF_SAMPLE_BRANCH_NO_TX_SHIFT		= 9, /* not in transaction */	PERF_SAMPLE_BRANCH_COND_SHIFT		= 10, /* conditional branches */ 	PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT	= 11, /* call/ret stack */	PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT	= 12, /* indirect jumps */	PERF_SAMPLE_BRANCH_CALL_SHIFT		= 13, /* direct call */ 	PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT	= 14, /* no flags */	PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT	= 15, /* no cycles */ 	PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT	= 16, /* save branch type */ 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */ 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */}; enum perf_branch_sample_type {	PERF_SAMPLE_BRANCH_USER		= 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,	PERF_SAMPLE_BRANCH_KERNEL	= 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,	PERF_SAMPLE_BRANCH_HV		= 1U << PERF_SAMPLE_BRANCH_HV_SHIFT, 	PERF_SAMPLE_BRANCH_ANY		= 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,	PERF_SAMPLE_BRANCH_ANY_CALL	= 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,	PERF_SAMPLE_BRANCH_ANY_RETURN	= 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,	PERF_SAMPLE_BRANCH_IND_CALL	= 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,	PERF_SAMPLE_BRANCH_ABORT_TX	= 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,	PERF_SAMPLE_BRANCH_IN_TX	= 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,	PERF_SAMPLE_BRANCH_NO_TX	= 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,	PERF_SAMPLE_BRANCH_COND		= 1U << PERF_SAMPLE_BRANCH_COND_SHIFT, 	PERF_SAMPLE_BRANCH_CALL_STACK	= 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,	PERF_SAMPLE_BRANCH_IND_JUMP	= 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,	PERF_SAMPLE_BRANCH_CALL		= 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT, 	PERF_SAMPLE_BRANCH_NO_FLAGS	= 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,	PERF_SAMPLE_BRANCH_NO_CYCLES	= 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT, 	PERF_SAMPLE_BRANCH_TYPE_SAVE	=		1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT, 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT, 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,}; /* * Common flow change classification */enum {	PERF_BR_UNKNOWN		= 0,	/* unknown */	PERF_BR_COND		= 1,	/* conditional */	PERF_BR_UNCOND		= 2,	/* unconditional  */	PERF_BR_IND		= 3,	/* indirect */	PERF_BR_CALL		= 4,	/* function call */	PERF_BR_IND_CALL	= 5,	/* indirect function call */	PERF_BR_RET		= 6,	/* function return */	PERF_BR_SYSCALL		= 7,	/* syscall */	PERF_BR_SYSRET		= 8,	/* syscall return */	PERF_BR_COND_CALL	= 9,	/* conditional function call */	PERF_BR_COND_RET	= 10,	/* conditional function return */	PERF_BR_MAX,}; #define PERF_SAMPLE_BRANCH_PLM_ALL \	(PERF_SAMPLE_BRANCH_USER|\	 PERF_SAMPLE_BRANCH_KERNEL|\	 PERF_SAMPLE_BRANCH_HV) /* * Values to determine ABI of the registers dump. */enum perf_sample_regs_abi {	PERF_SAMPLE_REGS_ABI_NONE	= 0,	PERF_SAMPLE_REGS_ABI_32		= 1,	PERF_SAMPLE_REGS_ABI_64		= 2,}; /* * Values for the memory transaction event qualifier, mostly for * abort events. Multiple bits can be set. */enum {	PERF_TXN_ELISION        = (1 << 0), /* From elision */	PERF_TXN_TRANSACTION    = (1 << 1), /* From transaction */	PERF_TXN_SYNC           = (1 << 2), /* Instruction is related */	PERF_TXN_ASYNC          = (1 << 3), /* Instruction not related */	PERF_TXN_RETRY          = (1 << 4), /* Retry possible */	PERF_TXN_CONFLICT       = (1 << 5), /* Conflict abort */	PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */	PERF_TXN_CAPACITY_READ  = (1 << 7), /* Capacity read abort */ 	PERF_TXN_MAX	        = (1 << 8), /* non-ABI */ 	/* bits 32..63 are reserved for the abort code */ 	PERF_TXN_ABORT_MASK  = (0xffffffffULL << 32),	PERF_TXN_ABORT_SHIFT = 32,}; /* * The format of the data returned by read() on a perf event fd, * as specified by attr.read_format: * * struct read_format { *	{ u64		value; *	  { u64		time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED *	  { u64		time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING *	  { u64		id;           } && PERF_FORMAT_ID *	} && !PERF_FORMAT_GROUP * *	{ u64		nr; *	  { u64		time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED *	  { u64		time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING *	  { u64		value; *	    { u64	id;           } && PERF_FORMAT_ID *	  }		cntr[nr]; *	} && PERF_FORMAT_GROUP * }; */enum perf_event_read_format {	PERF_FORMAT_TOTAL_TIME_ENABLED		= 1U << 0,	PERF_FORMAT_TOTAL_TIME_RUNNING		= 1U << 1,	PERF_FORMAT_ID				= 1U << 2,	PERF_FORMAT_GROUP			= 1U << 3, 	PERF_FORMAT_MAX = 1U << 4,		/* non-ABI */}; #define PERF_ATTR_SIZE_VER0	64	/* sizeof first published struct */#define PERF_ATTR_SIZE_VER1	72	/* add: config2 */#define PERF_ATTR_SIZE_VER2	80	/* add: branch_sample_type */#define PERF_ATTR_SIZE_VER3	96	/* add: sample_regs_user */					/* add: sample_stack_user */#define PERF_ATTR_SIZE_VER4	104	/* add: sample_regs_intr */#define PERF_ATTR_SIZE_VER5	112	/* add: aux_watermark */#define PERF_ATTR_SIZE_VER6	120	/* add: aux_sample_size */ /* * Hardware event_id to monitor via a performance monitoring event: * * @sample_max_stack: Max number of frame pointers in a callchain, *		      should be < /proc/sys/kernel/perf_event_max_stack */struct perf_event_attr { 	/*	 * Major type: hardware/software/tracepoint/etc.	 */	__u32			type; 	/*	 * Size of the attr structure, for fwd/bwd compat.	 */	__u32			size; 	/*	 * Type specific configuration information.	 */	__u64			config; 	union {		__u64		sample_period;		__u64		sample_freq;	}; 	__u64			sample_type;	__u64			read_format; 	__u64			disabled       :  1, /* off by default        */				inherit	       :  1, /* children inherit it   */				pinned	       :  1, /* must always be on PMU */				exclusive      :  1, /* only group on PMU     */				exclude_user   :  1, /* don't count user      */				exclude_kernel :  1, /* ditto kernel          */				exclude_hv     :  1, /* ditto hypervisor      */				exclude_idle   :  1, /* don't count when idle */				mmap           :  1, /* include mmap data     */				comm	       :  1, /* include comm data     */				freq           :  1, /* use freq, not period  */				inherit_stat   :  1, /* per task counts       */				enable_on_exec :  1, /* next exec enables     */				task           :  1, /* trace fork/exit       */				watermark      :  1, /* wakeup_watermark      */				/*				 * precise_ip:				 *				 *  0 - SAMPLE_IP can have arbitrary skid				 *  1 - SAMPLE_IP must have constant skid				 *  2 - SAMPLE_IP requested to have 0 skid				 *  3 - SAMPLE_IP must have 0 skid				 *				 *  See also PERF_RECORD_MISC_EXACT_IP				 */				precise_ip     :  2, /* skid constraint       */				mmap_data      :  1, /* non-exec mmap data    */				sample_id_all  :  1, /* sample_type all events */ 				exclude_host   :  1, /* don't count in host   */				exclude_guest  :  1, /* don't count in guest  */ 				exclude_callchain_kernel : 1, /* exclude kernel callchains */				exclude_callchain_user   : 1, /* exclude user callchains */				mmap2          :  1, /* include mmap with inode data     */				comm_exec      :  1, /* flag comm events that are due to an exec */				use_clockid    :  1, /* use @clockid for time fields */				context_switch :  1, /* context switch data */				write_backward :  1, /* Write ring buffer from end to beginning */				namespaces     :  1, /* include namespaces data */				ksymbol        :  1, /* include ksymbol events */				bpf_event      :  1, /* include bpf events */				aux_output     :  1, /* generate AUX records instead of events */				cgroup         :  1, /* include cgroup events */				text_poke      :  1, /* include text poke events */				__reserved_1   : 30; 	union {		__u32		wakeup_events;	  /* wakeup every n events */		__u32		wakeup_watermark; /* bytes before wakeup   */	}; 	__u32			bp_type;	union {		__u64		bp_addr;		__u64		kprobe_func; /* for perf_kprobe */		__u64		uprobe_path; /* for perf_uprobe */		__u64		config1; /* extension of config */	};	union {		__u64		bp_len;		__u64		kprobe_addr; /* when kprobe_func == NULL */		__u64		probe_offset; /* for perf_[k,u]probe */		__u64		config2; /* extension of config1 */	};	__u64	branch_sample_type; /* enum perf_branch_sample_type */ 	/*	 * Defines set of user regs to dump on samples.	 * See asm/perf_regs.h for details.	 */	__u64	sample_regs_user; 	/*	 * Defines size of the user stack to dump on samples.	 */	__u32	sample_stack_user; 	__s32	clockid;	/*	 * Defines set of regs to dump for each sample	 * state captured on:	 *  - precise = 0: PMU interrupt	 *  - precise > 0: sampled instruction	 *	 * See asm/perf_regs.h for details.	 */	__u64	sample_regs_intr; 	/*	 * Wakeup watermark for AUX area	 */	__u32	aux_watermark;	__u16	sample_max_stack;	__u16	__reserved_2;	__u32	aux_sample_size;	__u32	__reserved_3;}; /* * Structure used by below PERF_EVENT_IOC_QUERY_BPF command * to query bpf programs attached to the same perf tracepoint * as the given perf event. */struct perf_event_query_bpf {	/*	 * The below ids array length	 */	__u32	ids_len;	/*	 * Set by the kernel to indicate the number of	 * available programs	 */	__u32	prog_cnt;	/*	 * User provided buffer to store program ids	 */	__u32	ids[0];}; /* * Ioctls that can be done on a perf event fd: */#define PERF_EVENT_IOC_ENABLE			_IO ('$', 0)#define PERF_EVENT_IOC_DISABLE			_IO ('$', 1)#define PERF_EVENT_IOC_REFRESH			_IO ('$', 2)#define PERF_EVENT_IOC_RESET			_IO ('$', 3)#define PERF_EVENT_IOC_PERIOD			_IOW('$', 4, __u64)#define PERF_EVENT_IOC_SET_OUTPUT		_IO ('$', 5)#define PERF_EVENT_IOC_SET_FILTER		_IOW('$', 6, char *)#define PERF_EVENT_IOC_ID			_IOR('$', 7, __u64 *)#define PERF_EVENT_IOC_SET_BPF			_IOW('$', 8, __u32)#define PERF_EVENT_IOC_PAUSE_OUTPUT		_IOW('$', 9, __u32)#define PERF_EVENT_IOC_QUERY_BPF		_IOWR('$', 10, struct perf_event_query_bpf *)#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES	_IOW('$', 11, struct perf_event_attr *) enum perf_event_ioc_flags {	PERF_IOC_FLAG_GROUP		= 1U << 0,}; /* * Structure of the page that can be mapped via mmap */struct perf_event_mmap_page {	__u32	version;		/* version number of this structure */	__u32	compat_version;		/* lowest version this is compat with */ 	/*	 * Bits needed to read the hw events in user-space.	 *	 *   u32 seq, time_mult, time_shift, index, width;	 *   u64 count, enabled, running;	 *   u64 cyc, time_offset;	 *   s64 pmc = 0;	 *	 *   do {	 *     seq = pc->lock;	 *     barrier()	 *

Lines 1–500 of 1247.