blob: ea4405de175a3eb6892a29896bee45800c5936a2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -04002
3#undef TRACE_SYSTEM_VAR
4
5#ifdef CONFIG_PERF_EVENTS
6
7#undef __entry
8#define __entry entry
9
10#undef __get_dynamic_array
11#define __get_dynamic_array(field) \
12 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
13
14#undef __get_dynamic_array_len
15#define __get_dynamic_array_len(field) \
16 ((__entry->__data_loc_##field >> 16) & 0xffff)
17
18#undef __get_str
Daniel Bristot de Oliveira934de5f2016-07-01 20:44:34 -030019#define __get_str(field) ((char *)__get_dynamic_array(field))
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040020
21#undef __get_bitmask
22#define __get_bitmask(field) (char *)__get_dynamic_array(field)
23
Masami Hiramatsu55de2c02021-11-22 18:30:21 +090024#undef __get_rel_dynamic_array
25#define __get_rel_dynamic_array(field) \
26 ((void *)(&__entry->__rel_loc_##field) + \
27 sizeof(__entry->__rel_loc_##field) + \
28 (__entry->__rel_loc_##field & 0xffff))
29
30#undef __get_rel_dynamic_array_len
31#define __get_rel_dynamic_array_len(field) \
32 ((__entry->__rel_loc_##field >> 16) & 0xffff)
33
34#undef __get_rel_str
35#define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
36
37#undef __get_rel_bitmask
38#define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
39
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040040#undef __perf_count
41#define __perf_count(c) (__count = (c))
42
43#undef __perf_task
44#define __perf_task(t) (__task = (t))
45
46#undef DECLARE_EVENT_CLASS
47#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
48static notrace void \
49perf_trace_##call(void *__data, proto) \
50{ \
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -040051 struct trace_event_call *event_call = __data; \
Steven Rostedt (Red Hat)62323a12015-05-13 15:33:52 -040052 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
Steven Rostedt (Red Hat)a7237762015-05-13 15:27:47 -040053 struct trace_event_raw_##call *entry; \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040054 struct pt_regs *__regs; \
Alexei Starovoitove93735b2016-04-06 18:43:23 -070055 u64 __count = 1; \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040056 struct task_struct *__task = NULL; \
57 struct hlist_head *head; \
58 int __entry_size; \
59 int __data_size; \
60 int rctx; \
61 \
Steven Rostedt (Red Hat)d0ee8f42015-05-13 15:40:23 -040062 __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040063 \
64 head = this_cpu_ptr(event_call->perf_events); \
Yonghong Songe87c6bc2017-10-23 23:53:08 -070065 if (!bpf_prog_array_valid(event_call) && \
66 __builtin_constant_p(!__task) && !__task && \
67 hlist_empty(head)) \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040068 return; \
69 \
70 __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\
71 sizeof(u64)); \
72 __entry_size -= sizeof(u32); \
73 \
Alexei Starovoitov1e1dcd92016-04-06 18:43:24 -070074 entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040075 if (!entry) \
76 return; \
77 \
78 perf_fetch_caller_regs(__regs); \
79 \
80 tstruct \
81 \
82 { assign; } \
83 \
Alexei Starovoitov85b67bc2016-04-18 20:11:50 -070084 perf_trace_run_bpf_submit(entry, __entry_size, rctx, \
85 event_call, __count, __regs, \
86 head, __task); \
Steven Rostedt (Red Hat)ee53bbd2015-04-29 13:11:00 -040087}
88
89/*
90 * This part is compiled out, it is only here as a build time check
91 * to make sure that if the tracepoint handling changes, the
92 * perf probe will fail to compile unless it too is updated.
93 */
94#undef DEFINE_EVENT
95#define DEFINE_EVENT(template, call, proto, args) \
96static inline void perf_test_probe_##call(void) \
97{ \
98 check_trace_callback_type_##call(perf_trace_##template); \
99}
100
101
102#undef DEFINE_EVENT_PRINT
103#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
104 DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
105
106#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
107#endif /* CONFIG_PERF_EVENTS */