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);
36 struct ftrace_ops *next;
37 #ifdef CONFIG_DYNAMIC_FTRACE
38 struct ftrace_hash *notrace_hash;
39 struct ftrace_hash *filter_hash;
43 extern int function_trace_stop;
46 * Type of the current tracing.
48 enum ftrace_tracing_type_t {
49 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
50 FTRACE_TYPE_RETURN, /* Hook the return of the function */
53 /* Current tracing type, default is FTRACE_TYPE_ENTER */
54 extern enum ftrace_tracing_type_t ftrace_tracing_type;
57 * ftrace_stop - stop function tracer.
59 * A quick way to stop the function tracer. Note this an on off switch,
60 * it is not something that is recursive like preempt_disable.
61 * This does not disable the calling of mcount, it only stops the
62 * calling of functions from mcount.
64 static inline void ftrace_stop(void)
66 function_trace_stop = 1;
70 * ftrace_start - start the function tracer.
72 * This function is the inverse of ftrace_stop. This does not enable
73 * the function tracing if the function tracer is disabled. This only
74 * sets the function tracer flag to continue calling the functions
77 static inline void ftrace_start(void)
79 function_trace_stop = 0;
83 * The ftrace_ops must be a static and should also
84 * be read_mostly. These functions do modify read_mostly variables
85 * so use them sparely. Never free an ftrace_op or modify the
86 * next pointer after it has been registered. Even after unregistering
87 * it, the next pointer may still be used internally.
89 int register_ftrace_function(struct ftrace_ops *ops);
90 int unregister_ftrace_function(struct ftrace_ops *ops);
91 void clear_ftrace_function(void);
93 extern void ftrace_stub(unsigned long a0, unsigned long a1);
95 #else /* !CONFIG_FUNCTION_TRACER */
97 * (un)register_ftrace_function must be a macro since the ops parameter
98 * must not be evaluated.
100 #define register_ftrace_function(ops) ({ 0; })
101 #define unregister_ftrace_function(ops) ({ 0; })
102 static inline void clear_ftrace_function(void) { }
103 static inline void ftrace_kill(void) { }
104 static inline void ftrace_stop(void) { }
105 static inline void ftrace_start(void) { }
106 #endif /* CONFIG_FUNCTION_TRACER */
108 #ifdef CONFIG_STACK_TRACER
109 extern int stack_tracer_enabled;
111 stack_trace_sysctl(struct ctl_table *table, int write,
112 void __user *buffer, size_t *lenp,
116 struct ftrace_func_command {
117 struct list_head list;
119 int (*func)(char *func, char *cmd,
120 char *params, int enable);
123 #ifdef CONFIG_DYNAMIC_FTRACE
125 int ftrace_arch_code_modify_prepare(void);
126 int ftrace_arch_code_modify_post_process(void);
130 struct ftrace_probe_ops {
131 void (*func)(unsigned long ip,
132 unsigned long parent_ip,
134 int (*callback)(unsigned long ip, void **data);
135 void (*free)(void **data);
136 int (*print)(struct seq_file *m,
138 struct ftrace_probe_ops *ops,
143 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
146 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
149 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
150 extern void unregister_ftrace_function_probe_all(char *glob);
152 extern int ftrace_text_reserved(void *start, void *end);
155 FTRACE_FL_FREE = (1 << 0),
156 FTRACE_FL_ENABLED = (1 << 1),
161 unsigned long ip; /* address of mcount call-site */
162 struct dyn_ftrace *freelist;
166 struct dyn_ftrace *newlist;
168 struct dyn_arch_ftrace arch;
171 int ftrace_force_update(void);
172 void ftrace_set_filter(unsigned char *buf, int len, int reset);
174 int register_ftrace_command(struct ftrace_func_command *cmd);
175 int unregister_ftrace_command(struct ftrace_func_command *cmd);
177 /* defined in arch */
178 extern int ftrace_ip_converted(unsigned long ip);
179 extern int ftrace_dyn_arch_init(void *data);
180 extern int ftrace_update_ftrace_func(ftrace_func_t func);
181 extern void ftrace_caller(void);
182 extern void ftrace_call(void);
183 extern void mcount_call(void);
186 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
188 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
189 extern void ftrace_graph_caller(void);
190 extern int ftrace_enable_ftrace_graph_caller(void);
191 extern int ftrace_disable_ftrace_graph_caller(void);
193 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
194 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
198 * ftrace_make_nop - convert code into nop
199 * @mod: module structure if called by module load initialization
200 * @rec: the mcount call site record
201 * @addr: the address that the call site should be calling
203 * This is a very sensitive operation and great care needs
204 * to be taken by the arch. The operation should carefully
205 * read the location, check to see if what is read is indeed
206 * what we expect it to be, and then on success of the compare,
207 * it should write to the location.
209 * The code segment at @rec->ip should be a caller to @addr
213 * -EFAULT on error reading the location
214 * -EINVAL on a failed compare of the contents
215 * -EPERM on error writing to the location
216 * Any other value will be considered a failure.
218 extern int ftrace_make_nop(struct module *mod,
219 struct dyn_ftrace *rec, unsigned long addr);
222 * ftrace_make_call - convert a nop call site into a call to addr
223 * @rec: the mcount call site record
224 * @addr: the address that the call site should call
226 * This is a very sensitive operation and great care needs
227 * to be taken by the arch. The operation should carefully
228 * read the location, check to see if what is read is indeed
229 * what we expect it to be, and then on success of the compare,
230 * it should write to the location.
232 * The code segment at @rec->ip should be a nop
236 * -EFAULT on error reading the location
237 * -EINVAL on a failed compare of the contents
238 * -EPERM on error writing to the location
239 * Any other value will be considered a failure.
241 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
243 /* May be defined in arch */
244 extern int ftrace_arch_read_dyn_info(char *buf, int size);
246 extern int skip_trace(unsigned long ip);
248 extern void ftrace_disable_daemon(void);
249 extern void ftrace_enable_daemon(void);
251 static inline int skip_trace(unsigned long ip) { return 0; }
252 static inline int ftrace_force_update(void) { return 0; }
253 static inline void ftrace_set_filter(unsigned char *buf, int len, int reset)
256 static inline void ftrace_disable_daemon(void) { }
257 static inline void ftrace_enable_daemon(void) { }
258 static inline void ftrace_release_mod(struct module *mod) {}
259 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
263 static inline int unregister_ftrace_command(char *cmd_name)
267 static inline int ftrace_text_reserved(void *start, void *end)
271 #endif /* CONFIG_DYNAMIC_FTRACE */
273 /* totally disable ftrace - can not re-enable after this */
274 void ftrace_kill(void);
276 static inline void tracer_disable(void)
278 #ifdef CONFIG_FUNCTION_TRACER
284 * Ftrace disable/restore without lock. Some synchronization mechanism
285 * must be used to prevent ftrace_enabled to be changed between
288 static inline int __ftrace_enabled_save(void)
290 #ifdef CONFIG_FUNCTION_TRACER
291 int saved_ftrace_enabled = ftrace_enabled;
293 return saved_ftrace_enabled;
299 static inline void __ftrace_enabled_restore(int enabled)
301 #ifdef CONFIG_FUNCTION_TRACER
302 ftrace_enabled = enabled;
306 #ifndef HAVE_ARCH_CALLER_ADDR
307 # ifdef CONFIG_FRAME_POINTER
308 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
309 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
310 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
311 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
312 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
313 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
314 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
316 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
317 # define CALLER_ADDR1 0UL
318 # define CALLER_ADDR2 0UL
319 # define CALLER_ADDR3 0UL
320 # define CALLER_ADDR4 0UL
321 # define CALLER_ADDR5 0UL
322 # define CALLER_ADDR6 0UL
324 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
326 #ifdef CONFIG_IRQSOFF_TRACER
327 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
328 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
330 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
331 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
334 #ifdef CONFIG_PREEMPT_TRACER
335 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
336 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
338 static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { }
339 static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { }
342 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
343 extern void ftrace_init(void);
345 static inline void ftrace_init(void) { }
349 * Structure that defines an entry function trace.
351 struct ftrace_graph_ent {
352 unsigned long func; /* Current function */
357 * Structure that defines a return function trace.
359 struct ftrace_graph_ret {
360 unsigned long func; /* Current function */
361 unsigned long long calltime;
362 unsigned long long rettime;
363 /* Number of functions that overran the depth limit for current task */
364 unsigned long overrun;
368 /* Type of the callback handlers for tracing function graph*/
369 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
370 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
372 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
375 #define INIT_FTRACE_GRAPH .ret_stack = NULL,
378 * Stack of return addresses for functions
380 * Used in struct thread_info
382 struct ftrace_ret_stack {
385 unsigned long long calltime;
386 unsigned long long subtime;
391 * Primary handler of a function return.
392 * It relays on ftrace_return_to_handler.
393 * Defined in entry_32/64.S
395 extern void return_to_handler(void);
398 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
399 unsigned long frame_pointer);
402 * Sometimes we don't want to trace a function with the function
403 * graph tracer but we want them to keep traced by the usual function
404 * tracer if the function graph tracer is not configured.
406 #define __notrace_funcgraph notrace
409 * We want to which function is an entrypoint of a hardirq.
410 * That will help us to put a signal on output.
412 #define __irq_entry __attribute__((__section__(".irqentry.text")))
414 /* Limits of hardirq entrypoints */
415 extern char __irqentry_text_start[];
416 extern char __irqentry_text_end[];
418 #define FTRACE_RETFUNC_DEPTH 50
419 #define FTRACE_RETSTACK_ALLOC_SIZE 32
420 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
421 trace_func_graph_ent_t entryfunc);
423 extern void ftrace_graph_stop(void);
425 /* The current handlers in use */
426 extern trace_func_graph_ret_t ftrace_graph_return;
427 extern trace_func_graph_ent_t ftrace_graph_entry;
429 extern void unregister_ftrace_graph(void);
431 extern void ftrace_graph_init_task(struct task_struct *t);
432 extern void ftrace_graph_exit_task(struct task_struct *t);
433 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
435 static inline int task_curr_ret_stack(struct task_struct *t)
437 return t->curr_ret_stack;
440 static inline void pause_graph_tracing(void)
442 atomic_inc(¤t->tracing_graph_pause);
445 static inline void unpause_graph_tracing(void)
447 atomic_dec(¤t->tracing_graph_pause);
449 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
451 #define __notrace_funcgraph
453 #define INIT_FTRACE_GRAPH
455 static inline void ftrace_graph_init_task(struct task_struct *t) { }
456 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
457 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
459 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
460 trace_func_graph_ent_t entryfunc)
464 static inline void unregister_ftrace_graph(void) { }
466 static inline int task_curr_ret_stack(struct task_struct *tsk)
471 static inline void pause_graph_tracing(void) { }
472 static inline void unpause_graph_tracing(void) { }
473 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
475 #ifdef CONFIG_TRACING
477 /* flags for current->trace */
479 TSK_TRACE_FL_TRACE_BIT = 0,
480 TSK_TRACE_FL_GRAPH_BIT = 1,
483 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
484 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
487 static inline void set_tsk_trace_trace(struct task_struct *tsk)
489 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
492 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
494 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
497 static inline int test_tsk_trace_trace(struct task_struct *tsk)
499 return tsk->trace & TSK_TRACE_FL_TRACE;
502 static inline void set_tsk_trace_graph(struct task_struct *tsk)
504 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
507 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
509 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
512 static inline int test_tsk_trace_graph(struct task_struct *tsk)
514 return tsk->trace & TSK_TRACE_FL_GRAPH;
517 enum ftrace_dump_mode;
519 extern enum ftrace_dump_mode ftrace_dump_on_oops;
521 #ifdef CONFIG_PREEMPT
522 #define INIT_TRACE_RECURSION .trace_recursion = 0,
525 #endif /* CONFIG_TRACING */
527 #ifndef INIT_TRACE_RECURSION
528 #define INIT_TRACE_RECURSION
531 #ifdef CONFIG_FTRACE_SYSCALLS
533 unsigned long arch_syscall_addr(int nr);
535 #endif /* CONFIG_FTRACE_SYSCALLS */
537 #endif /* _LINUX_FTRACE_H */