History

Merge tag 'trace-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace

Pull tracing updates from Steven Rostedt: - New user_events interface. User space can register an event with the kernel describing the format of the event. Then it will receive a byte in a page mapping that it can check against. A privileged task can then enable that event like any other event, which will change the mapped byte to true, telling the user space application to start writing the event to the tracing buffer. - Add new "ftrace_boot_snapshot" kernel command line parameter. When set, the tracing buffer will be saved in the snapshot buffer at boot up when the kernel hands things over to user space. This will keep the traces that happened at boot up available even if user space boot up has tracing as well. - Have TRACE_EVENT_ENUM() also update trace event field type descriptions. Thus if a static array defines its size with an enum, the user space trace event parsers can still know how to parse that array. - Add new TRACE_CUSTOM_EVENT() macro. This acts the same as the TRACE_EVENT() macro, but will attach to an existing tracepoint. This will make one tracepoint be able to trace different content and not be stuck at only what the original TRACE_EVENT() macro exports. - Fixes to tracing error logging. - Better saving of cmdlines to PIDs when tracing (use the wakeup events for mapping). * tag 'trace-v5.18' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (30 commits) tracing: Have type enum modifications copy the strings user_events: Add trace event call as root for low permission cases tracing/user_events: Use alloc_pages instead of kzalloc() for register pages tracing: Add snapshot at end of kernel boot up tracing: Have TRACE_DEFINE_ENUM affect trace event types as well tracing: Fix strncpy warning in trace_events_synth.c user_events: Prevent dyn_event delete racing with ioctl add/delete tracing: Add TRACE_CUSTOM_EVENT() macro tracing: Move the defines to create TRACE_EVENTS into their own files tracing: Add sample code for custom trace events tracing: Allow custom events to be added to the tracefs directory tracing: Fix last_cmd_set() string management in histogram code user_events: Fix potential uninitialized pointer while parsing field tracing: Fix allocation of last_cmd in last_cmd_set() user_events: Add documentation file user_events: Add sample code for typical usage user_events: Add self-test for validator boundaries user_events: Add self-test for perf_event integration user_events: Add self-test for dynamic_events integration user_events: Add self-test for ftrace integration ...

Linus Torvalds committed 4 years ago

Commit 1bc19102 parents 20f463f 795301d39 files · +4169 −570Browse files

Showing the changes to include (14 of 39 files). Show all

Unified · Split

14 files
  1. include/linux/ftrace.h +10 −1
  2. include/linux/trace_events.h +23 −1
  3. include/trace/define_custom_trace.h +77 −0
  4. include/trace/stages/init.h +37 −0
  5. include/trace/stages/stage1_defines.h +51 −0
  6. include/trace/stages/stage2_defines.h +54 −0
  7. include/trace/stages/stage3_defines.h +135 −0
  8. include/trace/stages/stage4_defines.h +63 −0
  9. include/trace/stages/stage5_defines.h +89 −0
  10. include/trace/stages/stage6_defines.h +106 −0
  11. include/trace/stages/stage7_defines.h +36 −0
  12. include/trace/trace_custom_events.h +221 −0
  13. include/trace/trace_events.h +8 −542
  14. include/uapi/linux/user_events.h +116 −0
