6 #ifndef _LINUX_FTRACE_H
7 #define _LINUX_FTRACE_H
11 #include <linux/linkage.h>
12 #include <linux/bitops.h>
13 #include <linux/ptrace.h>
15 #include <linux/sched.h>
16 #include <linux/types.h>
20 #include <asm/ftrace.h>
27 #ifndef ARCH_SUPPORTS_FTRACE_OPS
28 #define ARCH_SUPPORTS_FTRACE_OPS 0
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;
52 void __user *
buffer,
size_t *lenp,
57 typedef void (*ftrace_func_t)(
unsigned long ip,
unsigned long parent_ip,
94 FTRACE_OPS_FL_ENABLED = 1 << 0,
95 FTRACE_OPS_FL_GLOBAL = 1 << 1,
96 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
97 FTRACE_OPS_FL_CONTROL = 1 << 3,
98 FTRACE_OPS_FL_SAVE_REGS = 1 << 4,
99 FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 5,
100 FTRACE_OPS_FL_RECURSION_SAFE = 1 << 6,
105 struct ftrace_ops *
next;
108 #ifdef CONFIG_DYNAMIC_FTRACE
109 struct ftrace_hash *notrace_hash;
110 struct ftrace_hash *filter_hash;
114 extern int function_trace_stop;
119 enum ftrace_tracing_type_t {
120 FTRACE_TYPE_ENTER = 0,
125 extern enum ftrace_tracing_type_t ftrace_tracing_type;
135 static inline void ftrace_stop(
void)
137 function_trace_stop = 1;
148 static inline void ftrace_start(
void)
150 function_trace_stop = 0;
173 static inline void ftrace_function_local_enable(
struct ftrace_ops *ops)
175 if (
WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
190 static inline void ftrace_function_local_disable(
struct ftrace_ops *ops)
192 if (
WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
207 static inline int ftrace_function_local_disabled(
struct ftrace_ops *ops)
213 extern void ftrace_stub(
unsigned long a0,
unsigned long a1,
221 #define register_ftrace_function(ops) ({ 0; })
222 #define unregister_ftrace_function(ops) ({ 0; })
229 static inline void ftrace_stop(
void) { }
230 static inline void ftrace_start(
void) { }
233 #ifdef CONFIG_STACK_TRACER
237 void __user *
buffer,
size_t *lenp,
249 #ifdef CONFIG_DYNAMIC_FTRACE
251 int ftrace_arch_code_modify_prepare(
void);
252 int ftrace_arch_code_modify_post_process(
void);
254 void ftrace_bug(
int err,
unsigned long ip);
258 struct ftrace_probe_ops {
260 unsigned long parent_ip,
266 struct ftrace_probe_ops *ops,
271 register_ftrace_function_probe(
char *glob,
struct ftrace_probe_ops *ops,
274 unregister_ftrace_function_probe(
char *glob,
struct ftrace_probe_ops *ops,
277 unregister_ftrace_function_probe_func(
char *glob,
struct ftrace_probe_ops *ops);
278 extern void unregister_ftrace_function_probe_all(
char *glob);
280 extern int ftrace_text_reserved(
void *
start,
void *
end);
302 FTRACE_FL_ENABLED = (1
UL << 29),
303 FTRACE_FL_REGS = (1
UL << 30),
304 FTRACE_FL_REGS_EN = (1
UL << 31)
307 #define FTRACE_FL_MASK (0x7UL << 29)
308 #define FTRACE_REF_MAX ((1UL << 29) - 1)
313 struct dyn_ftrace *freelist;
319 int ftrace_force_update(
void);
321 int remove,
int reset);
326 void ftrace_set_global_filter(
unsigned char *
buf,
int len,
int reset);
327 void ftrace_set_global_notrace(
unsigned char *
buf,
int len,
int reset);
334 FTRACE_UPDATE_CALLS = (1 << 0),
335 FTRACE_DISABLE_CALLS = (1 << 1),
336 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
337 FTRACE_START_FUNC_RET = (1 << 3),
338 FTRACE_STOP_FUNC_RET = (1 << 4),
354 FTRACE_UPDATE_IGNORE,
355 FTRACE_UPDATE_MAKE_CALL,
356 FTRACE_UPDATE_MODIFY_CALL,
357 FTRACE_UPDATE_MODIFY_CALL_REGS,
358 FTRACE_UPDATE_MAKE_NOP,
362 FTRACE_ITER_FILTER = (1 << 0),
363 FTRACE_ITER_NOTRACE = (1 << 1),
364 FTRACE_ITER_PRINTALL = (1 << 2),
365 FTRACE_ITER_DO_HASH = (1 << 3),
366 FTRACE_ITER_HASH = (1 << 4),
367 FTRACE_ITER_ENABLED = (1 << 5),
370 void arch_ftrace_update_code(
int command);
372 struct ftrace_rec_iter;
374 struct ftrace_rec_iter *ftrace_rec_iter_start(
void);
375 struct ftrace_rec_iter *ftrace_rec_iter_next(
struct ftrace_rec_iter *iter);
376 struct dyn_ftrace *ftrace_rec_iter_record(
struct ftrace_rec_iter *iter);
378 #define for_ftrace_rec_iter(iter) \
379 for (iter = ftrace_rec_iter_start(); \
381 iter = ftrace_rec_iter_next(iter))
384 int ftrace_update_record(
struct dyn_ftrace *rec,
int enable);
385 int ftrace_test_record(
struct dyn_ftrace *rec,
int enable);
386 void ftrace_run_stop_machine(
int command);
387 unsigned long ftrace_location(
unsigned long ip);
389 extern ftrace_func_t ftrace_trace_function;
393 ssize_t ftrace_filter_write(
struct file *
file,
const char __user *ubuf,
394 size_t cnt, loff_t *ppos);
395 ssize_t ftrace_notrace_write(
struct file *
file,
const char __user *ubuf,
396 size_t cnt, loff_t *ppos);
404 extern int ftrace_ip_converted(
unsigned long ip);
406 extern void ftrace_replace_code(
int enable);
408 extern void ftrace_caller(
void);
409 extern void ftrace_regs_caller(
void);
410 extern void ftrace_call(
void);
411 extern void ftrace_regs_call(
void);
412 extern void mcount_call(
void);
414 void ftrace_modify_all_code(
int command);
417 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
420 #ifndef FTRACE_REGS_ADDR
421 #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
422 # define FTRACE_REGS_ADDR ((unsigned long)ftrace_regs_caller)
424 # define FTRACE_REGS_ADDR FTRACE_ADDR
428 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
429 extern void ftrace_graph_caller(
void);
430 extern int ftrace_enable_ftrace_graph_caller(
void);
431 extern int ftrace_disable_ftrace_graph_caller(
void);
433 static inline int ftrace_enable_ftrace_graph_caller(
void) {
return 0; }
434 static inline int ftrace_disable_ftrace_graph_caller(
void) {
return 0; }
459 struct dyn_ftrace *rec,
unsigned long addr);
483 #ifdef ARCH_SUPPORTS_FTRACE_SAVE_REGS
505 extern int ftrace_modify_call(
struct dyn_ftrace *rec,
unsigned long old_addr,
509 static inline int ftrace_modify_call(
struct dyn_ftrace *rec,
unsigned long old_addr,
517 extern int ftrace_arch_read_dyn_info(
char *
buf,
int size);
519 extern int skip_trace(
unsigned long ip);
521 extern void ftrace_disable_daemon(
void);
522 extern void ftrace_enable_daemon(
void);
524 static inline int skip_trace(
unsigned long ip) {
return 0; }
525 static inline int ftrace_force_update(
void) {
return 0; }
526 static inline void ftrace_disable_daemon(
void) { }
527 static inline void ftrace_enable_daemon(
void) { }
528 static inline void ftrace_release_mod(
struct module *
mod) {}
533 static inline int unregister_ftrace_command(
char *cmd_name)
537 static inline int ftrace_text_reserved(
void *
start,
void *
end)
541 static inline unsigned long ftrace_location(
unsigned long ip)
551 #define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
552 #define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
553 #define ftrace_set_filter_ip(ops, ip, remove, reset) ({ -ENODEV; })
554 #define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
555 #define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
556 #define ftrace_free_filter(ops) do { } while (0)
558 static inline ssize_t ftrace_filter_write(
struct file *
file,
const char __user *ubuf,
559 size_t cnt, loff_t *ppos) {
return -
ENODEV; }
560 static inline ssize_t ftrace_notrace_write(
struct file *
file,
const char __user *ubuf,
561 size_t cnt, loff_t *ppos) {
return -
ENODEV; }
573 static inline void tracer_disable(
void)
575 #ifdef CONFIG_FUNCTION_TRACER
585 static inline int __ftrace_enabled_save(
void)
587 #ifdef CONFIG_FUNCTION_TRACER
588 int saved_ftrace_enabled = ftrace_enabled;
590 return saved_ftrace_enabled;
596 static inline void __ftrace_enabled_restore(
int enabled)
598 #ifdef CONFIG_FUNCTION_TRACER
603 #ifndef HAVE_ARCH_CALLER_ADDR
604 # ifdef CONFIG_FRAME_POINTER
605 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
606 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
607 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
608 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
609 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
610 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
611 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
613 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
614 # define CALLER_ADDR1 0UL
615 # define CALLER_ADDR2 0UL
616 # define CALLER_ADDR3 0UL
617 # define CALLER_ADDR4 0UL
618 # define CALLER_ADDR5 0UL
619 # define CALLER_ADDR6 0UL
623 #ifdef CONFIG_IRQSOFF_TRACER
624 extern void time_hardirqs_on(
unsigned long a0,
unsigned long a1);
625 extern void time_hardirqs_off(
unsigned long a0,
unsigned long a1);
627 static inline void time_hardirqs_on(
unsigned long a0,
unsigned long a1) { }
628 static inline void time_hardirqs_off(
unsigned long a0,
unsigned long a1) { }
631 #ifdef CONFIG_PREEMPT_TRACER
639 # define trace_preempt_on(a0, a1) do { } while (0)
640 # define trace_preempt_off(a0, a1) do { } while (0)
643 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
644 extern void ftrace_init(
void);
646 static inline void ftrace_init(
void) { }
673 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
676 #define INIT_FTRACE_GRAPH .ret_stack = NULL,
687 unsigned long long subtime;
700 unsigned long frame_pointer);
707 #define __notrace_funcgraph notrace
713 #define __irq_entry __attribute__((__section__(".irqentry.text")))
716 extern char __irqentry_text_start[];
717 extern char __irqentry_text_end[];
719 #define FTRACE_RETFUNC_DEPTH 50
720 #define FTRACE_RETSTACK_ALLOC_SIZE 32
724 extern void ftrace_graph_stop(
void);
730 extern void unregister_ftrace_graph(
void);
732 extern void ftrace_graph_init_task(
struct task_struct *
t);
733 extern void ftrace_graph_exit_task(
struct task_struct *
t);
734 extern void ftrace_graph_init_idle_task(
struct task_struct *
t,
int cpu);
736 static inline int task_curr_ret_stack(
struct task_struct *
t)
738 return t->curr_ret_stack;
741 static inline void pause_graph_tracing(
void)
746 static inline void unpause_graph_tracing(
void)
752 #define __notrace_funcgraph
754 #define INIT_FTRACE_GRAPH
756 static inline void ftrace_graph_init_task(
struct task_struct *
t) { }
757 static inline void ftrace_graph_exit_task(
struct task_struct *
t) { }
758 static inline void ftrace_graph_init_idle_task(
struct task_struct *
t,
int cpu) { }
765 static inline void unregister_ftrace_graph(
void) { }
767 static inline int task_curr_ret_stack(
struct task_struct *tsk)
772 static inline void pause_graph_tracing(
void) { }
773 static inline void unpause_graph_tracing(
void) { }
776 #ifdef CONFIG_TRACING
780 TSK_TRACE_FL_TRACE_BIT = 0,
781 TSK_TRACE_FL_GRAPH_BIT = 1,
784 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
785 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
788 static inline void set_tsk_trace_trace(
struct task_struct *tsk)
790 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
793 static inline void clear_tsk_trace_trace(
struct task_struct *tsk)
795 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
798 static inline int test_tsk_trace_trace(
struct task_struct *tsk)
800 return tsk->trace & TSK_TRACE_FL_TRACE;
803 static inline void set_tsk_trace_graph(
struct task_struct *tsk)
805 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
808 static inline void clear_tsk_trace_graph(
struct task_struct *tsk)
810 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
813 static inline int test_tsk_trace_graph(
struct task_struct *tsk)
815 return tsk->trace & TSK_TRACE_FL_GRAPH;
822 #ifdef CONFIG_PREEMPT
823 #define INIT_TRACE_RECURSION .trace_recursion = 0,
828 #ifndef INIT_TRACE_RECURSION
829 #define INIT_TRACE_RECURSION
832 #ifdef CONFIG_FTRACE_SYSCALLS