Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 2 | |
| 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 Oliveira | 934de5f | 2016-07-01 20:44:34 -0300 | [diff] [blame] | 19 | #define __get_str(field) ((char *)__get_dynamic_array(field)) |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 20 | |
| 21 | #undef __get_bitmask |
| 22 | #define __get_bitmask(field) (char *)__get_dynamic_array(field) |
| 23 | |
Masami Hiramatsu | 55de2c0 | 2021-11-22 18:30:21 +0900 | [diff] [blame] | 24 | #undef __get_rel_dynamic_array |
| 25 | #define __get_rel_dynamic_array(field) \ |
Kees Cook | c6d777a | 2022-01-25 14:00:37 -0800 | [diff] [blame] | 26 | ((void *)__entry + \ |
| 27 | offsetof(typeof(*__entry), __rel_loc_##field) + \ |
| 28 | sizeof(__entry->__rel_loc_##field) + \ |
Masami Hiramatsu | 55de2c0 | 2021-11-22 18:30:21 +0900 | [diff] [blame] | 29 | (__entry->__rel_loc_##field & 0xffff)) |
| 30 | |
| 31 | #undef __get_rel_dynamic_array_len |
| 32 | #define __get_rel_dynamic_array_len(field) \ |
| 33 | ((__entry->__rel_loc_##field >> 16) & 0xffff) |
| 34 | |
| 35 | #undef __get_rel_str |
| 36 | #define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field)) |
| 37 | |
| 38 | #undef __get_rel_bitmask |
| 39 | #define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field) |
| 40 | |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 41 | #undef __perf_count |
| 42 | #define __perf_count(c) (__count = (c)) |
| 43 | |
| 44 | #undef __perf_task |
| 45 | #define __perf_task(t) (__task = (t)) |
| 46 | |
| 47 | #undef DECLARE_EVENT_CLASS |
| 48 | #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ |
| 49 | static notrace void \ |
| 50 | perf_trace_##call(void *__data, proto) \ |
| 51 | { \ |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 52 | struct trace_event_call *event_call = __data; \ |
Steven Rostedt (Red Hat) | 62323a1 | 2015-05-13 15:33:52 -0400 | [diff] [blame] | 53 | struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 54 | struct trace_event_raw_##call *entry; \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 55 | struct pt_regs *__regs; \ |
Alexei Starovoitov | e93735b | 2016-04-06 18:43:23 -0700 | [diff] [blame] | 56 | u64 __count = 1; \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 57 | struct task_struct *__task = NULL; \ |
| 58 | struct hlist_head *head; \ |
| 59 | int __entry_size; \ |
| 60 | int __data_size; \ |
| 61 | int rctx; \ |
| 62 | \ |
Steven Rostedt (Red Hat) | d0ee8f4 | 2015-05-13 15:40:23 -0400 | [diff] [blame] | 63 | __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 64 | \ |
| 65 | head = this_cpu_ptr(event_call->perf_events); \ |
Yonghong Song | e87c6bc | 2017-10-23 23:53:08 -0700 | [diff] [blame] | 66 | if (!bpf_prog_array_valid(event_call) && \ |
| 67 | __builtin_constant_p(!__task) && !__task && \ |
| 68 | hlist_empty(head)) \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 69 | return; \ |
| 70 | \ |
| 71 | __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ |
| 72 | sizeof(u64)); \ |
| 73 | __entry_size -= sizeof(u32); \ |
| 74 | \ |
Alexei Starovoitov | 1e1dcd9 | 2016-04-06 18:43:24 -0700 | [diff] [blame] | 75 | entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 76 | if (!entry) \ |
| 77 | return; \ |
| 78 | \ |
| 79 | perf_fetch_caller_regs(__regs); \ |
| 80 | \ |
| 81 | tstruct \ |
| 82 | \ |
| 83 | { assign; } \ |
| 84 | \ |
Alexei Starovoitov | 85b67bc | 2016-04-18 20:11:50 -0700 | [diff] [blame] | 85 | perf_trace_run_bpf_submit(entry, __entry_size, rctx, \ |
| 86 | event_call, __count, __regs, \ |
| 87 | head, __task); \ |
Steven Rostedt (Red Hat) | ee53bbd | 2015-04-29 13:11:00 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* |
| 91 | * This part is compiled out, it is only here as a build time check |
| 92 | * to make sure that if the tracepoint handling changes, the |
| 93 | * perf probe will fail to compile unless it too is updated. |
| 94 | */ |
| 95 | #undef DEFINE_EVENT |
| 96 | #define DEFINE_EVENT(template, call, proto, args) \ |
| 97 | static inline void perf_test_probe_##call(void) \ |
| 98 | { \ |
| 99 | check_trace_callback_type_##call(perf_trace_##template); \ |
| 100 | } |
| 101 | |
| 102 | |
| 103 | #undef DEFINE_EVENT_PRINT |
| 104 | #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ |
| 105 | DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) |
| 106 | |
| 107 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) |
| 108 | #endif /* CONFIG_PERF_EVENTS */ |