hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/include/linux/tracepoint-defs.h
....@@ -11,6 +11,8 @@
1111 #include <linux/atomic.h>
1212 #include <linux/static_key.h>
1313
14
+struct static_call_key;
15
+
1416 struct trace_print_flags {
1517 unsigned long mask;
1618 const char *name;
....@@ -30,6 +32,9 @@
3032 struct tracepoint {
3133 const char *name; /* Tracepoint name */
3234 struct static_key key;
35
+ struct static_call_key *static_call_key;
36
+ void *static_call_tramp;
37
+ void *iterator;
3338 int (*regfunc)(void);
3439 void (*unregfunc)(void);
3540 struct tracepoint_func __rcu *funcs;
....@@ -45,6 +50,41 @@
4550 struct tracepoint *tp;
4651 void *bpf_func;
4752 u32 num_args;
53
+ u32 writable_size;
4854 } __aligned(32);
4955
56
+/*
57
+ * If a tracepoint needs to be called from a header file, it is not
58
+ * recommended to call it directly, as tracepoints in header files
59
+ * may cause side-effects and bloat the kernel. Instead, use
60
+ * tracepoint_enabled() to test if the tracepoint is enabled, then if
61
+ * it is, call a wrapper function defined in a C file that will then
62
+ * call the tracepoint.
63
+ *
64
+ * For "trace_foo_bar()", you would need to create a wrapper function
65
+ * in a C file to call trace_foo_bar():
66
+ * void do_trace_foo_bar(args) { trace_foo_bar(args); }
67
+ * Then in the header file, declare the tracepoint:
68
+ * DECLARE_TRACEPOINT(foo_bar);
69
+ * And call your wrapper:
70
+ * static inline void some_inlined_function() {
71
+ * [..]
72
+ * if (tracepoint_enabled(foo_bar))
73
+ * do_trace_foo_bar(args);
74
+ * [..]
75
+ * }
76
+ *
77
+ * Note: tracepoint_enabled(foo_bar) is equivalent to trace_foo_bar_enabled()
78
+ * but is safe to have in headers, where trace_foo_bar_enabled() is not.
79
+ */
80
+#define DECLARE_TRACEPOINT(tp) \
81
+ extern struct tracepoint __tracepoint_##tp
82
+
83
+#ifdef CONFIG_TRACEPOINTS
84
+# define tracepoint_enabled(tp) \
85
+ static_key_false(&(__tracepoint_##tp).key)
86
+#else
87
+# define tracepoint_enabled(tracepoint) false
88
+#endif
89
+
5090 #endif