1*5f3efd1dSVincent Donnefort /* SPDX-License-Identifier: GPL-2.0 */ 2*5f3efd1dSVincent Donnefort 3*5f3efd1dSVincent Donnefort #include <linux/trace_events.h> 4*5f3efd1dSVincent Donnefort #include <linux/trace_remote_event.h> 5*5f3efd1dSVincent Donnefort #include <linux/trace_seq.h> 6*5f3efd1dSVincent Donnefort #include <linux/stringify.h> 7*5f3efd1dSVincent Donnefort 8*5f3efd1dSVincent Donnefort #define REMOTE_EVENT_INCLUDE(__file) __stringify(../../__file) 9*5f3efd1dSVincent Donnefort 10*5f3efd1dSVincent Donnefort #ifdef REMOTE_EVENT_SECTION 11*5f3efd1dSVincent Donnefort # define __REMOTE_EVENT_SECTION(__name) __used __section(REMOTE_EVENT_SECTION"."#__name) 12*5f3efd1dSVincent Donnefort #else 13*5f3efd1dSVincent Donnefort # define __REMOTE_EVENT_SECTION(__name) 14*5f3efd1dSVincent Donnefort #endif 15*5f3efd1dSVincent Donnefort 16*5f3efd1dSVincent Donnefort #define REMOTE_PRINTK_COUNT_ARGS(__args...) \ 17*5f3efd1dSVincent Donnefort __COUNT_ARGS(, ##__args, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0) 18*5f3efd1dSVincent Donnefort 19*5f3efd1dSVincent Donnefort #define __remote_printk0() \ 20*5f3efd1dSVincent Donnefort trace_seq_putc(seq, '\n') 21*5f3efd1dSVincent Donnefort 22*5f3efd1dSVincent Donnefort #define __remote_printk1(__fmt) \ 23*5f3efd1dSVincent Donnefort trace_seq_puts(seq, " " __fmt "\n") \ 24*5f3efd1dSVincent Donnefort 25*5f3efd1dSVincent Donnefort #define __remote_printk2(__fmt, __args...) \ 26*5f3efd1dSVincent Donnefort do { \ 27*5f3efd1dSVincent Donnefort trace_seq_putc(seq, ' '); \ 28*5f3efd1dSVincent Donnefort trace_seq_printf(seq, __fmt, __args); \ 29*5f3efd1dSVincent Donnefort trace_seq_putc(seq, '\n'); \ 30*5f3efd1dSVincent Donnefort } while (0) 31*5f3efd1dSVincent Donnefort 32*5f3efd1dSVincent Donnefort /* Apply the appropriate trace_seq sequence according to the number of arguments */ 33*5f3efd1dSVincent Donnefort #define remote_printk(__args...) \ 34*5f3efd1dSVincent Donnefort CONCATENATE(__remote_printk, REMOTE_PRINTK_COUNT_ARGS(__args))(__args) 35*5f3efd1dSVincent Donnefort 36*5f3efd1dSVincent Donnefort #define RE_PRINTK(__args...) __args 37*5f3efd1dSVincent Donnefort 38*5f3efd1dSVincent Donnefort #define REMOTE_EVENT(__name, __id, __struct, __printk) \ 39*5f3efd1dSVincent Donnefort REMOTE_EVENT_FORMAT(__name, __struct); \ 40*5f3efd1dSVincent Donnefort static void remote_event_print_##__name(void *evt, struct trace_seq *seq) \ 41*5f3efd1dSVincent Donnefort { \ 42*5f3efd1dSVincent Donnefort struct remote_event_format_##__name __maybe_unused *__entry = evt; \ 43*5f3efd1dSVincent Donnefort trace_seq_puts(seq, #__name); \ 44*5f3efd1dSVincent Donnefort remote_printk(__printk); \ 45*5f3efd1dSVincent Donnefort } 46*5f3efd1dSVincent Donnefort #include REMOTE_EVENT_INCLUDE(REMOTE_EVENT_INCLUDE_FILE) 47*5f3efd1dSVincent Donnefort 48*5f3efd1dSVincent Donnefort #undef REMOTE_EVENT 49*5f3efd1dSVincent Donnefort #undef RE_PRINTK 50*5f3efd1dSVincent Donnefort #undef re_field 51*5f3efd1dSVincent Donnefort #define re_field(__type, __field) \ 52*5f3efd1dSVincent Donnefort { \ 53*5f3efd1dSVincent Donnefort .type = #__type, .name = #__field, \ 54*5f3efd1dSVincent Donnefort .size = sizeof(__type), .align = __alignof__(__type), \ 55*5f3efd1dSVincent Donnefort .is_signed = is_signed_type(__type), \ 56*5f3efd1dSVincent Donnefort }, 57*5f3efd1dSVincent Donnefort #define __entry REC 58*5f3efd1dSVincent Donnefort #define RE_PRINTK(__fmt, __args...) "\"" __fmt "\", " __stringify(__args) 59*5f3efd1dSVincent Donnefort #define REMOTE_EVENT(__name, __id, __struct, __printk) \ 60*5f3efd1dSVincent Donnefort static struct trace_event_fields remote_event_fields_##__name[] = { \ 61*5f3efd1dSVincent Donnefort __struct \ 62*5f3efd1dSVincent Donnefort {} \ 63*5f3efd1dSVincent Donnefort }; \ 64*5f3efd1dSVincent Donnefort static char remote_event_print_fmt_##__name[] = __printk; \ 65*5f3efd1dSVincent Donnefort static struct remote_event __REMOTE_EVENT_SECTION(__name) \ 66*5f3efd1dSVincent Donnefort remote_event_##__name = { \ 67*5f3efd1dSVincent Donnefort .name = #__name, \ 68*5f3efd1dSVincent Donnefort .id = __id, \ 69*5f3efd1dSVincent Donnefort .fields = remote_event_fields_##__name, \ 70*5f3efd1dSVincent Donnefort .print_fmt = remote_event_print_fmt_##__name, \ 71*5f3efd1dSVincent Donnefort .print = remote_event_print_##__name, \ 72*5f3efd1dSVincent Donnefort } 73*5f3efd1dSVincent Donnefort #include REMOTE_EVENT_INCLUDE(REMOTE_EVENT_INCLUDE_FILE) 74