2 * Ftrace header. For implementation details beyond the random comments
3 * scattered below, see: Documentation/trace/ftrace-design.txt
6 #ifndef _LINUX_FTRACE_H
7 #define _LINUX_FTRACE_H
9 #include <linux/trace_clock.h>
10 #include <linux/kallsyms.h>
11 #include <linux/linkage.h>
12 #include <linux/bitops.h>
13 #include <linux/module.h>
14 #include <linux/ktime.h>
15 #include <linux/sched.h>
16 #include <linux/types.h>
17 #include <linux/init.h>
20 #include <asm/ftrace.h>
22 #ifdef CONFIG_FUNCTION_TRACER
24 extern int ftrace_enabled;
26 ftrace_enable_sysctl(struct ctl_table *table, int write,
27 void __user *buffer, size_t *lenp,
30 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
34 struct ftrace_ops *next;
37 extern int function_trace_stop;
40 * Type of the current tracing.
42 enum ftrace_tracing_type_t {
43 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
44 FTRACE_TYPE_RETURN, /* Hook the return of the function */
47 /* Current tracing type, default is FTRACE_TYPE_ENTER */
48 extern enum ftrace_tracing_type_t ftrace_tracing_type;
51 * ftrace_stop - stop function tracer.
53 * A quick way to stop the function tracer. Note this an on off switch,
54 * it is not something that is recursive like preempt_disable.
55 * This does not disable the calling of mcount, it only stops the
56 * calling of functions from mcount.
58 static inline void ftrace_stop(void)
60 function_trace_stop = 1;
64 * ftrace_start - start the function tracer.
66 * This function is the inverse of ftrace_stop. This does not enable
67 * the function tracing if the function tracer is disabled. This only
68 * sets the function tracer flag to continue calling the functions
71 static inline void ftrace_start(void)
73 function_trace_stop = 0;
77 * The ftrace_ops must be a static and should also
78 * be read_mostly. These functions do modify read_mostly variables
79 * so use them sparely. Never free an ftrace_op or modify the
80 * next pointer after it has been registered. Even after unregistering
81 * it, the next pointer may still be used internally.
83 int register_ftrace_function(struct ftrace_ops *ops);
84 int unregister_ftrace_function(struct ftrace_ops *ops);
85 void clear_ftrace_function(void);
87 extern void ftrace_stub(unsigned long a0, unsigned long a1);
89 #else /* !CONFIG_FUNCTION_TRACER */
91 * (un)register_ftrace_function must be a macro since the ops parameter
92 * must not be evaluated.
94 #define register_ftrace_function(ops) ({ 0; })
95 #define unregister_ftrace_function(ops) ({ 0; })
96 static inline void clear_ftrace_function(void) { }
97 static inline void ftrace_kill(void) { }
98 static inline void ftrace_stop(void) { }
99 static inline void ftrace_start(void) { }
100 #endif /* CONFIG_FUNCTION_TRACER */
102 #ifdef CONFIG_STACK_TRACER
103 extern int stack_tracer_enabled;
105 stack_trace_sysctl(struct ctl_table *table, int write,
106 void __user *buffer, size_t *lenp,
110 struct ftrace_func_command {
111 struct list_head list;
113 int (*func)(char *func, char *cmd,
114 char *params, int enable);
117 #ifdef CONFIG_DYNAMIC_FTRACE
119 int ftrace_arch_code_modify_prepare(void);
120 int ftrace_arch_code_modify_post_process(void);
124 struct ftrace_probe_ops {
125 void (*func)(unsigned long ip,
126 unsigned long parent_ip,
128 int (*callback)(unsigned long ip, void **data);
129 void (*free)(void **data);
130 int (*print)(struct seq_file *m,
132 struct ftrace_probe_ops *ops,
137 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
140 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
143 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
144 extern void unregister_ftrace_function_probe_all(char *glob);
146 extern int ftrace_text_reserved(void *start, void *end);
149 FTRACE_FL_FREE = (1 << 0),
150 FTRACE_FL_FILTER = (1 << 1),
151 FTRACE_FL_ENABLED = (1 << 2),
156 unsigned long ip; /* address of mcount call-site */
157 struct dyn_ftrace *freelist;
161 struct dyn_ftrace *newlist;
163 struct dyn_arch_ftrace arch;
166 int ftrace_force_update(void);
167 void ftrace_set_filter(unsigned char *buf, int len, int reset);
169 int register_ftrace_command(struct ftrace_func_command *cmd);
170 int unregister_ftrace_command(struct ftrace_func_command *cmd);
172 /* defined in arch */
173 extern int ftrace_ip_converted(unsigned long ip);
174 extern int ftrace_dyn_arch_init(void *data);
175 extern int ftrace_update_ftrace_func(ftrace_func_t func);
176 extern void ftrace_caller(void);
177 extern void ftrace_call(void);
178 extern void mcount_call(void);
181 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
183 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
184 extern void ftrace_graph_caller(void);
185 extern int ftrace_enable_ftrace_graph_caller(void);
186 extern int ftrace_disable_ftrace_graph_caller(void);
188 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
189 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
193 * ftrace_make_nop - convert code into nop
194 * @mod: module structure if called by module load initialization
195 * @rec: the mcount call site record
196 * @addr: the address that the call site should be calling
198 * This is a very sensitive operation and great care needs
199 * to be taken by the arch. The operation should carefully
200 * read the location, check to see if what is read is indeed
201 * what we expect it to be, and then on success of the compare,
202 * it should write to the location.
204 * The code segment at @rec->ip should be a caller to @addr
208 * -EFAULT on error reading the location
209 * -EINVAL on a failed compare of the contents
210 * -EPERM on error writing to the location
211 * Any other value will be considered a failure.
213 extern int ftrace_make_nop(struct module *mod,
214 struct dyn_ftrace *rec, unsigned long addr);
217 * ftrace_make_call - convert a nop call site into a call to addr
218 * @rec: the mcount call site record
219 * @addr: the address that the call site should call
221 * This is a very sensitive operation and great care needs
222 * to be taken by the arch. The operation should carefully
223 * read the location, check to see if what is read is indeed
224 * what we expect it to be, and then on success of the compare,
225 * it should write to the location.
227 * The code segment at @rec->ip should be a nop
231 * -EFAULT on error reading the location
232 * -EINVAL on a failed compare of the contents
233 * -EPERM on error writing to the location
234 * Any other value will be considered a failure.
236 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
238 /* May be defined in arch */
239 extern int ftrace_arch_read_dyn_info(char *buf, int size);
241 extern int skip_trace(unsigned long ip);
243 extern void ftrace_disable_daemon(void);
244 extern void ftrace_enable_daemon(void);
246 static inline int skip_trace(unsigned long ip) { return 0; }
247 static inline int ftrace_force_update(void) { return 0; }
248 static inline void ftrace_set_filter(unsigned char *buf, int len, int reset)
251 static inline void ftrace_disable_daemon(void) { }
252 static inline void ftrace_enable_daemon(void) { }
253 static inline void ftrace_release_mod(struct module *mod) {}
254 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
258 static inline int unregister_ftrace_command(char *cmd_name)
262 static inline int ftrace_text_reserved(void *start, void *end)
266 #endif /* CONFIG_DYNAMIC_FTRACE */
268 /* totally disable ftrace - can not re-enable after this */
269 void ftrace_kill(void);
271 static inline void tracer_disable(void)
273 #ifdef CONFIG_FUNCTION_TRACER
279 * Ftrace disable/restore without lock. Some synchronization mechanism
280 * must be used to prevent ftrace_enabled to be changed between
283 static inline int __ftrace_enabled_save(void)
285 #ifdef CONFIG_FUNCTION_TRACER
286 int saved_ftrace_enabled = ftrace_enabled;
288 return saved_ftrace_enabled;
294 static inline void __ftrace_enabled_restore(int enabled)
296 #ifdef CONFIG_FUNCTION_TRACER
297 ftrace_enabled = enabled;
301 #ifndef HAVE_ARCH_CALLER_ADDR
302 # ifdef CONFIG_FRAME_POINTER
303 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
304 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
305 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
306 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
307 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
308 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
309 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
311 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
312 # define CALLER_ADDR1 0UL
313 # define CALLER_ADDR2 0UL
314 # define CALLER_ADDR3 0UL
315 # define CALLER_ADDR4 0UL
316 # define CALLER_ADDR5 0UL
317 # define CALLER_ADDR6 0UL
319 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
321 #ifdef CONFIG_IRQSOFF_TRACER
322 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
323 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
325 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
326 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
329 #ifdef CONFIG_PREEMPT_TRACER
330 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
331 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
333 static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { }
334 static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { }
337 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
338 extern void ftrace_init(void);
340 static inline void ftrace_init(void) { }
344 * Structure that defines an entry function trace.
346 struct ftrace_graph_ent {
347 unsigned long func; /* Current function */
352 * Structure that defines a return function trace.
354 struct ftrace_graph_ret {
355 unsigned long func; /* Current function */
356 unsigned long long calltime;
357 unsigned long long rettime;
358 /* Number of functions that overran the depth limit for current task */
359 unsigned long overrun;
363 /* Type of the callback handlers for tracing function graph*/
364 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
365 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
367 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
370 #define INIT_FTRACE_GRAPH .ret_stack = NULL,
373 * Stack of return addresses for functions
375 * Used in struct thread_info
377 struct ftrace_ret_stack {
380 unsigned long long calltime;
381 unsigned long long subtime;
386 * Primary handler of a function return.
387 * It relays on ftrace_return_to_handler.
388 * Defined in entry_32/64.S
390 extern void return_to_handler(void);
393 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
394 unsigned long frame_pointer);
397 * Sometimes we don't want to trace a function with the function
398 * graph tracer but we want them to keep traced by the usual function
399 * tracer if the function graph tracer is not configured.
401 #define __notrace_funcgraph notrace
404 * We want to which function is an entrypoint of a hardirq.
405 * That will help us to put a signal on output.
407 #define __irq_entry __attribute__((__section__(".irqentry.text")))
409 /* Limits of hardirq entrypoints */
410 extern char __irqentry_text_start[];
411 extern char __irqentry_text_end[];
413 #define FTRACE_RETFUNC_DEPTH 50
414 #define FTRACE_RETSTACK_ALLOC_SIZE 32
415 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
416 trace_func_graph_ent_t entryfunc);
418 extern void ftrace_graph_stop(void);
420 /* The current handlers in use */
421 extern trace_func_graph_ret_t ftrace_graph_return;
422 extern trace_func_graph_ent_t ftrace_graph_entry;
424 extern void unregister_ftrace_graph(void);
426 extern void ftrace_graph_init_task(struct task_struct *t);
427 extern void ftrace_graph_exit_task(struct task_struct *t);
428 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
430 static inline int task_curr_ret_stack(struct task_struct *t)
432 return t->curr_ret_stack;
435 static inline void pause_graph_tracing(void)
437 atomic_inc(¤t->tracing_graph_pause);
440 static inline void unpause_graph_tracing(void)
442 atomic_dec(¤t->tracing_graph_pause);
444 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
446 #define __notrace_funcgraph
448 #define INIT_FTRACE_GRAPH
450 static inline void ftrace_graph_init_task(struct task_struct *t) { }
451 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
452 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
454 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
455 trace_func_graph_ent_t entryfunc)
459 static inline void unregister_ftrace_graph(void) { }
461 static inline int task_curr_ret_stack(struct task_struct *tsk)
466 static inline void pause_graph_tracing(void) { }
467 static inline void unpause_graph_tracing(void) { }
468 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
470 #ifdef CONFIG_TRACING
472 /* flags for current->trace */
474 TSK_TRACE_FL_TRACE_BIT = 0,
475 TSK_TRACE_FL_GRAPH_BIT = 1,
478 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
479 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
482 static inline void set_tsk_trace_trace(struct task_struct *tsk)
484 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
487 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
489 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
492 static inline int test_tsk_trace_trace(struct task_struct *tsk)
494 return tsk->trace & TSK_TRACE_FL_TRACE;
497 static inline void set_tsk_trace_graph(struct task_struct *tsk)
499 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
502 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
504 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
507 static inline int test_tsk_trace_graph(struct task_struct *tsk)
509 return tsk->trace & TSK_TRACE_FL_GRAPH;
512 enum ftrace_dump_mode;
514 extern enum ftrace_dump_mode ftrace_dump_on_oops;
516 #ifdef CONFIG_PREEMPT
517 #define INIT_TRACE_RECURSION .trace_recursion = 0,
520 #endif /* CONFIG_TRACING */
522 #ifndef INIT_TRACE_RECURSION
523 #define INIT_TRACE_RECURSION
526 #ifdef CONFIG_FTRACE_SYSCALLS
528 unsigned long arch_syscall_addr(int nr);
530 #endif /* CONFIG_FTRACE_SYSCALLS */
532 #endif /* _LINUX_FTRACE_H */