]> Pileus Git - ~andy/linux/blob - include/linux/ftrace.h
Merge branch 'tip/perf/core' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[~andy/linux] / include / linux / ftrace.h
1 /*
2  * Ftrace header.  For implementation details beyond the random comments
3  * scattered below, see: Documentation/trace/ftrace-design.txt
4  */
5
6 #ifndef _LINUX_FTRACE_H
7 #define _LINUX_FTRACE_H
8
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>
18 #include <linux/fs.h>
19
20 #include <asm/ftrace.h>
21
22 #ifdef CONFIG_FUNCTION_TRACER
23
24 extern int ftrace_enabled;
25 extern int
26 ftrace_enable_sysctl(struct ctl_table *table, int write,
27                      void __user *buffer, size_t *lenp,
28                      loff_t *ppos);
29
30 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
31
32 struct ftrace_ops {
33         ftrace_func_t     func;
34         struct ftrace_ops *next;
35 };
36
37 extern int function_trace_stop;
38
39 /*
40  * Type of the current tracing.
41  */
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 */
45 };
46
47 /* Current tracing type, default is FTRACE_TYPE_ENTER */
48 extern enum ftrace_tracing_type_t ftrace_tracing_type;
49
50 /**
51  * ftrace_stop - stop function tracer.
52  *
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.
57  */
58 static inline void ftrace_stop(void)
59 {
60         function_trace_stop = 1;
61 }
62
63 /**
64  * ftrace_start - start the function tracer.
65  *
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
69  * from mcount.
70  */
71 static inline void ftrace_start(void)
72 {
73         function_trace_stop = 0;
74 }
75
76 /*
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.
82  */
83 int register_ftrace_function(struct ftrace_ops *ops);
84 int unregister_ftrace_function(struct ftrace_ops *ops);
85 void clear_ftrace_function(void);
86
87 extern void ftrace_stub(unsigned long a0, unsigned long a1);
88
89 #else /* !CONFIG_FUNCTION_TRACER */
90 /*
91  * (un)register_ftrace_function must be a macro since the ops parameter
92  * must not be evaluated.
93  */
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 */
101
102 #ifdef CONFIG_STACK_TRACER
103 extern int stack_tracer_enabled;
104 int
105 stack_trace_sysctl(struct ctl_table *table, int write,
106                    void __user *buffer, size_t *lenp,
107                    loff_t *ppos);
108 #endif
109
110 struct ftrace_func_command {
111         struct list_head        list;
112         char                    *name;
113         int                     (*func)(char *func, char *cmd,
114                                         char *params, int enable);
115 };
116
117 #ifdef CONFIG_DYNAMIC_FTRACE
118
119 int ftrace_arch_code_modify_prepare(void);
120 int ftrace_arch_code_modify_post_process(void);
121
122 struct seq_file;
123
124 struct ftrace_probe_ops {
125         void                    (*func)(unsigned long ip,
126                                         unsigned long parent_ip,
127                                         void **data);
128         int                     (*callback)(unsigned long ip, void **data);
129         void                    (*free)(void **data);
130         int                     (*print)(struct seq_file *m,
131                                          unsigned long ip,
132                                          struct ftrace_probe_ops *ops,
133                                          void *data);
134 };
135
136 extern int
137 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
138                               void *data);
139 extern void
140 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
141                                 void *data);
142 extern void
143 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
144 extern void unregister_ftrace_function_probe_all(char *glob);
145
146 extern int ftrace_text_reserved(void *start, void *end);
147
148 enum {
149         FTRACE_FL_FREE          = (1 << 0),
150         FTRACE_FL_FILTER        = (1 << 1),
151         FTRACE_FL_ENABLED       = (1 << 2),
152         FTRACE_FL_NOTRACE       = (1 << 3),
153 };
154
155 struct dyn_ftrace {
156         union {
157                 unsigned long           ip; /* address of mcount call-site */
158                 struct dyn_ftrace       *freelist;
159         };
160         union {
161                 unsigned long           flags;
162                 struct dyn_ftrace       *newlist;
163         };
164         struct dyn_arch_ftrace          arch;
165 };
166
167 int ftrace_force_update(void);
168 void ftrace_set_filter(unsigned char *buf, int len, int reset);
169
170 int register_ftrace_command(struct ftrace_func_command *cmd);
171 int unregister_ftrace_command(struct ftrace_func_command *cmd);
172
173 /* defined in arch */
174 extern int ftrace_ip_converted(unsigned long ip);
175 extern int ftrace_dyn_arch_init(void *data);
176 extern int ftrace_update_ftrace_func(ftrace_func_t func);
177 extern void ftrace_caller(void);
178 extern void ftrace_call(void);
179 extern void mcount_call(void);
180
181 #ifndef FTRACE_ADDR
182 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
183 #endif
184 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
185 extern void ftrace_graph_caller(void);
186 extern int ftrace_enable_ftrace_graph_caller(void);
187 extern int ftrace_disable_ftrace_graph_caller(void);
188 #else
189 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
190 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
191 #endif
192
193 /**
194  * ftrace_make_nop - convert code into nop
195  * @mod: module structure if called by module load initialization
196  * @rec: the mcount call site record
197  * @addr: the address that the call site should be calling
198  *
199  * This is a very sensitive operation and great care needs
200  * to be taken by the arch.  The operation should carefully
201  * read the location, check to see if what is read is indeed
202  * what we expect it to be, and then on success of the compare,
203  * it should write to the location.
204  *
205  * The code segment at @rec->ip should be a caller to @addr
206  *
207  * Return must be:
208  *  0 on success
209  *  -EFAULT on error reading the location
210  *  -EINVAL on a failed compare of the contents
211  *  -EPERM  on error writing to the location
212  * Any other value will be considered a failure.
213  */
214 extern int ftrace_make_nop(struct module *mod,
215                            struct dyn_ftrace *rec, unsigned long addr);
216
217 /**
218  * ftrace_make_call - convert a nop call site into a call to addr
219  * @rec: the mcount call site record
220  * @addr: the address that the call site should call
221  *
222  * This is a very sensitive operation and great care needs
223  * to be taken by the arch.  The operation should carefully
224  * read the location, check to see if what is read is indeed
225  * what we expect it to be, and then on success of the compare,
226  * it should write to the location.
227  *
228  * The code segment at @rec->ip should be a nop
229  *
230  * Return must be:
231  *  0 on success
232  *  -EFAULT on error reading the location
233  *  -EINVAL on a failed compare of the contents
234  *  -EPERM  on error writing to the location
235  * Any other value will be considered a failure.
236  */
237 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
238
239 /* May be defined in arch */
240 extern int ftrace_arch_read_dyn_info(char *buf, int size);
241
242 extern int skip_trace(unsigned long ip);
243
244 extern void ftrace_disable_daemon(void);
245 extern void ftrace_enable_daemon(void);
246 #else
247 static inline int skip_trace(unsigned long ip) { return 0; }
248 static inline int ftrace_force_update(void) { return 0; }
249 static inline void ftrace_set_filter(unsigned char *buf, int len, int reset)
250 {
251 }
252 static inline void ftrace_disable_daemon(void) { }
253 static inline void ftrace_enable_daemon(void) { }
254 static inline void ftrace_release_mod(struct module *mod) {}
255 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
256 {
257         return -EINVAL;
258 }
259 static inline int unregister_ftrace_command(char *cmd_name)
260 {
261         return -EINVAL;
262 }
263 static inline int ftrace_text_reserved(void *start, void *end)
264 {
265         return 0;
266 }
267 #endif /* CONFIG_DYNAMIC_FTRACE */
268
269 /* totally disable ftrace - can not re-enable after this */
270 void ftrace_kill(void);
271
272 static inline void tracer_disable(void)
273 {
274 #ifdef CONFIG_FUNCTION_TRACER
275         ftrace_enabled = 0;
276 #endif
277 }
278
279 /*
280  * Ftrace disable/restore without lock. Some synchronization mechanism
281  * must be used to prevent ftrace_enabled to be changed between
282  * disable/restore.
283  */
284 static inline int __ftrace_enabled_save(void)
285 {
286 #ifdef CONFIG_FUNCTION_TRACER
287         int saved_ftrace_enabled = ftrace_enabled;
288         ftrace_enabled = 0;
289         return saved_ftrace_enabled;
290 #else
291         return 0;
292 #endif
293 }
294
295 static inline void __ftrace_enabled_restore(int enabled)
296 {
297 #ifdef CONFIG_FUNCTION_TRACER
298         ftrace_enabled = enabled;
299 #endif
300 }
301
302 #ifndef HAVE_ARCH_CALLER_ADDR
303 # ifdef CONFIG_FRAME_POINTER
304 #  define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
305 #  define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
306 #  define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
307 #  define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
308 #  define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
309 #  define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
310 #  define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
311 # else
312 #  define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
313 #  define CALLER_ADDR1 0UL
314 #  define CALLER_ADDR2 0UL
315 #  define CALLER_ADDR3 0UL
316 #  define CALLER_ADDR4 0UL
317 #  define CALLER_ADDR5 0UL
318 #  define CALLER_ADDR6 0UL
319 # endif
320 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
321
322 #ifdef CONFIG_IRQSOFF_TRACER
323   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
324   extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
325 #else
326   static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
327   static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
328 #endif
329
330 #ifdef CONFIG_PREEMPT_TRACER
331   extern void trace_preempt_on(unsigned long a0, unsigned long a1);
332   extern void trace_preempt_off(unsigned long a0, unsigned long a1);
333 #else
334   static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { }
335   static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { }
336 #endif
337
338 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
339 extern void ftrace_init(void);
340 #else
341 static inline void ftrace_init(void) { }
342 #endif
343
344 /*
345  * Structure that defines an entry function trace.
346  */
347 struct ftrace_graph_ent {
348         unsigned long func; /* Current function */
349         int depth;
350 };
351
352 /*
353  * Structure that defines a return function trace.
354  */
355 struct ftrace_graph_ret {
356         unsigned long func; /* Current function */
357         unsigned long long calltime;
358         unsigned long long rettime;
359         /* Number of functions that overran the depth limit for current task */
360         unsigned long overrun;
361         int depth;
362 };
363
364 /* Type of the callback handlers for tracing function graph*/
365 typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
366 typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
367
368 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
369
370 /* for init task */
371 #define INIT_FTRACE_GRAPH               .ret_stack = NULL,
372
373 /*
374  * Stack of return addresses for functions
375  * of a thread.
376  * Used in struct thread_info
377  */
378 struct ftrace_ret_stack {
379         unsigned long ret;
380         unsigned long func;
381         unsigned long long calltime;
382         unsigned long long subtime;
383         unsigned long fp;
384 };
385
386 /*
387  * Primary handler of a function return.
388  * It relays on ftrace_return_to_handler.
389  * Defined in entry_32/64.S
390  */
391 extern void return_to_handler(void);
392
393 extern int
394 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
395                          unsigned long frame_pointer);
396
397 /*
398  * Sometimes we don't want to trace a function with the function
399  * graph tracer but we want them to keep traced by the usual function
400  * tracer if the function graph tracer is not configured.
401  */
402 #define __notrace_funcgraph             notrace
403
404 /*
405  * We want to which function is an entrypoint of a hardirq.
406  * That will help us to put a signal on output.
407  */
408 #define __irq_entry              __attribute__((__section__(".irqentry.text")))
409
410 /* Limits of hardirq entrypoints */
411 extern char __irqentry_text_start[];
412 extern char __irqentry_text_end[];
413
414 #define FTRACE_RETFUNC_DEPTH 50
415 #define FTRACE_RETSTACK_ALLOC_SIZE 32
416 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
417                                 trace_func_graph_ent_t entryfunc);
418
419 extern void ftrace_graph_stop(void);
420
421 /* The current handlers in use */
422 extern trace_func_graph_ret_t ftrace_graph_return;
423 extern trace_func_graph_ent_t ftrace_graph_entry;
424
425 extern void unregister_ftrace_graph(void);
426
427 extern void ftrace_graph_init_task(struct task_struct *t);
428 extern void ftrace_graph_exit_task(struct task_struct *t);
429 extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
430
431 static inline int task_curr_ret_stack(struct task_struct *t)
432 {
433         return t->curr_ret_stack;
434 }
435
436 static inline void pause_graph_tracing(void)
437 {
438         atomic_inc(&current->tracing_graph_pause);
439 }
440
441 static inline void unpause_graph_tracing(void)
442 {
443         atomic_dec(&current->tracing_graph_pause);
444 }
445 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
446
447 #define __notrace_funcgraph
448 #define __irq_entry
449 #define INIT_FTRACE_GRAPH
450
451 static inline void ftrace_graph_init_task(struct task_struct *t) { }
452 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
453 static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
454
455 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
456                           trace_func_graph_ent_t entryfunc)
457 {
458         return -1;
459 }
460 static inline void unregister_ftrace_graph(void) { }
461
462 static inline int task_curr_ret_stack(struct task_struct *tsk)
463 {
464         return -1;
465 }
466
467 static inline void pause_graph_tracing(void) { }
468 static inline void unpause_graph_tracing(void) { }
469 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
470
471 #ifdef CONFIG_TRACING
472
473 /* flags for current->trace */
474 enum {
475         TSK_TRACE_FL_TRACE_BIT  = 0,
476         TSK_TRACE_FL_GRAPH_BIT  = 1,
477 };
478 enum {
479         TSK_TRACE_FL_TRACE      = 1 << TSK_TRACE_FL_TRACE_BIT,
480         TSK_TRACE_FL_GRAPH      = 1 << TSK_TRACE_FL_GRAPH_BIT,
481 };
482
483 static inline void set_tsk_trace_trace(struct task_struct *tsk)
484 {
485         set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
486 }
487
488 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
489 {
490         clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
491 }
492
493 static inline int test_tsk_trace_trace(struct task_struct *tsk)
494 {
495         return tsk->trace & TSK_TRACE_FL_TRACE;
496 }
497
498 static inline void set_tsk_trace_graph(struct task_struct *tsk)
499 {
500         set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
501 }
502
503 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
504 {
505         clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
506 }
507
508 static inline int test_tsk_trace_graph(struct task_struct *tsk)
509 {
510         return tsk->trace & TSK_TRACE_FL_GRAPH;
511 }
512
513 enum ftrace_dump_mode;
514
515 extern enum ftrace_dump_mode ftrace_dump_on_oops;
516
517 #ifdef CONFIG_PREEMPT
518 #define INIT_TRACE_RECURSION            .trace_recursion = 0,
519 #endif
520
521 #endif /* CONFIG_TRACING */
522
523 #ifndef INIT_TRACE_RECURSION
524 #define INIT_TRACE_RECURSION
525 #endif
526
527 #ifdef CONFIG_FTRACE_SYSCALLS
528
529 unsigned long arch_syscall_addr(int nr);
530
531 #endif /* CONFIG_FTRACE_SYSCALLS */
532
533 #endif /* _LINUX_FTRACE_H */