xref: /OK3568_Linux_fs/kernel/include/linux/tracepoint-defs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef TRACEPOINT_DEFS_H
3*4882a593Smuzhiyun #define TRACEPOINT_DEFS_H 1
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun  * File can be included directly by headers who only want to access
7*4882a593Smuzhiyun  * tracepoint->key to guard out of line trace calls, or the definition of
8*4882a593Smuzhiyun  * trace_print_flags{_u64}. Otherwise linux/tracepoint.h should be used.
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/atomic.h>
12*4882a593Smuzhiyun #include <linux/static_key.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun struct static_call_key;
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun struct trace_print_flags {
17*4882a593Smuzhiyun 	unsigned long		mask;
18*4882a593Smuzhiyun 	const char		*name;
19*4882a593Smuzhiyun };
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun struct trace_print_flags_u64 {
22*4882a593Smuzhiyun 	unsigned long long	mask;
23*4882a593Smuzhiyun 	const char		*name;
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct tracepoint_func {
27*4882a593Smuzhiyun 	void *func;
28*4882a593Smuzhiyun 	void *data;
29*4882a593Smuzhiyun 	int prio;
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct tracepoint {
33*4882a593Smuzhiyun 	const char *name;		/* Tracepoint name */
34*4882a593Smuzhiyun 	struct static_key key;
35*4882a593Smuzhiyun 	struct static_call_key *static_call_key;
36*4882a593Smuzhiyun 	void *static_call_tramp;
37*4882a593Smuzhiyun 	void *iterator;
38*4882a593Smuzhiyun 	int (*regfunc)(void);
39*4882a593Smuzhiyun 	void (*unregfunc)(void);
40*4882a593Smuzhiyun 	struct tracepoint_func __rcu *funcs;
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
44*4882a593Smuzhiyun typedef const int tracepoint_ptr_t;
45*4882a593Smuzhiyun #else
46*4882a593Smuzhiyun typedef struct tracepoint * const tracepoint_ptr_t;
47*4882a593Smuzhiyun #endif
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun struct bpf_raw_event_map {
50*4882a593Smuzhiyun 	struct tracepoint	*tp;
51*4882a593Smuzhiyun 	void			*bpf_func;
52*4882a593Smuzhiyun 	u32			num_args;
53*4882a593Smuzhiyun 	u32			writable_size;
54*4882a593Smuzhiyun } __aligned(32);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun  * If a tracepoint needs to be called from a header file, it is not
58*4882a593Smuzhiyun  * recommended to call it directly, as tracepoints in header files
59*4882a593Smuzhiyun  * may cause side-effects and bloat the kernel. Instead, use
60*4882a593Smuzhiyun  * tracepoint_enabled() to test if the tracepoint is enabled, then if
61*4882a593Smuzhiyun  * it is, call a wrapper function defined in a C file that will then
62*4882a593Smuzhiyun  * call the tracepoint.
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * For "trace_foo_bar()", you would need to create a wrapper function
65*4882a593Smuzhiyun  * in a C file to call trace_foo_bar():
66*4882a593Smuzhiyun  *   void do_trace_foo_bar(args) { trace_foo_bar(args); }
67*4882a593Smuzhiyun  * Then in the header file, declare the tracepoint:
68*4882a593Smuzhiyun  *   DECLARE_TRACEPOINT(foo_bar);
69*4882a593Smuzhiyun  * And call your wrapper:
70*4882a593Smuzhiyun  *   static inline void some_inlined_function() {
71*4882a593Smuzhiyun  *            [..]
72*4882a593Smuzhiyun  *            if (tracepoint_enabled(foo_bar))
73*4882a593Smuzhiyun  *                    do_trace_foo_bar(args);
74*4882a593Smuzhiyun  *            [..]
75*4882a593Smuzhiyun  *   }
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * Note: tracepoint_enabled(foo_bar) is equivalent to trace_foo_bar_enabled()
78*4882a593Smuzhiyun  *   but is safe to have in headers, where trace_foo_bar_enabled() is not.
79*4882a593Smuzhiyun  */
80*4882a593Smuzhiyun #define DECLARE_TRACEPOINT(tp) \
81*4882a593Smuzhiyun 	extern struct tracepoint __tracepoint_##tp
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #ifdef CONFIG_TRACEPOINTS
84*4882a593Smuzhiyun # define tracepoint_enabled(tp) \
85*4882a593Smuzhiyun 	static_key_false(&(__tracepoint_##tp).key)
86*4882a593Smuzhiyun #else
87*4882a593Smuzhiyun # define tracepoint_enabled(tracepoint) false
88*4882a593Smuzhiyun #endif
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun #endif
91