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