Linux Audio

Check our new training course

Loading...
v3.5.6
 
  1#ifndef __PERF_RECORD_H
  2#define __PERF_RECORD_H
  3
  4#include <limits.h>
  5#include <stdio.h>
  6
  7#include "../perf.h"
  8#include "map.h"
  9
 10/*
 11 * PERF_SAMPLE_IP | PERF_SAMPLE_TID | *
 
 
 
 12 */
 13struct ip_event {
 14	struct perf_event_header header;
 15	u64 ip;
 16	u32 pid, tid;
 17	unsigned char __more_data[];
 18};
 19
 20struct mmap_event {
 21	struct perf_event_header header;
 22	u32 pid, tid;
 23	u64 start;
 24	u64 len;
 25	u64 pgoff;
 26	char filename[PATH_MAX];
 27};
 28
 29struct comm_event {
 30	struct perf_event_header header;
 31	u32 pid, tid;
 32	char comm[16];
 33};
 34
 35struct fork_event {
 36	struct perf_event_header header;
 37	u32 pid, ppid;
 38	u32 tid, ptid;
 39	u64 time;
 40};
 41
 42struct lost_event {
 43	struct perf_event_header header;
 44	u64 id;
 45	u64 lost;
 46};
 47
 
 48/*
 49 * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
 
 
 
 50 */
 51struct read_event {
 52	struct perf_event_header header;
 53	u32 pid, tid;
 54	u64 value;
 55	u64 time_enabled;
 56	u64 time_running;
 57	u64 id;
 58};
 59
 60
 61#define PERF_SAMPLE_MASK				\
 62	(PERF_SAMPLE_IP | PERF_SAMPLE_TID |		\
 63	 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |		\
 64	PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID |	\
 65	 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
 
 66
 67struct sample_event {
 68	struct perf_event_header        header;
 69	u64 array[];
 70};
 71
 72struct perf_sample {
 73	u64 ip;
 74	u32 pid, tid;
 75	u64 time;
 76	u64 addr;
 77	u64 id;
 78	u64 stream_id;
 79	u64 period;
 80	u32 cpu;
 81	u32 raw_size;
 82	void *raw_data;
 83	struct ip_callchain *callchain;
 84	struct branch_stack *branch_stack;
 85};
 86
 87#define BUILD_ID_SIZE 20
 88
 89struct build_id_event {
 90	struct perf_event_header header;
 91	pid_t			 pid;
 92	u8			 build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
 93	char			 filename[];
 94};
 95
 96enum perf_user_event_type { /* above any possible kernel type */
 97	PERF_RECORD_USER_TYPE_START		= 64,
 98	PERF_RECORD_HEADER_ATTR			= 64,
 99	PERF_RECORD_HEADER_EVENT_TYPE		= 65,
100	PERF_RECORD_HEADER_TRACING_DATA		= 66,
101	PERF_RECORD_HEADER_BUILD_ID		= 67,
102	PERF_RECORD_FINISHED_ROUND		= 68,
103	PERF_RECORD_HEADER_MAX
104};
105
106struct attr_event {
107	struct perf_event_header header;
108	struct perf_event_attr attr;
109	u64 id[];
110};
111
112#define MAX_EVENT_NAME 64
113
114struct perf_trace_event_type {
115	u64	event_id;
116	char	name[MAX_EVENT_NAME];
117};
118
119struct event_type_event {
120	struct perf_event_header header;
121	struct perf_trace_event_type event_type;
122};
123
124struct tracing_data_event {
125	struct perf_event_header header;
126	u32 size;
127};
128
129union perf_event {
130	struct perf_event_header	header;
131	struct ip_event			ip;
132	struct mmap_event		mmap;
133	struct comm_event		comm;
134	struct fork_event		fork;
135	struct lost_event		lost;
136	struct read_event		read;
137	struct sample_event		sample;
138	struct attr_event		attr;
139	struct event_type_event		event_type;
140	struct tracing_data_event	tracing_data;
141	struct build_id_event		build_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142};
143
144void perf_event__print_totals(void);
145
 
 
 
146struct perf_tool;
147struct thread_map;
148
149typedef int (*perf_event__handler_t)(struct perf_tool *tool,
 
 
 
 
 
 
 
 
 
 
 
150				     union perf_event *event,
151				     struct perf_sample *sample,
152				     struct machine *machine);
153
154int perf_event__synthesize_thread_map(struct perf_tool *tool,
155				      struct thread_map *threads,
156				      perf_event__handler_t process,
157				      struct machine *machine);
158int perf_event__synthesize_threads(struct perf_tool *tool,
159				   perf_event__handler_t process,
160				   struct machine *machine);
161int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
162				       perf_event__handler_t process,
163				       struct machine *machine,
164				       const char *symbol_name);
165
166int perf_event__synthesize_modules(struct perf_tool *tool,
167				   perf_event__handler_t process,
 
 
 
 
168				   struct machine *machine);
169
170int perf_event__process_comm(struct perf_tool *tool,
 
 
 
171			     union perf_event *event,
172			     struct perf_sample *sample,
173			     struct machine *machine);
174int perf_event__process_lost(struct perf_tool *tool,
175			     union perf_event *event,
176			     struct perf_sample *sample,
177			     struct machine *machine);
178int perf_event__process_mmap(struct perf_tool *tool,
179			     union perf_event *event,
180			     struct perf_sample *sample,
181			     struct machine *machine);
182int perf_event__process_task(struct perf_tool *tool,
183			     union perf_event *event,
184			     struct perf_sample *sample,
185			     struct machine *machine);
186int perf_event__process(struct perf_tool *tool,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187			union perf_event *event,
188			struct perf_sample *sample,
189			struct machine *machine);
190
191struct addr_location;
192int perf_event__preprocess_sample(const union perf_event *self,
193				  struct machine *machine,
194				  struct addr_location *al,
195				  struct perf_sample *sample,
196				  symbol_filter_t filter);
197
198const char *perf_event__name(unsigned int id);
199
200int perf_event__parse_sample(const union perf_event *event, u64 type,
201			     int sample_size, bool sample_id_all,
202			     struct perf_sample *sample, bool swapped);
203int perf_event__synthesize_sample(union perf_event *event, u64 type,
204				  const struct perf_sample *sample,
205				  bool swapped);
206
207size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
208size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
 
