Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef TRACEPOINT_DEFS_H
0003 #define TRACEPOINT_DEFS_H 1
0004 
0005 /*
0006  * File can be included directly by headers who only want to access
0007  * tracepoint->key to guard out of line trace calls, or the definition of
0008  * trace_print_flags{_u64}. Otherwise linux/tracepoint.h should be used.
0009  */
0010 
0011 #include <linux/atomic.h>
0012 #include <linux/static_key.h>
0013 
0014 struct static_call_key;
0015 
0016 struct trace_print_flags {
0017     unsigned long       mask;
0018     const char      *name;
0019 };
0020 
0021 struct trace_print_flags_u64 {
0022     unsigned long long  mask;
0023     const char      *name;
0024 };
0025 
0026 struct tracepoint_func {
0027     void *func;
0028     void *data;
0029     int prio;
0030 };
0031 
0032 struct tracepoint {
0033     const char *name;       /* Tracepoint name */
0034     struct static_key key;
0035     struct static_call_key *static_call_key;
0036     void *static_call_tramp;
0037     void *iterator;
0038     int (*regfunc)(void);
0039     void (*unregfunc)(void);
0040     struct tracepoint_func __rcu *funcs;
0041 };
0042 
0043 #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
0044 typedef const int tracepoint_ptr_t;
0045 #else
0046 typedef struct tracepoint * const tracepoint_ptr_t;
0047 #endif
0048 
0049 struct bpf_raw_event_map {
0050     struct tracepoint   *tp;
0051     void            *bpf_func;
0052     u32         num_args;
0053     u32         writable_size;
0054 } __aligned(32);
0055 
0056 /*
0057  * If a tracepoint needs to be called from a header file, it is not
0058  * recommended to call it directly, as tracepoints in header files
0059  * may cause side-effects and bloat the kernel. Instead, use
0060  * tracepoint_enabled() to test if the tracepoint is enabled, then if
0061  * it is, call a wrapper function defined in a C file that will then
0062  * call the tracepoint.
0063  *
0064  * For "trace_foo_bar()", you would need to create a wrapper function
0065  * in a C file to call trace_foo_bar():
0066  *   void do_trace_foo_bar(args) { trace_foo_bar(args); }
0067  * Then in the header file, declare the tracepoint:
0068  *   DECLARE_TRACEPOINT(foo_bar);
0069  * And call your wrapper:
0070  *   static inline void some_inlined_function() {
0071  *            [..]
0072  *            if (tracepoint_enabled(foo_bar))
0073  *                    do_trace_foo_bar(args);
0074  *            [..]
0075  *   }
0076  *
0077  * Note: tracepoint_enabled(foo_bar) is equivalent to trace_foo_bar_enabled()
0078  *   but is safe to have in headers, where trace_foo_bar_enabled() is not.
0079  */
0080 #define DECLARE_TRACEPOINT(tp) \
0081     extern struct tracepoint __tracepoint_##tp
0082 
0083 #ifdef CONFIG_TRACEPOINTS
0084 # define tracepoint_enabled(tp) \
0085     static_key_false(&(__tracepoint_##tp).key)
0086 #else
0087 # define tracepoint_enabled(tracepoint) false
0088 #endif
0089 
0090 #endif