xref: /openbmc/linux/include/trace/perf.h (revision 293d5b43)
1 
2 #undef TRACE_SYSTEM_VAR
3 
4 #ifdef CONFIG_PERF_EVENTS
5 
6 #undef __entry
7 #define __entry entry
8 
9 #undef __get_dynamic_array
10 #define __get_dynamic_array(field)	\
11 		((void *)__entry + (__entry->__data_loc_##field & 0xffff))
12 
13 #undef __get_dynamic_array_len
14 #define __get_dynamic_array_len(field)	\
15 		((__entry->__data_loc_##field >> 16) & 0xffff)
16 
17 #undef __get_str
18 #define __get_str(field) ((char *)__get_dynamic_array(field))
19 
20 #undef __get_bitmask
21 #define __get_bitmask(field) (char *)__get_dynamic_array(field)
22 
23 #undef __perf_count
24 #define __perf_count(c)	(__count = (c))
25 
26 #undef __perf_task
27 #define __perf_task(t)	(__task = (t))
28 
29 #undef DECLARE_EVENT_CLASS
30 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)	\
31 static notrace void							\
32 perf_trace_##call(void *__data, proto)					\
33 {									\
34 	struct trace_event_call *event_call = __data;			\
35 	struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
36 	struct trace_event_raw_##call *entry;				\
37 	struct bpf_prog *prog = event_call->prog;			\
38 	struct pt_regs *__regs;						\
39 	u64 __count = 1;						\
40 	struct task_struct *__task = NULL;				\
41 	struct hlist_head *head;					\
42 	int __entry_size;						\
43 	int __data_size;						\
44 	int rctx;							\
45 									\
46 	__data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
47 									\
48 	head = this_cpu_ptr(event_call->perf_events);			\
49 	if (!prog && __builtin_constant_p(!__task) && !__task &&	\
50 				hlist_empty(head))			\
51 		return;							\
52 									\
53 	__entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
54 			     sizeof(u64));				\
55 	__entry_size -= sizeof(u32);					\
56 									\
57 	entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx);	\
58 	if (!entry)							\
59 		return;							\
60 									\
61 	perf_fetch_caller_regs(__regs);					\
62 									\
63 	tstruct								\
64 									\
65 	{ assign; }							\
66 									\
67 	perf_trace_run_bpf_submit(entry, __entry_size, rctx,		\
68 				  event_call, __count, __regs,		\
69 				  head, __task);			\
70 }
71 
72 /*
73  * This part is compiled out, it is only here as a build time check
74  * to make sure that if the tracepoint handling changes, the
75  * perf probe will fail to compile unless it too is updated.
76  */
77 #undef DEFINE_EVENT
78 #define DEFINE_EVENT(template, call, proto, args)			\
79 static inline void perf_test_probe_##call(void)				\
80 {									\
81 	check_trace_callback_type_##call(perf_trace_##template);	\
82 }
83 
84 
85 #undef DEFINE_EVENT_PRINT
86 #define DEFINE_EVENT_PRINT(template, name, proto, args, print)	\
87 	DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
88 
89 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
90 #endif /* CONFIG_PERF_EVENTS */
91