209size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
210size_t perf_event__fprintf(union perf_event *event, FILE *fp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
212#endif /* __PERF_RECORD_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_RECORD_H
  3#define __PERF_RECORD_H
 
 
 
 
 
 
 
  4/*
  5 * The linux/stddef.h isn't need here, but is needed for __always_inline used
  6 * in files included from uapi/linux/perf_event.h such as
  7 * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
  8 * detected in at least musl libc, used in Alpine Linux. -acme
  9 */
 10#include <stdio.h>
 11#include <linux/stddef.h>
 12#include <perf/event.h>
 13#include <linux/types.h>
 14
 15struct dso;
 16struct machine;
 17struct perf_event_attr;
 18struct perf_sample;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 19
 20#ifdef __LP64__
 21/*
 22 * /usr/include/inttypes.h uses just 'lu' for PRIu64, but we end up defining
 23 * __u64 as long long unsigned int, and then -Werror=format= kicks in and
 24 * complains of the mismatched types, so use these two special extra PRI
 25 * macros to overcome that.
 26 */
 27#define PRI_lu64 "l" PRIu64
 28#define PRI_lx64 "l" PRIx64
 29#define PRI_ld64 "l" PRId64
 30#else
 31#define PRI_lu64 PRIu64
 32#define PRI_lx64 PRIx64
 33#define PRI_ld64 PRId64
 34#endif
 
 35
 36#define PERF_SAMPLE_MASK				\
 37	(PERF_SAMPLE_IP | PERF_SAMPLE_TID |		\
 38	 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR |		\
 39	PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID |	\
 40	 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD |		\
 41	 PERF_SAMPLE_IDENTIFIER)
 42
 43/* perf sample has 16 bits size limit */
 44#define PERF_SAMPLE_MAX_SIZE (1 << 16)
 45
 46struct ip_callchain {
 47	u64 nr;
 48	u64 ips[];
 49};
 50
 51struct branch_stack;
 52
 53enum {
 54	PERF_IP_FLAG_BRANCH		= 1ULL << 0,
 55	PERF_IP_FLAG_CALL		= 1ULL << 1,
 56	PERF_IP_FLAG_RETURN		= 1ULL << 2,
 57	PERF_IP_FLAG_CONDITIONAL	= 1ULL << 3,
 58	PERF_IP_FLAG_SYSCALLRET		= 1ULL << 4,
 59	PERF_IP_FLAG_ASYNC		= 1ULL << 5,
 60	PERF_IP_FLAG_INTERRUPT		= 1ULL << 6,
 61	PERF_IP_FLAG_TX_ABORT		= 1ULL << 7,
 62	PERF_IP_FLAG_TRACE_BEGIN	= 1ULL << 8,
 63	PERF_IP_FLAG_TRACE_END		= 1ULL << 9,
 64	PERF_IP_FLAG_IN_TX		= 1ULL << 10,
 65	PERF_IP_FLAG_VMENTRY		= 1ULL << 11,
 66	PERF_IP_FLAG_VMEXIT		= 1ULL << 12,
 67	PERF_IP_FLAG_INTR_DISABLE	= 1ULL << 13,
 68	PERF_IP_FLAG_INTR_TOGGLE	= 1ULL << 14,
 69	PERF_IP_FLAG_BRANCH_MISS	= 1ULL << 15,
 70};
 71
 72#define PERF_IP_FLAG_CHARS "bcrosyiABExghDt"
 73
 74#define PERF_BRANCH_MASK		(\
 75	PERF_IP_FLAG_BRANCH		|\
 76	PERF_IP_FLAG_CALL		|\
 77	PERF_IP_FLAG_RETURN		|\
 78	PERF_IP_FLAG_CONDITIONAL	|\
 79	PERF_IP_FLAG_SYSCALLRET		|\
 80	PERF_IP_FLAG_ASYNC		|\
 81	PERF_IP_FLAG_INTERRUPT		|\
 82	PERF_IP_FLAG_TX_ABORT		|\
 83	PERF_IP_FLAG_TRACE_BEGIN	|\
 84	PERF_IP_FLAG_TRACE_END		|\
 85	PERF_IP_FLAG_VMENTRY		|\
 86	PERF_IP_FLAG_VMEXIT)
 87
 88#define PERF_MEM_DATA_SRC_NONE \
 89	(PERF_MEM_S(OP, NA) |\
 90	 PERF_MEM_S(LVL, NA) |\
 91	 PERF_MEM_S(SNOOP, NA) |\
 92	 PERF_MEM_S(LOCK, NA) |\
 93	 PERF_MEM_S(TLB, NA) |\
 94	 PERF_MEM_S(LVLNUM, NA))
 95
 96/* Attribute type for custom synthesized events */
 97#define PERF_TYPE_SYNTH		(INT_MAX + 1U)
 98
 99/* Attribute config for custom synthesized events */
