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/ktime.h>
14 #include <linux/sched.h>
15 #include <linux/types.h>
16 #include <linux/init.h>
19 #include <asm/ftrace.h>
22 * If the arch supports passing the variable contents of
23 * function_trace_op as the third parameter back from the
24 * mcount call, then the arch should define this as 1.
26 #ifndef ARCH_SUPPORTS_FTRACE_OPS
27 #define ARCH_SUPPORTS_FTRACE_OPS 0
33 #ifdef CONFIG_FUNCTION_TRACER
35 extern int ftrace_enabled;
37 ftrace_enable_sysctl(struct ctl_table *table, int write,
38 void __user *buffer, size_t *lenp,
43 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
44 struct ftrace_ops *op);
47 * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
48 * set in the flags member.
50 * ENABLED - set/unset when ftrace_ops is registered/unregistered
51 * GLOBAL - set manualy by ftrace_ops user to denote the ftrace_ops
52 * is part of the global tracers sharing the same filter
53 * via set_ftrace_* debugfs files.
54 * DYNAMIC - set when ftrace_ops is registered to denote dynamically
55 * allocated ftrace_ops which need special care
56 * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
57 * could be controled by following calls:
58 * ftrace_function_local_enable
59 * ftrace_function_local_disable
62 FTRACE_OPS_FL_ENABLED = 1 << 0,
63 FTRACE_OPS_FL_GLOBAL = 1 << 1,
64 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
65 FTRACE_OPS_FL_CONTROL = 1 << 3,
70 struct ftrace_ops *next;
72 int __percpu *disabled;
73 #ifdef CONFIG_DYNAMIC_FTRACE
74 struct ftrace_hash *notrace_hash;
75 struct ftrace_hash *filter_hash;
79 extern int function_trace_stop;
82 * Type of the current tracing.
84 enum ftrace_tracing_type_t {
85 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
86 FTRACE_TYPE_RETURN, /* Hook the return of the function */
89 /* Current tracing type, default is FTRACE_TYPE_ENTER */
90 extern enum ftrace_tracing_type_t ftrace_tracing_type;
93 * ftrace_stop - stop function tracer.
95 * A quick way to stop the function tracer. Note this an on off switch,
96 * it is not something that is recursive like preempt_disable.
97 * This does not disable the calling of mcount, it only stops the
98 * calling of functions from mcount.
100 static inline void ftrace_stop(void)
102 function_trace_stop = 1;
106 * ftrace_start - start the function tracer.
108 * This function is the inverse of ftrace_stop. This does not enable
109 * the function tracing if the function tracer is disabled. This only
110 * sets the function tracer flag to continue calling the functions
113 static inline void ftrace_start(void)
115 function_trace_stop = 0;
119 * The ftrace_ops must be a static and should also
120 * be read_mostly. These functions do modify read_mostly variables
121 * so use them sparely. Never free an ftrace_op or modify the
122 * next pointer after it has been registered. Even after unregistering
123 * it, the next pointer may still be used internally.
125 int register_ftrace_function(struct ftrace_ops *ops);
126 int unregister_ftrace_function(struct ftrace_ops *ops);
127 void clear_ftrace_function(void);
130 * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
132 * This function enables tracing on current cpu by decreasing
133 * the per cpu control variable.
134 * It must be called with preemption disabled and only on ftrace_ops
135 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
136 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
138 static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
140 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
143 (*this_cpu_ptr(ops->disabled))--;
147 * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
149 * This function enables tracing on current cpu by decreasing
150 * the per cpu control variable.
151 * It must be called with preemption disabled and only on ftrace_ops
152 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
153 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
155 static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
157 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
160 (*this_cpu_ptr(ops->disabled))++;
164 * ftrace_function_local_disabled - returns ftrace_ops disabled value
167 * This function returns value of ftrace_ops::disabled on current cpu.
168 * It must be called with preemption disabled and only on ftrace_ops
169 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
170 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
172 static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
174 WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
175 return *this_cpu_ptr(ops->disabled);
178 extern void ftrace_stub(unsigned long a0, unsigned long a1, struct ftrace_ops *op);
180 #else /* !CONFIG_FUNCTION_TRACER */
182 * (un)register_ftrace_function must be a macro since the ops parameter
183 * must not be evaluated.
185 #define register_ftrace_function(ops) ({ 0; })
186 #define unregister_ftrace_function(ops) ({ 0; })
187 static inline void clear_ftrace_function(void) { }
188 static inline void ftrace_kill(void) { }
189 static inline void ftrace_stop(void) { }
190 static inline void ftrace_start(void) { }
191 #endif /* CONFIG_FUNCTION_TRACER */
193 #ifdef CONFIG_STACK_TRACER
194 extern int stack_tracer_enabled;
196 stack_trace_sysctl(struct ctl_table *table, int write,
197 void __user *buffer, size_t *lenp,
201 struct ftrace_func_command {
202 struct list_head list;
204 int (*func)(struct ftrace_hash *hash,
205 char *func, char *cmd,
206 char *params, int enable);
209 #ifdef CONFIG_DYNAMIC_FTRACE
211 int ftrace_arch_code_modify_prepare(void);
212 int ftrace_arch_code_modify_post_process(void);
214 void ftrace_bug(int err, unsigned long ip);
218 struct ftrace_probe_ops {
219 void (*func)(unsigned long ip,
220 unsigned long parent_ip,
222 int (*callback)(unsigned long ip, void **data);
223 void (*free)(void **data);
224 int (*print)(struct seq_file *m,
226 struct ftrace_probe_ops *ops,
231 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
234 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
237 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
238 extern void unregister_ftrace_function_probe_all(char *glob);
240 extern int ftrace_text_reserved(void *start, void *end);
243 FTRACE_FL_ENABLED = (1 << 30),
246 #define FTRACE_FL_MASK (0x3UL << 30)
247 #define FTRACE_REF_MAX ((1 << 30) - 1)
251 unsigned long ip; /* address of mcount call-site */
252 struct dyn_ftrace *freelist;
255 struct dyn_arch_ftrace arch;
258 int ftrace_force_update(void);
259 int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
261 int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
263 void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
264 void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
265 void ftrace_free_filter(struct ftrace_ops *ops);
267 int register_ftrace_command(struct ftrace_func_command *cmd);
268 int unregister_ftrace_command(struct ftrace_func_command *cmd);
271 FTRACE_UPDATE_CALLS = (1 << 0),
272 FTRACE_DISABLE_CALLS = (1 << 1),
273 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
274 FTRACE_START_FUNC_RET = (1 << 3),
275 FTRACE_STOP_FUNC_RET = (1 << 4),
279 FTRACE_UPDATE_IGNORE,
280 FTRACE_UPDATE_MAKE_CALL,
281 FTRACE_UPDATE_MAKE_NOP,
285 FTRACE_ITER_FILTER = (1 << 0),
286 FTRACE_ITER_NOTRACE = (1 << 1),
287 FTRACE_ITER_PRINTALL = (1 << 2),
288 FTRACE_ITER_DO_HASH = (1 << 3),
289 FTRACE_ITER_HASH = (1 << 4),
290 FTRACE_ITER_ENABLED = (1 << 5),
293 void arch_ftrace_update_code(int command);
295 struct ftrace_rec_iter;
297 struct ftrace_rec_iter *ftrace_rec_iter_start(void);
298 struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
299 struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
301 #define for_ftrace_rec_iter(iter) \
302 for (iter = ftrace_rec_iter_start(); \
304 iter = ftrace_rec_iter_next(iter))
307 int ftrace_update_record(struct dyn_ftrace *rec, int enable);
308 int ftrace_test_record(struct dyn_ftrace *rec, int enable);
309 void ftrace_run_stop_machine(int command);
310 unsigned long ftrace_location(unsigned long ip);
312 extern ftrace_func_t ftrace_trace_function;
314 int ftrace_regex_open(struct ftrace_ops *ops, int flag,
315 struct inode *inode, struct file *file);
316 ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
317 size_t cnt, loff_t *ppos);
318 ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
319 size_t cnt, loff_t *ppos);
320 loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
321 int ftrace_regex_release(struct inode *inode, struct file *file);
324 ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
326 /* defined in arch */
327 extern int ftrace_ip_converted(unsigned long ip);
328 extern int ftrace_dyn_arch_init(void *data);
329 extern void ftrace_replace_code(int enable);
330 extern int ftrace_update_ftrace_func(ftrace_func_t func);
331 extern void ftrace_caller(void);
332 extern void ftrace_call(void);
333 extern void mcount_call(void);
335 void ftrace_modify_all_code(int command);
338 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
340 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
341 extern void ftrace_graph_caller(void);
342 extern int ftrace_enable_ftrace_graph_caller(void);
343 extern int ftrace_disable_ftrace_graph_caller(void);
345 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
346 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
350 * ftrace_make_nop - convert code into nop
351 * @mod: module structure if called by module load initialization
352 * @rec: the mcount call site record
353 * @addr: the address that the call site should be calling
355 * This is a very sensitive operation and great care needs
356 * to be taken by the arch. The operation should carefully
357 * read the location, check to see if what is read is indeed
358 * what we expect it to be, and then on success of the compare,
359 * it should write to the location.
361 * The code segment at @rec->ip should be a caller to @addr
365 * -EFAULT on error reading the location
366 * -EINVAL on a failed compare of the contents
367 * -EPERM on error writing to the location
368 * Any other value will be considered a failure.
370 extern int ftrace_make_nop(struct module *mod,
371 struct dyn_ftrace *rec, unsigned long addr);
374 * ftrace_make_call - convert a nop call site into a call to addr
375 * @rec: the mcount call site record
376 * @addr: the address that the call site should call
378 * This is a very sensitive operation and great care needs
379 * to be taken by the arch. The operation should carefully
380 * read the location, check to see if what is read is indeed
381 * what we expect it to be, and then on success of the compare,
382 * it should write to the location.
384 * The code segment at @rec->ip should be a nop
388 * -EFAULT on error reading the location
389 * -EINVAL on a failed compare of the contents
390 * -EPERM on error writing to the location
391 * Any other value will be considered a failure.
393 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
395 /* May be defined in arch */
396 extern int ftrace_arch_read_dyn_info(char *buf, int size);
398 extern int skip_trace(unsigned long ip);
400 extern void ftrace_disable_daemon(void);
401 extern void ftrace_enable_daemon(void);
403 static inline int skip_trace(unsigned long ip) { return 0; }
404 static inline int ftrace_force_update(void) { return 0; }
405 static inline void ftrace_disable_daemon(void) { }
406 static inline void ftrace_enable_daemon(void) { }
407 static inline void ftrace_release_mod(struct module *mod) {}
408 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
412 static inline int unregister_ftrace_command(char *cmd_name)
416 static inline int ftrace_text_reserved(void *start, void *end)
422 * Again users of functions that have ftrace_ops may not
423 * have them defined when ftrace is not enabled, but these
424 * functions may still be called. Use a macro instead of inline.
426 #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
427 #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
428 #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
429 #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
430 #define ftrace_free_filter(ops) do { } while (0)
432 static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
433 size_t cnt, loff_t *ppos) { return -ENODEV; }
434 static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
435 size_t cnt, loff_t *ppos) { return -ENODEV; }
436 static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
441 ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
442 #endif /* CONFIG_DYNAMIC_FTRACE */
444 /* totally disable ftrace - can not re-enable after this */
445 void ftrace_kill(void);
447 static inline void tracer_disable(void)
449 #ifdef CONFIG_FUNCTION_TRACER
455 * Ftrace disable/restore without lock. Some synchronization mechanism
456 * must be used to prevent ftrace_enabled to be changed between
459 static inline int __ftrace_enabled_save(void)
461 #ifdef CONFIG_FUNCTION_TRACER
462 int saved_ftrace_enabled = ftrace_enabled;
464 return saved_ftrace_enabled;
470 static inline void __ftrace_enabled_restore(int enabled)
472 #ifdef CONFIG_FUNCTION_TRACER
473 ftrace_enabled = enabled;
477 #ifndef HAVE_ARCH_CALLER_ADDR
478 # ifdef CONFIG_FRAME_POINTER
479 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
480 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
481 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
482 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
483 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
484 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
485 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
487 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
488 # define CALLER_ADDR1 0UL
489 # define CALLER_ADDR2 0UL
490 # define CALLER_ADDR3 0UL
491 # define CALLER_ADDR4 0UL
492 # define CALLER_ADDR5 0UL
493 # define CALLER_ADDR6 0UL
495 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
497 #ifdef CONFIG_IRQSOFF_TRACER
498 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
499 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
501 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
502 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
505 #ifdef CONFIG_PREEMPT_TRACER
506 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
507 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
510 * Use defines instead of static inlines because some arches will make code out
511 * of the CALLER_ADDR, when we really want these to be a real nop.
513 # define trace_preempt_on(a0, a1) do { } while (0)
514 # define trace_preempt_off(a0, a1) do { } while (0)
517 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
518 extern void ftrace_init(void);
520 static inline void ftrace_init(void) { }
524 * Structure that defines an entry function trace.
526 struct ftrace_graph_ent {
527 unsigned long func; /* Current function */
532 * Structure that defines a return function trace.
534 struct ftrace_graph_ret {
535 unsigned long func; /* Current function */
536 unsigned long long calltime;
537 unsigned long long rettime;
538 /* Number of functions that overran the depth limit for current task */
539 unsigned long overrun;
543 /* Type of the callback handlers for tracing function graph*/
544 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
545 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
547 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
550 #define INIT_FTRACE_GRAPH .ret_stack = NULL,
553 * Stack of return addresses for functions
555 * Used in struct thread_info
557 struct ftrace_ret_stack {
560 unsigned long long calltime;
561 unsigned long long subtime;
566 * Primary handler of a function return.
567 * It relays on ftrace_return_to_handler.
568 * Defined in entry_32/64.S
570 extern void return_to_handler(void);
573 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
574 unsigned long frame_pointer);
577 * Sometimes we don't want to trace a function with the function
578 * graph tracer but we want them to keep traced by the usual function
579 * tracer if the function graph tracer is not configured.
581 #define __notrace_funcgraph notrace
584 * We want to which function is an entrypoint of a hardirq.
585 * That will help us to put a signal on output.
587 #define __irq_entry __attribute__((__section__(".irqentry.text")))
589 /* Limits of hardirq entrypoints */
590 extern char __irqentry_text_start[];
591 extern char __irqentry_text_end[];
593 #define FTRACE_RETFUNC_DEPTH 50
594 #define FTRACE_RETSTACK_ALLOC_SIZE 32
595 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
596 trace_func_graph_ent_t entryfunc);
598 extern void ftrace_graph_stop(void);
600 /* The current handlers in use */
601 extern trace_func_graph_ret_t ftrace_graph_return;
602 extern trace_func_graph_ent_t ftrace_graph_entry;
604 extern void unregister_ftrace_graph(void);
606 extern void ftrace_graph_init_task(struct task_struct *t);
607 extern void ftrace_graph_exit_task(struct task_struct *t);
608 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
610 static inline int task_curr_ret_stack(struct task_struct *t)
612 return t->curr_ret_stack;
615 static inline void pause_graph_tracing(void)
617 atomic_inc(¤t->tracing_graph_pause);
620 static inline void unpause_graph_tracing(void)
622 atomic_dec(¤t->tracing_graph_pause);
624 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
626 #define __notrace_funcgraph
628 #define INIT_FTRACE_GRAPH
630 static inline void ftrace_graph_init_task(struct task_struct *t) { }
631 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
632 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
634 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
635 trace_func_graph_ent_t entryfunc)
639 static inline void unregister_ftrace_graph(void) { }
641 static inline int task_curr_ret_stack(struct task_struct *tsk)
646 static inline void pause_graph_tracing(void) { }
647 static inline void unpause_graph_tracing(void) { }
648 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
650 #ifdef CONFIG_TRACING
652 /* flags for current->trace */
654 TSK_TRACE_FL_TRACE_BIT = 0,
655 TSK_TRACE_FL_GRAPH_BIT = 1,
658 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
659 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
662 static inline void set_tsk_trace_trace(struct task_struct *tsk)
664 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
667 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
669 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
672 static inline int test_tsk_trace_trace(struct task_struct *tsk)
674 return tsk->trace & TSK_TRACE_FL_TRACE;
677 static inline void set_tsk_trace_graph(struct task_struct *tsk)
679 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
682 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
684 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
687 static inline int test_tsk_trace_graph(struct task_struct *tsk)
689 return tsk->trace & TSK_TRACE_FL_GRAPH;
692 enum ftrace_dump_mode;
694 extern enum ftrace_dump_mode ftrace_dump_on_oops;
696 #ifdef CONFIG_PREEMPT
697 #define INIT_TRACE_RECURSION .trace_recursion = 0,
700 #endif /* CONFIG_TRACING */
702 #ifndef INIT_TRACE_RECURSION
703 #define INIT_TRACE_RECURSION
706 #ifdef CONFIG_FTRACE_SYSCALLS
708 unsigned long arch_syscall_addr(int nr);
710 #endif /* CONFIG_FTRACE_SYSCALLS */
712 #endif /* _LINUX_FTRACE_H */