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/ptrace.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>
23 * If the arch supports passing the variable contents of
24 * function_trace_op as the third parameter back from the
25 * mcount call, then the arch should define this as 1.
27 #ifndef ARCH_SUPPORTS_FTRACE_OPS
28 #define ARCH_SUPPORTS_FTRACE_OPS 0
32 * If the arch's mcount caller does not support all of ftrace's
33 * features, then it must call an indirect function that
34 * does. Or at least does enough to prevent any unwelcomed side effects.
36 #if !defined(CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST) || \
37 !ARCH_SUPPORTS_FTRACE_OPS
38 # define FTRACE_FORCE_LIST_FUNC 1
40 # define FTRACE_FORCE_LIST_FUNC 0
47 #ifdef CONFIG_FUNCTION_TRACER
49 extern int ftrace_enabled;
51 ftrace_enable_sysctl(struct ctl_table *table, int write,
52 void __user *buffer, size_t *lenp,
57 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
58 struct ftrace_ops *op, struct pt_regs *regs);
61 * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
62 * set in the flags member.
64 * ENABLED - set/unset when ftrace_ops is registered/unregistered
65 * GLOBAL - set manualy by ftrace_ops user to denote the ftrace_ops
66 * is part of the global tracers sharing the same filter
67 * via set_ftrace_* debugfs files.
68 * DYNAMIC - set when ftrace_ops is registered to denote dynamically
69 * allocated ftrace_ops which need special care
70 * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
71 * could be controled by following calls:
72 * ftrace_function_local_enable
73 * ftrace_function_local_disable
76 FTRACE_OPS_FL_ENABLED = 1 << 0,
77 FTRACE_OPS_FL_GLOBAL = 1 << 1,
78 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
79 FTRACE_OPS_FL_CONTROL = 1 << 3,
84 struct ftrace_ops *next;
86 int __percpu *disabled;
87 #ifdef CONFIG_DYNAMIC_FTRACE
88 struct ftrace_hash *notrace_hash;
89 struct ftrace_hash *filter_hash;
93 extern int function_trace_stop;
96 * Type of the current tracing.
98 enum ftrace_tracing_type_t {
99 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
100 FTRACE_TYPE_RETURN, /* Hook the return of the function */
103 /* Current tracing type, default is FTRACE_TYPE_ENTER */
104 extern enum ftrace_tracing_type_t ftrace_tracing_type;
107 * ftrace_stop - stop function tracer.
109 * A quick way to stop the function tracer. Note this an on off switch,
110 * it is not something that is recursive like preempt_disable.
111 * This does not disable the calling of mcount, it only stops the
112 * calling of functions from mcount.
114 static inline void ftrace_stop(void)
116 function_trace_stop = 1;
120 * ftrace_start - start the function tracer.
122 * This function is the inverse of ftrace_stop. This does not enable
123 * the function tracing if the function tracer is disabled. This only
124 * sets the function tracer flag to continue calling the functions
127 static inline void ftrace_start(void)
129 function_trace_stop = 0;
133 * The ftrace_ops must be a static and should also
134 * be read_mostly. These functions do modify read_mostly variables
135 * so use them sparely. Never free an ftrace_op or modify the
136 * next pointer after it has been registered. Even after unregistering
137 * it, the next pointer may still be used internally.
139 int register_ftrace_function(struct ftrace_ops *ops);
140 int unregister_ftrace_function(struct ftrace_ops *ops);
141 void clear_ftrace_function(void);
144 * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
146 * This function enables tracing on current cpu by decreasing
147 * the per cpu control variable.
148 * It must be called with preemption disabled and only on ftrace_ops
149 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
150 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
152 static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
154 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
157 (*this_cpu_ptr(ops->disabled))--;
161 * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
163 * This function enables tracing on current cpu by decreasing
164 * the per cpu control variable.
165 * It must be called with preemption disabled and only on ftrace_ops
166 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
167 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
169 static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
171 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
174 (*this_cpu_ptr(ops->disabled))++;
178 * ftrace_function_local_disabled - returns ftrace_ops disabled value
181 * This function returns value of ftrace_ops::disabled on current cpu.
182 * It must be called with preemption disabled and only on ftrace_ops
183 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
184 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
186 static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
188 WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
189 return *this_cpu_ptr(ops->disabled);
192 extern void ftrace_stub(unsigned long a0, unsigned long a1,
193 struct ftrace_ops *op, struct pt_regs *regs);
195 #else /* !CONFIG_FUNCTION_TRACER */
197 * (un)register_ftrace_function must be a macro since the ops parameter
198 * must not be evaluated.
200 #define register_ftrace_function(ops) ({ 0; })
201 #define unregister_ftrace_function(ops) ({ 0; })
202 static inline void clear_ftrace_function(void) { }
203 static inline void ftrace_kill(void) { }
204 static inline void ftrace_stop(void) { }
205 static inline void ftrace_start(void) { }
206 #endif /* CONFIG_FUNCTION_TRACER */
208 #ifdef CONFIG_STACK_TRACER
209 extern int stack_tracer_enabled;
211 stack_trace_sysctl(struct ctl_table *table, int write,
212 void __user *buffer, size_t *lenp,
216 struct ftrace_func_command {
217 struct list_head list;
219 int (*func)(struct ftrace_hash *hash,
220 char *func, char *cmd,
221 char *params, int enable);
224 #ifdef CONFIG_DYNAMIC_FTRACE
226 int ftrace_arch_code_modify_prepare(void);
227 int ftrace_arch_code_modify_post_process(void);
229 void ftrace_bug(int err, unsigned long ip);
233 struct ftrace_probe_ops {
234 void (*func)(unsigned long ip,
235 unsigned long parent_ip,
237 int (*callback)(unsigned long ip, void **data);
238 void (*free)(void **data);
239 int (*print)(struct seq_file *m,
241 struct ftrace_probe_ops *ops,
246 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
249 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
252 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
253 extern void unregister_ftrace_function_probe_all(char *glob);
255 extern int ftrace_text_reserved(void *start, void *end);
258 FTRACE_FL_ENABLED = (1 << 30),
261 #define FTRACE_FL_MASK (0x3UL << 30)
262 #define FTRACE_REF_MAX ((1 << 30) - 1)
266 unsigned long ip; /* address of mcount call-site */
267 struct dyn_ftrace *freelist;
270 struct dyn_arch_ftrace arch;
273 int ftrace_force_update(void);
274 int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
276 int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
278 void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
279 void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
280 void ftrace_free_filter(struct ftrace_ops *ops);
282 int register_ftrace_command(struct ftrace_func_command *cmd);
283 int unregister_ftrace_command(struct ftrace_func_command *cmd);
286 FTRACE_UPDATE_CALLS = (1 << 0),
287 FTRACE_DISABLE_CALLS = (1 << 1),
288 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
289 FTRACE_START_FUNC_RET = (1 << 3),
290 FTRACE_STOP_FUNC_RET = (1 << 4),
294 FTRACE_UPDATE_IGNORE,
295 FTRACE_UPDATE_MAKE_CALL,
296 FTRACE_UPDATE_MAKE_NOP,
300 FTRACE_ITER_FILTER = (1 << 0),
301 FTRACE_ITER_NOTRACE = (1 << 1),
302 FTRACE_ITER_PRINTALL = (1 << 2),
303 FTRACE_ITER_DO_HASH = (1 << 3),
304 FTRACE_ITER_HASH = (1 << 4),
305 FTRACE_ITER_ENABLED = (1 << 5),
308 void arch_ftrace_update_code(int command);
310 struct ftrace_rec_iter;
312 struct ftrace_rec_iter *ftrace_rec_iter_start(void);
313 struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
314 struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
316 #define for_ftrace_rec_iter(iter) \
317 for (iter = ftrace_rec_iter_start(); \
319 iter = ftrace_rec_iter_next(iter))
322 int ftrace_update_record(struct dyn_ftrace *rec, int enable);
323 int ftrace_test_record(struct dyn_ftrace *rec, int enable);
324 void ftrace_run_stop_machine(int command);
325 unsigned long ftrace_location(unsigned long ip);
327 extern ftrace_func_t ftrace_trace_function;
329 int ftrace_regex_open(struct ftrace_ops *ops, int flag,
330 struct inode *inode, struct file *file);
331 ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
332 size_t cnt, loff_t *ppos);
333 ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
334 size_t cnt, loff_t *ppos);
335 loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
336 int ftrace_regex_release(struct inode *inode, struct file *file);
339 ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
341 /* defined in arch */
342 extern int ftrace_ip_converted(unsigned long ip);
343 extern int ftrace_dyn_arch_init(void *data);
344 extern void ftrace_replace_code(int enable);
345 extern int ftrace_update_ftrace_func(ftrace_func_t func);
346 extern void ftrace_caller(void);
347 extern void ftrace_call(void);
348 extern void mcount_call(void);
350 void ftrace_modify_all_code(int command);
353 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
355 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
356 extern void ftrace_graph_caller(void);
357 extern int ftrace_enable_ftrace_graph_caller(void);
358 extern int ftrace_disable_ftrace_graph_caller(void);
360 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
361 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
365 * ftrace_make_nop - convert code into nop
366 * @mod: module structure if called by module load initialization
367 * @rec: the mcount call site record
368 * @addr: the address that the call site should be calling
370 * This is a very sensitive operation and great care needs
371 * to be taken by the arch. The operation should carefully
372 * read the location, check to see if what is read is indeed
373 * what we expect it to be, and then on success of the compare,
374 * it should write to the location.
376 * The code segment at @rec->ip should be a caller to @addr
380 * -EFAULT on error reading the location
381 * -EINVAL on a failed compare of the contents
382 * -EPERM on error writing to the location
383 * Any other value will be considered a failure.
385 extern int ftrace_make_nop(struct module *mod,
386 struct dyn_ftrace *rec, unsigned long addr);
389 * ftrace_make_call - convert a nop call site into a call to addr
390 * @rec: the mcount call site record
391 * @addr: the address that the call site should call
393 * This is a very sensitive operation and great care needs
394 * to be taken by the arch. The operation should carefully
395 * read the location, check to see if what is read is indeed
396 * what we expect it to be, and then on success of the compare,
397 * it should write to the location.
399 * The code segment at @rec->ip should be a nop
403 * -EFAULT on error reading the location
404 * -EINVAL on a failed compare of the contents
405 * -EPERM on error writing to the location
406 * Any other value will be considered a failure.
408 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
410 /* May be defined in arch */
411 extern int ftrace_arch_read_dyn_info(char *buf, int size);
413 extern int skip_trace(unsigned long ip);
415 extern void ftrace_disable_daemon(void);
416 extern void ftrace_enable_daemon(void);
418 static inline int skip_trace(unsigned long ip) { return 0; }
419 static inline int ftrace_force_update(void) { return 0; }
420 static inline void ftrace_disable_daemon(void) { }
421 static inline void ftrace_enable_daemon(void) { }
422 static inline void ftrace_release_mod(struct module *mod) {}
423 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
427 static inline int unregister_ftrace_command(char *cmd_name)
431 static inline int ftrace_text_reserved(void *start, void *end)
437 * Again users of functions that have ftrace_ops may not
438 * have them defined when ftrace is not enabled, but these
439 * functions may still be called. Use a macro instead of inline.
441 #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
442 #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
443 #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
444 #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
445 #define ftrace_free_filter(ops) do { } while (0)
447 static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
448 size_t cnt, loff_t *ppos) { return -ENODEV; }
449 static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
450 size_t cnt, loff_t *ppos) { return -ENODEV; }
451 static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
456 ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
457 #endif /* CONFIG_DYNAMIC_FTRACE */
459 /* totally disable ftrace - can not re-enable after this */
460 void ftrace_kill(void);
462 static inline void tracer_disable(void)
464 #ifdef CONFIG_FUNCTION_TRACER
470 * Ftrace disable/restore without lock. Some synchronization mechanism
471 * must be used to prevent ftrace_enabled to be changed between
474 static inline int __ftrace_enabled_save(void)
476 #ifdef CONFIG_FUNCTION_TRACER
477 int saved_ftrace_enabled = ftrace_enabled;
479 return saved_ftrace_enabled;
485 static inline void __ftrace_enabled_restore(int enabled)
487 #ifdef CONFIG_FUNCTION_TRACER
488 ftrace_enabled = enabled;
492 #ifndef HAVE_ARCH_CALLER_ADDR
493 # ifdef CONFIG_FRAME_POINTER
494 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
495 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
496 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
497 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
498 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
499 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
500 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
502 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
503 # define CALLER_ADDR1 0UL
504 # define CALLER_ADDR2 0UL
505 # define CALLER_ADDR3 0UL
506 # define CALLER_ADDR4 0UL
507 # define CALLER_ADDR5 0UL
508 # define CALLER_ADDR6 0UL
510 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
512 #ifdef CONFIG_IRQSOFF_TRACER
513 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
514 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
516 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
517 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
520 #ifdef CONFIG_PREEMPT_TRACER
521 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
522 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
525 * Use defines instead of static inlines because some arches will make code out
526 * of the CALLER_ADDR, when we really want these to be a real nop.
528 # define trace_preempt_on(a0, a1) do { } while (0)
529 # define trace_preempt_off(a0, a1) do { } while (0)
532 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
533 extern void ftrace_init(void);
535 static inline void ftrace_init(void) { }
539 * Structure that defines an entry function trace.
541 struct ftrace_graph_ent {
542 unsigned long func; /* Current function */
547 * Structure that defines a return function trace.
549 struct ftrace_graph_ret {
550 unsigned long func; /* Current function */
551 unsigned long long calltime;
552 unsigned long long rettime;
553 /* Number of functions that overran the depth limit for current task */
554 unsigned long overrun;
558 /* Type of the callback handlers for tracing function graph*/
559 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
560 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
562 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
565 #define INIT_FTRACE_GRAPH .ret_stack = NULL,
568 * Stack of return addresses for functions
570 * Used in struct thread_info
572 struct ftrace_ret_stack {
575 unsigned long long calltime;
576 unsigned long long subtime;
581 * Primary handler of a function return.
582 * It relays on ftrace_return_to_handler.
583 * Defined in entry_32/64.S
585 extern void return_to_handler(void);
588 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
589 unsigned long frame_pointer);
592 * Sometimes we don't want to trace a function with the function
593 * graph tracer but we want them to keep traced by the usual function
594 * tracer if the function graph tracer is not configured.
596 #define __notrace_funcgraph notrace
599 * We want to which function is an entrypoint of a hardirq.
600 * That will help us to put a signal on output.
602 #define __irq_entry __attribute__((__section__(".irqentry.text")))
604 /* Limits of hardirq entrypoints */
605 extern char __irqentry_text_start[];
606 extern char __irqentry_text_end[];
608 #define FTRACE_RETFUNC_DEPTH 50
609 #define FTRACE_RETSTACK_ALLOC_SIZE 32
610 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
611 trace_func_graph_ent_t entryfunc);
613 extern void ftrace_graph_stop(void);
615 /* The current handlers in use */
616 extern trace_func_graph_ret_t ftrace_graph_return;
617 extern trace_func_graph_ent_t ftrace_graph_entry;
619 extern void unregister_ftrace_graph(void);
621 extern void ftrace_graph_init_task(struct task_struct *t);
622 extern void ftrace_graph_exit_task(struct task_struct *t);
623 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
625 static inline int task_curr_ret_stack(struct task_struct *t)
627 return t->curr_ret_stack;
630 static inline void pause_graph_tracing(void)
632 atomic_inc(¤t->tracing_graph_pause);
635 static inline void unpause_graph_tracing(void)
637 atomic_dec(¤t->tracing_graph_pause);
639 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
641 #define __notrace_funcgraph
643 #define INIT_FTRACE_GRAPH
645 static inline void ftrace_graph_init_task(struct task_struct *t) { }
646 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
647 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
649 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
650 trace_func_graph_ent_t entryfunc)
654 static inline void unregister_ftrace_graph(void) { }
656 static inline int task_curr_ret_stack(struct task_struct *tsk)
661 static inline void pause_graph_tracing(void) { }
662 static inline void unpause_graph_tracing(void) { }
663 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
665 #ifdef CONFIG_TRACING
667 /* flags for current->trace */
669 TSK_TRACE_FL_TRACE_BIT = 0,
670 TSK_TRACE_FL_GRAPH_BIT = 1,
673 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
674 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
677 static inline void set_tsk_trace_trace(struct task_struct *tsk)
679 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
682 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
684 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
687 static inline int test_tsk_trace_trace(struct task_struct *tsk)
689 return tsk->trace & TSK_TRACE_FL_TRACE;
692 static inline void set_tsk_trace_graph(struct task_struct *tsk)
694 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
697 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
699 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
702 static inline int test_tsk_trace_graph(struct task_struct *tsk)
704 return tsk->trace & TSK_TRACE_FL_GRAPH;
707 enum ftrace_dump_mode;
709 extern enum ftrace_dump_mode ftrace_dump_on_oops;
711 #ifdef CONFIG_PREEMPT
712 #define INIT_TRACE_RECURSION .trace_recursion = 0,
715 #endif /* CONFIG_TRACING */
717 #ifndef INIT_TRACE_RECURSION
718 #define INIT_TRACE_RECURSION
721 #ifdef CONFIG_FTRACE_SYSCALLS
723 unsigned long arch_syscall_addr(int nr);
725 #endif /* CONFIG_FTRACE_SYSCALLS */
727 #endif /* _LINUX_FTRACE_H */