100enum perf_synth_id {
101	PERF_SYNTH_INTEL_PTWRITE,
102	PERF_SYNTH_INTEL_MWAIT,
103	PERF_SYNTH_INTEL_PWRE,
104	PERF_SYNTH_INTEL_EXSTOP,
105	PERF_SYNTH_INTEL_PWRX,
106	PERF_SYNTH_INTEL_CBR,
107	PERF_SYNTH_INTEL_PSB,
108	PERF_SYNTH_INTEL_EVT,
109	PERF_SYNTH_INTEL_IFLAG_CHG,
110};
111
112/*
113 * Raw data formats for synthesized events. Note that 4 bytes of padding are
114 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
115 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
116 * Refer perf_sample__synth_ptr() and perf_synth__raw_data().  It also means the
117 * structure sizes are 4 bytes bigger than the raw_size, refer
118 * perf_synth__raw_size().
119 */
120
121struct perf_synth_intel_ptwrite {
122	u32 padding;
123	union {
124		struct {
125			u32	ip		:  1,
126				reserved	: 31;
127		};
128		u32	flags;
129	};
130	u64	payload;
131};
132
133struct perf_synth_intel_mwait {
134	u32 padding;
135	u32 reserved;
136	union {
137		struct {
138			u64	hints		:  8,
139				reserved1	: 24,
140				extensions	:  2,
141				reserved2	: 30;
142		};
143		u64	payload;
144	};
145};
146
147struct perf_synth_intel_pwre {
148	u32 padding;
149	u32 reserved;
150	union {
151		struct {
152			u64	reserved1	:  7,
153				hw		:  1,
154				subcstate	:  4,
155				cstate		:  4,
156				reserved2	: 48;
157		};
158		u64	payload;
159	};
160};
161
162struct perf_synth_intel_exstop {
163	u32 padding;
164	union {
165		struct {
166			u32	ip		:  1,
167				reserved	: 31;
168		};
169		u32	flags;
170	};
171};
172
173struct perf_synth_intel_pwrx {
174	u32 padding;
175	u32 reserved;
176	union {
177		struct {
178			u64	deepest_cstate	:  4,
179				last_cstate	:  4,
180				wake_reason	:  4,
181				reserved1	: 52;
182		};
183		u64	payload;
184	};
185};
186
187struct perf_synth_intel_cbr {
188	u32 padding;
189	union {
190		struct {
191			u32	cbr		:  8,
192				reserved1	:  8,
193				max_nonturbo	:  8,
194				reserved2	:  8;
195		};
196		u32	flags;
197	};
198	u32 freq;
199	u32 reserved3;
200};
201
202struct perf_synth_intel_psb {
203	u32 padding;
204	u32 reserved;
205	u64 offset;
206};
207
208struct perf_synth_intel_evd {
209	union {
210		struct {
211			u8	evd_type;
212			u8	reserved[7];
213		};
214		u64	et;
215	};
216	u64	payload;
217};
218
219/* Intel PT Event Trace */
220struct perf_synth_intel_evt {
221	u32 padding;
222	union {
223		struct {
224			u32	type		:  5,
225				reserved	:  2,
226				ip		:  1,
227				vector		:  8,
228				evd_cnt		: 16;
229		};
230		u32	cfe;
231	};
232	struct perf_synth_intel_evd evd[0];
233};
234
235struct perf_synth_intel_iflag_chg {
236	u32 padding;
237	union {
238		struct {
239			u32	iflag		:  1,
240				via_branch	:  1;
241		};
242		u32	flags;
243	};
244	u64	branch_ip; /* If via_branch */
245};
246
247static inline void *perf_synth__raw_data(void *p)
248{
249	return p + 4;
250}
251
252#define perf_synth__raw_size(d) (sizeof(d) - 4)
253
254#define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
255
256enum {
257	PERF_STAT_ROUND_TYPE__INTERVAL	= 0,
258	PERF_STAT_ROUND_TYPE__FINAL	= 1,
259};
260
261void perf_event__print_totals(void);
262
263struct perf_cpu_map;
264struct perf_record_stat_config;
265struct perf_stat_config;
266struct perf_tool;
 
