18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM_VAR 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#ifdef CONFIG_PERF_EVENTS 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#undef __entry 88c2ecf20Sopenharmony_ci#define __entry entry 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#undef __get_dynamic_array 118c2ecf20Sopenharmony_ci#define __get_dynamic_array(field) \ 128c2ecf20Sopenharmony_ci ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#undef __get_dynamic_array_len 158c2ecf20Sopenharmony_ci#define __get_dynamic_array_len(field) \ 168c2ecf20Sopenharmony_ci ((__entry->__data_loc_##field >> 16) & 0xffff) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#undef __get_str 198c2ecf20Sopenharmony_ci#define __get_str(field) ((char *)__get_dynamic_array(field)) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#undef __get_bitmask 228c2ecf20Sopenharmony_ci#define __get_bitmask(field) (char *)__get_dynamic_array(field) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#undef __perf_count 258c2ecf20Sopenharmony_ci#define __perf_count(c) (__count = (c)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#undef __perf_task 288c2ecf20Sopenharmony_ci#define __perf_task(t) (__task = (t)) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 318c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 328c2ecf20Sopenharmony_cistatic notrace void \ 338c2ecf20Sopenharmony_ciperf_trace_##call(void *__data, proto) \ 348c2ecf20Sopenharmony_ci{ \ 358c2ecf20Sopenharmony_ci struct trace_event_call *event_call = __data; \ 368c2ecf20Sopenharmony_ci struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ 378c2ecf20Sopenharmony_ci struct trace_event_raw_##call *entry; \ 388c2ecf20Sopenharmony_ci struct pt_regs *__regs; \ 398c2ecf20Sopenharmony_ci u64 __count = 1; \ 408c2ecf20Sopenharmony_ci struct task_struct *__task = NULL; \ 418c2ecf20Sopenharmony_ci struct hlist_head *head; \ 428c2ecf20Sopenharmony_ci int __entry_size; \ 438c2ecf20Sopenharmony_ci int __data_size; \ 448c2ecf20Sopenharmony_ci int rctx; \ 458c2ecf20Sopenharmony_ci \ 468c2ecf20Sopenharmony_ci __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \ 478c2ecf20Sopenharmony_ci \ 488c2ecf20Sopenharmony_ci head = this_cpu_ptr(event_call->perf_events); \ 498c2ecf20Sopenharmony_ci if (!bpf_prog_array_valid(event_call) && \ 508c2ecf20Sopenharmony_ci __builtin_constant_p(!__task) && !__task && \ 518c2ecf20Sopenharmony_ci hlist_empty(head)) \ 528c2ecf20Sopenharmony_ci return; \ 538c2ecf20Sopenharmony_ci \ 548c2ecf20Sopenharmony_ci __entry_size = ALIGN(__data_size + sizeof(*entry) + sizeof(u32),\ 558c2ecf20Sopenharmony_ci sizeof(u64)); \ 568c2ecf20Sopenharmony_ci __entry_size -= sizeof(u32); \ 578c2ecf20Sopenharmony_ci \ 588c2ecf20Sopenharmony_ci entry = perf_trace_buf_alloc(__entry_size, &__regs, &rctx); \ 598c2ecf20Sopenharmony_ci if (!entry) \ 608c2ecf20Sopenharmony_ci return; \ 618c2ecf20Sopenharmony_ci \ 628c2ecf20Sopenharmony_ci perf_fetch_caller_regs(__regs); \ 638c2ecf20Sopenharmony_ci \ 648c2ecf20Sopenharmony_ci tstruct \ 658c2ecf20Sopenharmony_ci \ 668c2ecf20Sopenharmony_ci { assign; } \ 678c2ecf20Sopenharmony_ci \ 688c2ecf20Sopenharmony_ci perf_trace_run_bpf_submit(entry, __entry_size, rctx, \ 698c2ecf20Sopenharmony_ci event_call, __count, __regs, \ 708c2ecf20Sopenharmony_ci head, __task); \ 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci/* 748c2ecf20Sopenharmony_ci * This part is compiled out, it is only here as a build time check 758c2ecf20Sopenharmony_ci * to make sure that if the tracepoint handling changes, the 768c2ecf20Sopenharmony_ci * perf probe will fail to compile unless it too is updated. 778c2ecf20Sopenharmony_ci */ 788c2ecf20Sopenharmony_ci#undef DEFINE_EVENT 798c2ecf20Sopenharmony_ci#define DEFINE_EVENT(template, call, proto, args) \ 808c2ecf20Sopenharmony_cistatic inline void perf_test_probe_##call(void) \ 818c2ecf20Sopenharmony_ci{ \ 828c2ecf20Sopenharmony_ci check_trace_callback_type_##call(perf_trace_##template); \ 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 878c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ 888c2ecf20Sopenharmony_ci DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 918c2ecf20Sopenharmony_ci#endif /* CONFIG_PERF_EVENTS */ 92