include/linux/ftrace.h+10−1
@@ -30,6 +30,12 @@ · 29 unmodified lines
30#define ARCH_SUPPORTS_FTRACE_OPS 030#define ARCH_SUPPORTS_FTRACE_OPS 0
31#endif31#endif
32 32
33#ifdef CONFIG_TRACING
34extern void ftrace_boot_snapshot(void);
35#else
36static inline void ftrace_boot_snapshot(void) { }
37#endif
38
33#ifdef CONFIG_FUNCTION_TRACER39#ifdef CONFIG_FUNCTION_TRACER
34struct ftrace_ops;40struct ftrace_ops;
35struct ftrace_regs;41struct ftrace_regs;
@@ -215,7 +221,10 @@ struct ftrace_ops_hash { · 179 unmodified lines
215void ftrace_free_init_mem(void);221void ftrace_free_init_mem(void);
216void ftrace_free_mem(struct module *mod, void *start, void *end);222void ftrace_free_mem(struct module *mod, void *start, void *end);
217#else223#else
218static inline void ftrace_free_init_mem(void) { }224static inline void ftrace_free_init_mem(void)
225{
226 ftrace_boot_snapshot();
227}
219static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }228static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
220#endif229#endif
221 230
include/linux/trace_events.h+23−1
@@ -315,6 +315,7 @@ enum { · 314 unmodified lines
315 TRACE_EVENT_FL_KPROBE_BIT,315 TRACE_EVENT_FL_KPROBE_BIT,
316 TRACE_EVENT_FL_UPROBE_BIT,316 TRACE_EVENT_FL_UPROBE_BIT,
317 TRACE_EVENT_FL_EPROBE_BIT,317 TRACE_EVENT_FL_EPROBE_BIT,
318 TRACE_EVENT_FL_CUSTOM_BIT,
318};319};
319 320
320/*321/*
@@ -328,6 +329,9 @@ enum { · 7 unmodified lines
328 * KPROBE - Event is a kprobe329 * KPROBE - Event is a kprobe
329 * UPROBE - Event is a uprobe330 * UPROBE - Event is a uprobe
330 * EPROBE - Event is an event probe331 * EPROBE - Event is an event probe
332 * CUSTOM - Event is a custom event (to be attached to an exsiting tracepoint)
333 * This is set when the custom event has not been attached
334 * to a tracepoint yet, then it is cleared when it is.
331 */335 */
332enum {336enum {
333 TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),337 TRACE_EVENT_FL_FILTERED = (1 << TRACE_EVENT_FL_FILTERED_BIT),
@@ -339,6 +343,7 @@ enum { · 5 unmodified lines
339 TRACE_EVENT_FL_KPROBE = (1 << TRACE_EVENT_FL_KPROBE_BIT),343 TRACE_EVENT_FL_KPROBE = (1 << TRACE_EVENT_FL_KPROBE_BIT),
340 TRACE_EVENT_FL_UPROBE = (1 << TRACE_EVENT_FL_UPROBE_BIT),344 TRACE_EVENT_FL_UPROBE = (1 << TRACE_EVENT_FL_UPROBE_BIT),
341 TRACE_EVENT_FL_EPROBE = (1 << TRACE_EVENT_FL_EPROBE_BIT),345 TRACE_EVENT_FL_EPROBE = (1 << TRACE_EVENT_FL_EPROBE_BIT),
346 TRACE_EVENT_FL_CUSTOM = (1 << TRACE_EVENT_FL_CUSTOM_BIT),
342};347};
343 348
344#define TRACE_EVENT_FL_UKPROBE (TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE)349#define TRACE_EVENT_FL_UKPROBE (TRACE_EVENT_FL_KPROBE | TRACE_EVENT_FL_UPROBE)
@@ -440,7 +445,9 @@ static inline bool bpf_prog_array_valid(struct trace_event_call *call) · 95 unmodified lines
440static inline const char *445static inline const char *
441trace_event_name(struct trace_event_call *call)446trace_event_name(struct trace_event_call *call)
442{447{
443 if (call->flags & TRACE_EVENT_FL_TRACEPOINT)448 if (call->flags & TRACE_EVENT_FL_CUSTOM)
449 return call->name;
450 else if (call->flags & TRACE_EVENT_FL_TRACEPOINT)
444 return call->tp ? call->tp->name : NULL;451 return call->tp ? call->tp->name : NULL;
445 else452 else
446 return call->name;453 return call->name;
@@ -903,3 +910,18 @@ perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type, · 456 unmodified lines
903#endif910#endif
904 911
905#endif /* _LINUX_TRACE_EVENT_H */912#endif /* _LINUX_TRACE_EVENT_H */
913
914/*
915 * Note: we keep the TRACE_CUSTOM_EVENT outside the include file ifdef protection.
916 * This is due to the way trace custom events work. If a file includes two
917 * trace event headers under one "CREATE_CUSTOM_TRACE_EVENTS" the first include
918 * will override the TRACE_CUSTOM_EVENT and break the second include.
919 */
920
921#ifndef TRACE_CUSTOM_EVENT
922
923#define DECLARE_CUSTOM_EVENT_CLASS(name, proto, args, tstruct, assign, print)
924#define DEFINE_CUSTOM_EVENT(template, name, proto, args)
925#define TRACE_CUSTOM_EVENT(name, proto, args, struct, assign, print)
926
927#endif /* ifdef TRACE_CUSTOM_EVENT (see note above) */
include/trace/define_custom_trace.h+77−0
@@ -0,0 +1,77 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Trace files that want to automate creation of all tracepoints defined
4 * in their file should include this file. The following are macros that the
5 * trace file may define:
6 *
7 * TRACE_SYSTEM defines the system the tracepoint is for
8 *
9 * TRACE_INCLUDE_FILE if the file name is something other than TRACE_SYSTEM.h
10 * This macro may be defined to tell define_trace.h what file to include.
11 * Note, leave off the ".h".
12 *
13 * TRACE_INCLUDE_PATH if the path is something other than core kernel include/trace
14 * then this macro can define the path to use. Note, the path is relative to
15 * define_trace.h, not the file including it. Full path names for out of tree
16 * modules must be used.
17 */
18
19#ifdef CREATE_CUSTOM_TRACE_EVENTS
20
21/* Prevent recursion */
22#undef CREATE_CUSTOM_TRACE_EVENTS
23
24#include <linux/stringify.h>
25
26#undef TRACE_CUSTOM_EVENT
27#define TRACE_CUSTOM_EVENT(name, proto, args, tstruct, assign, print)
28
29#undef DEFINE_CUSTOM_EVENT
30#define DEFINE_CUSTOM_EVENT(template, name, proto, args)
31
32#undef TRACE_INCLUDE
33#undef __TRACE_INCLUDE
34
35#ifndef TRACE_INCLUDE_FILE
36# define TRACE_INCLUDE_FILE TRACE_SYSTEM
37# define UNDEF_TRACE_INCLUDE_FILE
38#endif
39
40#ifndef TRACE_INCLUDE_PATH
41# define __TRACE_INCLUDE(system) <trace/events/system.h>
42# define UNDEF_TRACE_INCLUDE_PATH
43#else
44# define __TRACE_INCLUDE(system) __stringify(TRACE_INCLUDE_PATH/system.h)
45#endif
46
47# define TRACE_INCLUDE(system) __TRACE_INCLUDE(system)
48
49/* Let the trace headers be reread */
50#define TRACE_CUSTOM_MULTI_READ
51
52#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
53
54#ifdef TRACEPOINTS_ENABLED
55#include <trace/trace_custom_events.h>
56#endif
57
58#undef TRACE_CUSTOM_EVENT
59#undef DECLARE_CUSTOM_EVENT_CLASS
60#undef DEFINE_CUSTOM_EVENT
61#undef TRACE_CUSTOM_MULTI_READ
62
63/* Only undef what we defined in this file */
64#ifdef UNDEF_TRACE_INCLUDE_FILE
65# undef TRACE_INCLUDE_FILE
66# undef UNDEF_TRACE_INCLUDE_FILE
67#endif
68
69#ifdef UNDEF_TRACE_INCLUDE_PATH
70# undef TRACE_INCLUDE_PATH
71# undef UNDEF_TRACE_INCLUDE_PATH
72#endif
73
74/* We may be processing more files */
75#define CREATE_CUSTOM_TRACE_POINTS
76
77#endif /* CREATE_CUSTOM_TRACE_POINTS */
include/trace/stages/init.h+37−0
@@ -0,0 +1,37 @@
1
2#define __app__(x, y) str__##x##y
3#define __app(x, y) __app__(x, y)
4
5#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
6
7#define TRACE_MAKE_SYSTEM_STR() \
8 static const char TRACE_SYSTEM_STRING[] = \
9 __stringify(TRACE_SYSTEM)
10
11TRACE_MAKE_SYSTEM_STR();
12
13#undef TRACE_DEFINE_ENUM
14#define TRACE_DEFINE_ENUM(a) \
15 static struct trace_eval_map __used __initdata \
16 __##TRACE_SYSTEM##_##a = \
17 { \
18 .system = TRACE_SYSTEM_STRING, \
19 .eval_string = #a, \
20 .eval_value = a \
21 }; \
22 static struct trace_eval_map __used \
23 __section("_ftrace_eval_map") \
24 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
25
26#undef TRACE_DEFINE_SIZEOF
27#define TRACE_DEFINE_SIZEOF(a) \
28 static struct trace_eval_map __used __initdata \
29 __##TRACE_SYSTEM##_##a = \
30 { \
31 .system = TRACE_SYSTEM_STRING, \
32 .eval_string = "sizeof(" #a ")", \
33 .eval_value = sizeof(a) \
34 }; \
35 static struct trace_eval_map __used \
36 __section("_ftrace_eval_map") \
37 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
include/trace/stages/stage1_defines.h+51−0
@@ -0,0 +1,51 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 1 definitions for creating trace events */
4
5#undef __field
6#define __field(type, item) type item;
7
8#undef __field_ext
9#define __field_ext(type, item, filter_type) type item;
10
11#undef __field_struct
12#define __field_struct(type, item) type item;
13
14#undef __field_struct_ext
15#define __field_struct_ext(type, item, filter_type) type item;
16
17#undef __array
18#define __array(type, item, len) type item[len];
19
20#undef __dynamic_array
21#define __dynamic_array(type, item, len) u32 __data_loc_##item;
22
23#undef __string
24#define __string(item, src) __dynamic_array(char, item, -1)
25
26#undef __string_len
27#define __string_len(item, src, len) __dynamic_array(char, item, -1)
28
29#undef __bitmask
30#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
31
32#undef __sockaddr
33#define __sockaddr(field, len) __dynamic_array(u8, field, len)
34
35#undef __rel_dynamic_array
36#define __rel_dynamic_array(type, item, len) u32 __rel_loc_##item;
37
38#undef __rel_string
39#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
40
41#undef __rel_string_len
42#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
43
44#undef __rel_bitmask
45#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1)
46
47#undef __rel_sockaddr
48#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
49
50#undef TP_STRUCT__entry
51#define TP_STRUCT__entry(args...) args
include/trace/stages/stage2_defines.h+54−0
@@ -0,0 +1,54 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 2 definitions for creating trace events */
4
5#undef TRACE_DEFINE_ENUM
6#define TRACE_DEFINE_ENUM(a)
7
8#undef TRACE_DEFINE_SIZEOF
9#define TRACE_DEFINE_SIZEOF(a)
10
11#undef __field
12#define __field(type, item)
13
14#undef __field_ext
15#define __field_ext(type, item, filter_type)
16
17#undef __field_struct
18#define __field_struct(type, item)
19
20#undef __field_struct_ext
21#define __field_struct_ext(type, item, filter_type)
22
23#undef __array
24#define __array(type, item, len)
25
26#undef __dynamic_array
27#define __dynamic_array(type, item, len) u32 item;
28
29#undef __string
30#define __string(item, src) __dynamic_array(char, item, -1)
31
32#undef __string_len
33#define __string_len(item, src, len) __dynamic_array(char, item, -1)
34
35#undef __bitmask
36#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
37
38#undef __sockaddr
39#define __sockaddr(field, len) __dynamic_array(u8, field, len)
40
41#undef __rel_dynamic_array
42#define __rel_dynamic_array(type, item, len) u32 item;
43
44#undef __rel_string
45#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
46
47#undef __rel_string_len
48#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
49
50#undef __rel_bitmask
51#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
52
53#undef __rel_sockaddr
54#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
include/trace/stages/stage3_defines.h+135−0
@@ -0,0 +1,135 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 3 definitions for creating trace events */
4
5#undef __entry
6#define __entry field
7
8#undef TP_printk
9#define TP_printk(fmt, args...) fmt "\n", args
10
11#undef __get_dynamic_array
12#define __get_dynamic_array(field) \
13 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
14
15#undef __get_dynamic_array_len
16#define __get_dynamic_array_len(field) \
17 ((__entry->__data_loc_##field >> 16) & 0xffff)
18
19#undef __get_str
20#define __get_str(field) ((char *)__get_dynamic_array(field))
21
22#undef __get_rel_dynamic_array
23#define __get_rel_dynamic_array(field) \
24 ((void *)__entry + \
25 offsetof(typeof(*__entry), __rel_loc_##field) + \
26 sizeof(__entry->__rel_loc_##field) + \
27 (__entry->__rel_loc_##field & 0xffff))
28
29#undef __get_rel_dynamic_array_len
30#define __get_rel_dynamic_array_len(field) \
31 ((__entry->__rel_loc_##field >> 16) & 0xffff)
32
33#undef __get_rel_str
34#define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
35
36#undef __get_bitmask
37#define __get_bitmask(field) \
38 ({ \
39 void *__bitmask = __get_dynamic_array(field); \
40 unsigned int __bitmask_size; \
41 __bitmask_size = __get_dynamic_array_len(field); \
42 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
43 })
44
45#undef __get_rel_bitmask
46#define __get_rel_bitmask(field) \
47 ({ \
48 void *__bitmask = __get_rel_dynamic_array(field); \
49 unsigned int __bitmask_size; \
50 __bitmask_size = __get_rel_dynamic_array_len(field); \
51 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
52 })
53
54#undef __get_sockaddr
55#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
56
57#undef __get_rel_sockaddr
58#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
59
60#undef __print_flags
61#define __print_flags(flag, delim, flag_array...) \
62 ({ \
63 static const struct trace_print_flags __flags[] = \
64 { flag_array, { -1, NULL }}; \
65 trace_print_flags_seq(p, delim, flag, __flags); \
66 })
67
68#undef __print_symbolic
69#define __print_symbolic(value, symbol_array...) \
70 ({ \
71 static const struct trace_print_flags symbols[] = \
72 { symbol_array, { -1, NULL }}; \
73 trace_print_symbols_seq(p, value, symbols); \
74 })
75
76#undef __print_flags_u64
77#undef __print_symbolic_u64
78#if BITS_PER_LONG == 32
79#define __print_flags_u64(flag, delim, flag_array...) \
80 ({ \
81 static const struct trace_print_flags_u64 __flags[] = \
82 { flag_array, { -1, NULL } }; \
83 trace_print_flags_seq_u64(p, delim, flag, __flags); \
84 })
85
86#define __print_symbolic_u64(value, symbol_array...) \
87 ({ \
88 static const struct trace_print_flags_u64 symbols[] = \
89 { symbol_array, { -1, NULL } }; \
90 trace_print_symbols_seq_u64(p, value, symbols); \
91 })
92#else
93#define __print_flags_u64(flag, delim, flag_array...) \
94 __print_flags(flag, delim, flag_array)
95
96#define __print_symbolic_u64(value, symbol_array...) \
97 __print_symbolic(value, symbol_array)
98#endif
99
100#undef __print_hex
101#define __print_hex(buf, buf_len) \
102 trace_print_hex_seq(p, buf, buf_len, false)
103
104#undef __print_hex_str
105#define __print_hex_str(buf, buf_len) \
106 trace_print_hex_seq(p, buf, buf_len, true)
107
108#undef __print_array
109#define __print_array(array, count, el_size) \
110 ({ \
111 BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
112 el_size != 4 && el_size != 8); \
113 trace_print_array_seq(p, array, count, el_size); \
114 })
115
116#undef __print_hex_dump
117#define __print_hex_dump(prefix_str, prefix_type, \
118 rowsize, groupsize, buf, len, ascii) \
119 trace_print_hex_dump_seq(p, prefix_str, prefix_type, \
120 rowsize, groupsize, buf, len, ascii)
121
122#undef __print_ns_to_secs
123#define __print_ns_to_secs(value) \
124 ({ \
125 u64 ____val = (u64)(value); \
126 do_div(____val, NSEC_PER_SEC); \
127 ____val; \
128 })
129
130#undef __print_ns_without_secs
131#define __print_ns_without_secs(value) \
132 ({ \
133 u64 ____val = (u64)(value); \
134 (u32) do_div(____val, NSEC_PER_SEC); \
135 })
include/trace/stages/stage4_defines.h+63−0
@@ -0,0 +1,63 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 4 definitions for creating trace events */
4
5#undef __field_ext
6#define __field_ext(_type, _item, _filter_type) { \
7 .type = #_type, .name = #_item, \
8 .size = sizeof(_type), .align = __alignof__(_type), \
9 .is_signed = is_signed_type(_type), .filter_type = _filter_type },
10
11#undef __field_struct_ext
12#define __field_struct_ext(_type, _item, _filter_type) { \
13 .type = #_type, .name = #_item, \
14 .size = sizeof(_type), .align = __alignof__(_type), \
15 0, .filter_type = _filter_type },
16
17#undef __field
18#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
19
20#undef __field_struct
21#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
22
23#undef __array
24#define __array(_type, _item, _len) { \
25 .type = #_type"["__stringify(_len)"]", .name = #_item, \
26 .size = sizeof(_type[_len]), .align = __alignof__(_type), \
27 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
28
29#undef __dynamic_array
30#define __dynamic_array(_type, _item, _len) { \
31 .type = "__data_loc " #_type "[]", .name = #_item, \
32 .size = 4, .align = 4, \
33 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
34
35#undef __string
36#define __string(item, src) __dynamic_array(char, item, -1)
37
38#undef __string_len
39#define __string_len(item, src, len) __dynamic_array(char, item, -1)
40
41#undef __bitmask
42#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
43
44#undef __sockaddr
45#define __sockaddr(field, len) __dynamic_array(u8, field, len)
46
47#undef __rel_dynamic_array
48#define __rel_dynamic_array(_type, _item, _len) { \
49 .type = "__rel_loc " #_type "[]", .name = #_item, \
50 .size = 4, .align = 4, \
51 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
52
53#undef __rel_string
54#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
55
56#undef __rel_string_len
57#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
58
59#undef __rel_bitmask
60#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
61
62#undef __rel_sockaddr
63#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
include/trace/stages/stage5_defines.h+89−0
@@ -0,0 +1,89 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 5 definitions for creating trace events */
4
5/*
6 * remember the offset of each array from the beginning of the event.
7 */
8
9#undef __entry
10#define __entry entry
11
12#undef __field
13#define __field(type, item)
14
15#undef __field_ext
16#define __field_ext(type, item, filter_type)
17
18#undef __field_struct
19#define __field_struct(type, item)
20
21#undef __field_struct_ext
22#define __field_struct_ext(type, item, filter_type)
23
24#undef __array
25#define __array(type, item, len)
26
27#undef __dynamic_array
28#define __dynamic_array(type, item, len) \
29 __item_length = (len) * sizeof(type); \
30 __data_offsets->item = __data_size + \
31 offsetof(typeof(*entry), __data); \
32 __data_offsets->item |= __item_length << 16; \
33 __data_size += __item_length;
34
35#undef __string
36#define __string(item, src) __dynamic_array(char, item, \
37 strlen((src) ? (const char *)(src) : "(null)") + 1)
38
39#undef __string_len
40#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
41
42#undef __rel_dynamic_array
43#define __rel_dynamic_array(type, item, len) \
44 __item_length = (len) * sizeof(type); \
45 __data_offsets->item = __data_size + \
46 offsetof(typeof(*entry), __data) - \
47 offsetof(typeof(*entry), __rel_loc_##item) - \
48 sizeof(u32); \
49 __data_offsets->item |= __item_length << 16; \
50 __data_size += __item_length;
51
52#undef __rel_string
53#define __rel_string(item, src) __rel_dynamic_array(char, item, \
54 strlen((src) ? (const char *)(src) : "(null)") + 1)
55
56#undef __rel_string_len
57#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
58/*
59 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
60 * num_possible_cpus().
61 */
62#define __bitmask_size_in_bytes_raw(nr_bits) \
63 (((nr_bits) + 7) / 8)
64
65#define __bitmask_size_in_longs(nr_bits) \
66 ((__bitmask_size_in_bytes_raw(nr_bits) + \
67 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
68
69/*
70 * __bitmask_size_in_bytes is the number of bytes needed to hold
71 * num_possible_cpus() padded out to the nearest long. This is what
72 * is saved in the buffer, just to be consistent.
73 */
74#define __bitmask_size_in_bytes(nr_bits) \
75 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
76
77#undef __bitmask
78#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
79 __bitmask_size_in_longs(nr_bits))
80
81#undef __rel_bitmask
82#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \
83 __bitmask_size_in_longs(nr_bits))
84
85#undef __sockaddr
86#define __sockaddr(field, len) __dynamic_array(u8, field, len)
87
88#undef __rel_sockaddr
89#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
include/trace/stages/stage6_defines.h+106−0
@@ -0,0 +1,106 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 6 definitions for creating trace events */
4
5#undef __entry
6#define __entry entry
7
8#undef __field
9#define __field(type, item)
10
11#undef __field_struct
12#define __field_struct(type, item)
13
14#undef __array
15#define __array(type, item, len)
16
17#undef __dynamic_array
18#define __dynamic_array(type, item, len) \
19 __entry->__data_loc_##item = __data_offsets.item;
20
21#undef __string
22#define __string(item, src) __dynamic_array(char, item, -1)
23
24#undef __string_len
25#define __string_len(item, src, len) __dynamic_array(char, item, -1)
26
27#undef __assign_str
28#define __assign_str(dst, src) \
29 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
30
31#undef __assign_str_len
32#define __assign_str_len(dst, src, len) \
33 do { \
34 memcpy(__get_str(dst), (src), (len)); \
35 __get_str(dst)[len] = '\0'; \
36 } while(0)
37
38#undef __bitmask
39#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
40
41#undef __get_bitmask
42#define __get_bitmask(field) (char *)__get_dynamic_array(field)
43
44#undef __assign_bitmask
45#define __assign_bitmask(dst, src, nr_bits) \
46 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
47
48#undef __sockaddr
49#define __sockaddr(field, len) __dynamic_array(u8, field, len)
50
51#undef __get_sockaddr
52#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
53
54#undef __assign_sockaddr
55#define __assign_sockaddr(dest, src, len) \
56 memcpy(__get_dynamic_array(dest), src, len)
57
58#undef __rel_dynamic_array
59#define __rel_dynamic_array(type, item, len) \
60 __entry->__rel_loc_##item = __data_offsets.item;
61
62#undef __rel_string
63#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
64
65#undef __rel_string_len
66#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
67
68#undef __assign_rel_str
69#define __assign_rel_str(dst, src) \
70 strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
71
72#undef __assign_rel_str_len
73#define __assign_rel_str_len(dst, src, len) \
74 do { \
75 memcpy(__get_rel_str(dst), (src), (len)); \
76 __get_rel_str(dst)[len] = '\0'; \
77 } while (0)
78
79#undef __rel_bitmask
80#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
81
82#undef __get_rel_bitmask
83#define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
84
85#undef __assign_rel_bitmask
86#define __assign_rel_bitmask(dst, src, nr_bits) \
87 memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
88
89#undef __rel_sockaddr
90#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
91
92#undef __get_rel_sockaddr
93#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
94
95#undef __assign_rel_sockaddr
96#define __assign_rel_sockaddr(dest, src, len) \
97 memcpy(__get_rel_dynamic_array(dest), src, len)
98
99#undef TP_fast_assign
100#define TP_fast_assign(args...) args
101
102#undef __perf_count
103#define __perf_count(c) (c)
104
105#undef __perf_task
106#define __perf_task(t) (t)
include/trace/stages/stage7_defines.h+36−0
@@ -0,0 +1,36 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2
3/* Stage 7 definitions for creating trace events */
4
5#undef __entry
6#define __entry REC
7
8#undef __print_flags
9#undef __print_symbolic
10#undef __print_hex
11#undef __print_hex_str
12#undef __get_dynamic_array
13#undef __get_dynamic_array_len
14#undef __get_str
15#undef __get_bitmask
16#undef __get_sockaddr
17#undef __get_rel_dynamic_array
18#undef __get_rel_dynamic_array_len
19#undef __get_rel_str
20#undef __get_rel_bitmask
21#undef __get_rel_sockaddr
22#undef __print_array
23#undef __print_hex_dump
24
25/*
26 * The below is not executed in the kernel. It is only what is
27 * displayed in the print format for userspace to parse.
28 */
29#undef __print_ns_to_secs
30#define __print_ns_to_secs(val) (val) / 1000000000UL
31
32#undef __print_ns_without_secs
33#define __print_ns_without_secs(val) (val) % 1000000000UL
34
35#undef TP_printk
36#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
include/trace/trace_custom_events.h+221−0
@@ -0,0 +1,221 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * This is similar to the trace_events.h file, but is to only
4 * create custom trace events to be attached to existing tracepoints.
5 * Where as the TRACE_EVENT() macro (from trace_events.h) will create
6 * both the trace event and the tracepoint it will attach the event to,
7 * TRACE_CUSTOM_EVENT() is to create only a custom version of an existing
8 * trace event (created by TRACE_EVENT() or DEFINE_EVENT()), and will
9 * be placed in the "custom" system.
10 */
11
12#include <linux/trace_events.h>
13
14/* All custom events are placed in the custom group */
15#undef TRACE_SYSTEM
16#define TRACE_SYSTEM custom
17
18#ifndef TRACE_SYSTEM_VAR
19#define TRACE_SYSTEM_VAR TRACE_SYSTEM
20#endif
21
22/* The init stage creates the system string and enum mappings */
23
24#include "stages/init.h"
25
26#undef TRACE_CUSTOM_EVENT
27#define TRACE_CUSTOM_EVENT(name, proto, args, tstruct, assign, print) \
28 DECLARE_CUSTOM_EVENT_CLASS(name, \
29 PARAMS(proto), \
30 PARAMS(args), \
31 PARAMS(tstruct), \
32 PARAMS(assign), \
33 PARAMS(print)); \
34 DEFINE_CUSTOM_EVENT(name, name, PARAMS(proto), PARAMS(args));
35
36/* Stage 1 creates the structure of the recorded event layout */
37
38#include "stages/stage1_defines.h"
39
40#undef DECLARE_CUSTOM_EVENT_CLASS
41#define DECLARE_CUSTOM_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
42 struct trace_custom_event_raw_##name { \
43 struct trace_entry ent; \
44 tstruct \
45 char __data[]; \
46 }; \
47 \
48 static struct trace_event_class custom_event_class_##name;
49
50#undef DEFINE_CUSTOM_EVENT
51#define DEFINE_CUSTOM_EVENT(template, name, proto, args) \
52 static struct trace_event_call __used \
53 __attribute__((__aligned__(4))) custom_event_##name
54
55#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
56
57/* Stage 2 creates the custom class */
58
59#include "stages/stage2_defines.h"
60
61#undef DECLARE_CUSTOM_EVENT_CLASS
62#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
63 struct trace_custom_event_data_offsets_##call { \
64 tstruct; \
65 };
66
67#undef DEFINE_CUSTOM_EVENT
68#define DEFINE_CUSTOM_EVENT(template, name, proto, args)
69
70#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
71
72/* Stage 3 create the way to print the custom event */
73
74#include "stages/stage3_defines.h"
75
76#undef DECLARE_CUSTOM_EVENT_CLASS
77#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
78static notrace enum print_line_t \
79trace_custom_raw_output_##call(struct trace_iterator *iter, int flags, \
80 struct trace_event *trace_event) \
81{ \
82 struct trace_seq *s = &iter->seq; \
83 struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
84 struct trace_custom_event_raw_##call *field; \
85 int ret; \
86 \
87 field = (typeof(field))iter->ent; \
88 \
89 ret = trace_raw_output_prep(iter, trace_event); \
90 if (ret != TRACE_TYPE_HANDLED) \
91 return ret; \
92 \
93 trace_event_printf(iter, print); \
94 \
95 return trace_handle_return(s); \
96} \
97static struct trace_event_functions trace_custom_event_type_funcs_##call = { \
98 .trace = trace_custom_raw_output_##call, \
99};
100
101#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
102
103/* Stage 4 creates the offset layout for the fields */
104
105#include "stages/stage4_defines.h"
106
107#undef DECLARE_CUSTOM_EVENT_CLASS
108#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, func, print) \
109static struct trace_event_fields trace_custom_event_fields_##call[] = { \
110 tstruct \
111 {} };
112
113#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
114
115/* Stage 5 creates the helper function for dynamic fields */
116
117#include "stages/stage5_defines.h"
118
119#undef DECLARE_CUSTOM_EVENT_CLASS
120#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
121static inline notrace int trace_custom_event_get_offsets_##call( \
122 struct trace_custom_event_data_offsets_##call *__data_offsets, proto) \
123{ \
124 int __data_size = 0; \
125 int __maybe_unused __item_length; \
126 struct trace_custom_event_raw_##call __maybe_unused *entry; \
127 \
128 tstruct; \
129 \
130 return __data_size; \
131}
132
133#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
134
135/* Stage 6 creates the probe function that records the event */
136
137#include "stages/stage6_defines.h"
138
139#undef DECLARE_CUSTOM_EVENT_CLASS
140#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
141 \
142static notrace void \
143trace_custom_event_raw_event_##call(void *__data, proto) \
144{ \
145 struct trace_event_file *trace_file = __data; \
146 struct trace_custom_event_data_offsets_##call __maybe_unused __data_offsets; \
147 struct trace_event_buffer fbuffer; \
148 struct trace_custom_event_raw_##call *entry; \
149 int __data_size; \
150 \
151 if (trace_trigger_soft_disabled(trace_file)) \
152 return; \
153 \
154 __data_size = trace_custom_event_get_offsets_##call(&__data_offsets, args); \
155 \
156 entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
157 sizeof(*entry) + __data_size); \
158 \
159 if (!entry) \
160 return; \
161 \
162 tstruct \
163 \
164 { assign; } \
165 \
166 trace_event_buffer_commit(&fbuffer); \
167}
168/*
169 * The ftrace_test_custom_probe is compiled out, it is only here as a build time check
170 * to make sure that if the tracepoint handling changes, the ftrace probe will
171 * fail to compile unless it too is updated.
172 */
173
174#undef DEFINE_CUSTOM_EVENT
175#define DEFINE_CUSTOM_EVENT(template, call, proto, args) \
176static inline void ftrace_test_custom_probe_##call(void) \
177{ \
178 check_trace_callback_type_##call(trace_custom_event_raw_event_##template); \
179}
180
181#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
182
183/* Stage 7 creates the actual class and event structure for the custom event */
184
185#include "stages/stage7_defines.h"
186
187#undef DECLARE_CUSTOM_EVENT_CLASS
188#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
189static char custom_print_fmt_##call[] = print; \
190static struct trace_event_class __used __refdata custom_event_class_##call = { \
191 .system = TRACE_SYSTEM_STRING, \
192 .fields_array = trace_custom_event_fields_##call, \
193 .fields = LIST_HEAD_INIT(custom_event_class_##call.fields),\
194 .raw_init = trace_event_raw_init, \
195 .probe = trace_custom_event_raw_event_##call, \
196 .reg = trace_event_reg, \
197};
198
199#undef DEFINE_CUSTOM_EVENT
200#define DEFINE_CUSTOM_EVENT(template, call, proto, args) \
201 \
202static struct trace_event_call __used custom_event_##call = { \
203 .name = #call, \
204 .class = &custom_event_class_##template, \
205 .event.funcs = &trace_custom_event_type_funcs_##template, \
206 .print_fmt = custom_print_fmt_##template, \
207 .flags = TRACE_EVENT_FL_CUSTOM, \
208}; \
209static inline int trace_custom_event_##call##_update(struct tracepoint *tp) \
210{ \
211 if (tp->name && strcmp(tp->name, #call) == 0) { \
212 custom_event_##call.tp = tp; \
213 custom_event_##call.flags = TRACE_EVENT_FL_TRACEPOINT; \
214 return 1; \
215 } \
216 return 0; \
217} \
218static struct trace_event_call __used \
219__section("_ftrace_events") *__custom_event_##call = &custom_event_##call
220
221#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
include/trace/trace_events.h+8−542
@@ -24,42 +24,7 @@ · 23 unmodified lines
24#define TRACE_SYSTEM_VAR TRACE_SYSTEM24#define TRACE_SYSTEM_VAR TRACE_SYSTEM
25#endif25#endif
26 26
27#define __app__(x, y) str__##x##y27#include "stages/init.h"
28#define __app(x, y) __app__(x, y)
29
30#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
31
32#define TRACE_MAKE_SYSTEM_STR() \
33 static const char TRACE_SYSTEM_STRING[] = \
34 __stringify(TRACE_SYSTEM)
35
36TRACE_MAKE_SYSTEM_STR();
37
38#undef TRACE_DEFINE_ENUM
39#define TRACE_DEFINE_ENUM(a) \
40 static struct trace_eval_map __used __initdata \
41 __##TRACE_SYSTEM##_##a = \
42 { \
43 .system = TRACE_SYSTEM_STRING, \
44 .eval_string = #a, \
45 .eval_value = a \
46 }; \
47 static struct trace_eval_map __used \
48 __section("_ftrace_eval_map") \
49 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
50
51#undef TRACE_DEFINE_SIZEOF
52#define TRACE_DEFINE_SIZEOF(a) \
53 static struct trace_eval_map __used __initdata \
54 __##TRACE_SYSTEM##_##a = \
55 { \
56 .system = TRACE_SYSTEM_STRING, \
57 .eval_string = "sizeof(" #a ")", \
58 .eval_value = sizeof(a) \
59 }; \
60 static struct trace_eval_map __used \
61 __section("_ftrace_eval_map") \
62 *TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
63 28
64/*29/*
65 * DECLARE_EVENT_CLASS can be used to add a generic function30 * DECLARE_EVENT_CLASS can be used to add a generic function
@@ -80,54 +45,7 @@ TRACE_MAKE_SYSTEM_STR(); · 14 unmodified lines
80 PARAMS(print)); \45 PARAMS(print)); \
81 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));46 DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
82 47
83 48#include "stages/stage1_defines.h"
84#undef __field
85#define __field(type, item) type item;
86
87#undef __field_ext
88#define __field_ext(type, item, filter_type) type item;
89
90#undef __field_struct
91#define __field_struct(type, item) type item;
92
93#undef __field_struct_ext
94#define __field_struct_ext(type, item, filter_type) type item;
95
96#undef __array
97#define __array(type, item, len) type item[len];
98
99#undef __dynamic_array
100#define __dynamic_array(type, item, len) u32 __data_loc_##item;
101
102#undef __string
103#define __string(item, src) __dynamic_array(char, item, -1)
104
105#undef __string_len
106#define __string_len(item, src, len) __dynamic_array(char, item, -1)
107
108#undef __bitmask
109#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
110
111#undef __sockaddr
112#define __sockaddr(field, len) __dynamic_array(u8, field, len)
113
114#undef __rel_dynamic_array
115#define __rel_dynamic_array(type, item, len) u32 __rel_loc_##item;
116
117#undef __rel_string
118#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
119
120#undef __rel_string_len
121#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
122
123#undef __rel_bitmask
124#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(char, item, -1)
125
126#undef __rel_sockaddr
127#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
128
129#undef TP_STRUCT__entry
130#define TP_STRUCT__entry(args...) args
131 49
132#undef DECLARE_EVENT_CLASS50#undef DECLARE_EVENT_CLASS
133#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \51#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
@@ -191,56 +109,7 @@ TRACE_MAKE_SYSTEM_STR(); · 57 unmodified lines
191 * The size of an array is also encoded, in the higher 16 bits of <item>.109 * The size of an array is also encoded, in the higher 16 bits of <item>.
192 */110 */
193 111
194#undef TRACE_DEFINE_ENUM112#include "stages/stage2_defines.h"
195#define TRACE_DEFINE_ENUM(a)
196
197#undef TRACE_DEFINE_SIZEOF
198#define TRACE_DEFINE_SIZEOF(a)
199
200#undef __field
201#define __field(type, item)
202
203#undef __field_ext
204#define __field_ext(type, item, filter_type)
205
206#undef __field_struct
207#define __field_struct(type, item)
208
209#undef __field_struct_ext
210#define __field_struct_ext(type, item, filter_type)
211
212#undef __array
213#define __array(type, item, len)
214
215#undef __dynamic_array
216#define __dynamic_array(type, item, len) u32 item;
217
218#undef __string
219#define __string(item, src) __dynamic_array(char, item, -1)
220
221#undef __string_len
222#define __string_len(item, src, len) __dynamic_array(char, item, -1)
223
224#undef __bitmask
225#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
226
227#undef __sockaddr
228#define __sockaddr(field, len) __dynamic_array(u8, field, len)
229
230#undef __rel_dynamic_array
231#define __rel_dynamic_array(type, item, len) u32 item;
232
233#undef __rel_string
234#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
235
236#undef __rel_string_len
237#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
238
239#undef __rel_bitmask
240#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
241
242#undef __rel_sockaddr
243#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
244 113
245#undef DECLARE_EVENT_CLASS114#undef DECLARE_EVENT_CLASS
246#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \115#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -312,137 +181,7 @@ TRACE_MAKE_SYSTEM_STR(); · 65 unmodified lines
312 * in binary.181 * in binary.
313 */182 */
314 183
315#undef __entry184#include "stages/stage3_defines.h"
316#define __entry field
317
318#undef TP_printk
319#define TP_printk(fmt, args...) fmt "\n", args
320
321#undef __get_dynamic_array
322#define __get_dynamic_array(field) \
323 ((void *)__entry + (__entry->__data_loc_##field & 0xffff))
324
325#undef __get_dynamic_array_len
326#define __get_dynamic_array_len(field) \
327 ((__entry->__data_loc_##field >> 16) & 0xffff)
328
329#undef __get_str
330#define __get_str(field) ((char *)__get_dynamic_array(field))
331
332#undef __get_rel_dynamic_array
333#define __get_rel_dynamic_array(field) \
334 ((void *)__entry + \
335 offsetof(typeof(*__entry), __rel_loc_##field) + \
336 sizeof(__entry->__rel_loc_##field) + \
337 (__entry->__rel_loc_##field & 0xffff))
338
339#undef __get_rel_dynamic_array_len
340#define __get_rel_dynamic_array_len(field) \
341 ((__entry->__rel_loc_##field >> 16) & 0xffff)
342
343#undef __get_rel_str
344#define __get_rel_str(field) ((char *)__get_rel_dynamic_array(field))
345
346#undef __get_bitmask
347#define __get_bitmask(field) \
348 ({ \
349 void *__bitmask = __get_dynamic_array(field); \
350 unsigned int __bitmask_size; \
351 __bitmask_size = __get_dynamic_array_len(field); \
352 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
353 })
354
355#undef __get_rel_bitmask
356#define __get_rel_bitmask(field) \
357 ({ \
358 void *__bitmask = __get_rel_dynamic_array(field); \
359 unsigned int __bitmask_size; \
360 __bitmask_size = __get_rel_dynamic_array_len(field); \
361 trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
362 })
363
364#undef __get_sockaddr
365#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
366
367#undef __get_rel_sockaddr
368#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
369
370#undef __print_flags
371#define __print_flags(flag, delim, flag_array...) \
372 ({ \
373 static const struct trace_print_flags __flags[] = \
374 { flag_array, { -1, NULL }}; \
375 trace_print_flags_seq(p, delim, flag, __flags); \
376 })
377
378#undef __print_symbolic
379#define __print_symbolic(value, symbol_array...) \
380 ({ \
381 static const struct trace_print_flags symbols[] = \
382 { symbol_array, { -1, NULL }}; \
383 trace_print_symbols_seq(p, value, symbols); \
384 })
385
386#undef __print_flags_u64
387#undef __print_symbolic_u64
388#if BITS_PER_LONG == 32
389#define __print_flags_u64(flag, delim, flag_array...) \
390 ({ \
391 static const struct trace_print_flags_u64 __flags[] = \
392 { flag_array, { -1, NULL } }; \
393 trace_print_flags_seq_u64(p, delim, flag, __flags); \
394 })
395
396#define __print_symbolic_u64(value, symbol_array...) \
397 ({ \
398 static const struct trace_print_flags_u64 symbols[] = \
399 { symbol_array, { -1, NULL } }; \
400 trace_print_symbols_seq_u64(p, value, symbols); \
401 })
402#else
403#define __print_flags_u64(flag, delim, flag_array...) \
404 __print_flags(flag, delim, flag_array)
405
406#define __print_symbolic_u64(value, symbol_array...) \
407 __print_symbolic(value, symbol_array)
408#endif
409
410#undef __print_hex
411#define __print_hex(buf, buf_len) \
412 trace_print_hex_seq(p, buf, buf_len, false)
413
414#undef __print_hex_str
415#define __print_hex_str(buf, buf_len) \
416 trace_print_hex_seq(p, buf, buf_len, true)
417
418#undef __print_array
419#define __print_array(array, count, el_size) \
420 ({ \
421 BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
422 el_size != 4 && el_size != 8); \
423 trace_print_array_seq(p, array, count, el_size); \
424 })
425
426#undef __print_hex_dump
427#define __print_hex_dump(prefix_str, prefix_type, \
428 rowsize, groupsize, buf, len, ascii) \
429 trace_print_hex_dump_seq(p, prefix_str, prefix_type, \
430 rowsize, groupsize, buf, len, ascii)
431
432#undef __print_ns_to_secs
433#define __print_ns_to_secs(value) \
434 ({ \
435 u64 ____val = (u64)(value); \
436 do_div(____val, NSEC_PER_SEC); \
437 ____val; \
438 })
439
440#undef __print_ns_without_secs
441#define __print_ns_without_secs(value) \
442 ({ \
443 u64 ____val = (u64)(value); \
444 (u32) do_div(____val, NSEC_PER_SEC); \
445 })
446 185
447#undef DECLARE_EVENT_CLASS186#undef DECLARE_EVENT_CLASS
448#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \187#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -497,65 +236,7 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \ · 48 unmodified lines
497 236
498#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)237#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
499 238
500#undef __field_ext239#include "stages/stage4_defines.h"
501#define __field_ext(_type, _item, _filter_type) { \
502 .type = #_type, .name = #_item, \
503 .size = sizeof(_type), .align = __alignof__(_type), \
504 .is_signed = is_signed_type(_type), .filter_type = _filter_type },
505
506#undef __field_struct_ext
507#define __field_struct_ext(_type, _item, _filter_type) { \
508 .type = #_type, .name = #_item, \
509 .size = sizeof(_type), .align = __alignof__(_type), \
510 0, .filter_type = _filter_type },
511
512#undef __field
513#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
514
515#undef __field_struct
516#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
517
518#undef __array
519#define __array(_type, _item, _len) { \
520 .type = #_type"["__stringify(_len)"]", .name = #_item, \
521 .size = sizeof(_type[_len]), .align = __alignof__(_type), \
522 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
523
524#undef __dynamic_array
525#define __dynamic_array(_type, _item, _len) { \
526 .type = "__data_loc " #_type "[]", .name = #_item, \
527 .size = 4, .align = 4, \
528 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
529
530#undef __string
531#define __string(item, src) __dynamic_array(char, item, -1)
532
533#undef __string_len
534#define __string_len(item, src, len) __dynamic_array(char, item, -1)
535
536#undef __bitmask
537#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
538
539#undef __sockaddr
540#define __sockaddr(field, len) __dynamic_array(u8, field, len)
541
542#undef __rel_dynamic_array
543#define __rel_dynamic_array(_type, _item, _len) { \
544 .type = "__rel_loc " #_type "[]", .name = #_item, \
545 .size = 4, .align = 4, \
546 .is_signed = is_signed_type(_type), .filter_type = FILTER_OTHER },
547
548#undef __rel_string
549#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
550
551#undef __rel_string_len
552#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
553
554#undef __rel_bitmask
555#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
556
557#undef __rel_sockaddr
558#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
559 240
560#undef DECLARE_EVENT_CLASS241#undef DECLARE_EVENT_CLASS
561#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \242#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
@@ -568,91 +249,7 @@ static struct trace_event_fields trace_event_fields_##call[] = { \ · 6 unmodified lines
568 249
569#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)250#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
570 251
571/*252#include "stages/stage5_defines.h"
572 * remember the offset of each array from the beginning of the event.
573 */
574
575#undef __entry
576#define __entry entry
577
578#undef __field
579#define __field(type, item)
580
581#undef __field_ext
582#define __field_ext(type, item, filter_type)
583
584#undef __field_struct
585#define __field_struct(type, item)
586
587#undef __field_struct_ext
588#define __field_struct_ext(type, item, filter_type)
589
590#undef __array
591#define __array(type, item, len)
592
593#undef __dynamic_array
594#define __dynamic_array(type, item, len) \
595 __item_length = (len) * sizeof(type); \
596 __data_offsets->item = __data_size + \
597 offsetof(typeof(*entry), __data); \
598 __data_offsets->item |= __item_length << 16; \
599 __data_size += __item_length;
600
601#undef __string
602#define __string(item, src) __dynamic_array(char, item, \
603 strlen((src) ? (const char *)(src) : "(null)") + 1)
604
605#undef __string_len
606#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
607
608#undef __rel_dynamic_array
609#define __rel_dynamic_array(type, item, len) \
610 __item_length = (len) * sizeof(type); \
611 __data_offsets->item = __data_size + \
612 offsetof(typeof(*entry), __data) - \
613 offsetof(typeof(*entry), __rel_loc_##item) - \
614 sizeof(u32); \
615 __data_offsets->item |= __item_length << 16; \
616 __data_size += __item_length;
617
618#undef __rel_string
619#define __rel_string(item, src) __rel_dynamic_array(char, item, \
620 strlen((src) ? (const char *)(src) : "(null)") + 1)
621
622#undef __rel_string_len
623#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, (len) + 1)
624/*
625 * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
626 * num_possible_cpus().
627 */
628#define __bitmask_size_in_bytes_raw(nr_bits) \
629 (((nr_bits) + 7) / 8)
630
631#define __bitmask_size_in_longs(nr_bits) \
632 ((__bitmask_size_in_bytes_raw(nr_bits) + \
633 ((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
634
635/*
636 * __bitmask_size_in_bytes is the number of bytes needed to hold
637 * num_possible_cpus() padded out to the nearest long. This is what
638 * is saved in the buffer, just to be consistent.
639 */
640#define __bitmask_size_in_bytes(nr_bits) \
641 (__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
642
643#undef __bitmask
644#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
645 __bitmask_size_in_longs(nr_bits))
646
647#undef __rel_bitmask
648#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, \
649 __bitmask_size_in_longs(nr_bits))
650
651#undef __sockaddr
652#define __sockaddr(field, len) __dynamic_array(u8, field, len)
653
654#undef __rel_sockaddr
655#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
656 253
657#undef DECLARE_EVENT_CLASS254#undef DECLARE_EVENT_CLASS
658#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \255#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -775,107 +372,7 @@ static inline notrace int trace_event_get_offsets_##call( \ · 116 unmodified lines
775#define _TRACE_PERF_INIT(call)372#define _TRACE_PERF_INIT(call)
776#endif /* CONFIG_PERF_EVENTS */373#endif /* CONFIG_PERF_EVENTS */
777 374
778#undef __entry375#include "stages/stage6_defines.h"
779#define __entry entry
780
781#undef __field
782#define __field(type, item)
783
784#undef __field_struct
785#define __field_struct(type, item)
786
787#undef __array
788#define __array(type, item, len)
789
790#undef __dynamic_array
791#define __dynamic_array(type, item, len) \
792 __entry->__data_loc_##item = __data_offsets.item;
793
794#undef __string
795#define __string(item, src) __dynamic_array(char, item, -1)
796
797#undef __string_len
798#define __string_len(item, src, len) __dynamic_array(char, item, -1)
799
800#undef __assign_str
801#define __assign_str(dst, src) \
802 strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
803
804#undef __assign_str_len
805#define __assign_str_len(dst, src, len) \
806 do { \
807 memcpy(__get_str(dst), (src), (len)); \
808 __get_str(dst)[len] = '\0'; \
809 } while(0)
810
811#undef __bitmask
812#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
813
814#undef __get_bitmask
815#define __get_bitmask(field) (char *)__get_dynamic_array(field)
816
817#undef __assign_bitmask
818#define __assign_bitmask(dst, src, nr_bits) \
819 memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
820
821#undef __sockaddr
822#define __sockaddr(field, len) __dynamic_array(u8, field, len)
823
824#undef __get_sockaddr
825#define __get_sockaddr(field) ((struct sockaddr *)__get_dynamic_array(field))
826
827#define __assign_sockaddr(dest, src, len) \
828 memcpy(__get_dynamic_array(dest), src, len)
829
830#undef __rel_dynamic_array
831#define __rel_dynamic_array(type, item, len) \
832 __entry->__rel_loc_##item = __data_offsets.item;
833
834#undef __rel_string
835#define __rel_string(item, src) __rel_dynamic_array(char, item, -1)
836
837#undef __rel_string_len
838#define __rel_string_len(item, src, len) __rel_dynamic_array(char, item, -1)
839
840#undef __assign_rel_str
841#define __assign_rel_str(dst, src) \
842 strcpy(__get_rel_str(dst), (src) ? (const char *)(src) : "(null)");
843
844#undef __assign_rel_str_len
845#define __assign_rel_str_len(dst, src, len) \
846 do { \
847 memcpy(__get_rel_str(dst), (src), (len)); \
848 __get_rel_str(dst)[len] = '\0'; \
849 } while (0)
850
851#undef __rel_bitmask
852#define __rel_bitmask(item, nr_bits) __rel_dynamic_array(unsigned long, item, -1)
853
854#undef __get_rel_bitmask
855#define __get_rel_bitmask(field) (char *)__get_rel_dynamic_array(field)
856
857#undef __assign_rel_bitmask
858#define __assign_rel_bitmask(dst, src, nr_bits) \
859 memcpy(__get_rel_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
860
861#undef __rel_sockaddr
862#define __rel_sockaddr(field, len) __rel_dynamic_array(u8, field, len)
863
864#undef __get_rel_sockaddr
865#define __get_rel_sockaddr(field) ((struct sockaddr *)__get_rel_dynamic_array(field))
866
867#define __assign_rel_sockaddr(dest, src, len) \
868 memcpy(__get_rel_dynamic_array(dest), src, len)
869
870
871#undef TP_fast_assign
872#define TP_fast_assign(args...) args
873
874#undef __perf_count
875#define __perf_count(c) (c)
876
877#undef __perf_task
878#define __perf_task(t) (t)
879 376
880#undef DECLARE_EVENT_CLASS377#undef DECLARE_EVENT_CLASS
881#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \378#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -921,38 +418,7 @@ static inline void ftrace_test_probe_##call(void) \ · 39 unmodified lines
921 418
922#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)419#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
923 420
924#undef __entry421#include "stages/stage7_defines.h"
925#define __entry REC
926
927#undef __print_flags
928#undef __print_symbolic
929#undef __print_hex
930#undef __print_hex_str
931#undef __get_dynamic_array
932#undef __get_dynamic_array_len
933#undef __get_str
934#undef __get_bitmask
935#undef __get_sockaddr
936#undef __get_rel_dynamic_array
937#undef __get_rel_dynamic_array_len
938#undef __get_rel_str
939#undef __get_rel_bitmask
940#undef __get_rel_sockaddr
941#undef __print_array
942#undef __print_hex_dump
943
944/*
945 * The below is not executed in the kernel. It is only what is
946 * displayed in the print format for userspace to parse.
947 */
948#undef __print_ns_to_secs
949#define __print_ns_to_secs(val) (val) / 1000000000UL
950
951#undef __print_ns_without_secs
952#define __print_ns_without_secs(val) (val) % 1000000000UL
953
954#undef TP_printk
955#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
956 422
957#undef DECLARE_EVENT_CLASS423#undef DECLARE_EVENT_CLASS
958#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \424#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
include/uapi/linux/user_events.h+116−0
@@ -0,0 +1,116 @@
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copyright (c) 2021, Microsoft Corporation.
4 *
5 * Authors:
6 * Beau Belgrave <beaub@linux.microsoft.com>
7 */
8#ifndef _UAPI_LINUX_USER_EVENTS_H
9#define _UAPI_LINUX_USER_EVENTS_H
10
11#include <linux/types.h>
12#include <linux/ioctl.h>
13
14#ifdef __KERNEL__
15#include <linux/uio.h>
16#else
17#include <sys/uio.h>
18#endif
19
20#define USER_EVENTS_SYSTEM "user_events"
21#define USER_EVENTS_PREFIX "u:"
22
23/* Bits 0-6 are for known probe types, Bit 7 is for unknown probes */
24#define EVENT_BIT_FTRACE 0
25#define EVENT_BIT_PERF 1
26#define EVENT_BIT_OTHER 7
27
28#define EVENT_STATUS_FTRACE (1 << EVENT_BIT_FTRACE)
29#define EVENT_STATUS_PERF (1 << EVENT_BIT_PERF)
30#define EVENT_STATUS_OTHER (1 << EVENT_BIT_OTHER)
31
32/* Create dynamic location entry within a 32-bit value */
33#define DYN_LOC(offset, size) ((size) << 16 | (offset))
34
35/* Use raw iterator for attached BPF program(s), no affect on ftrace/perf */
36#define FLAG_BPF_ITER (1 << 0)
37
38/*
39 * Describes an event registration and stores the results of the registration.
40 * This structure is passed to the DIAG_IOCSREG ioctl, callers at a minimum
41 * must set the size and name_args before invocation.
42 */
43struct user_reg {
44
45 /* Input: Size of the user_reg structure being used */
46 __u32 size;
47
48 /* Input: Pointer to string with event name, description and flags */
49 __u64 name_args;
50
51 /* Output: Byte index of the event within the status page */
52 __u32 status_index;
53
54 /* Output: Index of the event to use when writing data */
55 __u32 write_index;
56};
57
58#define DIAG_IOC_MAGIC '*'
59
60/* Requests to register a user_event */
61#define DIAG_IOCSREG _IOWR(DIAG_IOC_MAGIC, 0, struct user_reg*)
62
63/* Requests to delete a user_event */
64#define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char*)
65
66/* Data type that was passed to the BPF program */
67enum {
68 /* Data resides in kernel space */
69 USER_BPF_DATA_KERNEL,
70
71 /* Data resides in user space */
72 USER_BPF_DATA_USER,
73
74 /* Data is a pointer to a user_bpf_iter structure */
75 USER_BPF_DATA_ITER,
76};
77
78/*
79 * Describes an iovec iterator that BPF programs can use to access data for
80 * a given user_event write() / writev() call.
81 */
82struct user_bpf_iter {
83
84 /* Offset of the data within the first iovec */
85 __u32 iov_offset;
86
87 /* Number of iovec structures */
88 __u32 nr_segs;
89
90 /* Pointer to iovec structures */
91 const struct iovec *iov;
92};
93
94/* Context that BPF programs receive when attached to a user_event */
95struct user_bpf_context {
96
97 /* Data type being passed (see union below) */
98 __u32 data_type;
99
100 /* Length of the data */
101 __u32 data_len;
102
103 /* Pointer to data, varies by data type */
104 union {
105 /* Kernel data (data_type == USER_BPF_DATA_KERNEL) */
106 void *kdata;
107
108 /* User data (data_type == USER_BPF_DATA_USER) */
109 void *udata;
110
111 /* Direct iovec (data_type == USER_BPF_DATA_ITER) */
112 struct user_bpf_iter *iter;
113 };
114};
115
116#endif /* _UAPI_LINUX_USER_EVENTS_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t