18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Stage 1 of the trace events. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Override the macros in the event tracepoint header <trace/events/XXX.h> 68c2ecf20Sopenharmony_ci * to include the following: 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * struct trace_event_raw_<call> { 98c2ecf20Sopenharmony_ci * struct trace_entry ent; 108c2ecf20Sopenharmony_ci * <type> <item>; 118c2ecf20Sopenharmony_ci * <type2> <item2>[<len>]; 128c2ecf20Sopenharmony_ci * [...] 138c2ecf20Sopenharmony_ci * }; 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * The <type> <item> is created by the __field(type, item) macro or 168c2ecf20Sopenharmony_ci * the __array(type2, item2, len) macro. 178c2ecf20Sopenharmony_ci * We simply do "type item;", and that will create the fields 188c2ecf20Sopenharmony_ci * in the structure. 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <linux/trace_events.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#ifndef TRACE_SYSTEM_VAR 248c2ecf20Sopenharmony_ci#define TRACE_SYSTEM_VAR TRACE_SYSTEM 258c2ecf20Sopenharmony_ci#endif 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define __app__(x, y) str__##x##y 288c2ecf20Sopenharmony_ci#define __app(x, y) __app__(x, y) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define TRACE_MAKE_SYSTEM_STR() \ 338c2ecf20Sopenharmony_ci static const char TRACE_SYSTEM_STRING[] = \ 348c2ecf20Sopenharmony_ci __stringify(TRACE_SYSTEM) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciTRACE_MAKE_SYSTEM_STR(); 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#undef TRACE_DEFINE_ENUM 398c2ecf20Sopenharmony_ci#define TRACE_DEFINE_ENUM(a) \ 408c2ecf20Sopenharmony_ci static struct trace_eval_map __used __initdata \ 418c2ecf20Sopenharmony_ci __##TRACE_SYSTEM##_##a = \ 428c2ecf20Sopenharmony_ci { \ 438c2ecf20Sopenharmony_ci .system = TRACE_SYSTEM_STRING, \ 448c2ecf20Sopenharmony_ci .eval_string = #a, \ 458c2ecf20Sopenharmony_ci .eval_value = a \ 468c2ecf20Sopenharmony_ci }; \ 478c2ecf20Sopenharmony_ci static struct trace_eval_map __used \ 488c2ecf20Sopenharmony_ci __section("_ftrace_eval_map") \ 498c2ecf20Sopenharmony_ci *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#undef TRACE_DEFINE_SIZEOF 528c2ecf20Sopenharmony_ci#define TRACE_DEFINE_SIZEOF(a) \ 538c2ecf20Sopenharmony_ci static struct trace_eval_map __used __initdata \ 548c2ecf20Sopenharmony_ci __##TRACE_SYSTEM##_##a = \ 558c2ecf20Sopenharmony_ci { \ 568c2ecf20Sopenharmony_ci .system = TRACE_SYSTEM_STRING, \ 578c2ecf20Sopenharmony_ci .eval_string = "sizeof(" #a ")", \ 588c2ecf20Sopenharmony_ci .eval_value = sizeof(a) \ 598c2ecf20Sopenharmony_ci }; \ 608c2ecf20Sopenharmony_ci static struct trace_eval_map __used \ 618c2ecf20Sopenharmony_ci __section("_ftrace_eval_map") \ 628c2ecf20Sopenharmony_ci *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* 658c2ecf20Sopenharmony_ci * DECLARE_EVENT_CLASS can be used to add a generic function 668c2ecf20Sopenharmony_ci * handlers for events. That is, if all events have the same 678c2ecf20Sopenharmony_ci * parameters and just have distinct trace points. 688c2ecf20Sopenharmony_ci * Each tracepoint can be defined with DEFINE_EVENT and that 698c2ecf20Sopenharmony_ci * will map the DECLARE_EVENT_CLASS to the tracepoint. 708c2ecf20Sopenharmony_ci * 718c2ecf20Sopenharmony_ci * TRACE_EVENT is a one to one mapping between tracepoint and template. 728c2ecf20Sopenharmony_ci */ 738c2ecf20Sopenharmony_ci#undef TRACE_EVENT 748c2ecf20Sopenharmony_ci#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \ 758c2ecf20Sopenharmony_ci DECLARE_EVENT_CLASS(name, \ 768c2ecf20Sopenharmony_ci PARAMS(proto), \ 778c2ecf20Sopenharmony_ci PARAMS(args), \ 788c2ecf20Sopenharmony_ci PARAMS(tstruct), \ 798c2ecf20Sopenharmony_ci PARAMS(assign), \ 808c2ecf20Sopenharmony_ci PARAMS(print)); \ 818c2ecf20Sopenharmony_ci DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#undef __field 858c2ecf20Sopenharmony_ci#define __field(type, item) type item; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#undef __field_ext 888c2ecf20Sopenharmony_ci#define __field_ext(type, item, filter_type) type item; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci#undef __field_struct 918c2ecf20Sopenharmony_ci#define __field_struct(type, item) type item; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#undef __field_struct_ext 948c2ecf20Sopenharmony_ci#define __field_struct_ext(type, item, filter_type) type item; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci#undef __array 978c2ecf20Sopenharmony_ci#define __array(type, item, len) type item[len]; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#undef __dynamic_array 1008c2ecf20Sopenharmony_ci#define __dynamic_array(type, item, len) u32 __data_loc_##item; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#undef __string 1038c2ecf20Sopenharmony_ci#define __string(item, src) __dynamic_array(char, item, -1) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci#undef __bitmask 1068c2ecf20Sopenharmony_ci#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1) 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci#undef TP_STRUCT__entry 1098c2ecf20Sopenharmony_ci#define TP_STRUCT__entry(args...) args 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 1128c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \ 1138c2ecf20Sopenharmony_ci struct trace_event_raw_##name { \ 1148c2ecf20Sopenharmony_ci struct trace_entry ent; \ 1158c2ecf20Sopenharmony_ci tstruct \ 1168c2ecf20Sopenharmony_ci char __data[0]; \ 1178c2ecf20Sopenharmony_ci }; \ 1188c2ecf20Sopenharmony_ci \ 1198c2ecf20Sopenharmony_ci static struct trace_event_class event_class_##name; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#undef DEFINE_EVENT 1228c2ecf20Sopenharmony_ci#define DEFINE_EVENT(template, name, proto, args) \ 1238c2ecf20Sopenharmony_ci static struct trace_event_call __used \ 1248c2ecf20Sopenharmony_ci __attribute__((__aligned__(4))) event_##name 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_FN 1278c2ecf20Sopenharmony_ci#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \ 1288c2ecf20Sopenharmony_ci DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 1318c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ 1328c2ecf20Sopenharmony_ci DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci/* Callbacks are meaningless to ftrace. */ 1358c2ecf20Sopenharmony_ci#undef TRACE_EVENT_FN 1368c2ecf20Sopenharmony_ci#define TRACE_EVENT_FN(name, proto, args, tstruct, \ 1378c2ecf20Sopenharmony_ci assign, print, reg, unreg) \ 1388c2ecf20Sopenharmony_ci TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \ 1398c2ecf20Sopenharmony_ci PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_ci#undef TRACE_EVENT_FN_COND 1428c2ecf20Sopenharmony_ci#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \ 1438c2ecf20Sopenharmony_ci assign, print, reg, unreg) \ 1448c2ecf20Sopenharmony_ci TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \ 1458c2ecf20Sopenharmony_ci PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#undef TRACE_EVENT_FLAGS 1488c2ecf20Sopenharmony_ci#define TRACE_EVENT_FLAGS(name, value) \ 1498c2ecf20Sopenharmony_ci __TRACE_EVENT_FLAGS(name, value) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci#undef TRACE_EVENT_PERF_PERM 1528c2ecf20Sopenharmony_ci#define TRACE_EVENT_PERF_PERM(name, expr...) \ 1538c2ecf20Sopenharmony_ci __TRACE_EVENT_PERF_PERM(name, expr) 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci/* 1588c2ecf20Sopenharmony_ci * Stage 2 of the trace events. 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * Include the following: 1618c2ecf20Sopenharmony_ci * 1628c2ecf20Sopenharmony_ci * struct trace_event_data_offsets_<call> { 1638c2ecf20Sopenharmony_ci * u32 <item1>; 1648c2ecf20Sopenharmony_ci * u32 <item2>; 1658c2ecf20Sopenharmony_ci * [...] 1668c2ecf20Sopenharmony_ci * }; 1678c2ecf20Sopenharmony_ci * 1688c2ecf20Sopenharmony_ci * The __dynamic_array() macro will create each u32 <item>, this is 1698c2ecf20Sopenharmony_ci * to keep the offset of each array from the beginning of the event. 1708c2ecf20Sopenharmony_ci * The size of an array is also encoded, in the higher 16 bits of <item>. 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ci#undef TRACE_DEFINE_ENUM 1748c2ecf20Sopenharmony_ci#define TRACE_DEFINE_ENUM(a) 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#undef TRACE_DEFINE_SIZEOF 1778c2ecf20Sopenharmony_ci#define TRACE_DEFINE_SIZEOF(a) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci#undef __field 1808c2ecf20Sopenharmony_ci#define __field(type, item) 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci#undef __field_ext 1838c2ecf20Sopenharmony_ci#define __field_ext(type, item, filter_type) 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#undef __field_struct 1868c2ecf20Sopenharmony_ci#define __field_struct(type, item) 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci#undef __field_struct_ext 1898c2ecf20Sopenharmony_ci#define __field_struct_ext(type, item, filter_type) 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#undef __array 1928c2ecf20Sopenharmony_ci#define __array(type, item, len) 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#undef __dynamic_array 1958c2ecf20Sopenharmony_ci#define __dynamic_array(type, item, len) u32 item; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci#undef __string 1988c2ecf20Sopenharmony_ci#define __string(item, src) __dynamic_array(char, item, -1) 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci#undef __bitmask 2018c2ecf20Sopenharmony_ci#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 2048c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 2058c2ecf20Sopenharmony_ci struct trace_event_data_offsets_##call { \ 2068c2ecf20Sopenharmony_ci tstruct; \ 2078c2ecf20Sopenharmony_ci }; 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ci#undef DEFINE_EVENT 2108c2ecf20Sopenharmony_ci#define DEFINE_EVENT(template, name, proto, args) 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 2138c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, name, proto, args, print) 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci#undef TRACE_EVENT_FLAGS 2168c2ecf20Sopenharmony_ci#define TRACE_EVENT_FLAGS(event, flag) 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci#undef TRACE_EVENT_PERF_PERM 2198c2ecf20Sopenharmony_ci#define TRACE_EVENT_PERF_PERM(event, expr...) 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci/* 2248c2ecf20Sopenharmony_ci * Stage 3 of the trace events. 2258c2ecf20Sopenharmony_ci * 2268c2ecf20Sopenharmony_ci * Override the macros in the event tracepoint header <trace/events/XXX.h> 2278c2ecf20Sopenharmony_ci * to include the following: 2288c2ecf20Sopenharmony_ci * 2298c2ecf20Sopenharmony_ci * enum print_line_t 2308c2ecf20Sopenharmony_ci * trace_raw_output_<call>(struct trace_iterator *iter, int flags) 2318c2ecf20Sopenharmony_ci * { 2328c2ecf20Sopenharmony_ci * struct trace_seq *s = &iter->seq; 2338c2ecf20Sopenharmony_ci * struct trace_event_raw_<call> *field; <-- defined in stage 1 2348c2ecf20Sopenharmony_ci * struct trace_entry *entry; 2358c2ecf20Sopenharmony_ci * struct trace_seq *p = &iter->tmp_seq; 2368c2ecf20Sopenharmony_ci * int ret; 2378c2ecf20Sopenharmony_ci * 2388c2ecf20Sopenharmony_ci * entry = iter->ent; 2398c2ecf20Sopenharmony_ci * 2408c2ecf20Sopenharmony_ci * if (entry->type != event_<call>->event.type) { 2418c2ecf20Sopenharmony_ci * WARN_ON_ONCE(1); 2428c2ecf20Sopenharmony_ci * return TRACE_TYPE_UNHANDLED; 2438c2ecf20Sopenharmony_ci * } 2448c2ecf20Sopenharmony_ci * 2458c2ecf20Sopenharmony_ci * field = (typeof(field))entry; 2468c2ecf20Sopenharmony_ci * 2478c2ecf20Sopenharmony_ci * trace_seq_init(p); 2488c2ecf20Sopenharmony_ci * ret = trace_seq_printf(s, "%s: ", <call>); 2498c2ecf20Sopenharmony_ci * if (ret) 2508c2ecf20Sopenharmony_ci * ret = trace_seq_printf(s, <TP_printk> "\n"); 2518c2ecf20Sopenharmony_ci * if (!ret) 2528c2ecf20Sopenharmony_ci * return TRACE_TYPE_PARTIAL_LINE; 2538c2ecf20Sopenharmony_ci * 2548c2ecf20Sopenharmony_ci * return TRACE_TYPE_HANDLED; 2558c2ecf20Sopenharmony_ci * } 2568c2ecf20Sopenharmony_ci * 2578c2ecf20Sopenharmony_ci * This is the method used to print the raw event to the trace 2588c2ecf20Sopenharmony_ci * output format. Note, this is not needed if the data is read 2598c2ecf20Sopenharmony_ci * in binary. 2608c2ecf20Sopenharmony_ci */ 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci#undef __entry 2638c2ecf20Sopenharmony_ci#define __entry field 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci#undef TP_printk 2668c2ecf20Sopenharmony_ci#define TP_printk(fmt, args...) fmt "\n", args 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci#undef __get_dynamic_array 2698c2ecf20Sopenharmony_ci#define __get_dynamic_array(field) \ 2708c2ecf20Sopenharmony_ci ((void *)__entry + (__entry->__data_loc_##field & 0xffff)) 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci#undef __get_dynamic_array_len 2738c2ecf20Sopenharmony_ci#define __get_dynamic_array_len(field) \ 2748c2ecf20Sopenharmony_ci ((__entry->__data_loc_##field >> 16) & 0xffff) 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci#undef __get_str 2778c2ecf20Sopenharmony_ci#define __get_str(field) ((char *)__get_dynamic_array(field)) 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci#undef __get_bitmask 2808c2ecf20Sopenharmony_ci#define __get_bitmask(field) \ 2818c2ecf20Sopenharmony_ci ({ \ 2828c2ecf20Sopenharmony_ci void *__bitmask = __get_dynamic_array(field); \ 2838c2ecf20Sopenharmony_ci unsigned int __bitmask_size; \ 2848c2ecf20Sopenharmony_ci __bitmask_size = __get_dynamic_array_len(field); \ 2858c2ecf20Sopenharmony_ci trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \ 2868c2ecf20Sopenharmony_ci }) 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci#undef __print_flags 2898c2ecf20Sopenharmony_ci#define __print_flags(flag, delim, flag_array...) \ 2908c2ecf20Sopenharmony_ci ({ \ 2918c2ecf20Sopenharmony_ci static const struct trace_print_flags __flags[] = \ 2928c2ecf20Sopenharmony_ci { flag_array, { -1, NULL }}; \ 2938c2ecf20Sopenharmony_ci trace_print_flags_seq(p, delim, flag, __flags); \ 2948c2ecf20Sopenharmony_ci }) 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci#undef __print_symbolic 2978c2ecf20Sopenharmony_ci#define __print_symbolic(value, symbol_array...) \ 2988c2ecf20Sopenharmony_ci ({ \ 2998c2ecf20Sopenharmony_ci static const struct trace_print_flags symbols[] = \ 3008c2ecf20Sopenharmony_ci { symbol_array, { -1, NULL }}; \ 3018c2ecf20Sopenharmony_ci trace_print_symbols_seq(p, value, symbols); \ 3028c2ecf20Sopenharmony_ci }) 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci#undef __print_flags_u64 3058c2ecf20Sopenharmony_ci#undef __print_symbolic_u64 3068c2ecf20Sopenharmony_ci#if BITS_PER_LONG == 32 3078c2ecf20Sopenharmony_ci#define __print_flags_u64(flag, delim, flag_array...) \ 3088c2ecf20Sopenharmony_ci ({ \ 3098c2ecf20Sopenharmony_ci static const struct trace_print_flags_u64 __flags[] = \ 3108c2ecf20Sopenharmony_ci { flag_array, { -1, NULL } }; \ 3118c2ecf20Sopenharmony_ci trace_print_flags_seq_u64(p, delim, flag, __flags); \ 3128c2ecf20Sopenharmony_ci }) 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_ci#define __print_symbolic_u64(value, symbol_array...) \ 3158c2ecf20Sopenharmony_ci ({ \ 3168c2ecf20Sopenharmony_ci static const struct trace_print_flags_u64 symbols[] = \ 3178c2ecf20Sopenharmony_ci { symbol_array, { -1, NULL } }; \ 3188c2ecf20Sopenharmony_ci trace_print_symbols_seq_u64(p, value, symbols); \ 3198c2ecf20Sopenharmony_ci }) 3208c2ecf20Sopenharmony_ci#else 3218c2ecf20Sopenharmony_ci#define __print_flags_u64(flag, delim, flag_array...) \ 3228c2ecf20Sopenharmony_ci __print_flags(flag, delim, flag_array) 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci#define __print_symbolic_u64(value, symbol_array...) \ 3258c2ecf20Sopenharmony_ci __print_symbolic(value, symbol_array) 3268c2ecf20Sopenharmony_ci#endif 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci#undef __print_hex 3298c2ecf20Sopenharmony_ci#define __print_hex(buf, buf_len) \ 3308c2ecf20Sopenharmony_ci trace_print_hex_seq(p, buf, buf_len, false) 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci#undef __print_hex_str 3338c2ecf20Sopenharmony_ci#define __print_hex_str(buf, buf_len) \ 3348c2ecf20Sopenharmony_ci trace_print_hex_seq(p, buf, buf_len, true) 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci#undef __print_array 3378c2ecf20Sopenharmony_ci#define __print_array(array, count, el_size) \ 3388c2ecf20Sopenharmony_ci ({ \ 3398c2ecf20Sopenharmony_ci BUILD_BUG_ON(el_size != 1 && el_size != 2 && \ 3408c2ecf20Sopenharmony_ci el_size != 4 && el_size != 8); \ 3418c2ecf20Sopenharmony_ci trace_print_array_seq(p, array, count, el_size); \ 3428c2ecf20Sopenharmony_ci }) 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci#undef __print_hex_dump 3458c2ecf20Sopenharmony_ci#define __print_hex_dump(prefix_str, prefix_type, \ 3468c2ecf20Sopenharmony_ci rowsize, groupsize, buf, len, ascii) \ 3478c2ecf20Sopenharmony_ci trace_print_hex_dump_seq(p, prefix_str, prefix_type, \ 3488c2ecf20Sopenharmony_ci rowsize, groupsize, buf, len, ascii) 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 3518c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 3528c2ecf20Sopenharmony_cistatic notrace enum print_line_t \ 3538c2ecf20Sopenharmony_citrace_raw_output_##call(struct trace_iterator *iter, int flags, \ 3548c2ecf20Sopenharmony_ci struct trace_event *trace_event) \ 3558c2ecf20Sopenharmony_ci{ \ 3568c2ecf20Sopenharmony_ci struct trace_seq *s = &iter->seq; \ 3578c2ecf20Sopenharmony_ci struct trace_seq __maybe_unused *p = &iter->tmp_seq; \ 3588c2ecf20Sopenharmony_ci struct trace_event_raw_##call *field; \ 3598c2ecf20Sopenharmony_ci int ret; \ 3608c2ecf20Sopenharmony_ci \ 3618c2ecf20Sopenharmony_ci field = (typeof(field))iter->ent; \ 3628c2ecf20Sopenharmony_ci \ 3638c2ecf20Sopenharmony_ci ret = trace_raw_output_prep(iter, trace_event); \ 3648c2ecf20Sopenharmony_ci if (ret != TRACE_TYPE_HANDLED) \ 3658c2ecf20Sopenharmony_ci return ret; \ 3668c2ecf20Sopenharmony_ci \ 3678c2ecf20Sopenharmony_ci trace_event_printf(iter, print); \ 3688c2ecf20Sopenharmony_ci \ 3698c2ecf20Sopenharmony_ci return trace_handle_return(s); \ 3708c2ecf20Sopenharmony_ci} \ 3718c2ecf20Sopenharmony_cistatic struct trace_event_functions trace_event_type_funcs_##call = { \ 3728c2ecf20Sopenharmony_ci .trace = trace_raw_output_##call, \ 3738c2ecf20Sopenharmony_ci}; 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 3768c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ 3778c2ecf20Sopenharmony_cistatic notrace enum print_line_t \ 3788c2ecf20Sopenharmony_citrace_raw_output_##call(struct trace_iterator *iter, int flags, \ 3798c2ecf20Sopenharmony_ci struct trace_event *event) \ 3808c2ecf20Sopenharmony_ci{ \ 3818c2ecf20Sopenharmony_ci struct trace_event_raw_##template *field; \ 3828c2ecf20Sopenharmony_ci struct trace_entry *entry; \ 3838c2ecf20Sopenharmony_ci struct trace_seq *p = &iter->tmp_seq; \ 3848c2ecf20Sopenharmony_ci \ 3858c2ecf20Sopenharmony_ci entry = iter->ent; \ 3868c2ecf20Sopenharmony_ci \ 3878c2ecf20Sopenharmony_ci if (entry->type != event_##call.event.type) { \ 3888c2ecf20Sopenharmony_ci WARN_ON_ONCE(1); \ 3898c2ecf20Sopenharmony_ci return TRACE_TYPE_UNHANDLED; \ 3908c2ecf20Sopenharmony_ci } \ 3918c2ecf20Sopenharmony_ci \ 3928c2ecf20Sopenharmony_ci field = (typeof(field))entry; \ 3938c2ecf20Sopenharmony_ci \ 3948c2ecf20Sopenharmony_ci trace_seq_init(p); \ 3958c2ecf20Sopenharmony_ci return trace_output_call(iter, #call, print); \ 3968c2ecf20Sopenharmony_ci} \ 3978c2ecf20Sopenharmony_cistatic struct trace_event_functions trace_event_type_funcs_##call = { \ 3988c2ecf20Sopenharmony_ci .trace = trace_raw_output_##call, \ 3998c2ecf20Sopenharmony_ci}; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci#define ALIGN_STRUCTFIELD(type) ((int)(__alignof__(struct {type b;}))) 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci#undef __field_ext 4068c2ecf20Sopenharmony_ci#define __field_ext(_type, _item, _filter_type) { \ 4078c2ecf20Sopenharmony_ci .type = #_type, .name = #_item, \ 4088c2ecf20Sopenharmony_ci .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ 4098c2ecf20Sopenharmony_ci .is_signed = is_signed_type(_type), .filter_type = _filter_type }, 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci#undef __field_struct_ext 4128c2ecf20Sopenharmony_ci#define __field_struct_ext(_type, _item, _filter_type) { \ 4138c2ecf20Sopenharmony_ci .type = #_type, .name = #_item, \ 4148c2ecf20Sopenharmony_ci .size = sizeof(_type), .align = ALIGN_STRUCTFIELD(_type), \ 4158c2ecf20Sopenharmony_ci 0, .filter_type = _filter_type }, 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_ci#undef __field 4188c2ecf20Sopenharmony_ci#define __field(type, item) __field_ext(type, item, FILTER_OTHER) 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci#undef __field_struct 4218c2ecf20Sopenharmony_ci#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER) 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci#undef __array 4248c2ecf20Sopenharmony_ci#define __array(_type, _item, _len) { \ 4258c2ecf20Sopenharmony_ci .type = #_type"["__stringify(_len)"]", .name = #_item, \ 4268c2ecf20Sopenharmony_ci .size = sizeof(_type[_len]), .align = ALIGN_STRUCTFIELD(_type), \ 4278c2ecf20Sopenharmony_ci .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci#undef __dynamic_array 4308c2ecf20Sopenharmony_ci#define __dynamic_array(_type, _item, _len) { \ 4318c2ecf20Sopenharmony_ci .type = "__data_loc " #_type "[]", .name = #_item, \ 4328c2ecf20Sopenharmony_ci .size = 4, .align = 4, \ 4338c2ecf20Sopenharmony_ci .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER }, 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci#undef __string 4368c2ecf20Sopenharmony_ci#define __string(item, src) __dynamic_array(char, item, -1) 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci#undef __bitmask 4398c2ecf20Sopenharmony_ci#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 4428c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \ 4438c2ecf20Sopenharmony_cistatic struct trace_event_fields trace_event_fields_##call[] = { \ 4448c2ecf20Sopenharmony_ci tstruct \ 4458c2ecf20Sopenharmony_ci {} }; 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 4488c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, name, proto, args, print) 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci/* 4538c2ecf20Sopenharmony_ci * remember the offset of each array from the beginning of the event. 4548c2ecf20Sopenharmony_ci */ 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci#undef __entry 4578c2ecf20Sopenharmony_ci#define __entry entry 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci#undef __field 4608c2ecf20Sopenharmony_ci#define __field(type, item) 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci#undef __field_ext 4638c2ecf20Sopenharmony_ci#define __field_ext(type, item, filter_type) 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci#undef __field_struct 4668c2ecf20Sopenharmony_ci#define __field_struct(type, item) 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci#undef __field_struct_ext 4698c2ecf20Sopenharmony_ci#define __field_struct_ext(type, item, filter_type) 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci#undef __array 4728c2ecf20Sopenharmony_ci#define __array(type, item, len) 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci#undef __dynamic_array 4758c2ecf20Sopenharmony_ci#define __dynamic_array(type, item, len) \ 4768c2ecf20Sopenharmony_ci __item_length = (len) * sizeof(type); \ 4778c2ecf20Sopenharmony_ci __data_offsets->item = __data_size + \ 4788c2ecf20Sopenharmony_ci offsetof(typeof(*entry), __data); \ 4798c2ecf20Sopenharmony_ci __data_offsets->item |= __item_length << 16; \ 4808c2ecf20Sopenharmony_ci __data_size += __item_length; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci#undef __string 4838c2ecf20Sopenharmony_ci#define __string(item, src) __dynamic_array(char, item, \ 4848c2ecf20Sopenharmony_ci strlen((src) ? (const char *)(src) : "(null)") + 1) 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci/* 4878c2ecf20Sopenharmony_ci * __bitmask_size_in_bytes_raw is the number of bytes needed to hold 4888c2ecf20Sopenharmony_ci * num_possible_cpus(). 4898c2ecf20Sopenharmony_ci */ 4908c2ecf20Sopenharmony_ci#define __bitmask_size_in_bytes_raw(nr_bits) \ 4918c2ecf20Sopenharmony_ci (((nr_bits) + 7) / 8) 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci#define __bitmask_size_in_longs(nr_bits) \ 4948c2ecf20Sopenharmony_ci ((__bitmask_size_in_bytes_raw(nr_bits) + \ 4958c2ecf20Sopenharmony_ci ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8)) 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci/* 4988c2ecf20Sopenharmony_ci * __bitmask_size_in_bytes is the number of bytes needed to hold 4998c2ecf20Sopenharmony_ci * num_possible_cpus() padded out to the nearest long. This is what 5008c2ecf20Sopenharmony_ci * is saved in the buffer, just to be consistent. 5018c2ecf20Sopenharmony_ci */ 5028c2ecf20Sopenharmony_ci#define __bitmask_size_in_bytes(nr_bits) \ 5038c2ecf20Sopenharmony_ci (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8)) 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci#undef __bitmask 5068c2ecf20Sopenharmony_ci#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \ 5078c2ecf20Sopenharmony_ci __bitmask_size_in_longs(nr_bits)) 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 5108c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 5118c2ecf20Sopenharmony_cistatic inline notrace int trace_event_get_offsets_##call( \ 5128c2ecf20Sopenharmony_ci struct trace_event_data_offsets_##call *__data_offsets, proto) \ 5138c2ecf20Sopenharmony_ci{ \ 5148c2ecf20Sopenharmony_ci int __data_size = 0; \ 5158c2ecf20Sopenharmony_ci int __maybe_unused __item_length; \ 5168c2ecf20Sopenharmony_ci struct trace_event_raw_##call __maybe_unused *entry; \ 5178c2ecf20Sopenharmony_ci \ 5188c2ecf20Sopenharmony_ci tstruct; \ 5198c2ecf20Sopenharmony_ci \ 5208c2ecf20Sopenharmony_ci return __data_size; \ 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci/* 5268c2ecf20Sopenharmony_ci * Stage 4 of the trace events. 5278c2ecf20Sopenharmony_ci * 5288c2ecf20Sopenharmony_ci * Override the macros in the event tracepoint header <trace/events/XXX.h> 5298c2ecf20Sopenharmony_ci * to include the following: 5308c2ecf20Sopenharmony_ci * 5318c2ecf20Sopenharmony_ci * For those macros defined with TRACE_EVENT: 5328c2ecf20Sopenharmony_ci * 5338c2ecf20Sopenharmony_ci * static struct trace_event_call event_<call>; 5348c2ecf20Sopenharmony_ci * 5358c2ecf20Sopenharmony_ci * static void trace_event_raw_event_<call>(void *__data, proto) 5368c2ecf20Sopenharmony_ci * { 5378c2ecf20Sopenharmony_ci * struct trace_event_file *trace_file = __data; 5388c2ecf20Sopenharmony_ci * struct trace_event_call *event_call = trace_file->event_call; 5398c2ecf20Sopenharmony_ci * struct trace_event_data_offsets_<call> __maybe_unused __data_offsets; 5408c2ecf20Sopenharmony_ci * unsigned long eflags = trace_file->flags; 5418c2ecf20Sopenharmony_ci * enum event_trigger_type __tt = ETT_NONE; 5428c2ecf20Sopenharmony_ci * struct ring_buffer_event *event; 5438c2ecf20Sopenharmony_ci * struct trace_event_raw_<call> *entry; <-- defined in stage 1 5448c2ecf20Sopenharmony_ci * struct trace_buffer *buffer; 5458c2ecf20Sopenharmony_ci * unsigned long irq_flags; 5468c2ecf20Sopenharmony_ci * int __data_size; 5478c2ecf20Sopenharmony_ci * int pc; 5488c2ecf20Sopenharmony_ci * 5498c2ecf20Sopenharmony_ci * if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) { 5508c2ecf20Sopenharmony_ci * if (eflags & EVENT_FILE_FL_TRIGGER_MODE) 5518c2ecf20Sopenharmony_ci * event_triggers_call(trace_file, NULL); 5528c2ecf20Sopenharmony_ci * if (eflags & EVENT_FILE_FL_SOFT_DISABLED) 5538c2ecf20Sopenharmony_ci * return; 5548c2ecf20Sopenharmony_ci * } 5558c2ecf20Sopenharmony_ci * 5568c2ecf20Sopenharmony_ci * local_save_flags(irq_flags); 5578c2ecf20Sopenharmony_ci * pc = preempt_count(); 5588c2ecf20Sopenharmony_ci * 5598c2ecf20Sopenharmony_ci * __data_size = trace_event_get_offsets_<call>(&__data_offsets, args); 5608c2ecf20Sopenharmony_ci * 5618c2ecf20Sopenharmony_ci * event = trace_event_buffer_lock_reserve(&buffer, trace_file, 5628c2ecf20Sopenharmony_ci * event_<call>->event.type, 5638c2ecf20Sopenharmony_ci * sizeof(*entry) + __data_size, 5648c2ecf20Sopenharmony_ci * irq_flags, pc); 5658c2ecf20Sopenharmony_ci * if (!event) 5668c2ecf20Sopenharmony_ci * return; 5678c2ecf20Sopenharmony_ci * entry = ring_buffer_event_data(event); 5688c2ecf20Sopenharmony_ci * 5698c2ecf20Sopenharmony_ci * { <assign>; } <-- Here we assign the entries by the __field and 5708c2ecf20Sopenharmony_ci * __array macros. 5718c2ecf20Sopenharmony_ci * 5728c2ecf20Sopenharmony_ci * if (eflags & EVENT_FILE_FL_TRIGGER_COND) 5738c2ecf20Sopenharmony_ci * __tt = event_triggers_call(trace_file, entry); 5748c2ecf20Sopenharmony_ci * 5758c2ecf20Sopenharmony_ci * if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, 5768c2ecf20Sopenharmony_ci * &trace_file->flags)) 5778c2ecf20Sopenharmony_ci * ring_buffer_discard_commit(buffer, event); 5788c2ecf20Sopenharmony_ci * else if (!filter_check_discard(trace_file, entry, buffer, event)) 5798c2ecf20Sopenharmony_ci * trace_buffer_unlock_commit(buffer, event, irq_flags, pc); 5808c2ecf20Sopenharmony_ci * 5818c2ecf20Sopenharmony_ci * if (__tt) 5828c2ecf20Sopenharmony_ci * event_triggers_post_call(trace_file, __tt); 5838c2ecf20Sopenharmony_ci * } 5848c2ecf20Sopenharmony_ci * 5858c2ecf20Sopenharmony_ci * static struct trace_event ftrace_event_type_<call> = { 5868c2ecf20Sopenharmony_ci * .trace = trace_raw_output_<call>, <-- stage 2 5878c2ecf20Sopenharmony_ci * }; 5888c2ecf20Sopenharmony_ci * 5898c2ecf20Sopenharmony_ci * static char print_fmt_<call>[] = <TP_printk>; 5908c2ecf20Sopenharmony_ci * 5918c2ecf20Sopenharmony_ci * static struct trace_event_class __used event_class_<template> = { 5928c2ecf20Sopenharmony_ci * .system = "<system>", 5938c2ecf20Sopenharmony_ci * .fields_array = trace_event_fields_<call>, 5948c2ecf20Sopenharmony_ci * .fields = LIST_HEAD_INIT(event_class_##call.fields), 5958c2ecf20Sopenharmony_ci * .raw_init = trace_event_raw_init, 5968c2ecf20Sopenharmony_ci * .probe = trace_event_raw_event_##call, 5978c2ecf20Sopenharmony_ci * .reg = trace_event_reg, 5988c2ecf20Sopenharmony_ci * }; 5998c2ecf20Sopenharmony_ci * 6008c2ecf20Sopenharmony_ci * static struct trace_event_call event_<call> = { 6018c2ecf20Sopenharmony_ci * .class = event_class_<template>, 6028c2ecf20Sopenharmony_ci * { 6038c2ecf20Sopenharmony_ci * .tp = &__tracepoint_<call>, 6048c2ecf20Sopenharmony_ci * }, 6058c2ecf20Sopenharmony_ci * .event = &ftrace_event_type_<call>, 6068c2ecf20Sopenharmony_ci * .print_fmt = print_fmt_<call>, 6078c2ecf20Sopenharmony_ci * .flags = TRACE_EVENT_FL_TRACEPOINT, 6088c2ecf20Sopenharmony_ci * }; 6098c2ecf20Sopenharmony_ci * // its only safe to use pointers when doing linker tricks to 6108c2ecf20Sopenharmony_ci * // create an array. 6118c2ecf20Sopenharmony_ci * static struct trace_event_call __used 6128c2ecf20Sopenharmony_ci * __section("_ftrace_events") *__event_<call> = &event_<call>; 6138c2ecf20Sopenharmony_ci * 6148c2ecf20Sopenharmony_ci */ 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci#ifdef CONFIG_PERF_EVENTS 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci#define _TRACE_PERF_PROTO(call, proto) \ 6198c2ecf20Sopenharmony_ci static notrace void \ 6208c2ecf20Sopenharmony_ci perf_trace_##call(void *__data, proto); 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci#define _TRACE_PERF_INIT(call) \ 6238c2ecf20Sopenharmony_ci .perf_probe = perf_trace_##call, 6248c2ecf20Sopenharmony_ci 6258c2ecf20Sopenharmony_ci#else 6268c2ecf20Sopenharmony_ci#define _TRACE_PERF_PROTO(call, proto) 6278c2ecf20Sopenharmony_ci#define _TRACE_PERF_INIT(call) 6288c2ecf20Sopenharmony_ci#endif /* CONFIG_PERF_EVENTS */ 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci#undef __entry 6318c2ecf20Sopenharmony_ci#define __entry entry 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci#undef __field 6348c2ecf20Sopenharmony_ci#define __field(type, item) 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci#undef __field_struct 6378c2ecf20Sopenharmony_ci#define __field_struct(type, item) 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci#undef __array 6408c2ecf20Sopenharmony_ci#define __array(type, item, len) 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci#undef __dynamic_array 6438c2ecf20Sopenharmony_ci#define __dynamic_array(type, item, len) \ 6448c2ecf20Sopenharmony_ci __entry->__data_loc_##item = __data_offsets.item; 6458c2ecf20Sopenharmony_ci 6468c2ecf20Sopenharmony_ci#undef __string 6478c2ecf20Sopenharmony_ci#define __string(item, src) __dynamic_array(char, item, -1) 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci#undef __assign_str 6508c2ecf20Sopenharmony_ci#define __assign_str(dst, src) \ 6518c2ecf20Sopenharmony_ci strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)"); 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci#undef __bitmask 6548c2ecf20Sopenharmony_ci#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1) 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci#undef __get_bitmask 6578c2ecf20Sopenharmony_ci#define __get_bitmask(field) (char *)__get_dynamic_array(field) 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci#undef __assign_bitmask 6608c2ecf20Sopenharmony_ci#define __assign_bitmask(dst, src, nr_bits) \ 6618c2ecf20Sopenharmony_ci memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits)) 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci#undef TP_fast_assign 6648c2ecf20Sopenharmony_ci#define TP_fast_assign(args...) args 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci#undef __perf_count 6678c2ecf20Sopenharmony_ci#define __perf_count(c) (c) 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci#undef __perf_task 6708c2ecf20Sopenharmony_ci#define __perf_task(t) (t) 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 6738c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 6748c2ecf20Sopenharmony_ci \ 6758c2ecf20Sopenharmony_cistatic notrace void \ 6768c2ecf20Sopenharmony_citrace_event_raw_event_##call(void *__data, proto) \ 6778c2ecf20Sopenharmony_ci{ \ 6788c2ecf20Sopenharmony_ci struct trace_event_file *trace_file = __data; \ 6798c2ecf20Sopenharmony_ci struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ 6808c2ecf20Sopenharmony_ci struct trace_event_buffer fbuffer; \ 6818c2ecf20Sopenharmony_ci struct trace_event_raw_##call *entry; \ 6828c2ecf20Sopenharmony_ci int __data_size; \ 6838c2ecf20Sopenharmony_ci \ 6848c2ecf20Sopenharmony_ci if (trace_trigger_soft_disabled(trace_file)) \ 6858c2ecf20Sopenharmony_ci return; \ 6868c2ecf20Sopenharmony_ci \ 6878c2ecf20Sopenharmony_ci __data_size = trace_event_get_offsets_##call(&__data_offsets, args); \ 6888c2ecf20Sopenharmony_ci \ 6898c2ecf20Sopenharmony_ci entry = trace_event_buffer_reserve(&fbuffer, trace_file, \ 6908c2ecf20Sopenharmony_ci sizeof(*entry) + __data_size); \ 6918c2ecf20Sopenharmony_ci \ 6928c2ecf20Sopenharmony_ci if (!entry) \ 6938c2ecf20Sopenharmony_ci return; \ 6948c2ecf20Sopenharmony_ci \ 6958c2ecf20Sopenharmony_ci tstruct \ 6968c2ecf20Sopenharmony_ci \ 6978c2ecf20Sopenharmony_ci { assign; } \ 6988c2ecf20Sopenharmony_ci \ 6998c2ecf20Sopenharmony_ci trace_event_buffer_commit(&fbuffer); \ 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci/* 7028c2ecf20Sopenharmony_ci * The ftrace_test_probe is compiled out, it is only here as a build time check 7038c2ecf20Sopenharmony_ci * to make sure that if the tracepoint handling changes, the ftrace probe will 7048c2ecf20Sopenharmony_ci * fail to compile unless it too is updated. 7058c2ecf20Sopenharmony_ci */ 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci#undef DEFINE_EVENT 7088c2ecf20Sopenharmony_ci#define DEFINE_EVENT(template, call, proto, args) \ 7098c2ecf20Sopenharmony_cistatic inline void ftrace_test_probe_##call(void) \ 7108c2ecf20Sopenharmony_ci{ \ 7118c2ecf20Sopenharmony_ci check_trace_callback_type_##call(trace_event_raw_event_##template); \ 7128c2ecf20Sopenharmony_ci} 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci#undef __entry 7178c2ecf20Sopenharmony_ci#define __entry REC 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci#undef __print_flags 7208c2ecf20Sopenharmony_ci#undef __print_symbolic 7218c2ecf20Sopenharmony_ci#undef __print_hex 7228c2ecf20Sopenharmony_ci#undef __print_hex_str 7238c2ecf20Sopenharmony_ci#undef __get_dynamic_array 7248c2ecf20Sopenharmony_ci#undef __get_dynamic_array_len 7258c2ecf20Sopenharmony_ci#undef __get_str 7268c2ecf20Sopenharmony_ci#undef __get_bitmask 7278c2ecf20Sopenharmony_ci#undef __print_array 7288c2ecf20Sopenharmony_ci#undef __print_hex_dump 7298c2ecf20Sopenharmony_ci 7308c2ecf20Sopenharmony_ci#undef TP_printk 7318c2ecf20Sopenharmony_ci#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args) 7328c2ecf20Sopenharmony_ci 7338c2ecf20Sopenharmony_ci#undef DECLARE_EVENT_CLASS 7348c2ecf20Sopenharmony_ci#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 7358c2ecf20Sopenharmony_ci_TRACE_PERF_PROTO(call, PARAMS(proto)); \ 7368c2ecf20Sopenharmony_cistatic char print_fmt_##call[] = print; \ 7378c2ecf20Sopenharmony_cistatic struct trace_event_class __used __refdata event_class_##call = { \ 7388c2ecf20Sopenharmony_ci .system = TRACE_SYSTEM_STRING, \ 7398c2ecf20Sopenharmony_ci .fields_array = trace_event_fields_##call, \ 7408c2ecf20Sopenharmony_ci .fields = LIST_HEAD_INIT(event_class_##call.fields),\ 7418c2ecf20Sopenharmony_ci .raw_init = trace_event_raw_init, \ 7428c2ecf20Sopenharmony_ci .probe = trace_event_raw_event_##call, \ 7438c2ecf20Sopenharmony_ci .reg = trace_event_reg, \ 7448c2ecf20Sopenharmony_ci _TRACE_PERF_INIT(call) \ 7458c2ecf20Sopenharmony_ci}; 7468c2ecf20Sopenharmony_ci 7478c2ecf20Sopenharmony_ci#undef DEFINE_EVENT 7488c2ecf20Sopenharmony_ci#define DEFINE_EVENT(template, call, proto, args) \ 7498c2ecf20Sopenharmony_ci \ 7508c2ecf20Sopenharmony_cistatic struct trace_event_call __used event_##call = { \ 7518c2ecf20Sopenharmony_ci .class = &event_class_##template, \ 7528c2ecf20Sopenharmony_ci { \ 7538c2ecf20Sopenharmony_ci .tp = &__tracepoint_##call, \ 7548c2ecf20Sopenharmony_ci }, \ 7558c2ecf20Sopenharmony_ci .event.funcs = &trace_event_type_funcs_##template, \ 7568c2ecf20Sopenharmony_ci .print_fmt = print_fmt_##template, \ 7578c2ecf20Sopenharmony_ci .flags = TRACE_EVENT_FL_TRACEPOINT, \ 7588c2ecf20Sopenharmony_ci}; \ 7598c2ecf20Sopenharmony_cistatic struct trace_event_call __used \ 7608c2ecf20Sopenharmony_ci__section("_ftrace_events") *__event_##call = &event_##call 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci#undef DEFINE_EVENT_PRINT 7638c2ecf20Sopenharmony_ci#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ 7648c2ecf20Sopenharmony_ci \ 7658c2ecf20Sopenharmony_cistatic char print_fmt_##call[] = print; \ 7668c2ecf20Sopenharmony_ci \ 7678c2ecf20Sopenharmony_cistatic struct trace_event_call __used event_##call = { \ 7688c2ecf20Sopenharmony_ci .class = &event_class_##template, \ 7698c2ecf20Sopenharmony_ci { \ 7708c2ecf20Sopenharmony_ci .tp = &__tracepoint_##call, \ 7718c2ecf20Sopenharmony_ci }, \ 7728c2ecf20Sopenharmony_ci .event.funcs = &trace_event_type_funcs_##call, \ 7738c2ecf20Sopenharmony_ci .print_fmt = print_fmt_##call, \ 7748c2ecf20Sopenharmony_ci .flags = TRACE_EVENT_FL_TRACEPOINT, \ 7758c2ecf20Sopenharmony_ci}; \ 7768c2ecf20Sopenharmony_cistatic struct trace_event_call __used \ 7778c2ecf20Sopenharmony_ci__section("_ftrace_events") *__event_##call = &event_##call 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 780