267
268void perf_event__read_stat_config(struct perf_stat_config *config,
269				  struct perf_record_stat_config *event);
270
271int perf_event__process_comm(const struct perf_tool *tool,
272			     union perf_event *event,
273			     struct perf_sample *sample,
274			     struct machine *machine);
275int perf_event__process_lost(const struct perf_tool *tool,
276			     union perf_event *event,
277			     struct perf_sample *sample,
278			     struct machine *machine);
279int perf_event__process_lost_samples(const struct perf_tool *tool,
280				     union perf_event *event,
281				     struct perf_sample *sample,
282				     struct machine *machine);
283int perf_event__process_aux(const struct perf_tool *tool,
284			    union perf_event *event,
285			    struct perf_sample *sample,
286			    struct machine *machine);
287int perf_event__process_itrace_start(const struct perf_tool *tool,
288				     union perf_event *event,
289				     struct perf_sample *sample,
290				     struct machine *machine);
291int perf_event__process_aux_output_hw_id(const struct perf_tool *tool,
292					 union perf_event *event,
293					 struct perf_sample *sample,
294					 struct machine *machine);
295int perf_event__process_switch(const struct perf_tool *tool,
296			       union perf_event *event,
297			       struct perf_sample *sample,
298			       struct machine *machine);
299int perf_event__process_namespaces(const struct perf_tool *tool,
300				   union perf_event *event,
301				   struct perf_sample *sample,
302				   struct machine *machine);
303int perf_event__process_cgroup(const struct perf_tool *tool,
304			       union perf_event *event,
305			       struct perf_sample *sample,
306			       struct machine *machine);
307int perf_event__process_mmap(const struct perf_tool *tool,
308			     union perf_event *event,
309			     struct perf_sample *sample,
310			     struct machine *machine);
311int perf_event__process_mmap2(const struct perf_tool *tool,
312			     union perf_event *event,
313			     struct perf_sample *sample,
314			     struct machine *machine);
315int perf_event__process_fork(const struct perf_tool *tool,
316			     union perf_event *event,
317			     struct perf_sample *sample,
318			     struct machine *machine);
319int perf_event__process_exit(const struct perf_tool *tool,
320			     union perf_event *event,
321			     struct perf_sample *sample,
322			     struct machine *machine);
323int perf_event__exit_del_thread(const struct perf_tool *tool,
324				union perf_event *event,
325				struct perf_sample *sample,
326				struct machine *machine);
327int perf_event__process_ksymbol(const struct perf_tool *tool,
328				union perf_event *event,
329				struct perf_sample *sample,
330				struct machine *machine);
331int perf_event__process_bpf(const struct perf_tool *tool,
332			    union perf_event *event,
333			    struct perf_sample *sample,
334			    struct machine *machine);
335int perf_event__process_text_poke(const struct perf_tool *tool,
336				  union perf_event *event,
337				  struct perf_sample *sample,
338				  struct machine *machine);
339int perf_event__process(const struct perf_tool *tool,
340			union perf_event *event,
341			struct perf_sample *sample,
342			struct machine *machine);
343
344bool is_bts_event(struct perf_event_attr *attr);
345bool sample_addr_correlates_sym(struct perf_event_attr *attr);
 
 
 
 
346
347const char *perf_event__name(unsigned int id);
348
 
 
 
 
 
 
 
