xref: /linux/kernel/trace/ftrace_internal.h (revision 44f57d78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_KERNEL_FTRACE_INTERNAL_H
3 #define  _LINUX_KERNEL_FTRACE_INTERNAL_H
4 
5 #ifdef CONFIG_FUNCTION_TRACER
6 
7 /*
8  * Traverse the ftrace_global_list, invoking all entries.  The reason that we
9  * can use rcu_dereference_raw_notrace() is that elements removed from this list
10  * are simply leaked, so there is no need to interact with a grace-period
11  * mechanism.  The rcu_dereference_raw_notrace() calls are needed to handle
12  * concurrent insertions into the ftrace_global_list.
13  *
14  * Silly Alpha and silly pointer-speculation compiler optimizations!
15  */
16 #define do_for_each_ftrace_op(op, list)			\
17 	op = rcu_dereference_raw_notrace(list);			\
18 	do
19 
20 /*
21  * Optimized for just a single item in the list (as that is the normal case).
22  */
23 #define while_for_each_ftrace_op(op)				\
24 	while (likely(op = rcu_dereference_raw_notrace((op)->next)) &&	\
25 	       unlikely((op) != &ftrace_list_end))
26 
27 extern struct ftrace_ops __rcu *ftrace_ops_list;
28 extern struct ftrace_ops ftrace_list_end;
29 extern struct mutex ftrace_lock;
30 extern struct ftrace_ops global_ops;
31 
32 #ifdef CONFIG_DYNAMIC_FTRACE
33 
34 int ftrace_startup(struct ftrace_ops *ops, int command);
35 int ftrace_shutdown(struct ftrace_ops *ops, int command);
36 int ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs);
37 
38 #else /* !CONFIG_DYNAMIC_FTRACE */
39 
40 int __register_ftrace_function(struct ftrace_ops *ops);
41 int __unregister_ftrace_function(struct ftrace_ops *ops);
42 /* Keep as macros so we do not need to define the commands */
43 # define ftrace_startup(ops, command)					\
44 	({								\
45 		int ___ret = __register_ftrace_function(ops);		\
46 		if (!___ret)						\
47 			(ops)->flags |= FTRACE_OPS_FL_ENABLED;		\
48 		___ret;							\
49 	})
50 # define ftrace_shutdown(ops, command)					\
51 	({								\
52 		int ___ret = __unregister_ftrace_function(ops);		\
53 		if (!___ret)						\
54 			(ops)->flags &= ~FTRACE_OPS_FL_ENABLED;		\
55 		___ret;							\
56 	})
57 static inline int
58 ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs)
59 {
60 	return 1;
61 }
62 #endif /* CONFIG_DYNAMIC_FTRACE */
63 
64 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
65 extern int ftrace_graph_active;
66 void update_function_graph_func(void);
67 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
68 # define ftrace_graph_active 0
69 static inline void update_function_graph_func(void) { }
70 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
71 
72 #else /* !CONFIG_FUNCTION_TRACER */
73 #endif /* CONFIG_FUNCTION_TRACER */
74 
75 #endif
76