349size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
350size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
351size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
352size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
353size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
354size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
355size_t perf_event__fprintf_aux_output_hw_id(union perf_event *event, FILE *fp);
356size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
357size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
358size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
359size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
360size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
361size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
362size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
363size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
364size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
365
366int kallsyms__get_function_start(const char *kallsyms_filename,
367				 const char *symbol_name, u64 *addr);
368int kallsyms__get_symbol_start(const char *kallsyms_filename,
369			       const char *symbol_name, u64 *addr);
370
371void event_attr_init(struct perf_event_attr *attr);
372
373int perf_event_paranoid(void);
374bool perf_event_paranoid_check(int max_level);
375
376extern int sysctl_perf_event_max_stack;
377extern int sysctl_perf_event_max_contexts_per_stack;
378extern unsigned int proc_map_timeout;
379
380#define PAGE_SIZE_NAME_LEN	32
381char *get_page_size_name(u64 size, char *str);
382
383void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type);
384void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type);
385const char *arch_perf_header_entry(const char *se_header);
386int arch_support_sort_key(const char *sort_key);
387
388static inline bool perf_event_header__cpumode_is_guest(u8 cpumode)
389{
390	return cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
391	       cpumode == PERF_RECORD_MISC_GUEST_USER;
392}
393
394static inline bool perf_event_header__misc_is_guest(u16 misc)
395{
396	return perf_event_header__cpumode_is_guest(misc & PERF_RECORD_MISC_CPUMODE_MASK);
397}
398
399static inline bool perf_event_header__is_guest(const struct perf_event_header *header)
400{
401	return perf_event_header__misc_is_guest(header->misc);
402}
403
404static inline bool perf_event__is_guest(const union perf_event *event)
405{
406	return perf_event_header__is_guest(&event->header);
407}
408
409#endif /* __PERF_RECORD_H */