]> git.karo-electronics.de Git - mv-sheeva.git/blob - include/linux/ftrace.h
ftrace: Create a global_ops to hold the filter and notrace hashes
[mv-sheeva.git] / 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_hash;
33
34 struct ftrace_ops {
35         ftrace_func_t                   func;
36         struct ftrace_ops               *next;
37 #ifdef CONFIG_DYNAMIC_FTRACE
38         struct ftrace_hash              *notrace_hash;
39         struct ftrace_hash              *filter_hash;
40 #endif
41 };
42
43 extern int function_trace_stop;
44
45 /*
46  * Type of the current tracing.
47  */
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 */
51 };
52
53 /* Current tracing type, default is FTRACE_TYPE_ENTER */
54 extern enum ftrace_tracing_type_t ftrace_tracing_type;
55
56 /**
57  * ftrace_stop - stop function tracer.
58  *
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.
63  */
64 static inline void ftrace_stop(void)
65 {
66         function_trace_stop = 1;
67 }
68
69 /**
70  * ftrace_start - start the function tracer.
71  *
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
75  * from mcount.
76  */
77 static inline void ftrace_start(void)
78 {
79         function_trace_stop = 0;
80 }
81
82 /*
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.
88  */
89 int register_ftrace_function(struct ftrace_ops *ops);
90 int unregister_ftrace_function(struct ftrace_ops *ops);
91 void clear_ftrace_function(void);
92
93 extern void ftrace_stub(unsigned long a0, unsigned long a1);
94
95 #else /* !CONFIG_FUNCTION_TRACER */
96 /*
97  * (un)register_ftrace_function must be a macro since the ops parameter
98  * must not be evaluated.
99  */
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 */
107
108 #ifdef CONFIG_STACK_TRACER
109 extern int stack_tracer_enabled;
110 int
111 stack_trace_sysctl(struct ctl_table *table, int write,
112                    void __user *buffer, size_t *lenp,
113                    loff_t *ppos);
114 #endif
115
116 struct ftrace_func_command {
117         struct list_head        list;
118         char                    *name;
119         int                     (*func)(char *func, char *cmd,
120                                         char *params, int enable);
121 };
122
123 #ifdef CONFIG_DYNAMIC_FTRACE
124
125 int ftrace_arch_code_modify_prepare(void);
126 int ftrace_arch_code_modify_post_process(void);
127
128 struct seq_file;
129
130 struct ftrace_probe_ops {
131         void                    (*func)(unsigned long ip,
132                                         unsigned long parent_ip,
133                                         void **data);
134         int                     (*callback)(unsigned long ip, void **data);
135         void                    (*free)(void **data);
136         int                     (*print)(struct seq_file *m,
137                                          unsigned long ip,
138                                          struct ftrace_probe_ops *ops,
139                                          void *data);
140 };
141
142 extern int
143 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
144                               void *data);
145 extern void
146 unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
147                                 void *data);
148 extern void
149 unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
150 extern void unregister_ftrace_function_probe_all(char *glob);
151
152 extern int ftrace_text_reserved(void *start, void *end);
153
154 enum {
155         FTRACE_FL_FREE          = (1 << 0),
156         FTRACE_FL_ENABLED       = (1 << 1),
157 };
158
159 struct dyn_ftrace {
160         union {
161                 unsigned long           ip; /* address of mcount call-site */
162                 struct dyn_ftrace       *freelist;
163         };
164         union {
165                 unsigned long           flags;
166                 struct dyn_ftrace       *newlist;
167         };
168         struct dyn_arch_ftrace          arch;
169 };
170
171 int ftrace_force_update(void);
172 void ftrace_set_filter(unsigned char *buf, int len, int reset);
173
174 int register_ftrace_command(struct ftrace_func_command *cmd);
175 int unregister_ftrace_command(struct ftrace_func_command *cmd);
176
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);
184
185 #ifndef FTRACE_ADDR
186 #define FTRACE_ADDR ((unsigned long)ftrace_caller)
187 #endif
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);
192 #else
193 static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
194 static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
195 #endif
196
197 /**
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
202  *
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.
208  *
209  * The code segment at @rec->ip should be a caller to @addr
210  *
211  * Return must be:
212  *  0 on success
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.
217  */
218 extern int ftrace_make_nop(struct module *mod,
219                            struct dyn_ftrace *rec, unsigned long addr);
220
221 /**
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
225  *
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.
231  *
232  * The code segment at @rec->ip should be a nop
233  *
234  * Return must be:
235  *  0 on success
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.
240  */
241 extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
242
243 /* May be defined in arch */
244 extern int ftrace_arch_read_dyn_info(char *buf, int size);
245
246 extern int skip_trace(unsigned long ip);
247
248 extern void ftrace_disable_daemon(void);
249 extern void ftrace_enable_daemon(void);
250 #else
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)
254 {
255 }
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)
260 {
261         return -EINVAL;
262 }
263 static inline int unregister_ftrace_command(char *cmd_name)
264 {
265         return -EINVAL;
266 }
267 static inline int ftrace_text_reserved(void *start, void *end)
268 {
269         return 0;
270 }
271 #endif /* CONFIG_DYNAMIC_FTRACE */
272
273 /* totally disable ftrace - can not re-enable after this */
274 void ftrace_kill(void);
275
276 static inline void tracer_disable(void)
277 {
278 #ifdef CONFIG_FUNCTION_TRACER
279         ftrace_enabled = 0;
280 #endif
281 }
282
283 /*
284  * Ftrace disable/restore without lock. Some synchronization mechanism
285  * must be used to prevent ftrace_enabled to be changed between
286  * disable/restore.
287  */
288 static inline int __ftrace_enabled_save(void)
289 {
290 #ifdef CONFIG_FUNCTION_TRACER
291         int saved_ftrace_enabled = ftrace_enabled;
292         ftrace_enabled = 0;
293         return saved_ftrace_enabled;
294 #else
295         return 0;
296 #endif
297 }
298
299 static inline void __ftrace_enabled_restore(int enabled)
300 {
301 #ifdef CONFIG_FUNCTION_TRACER
302         ftrace_enabled = enabled;
303 #endif
304 }
305
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))
315 # else
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
323 # endif
324 #endif /* ifndef HAVE_ARCH_CALLER_ADDR */
325
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);
329 #else
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) { }
332 #endif
333
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);
337 #else
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) { }
340 #endif
341
342 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
343 extern void ftrace_init(void);
344 #else
345 static inline void ftrace_init(void) { }
346 #endif
347
348 /*
349  * Structure that defines an entry function trace.
350  */
351 struct ftrace_graph_ent {
352         unsigned long func; /* Current function */
353         int depth;
354 };
355
356 /*
357  * Structure that defines a return function trace.
358  */
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;
365         int depth;
366 };
367
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 */
371
372 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
373
374 /* for init task */
375 #define INIT_FTRACE_GRAPH               .ret_stack = NULL,
376
377 /*
378  * Stack of return addresses for functions
379  * of a thread.
380  * Used in struct thread_info
381  */
382 struct ftrace_ret_stack {
383         unsigned long ret;
384         unsigned long func;
385         unsigned long long calltime;
386         unsigned long long subtime;
387         unsigned long fp;
388 };
389
390 /*
391  * Primary handler of a function return.
392  * It relays on ftrace_return_to_handler.
393  * Defined in entry_32/64.S
394  */
395 extern void return_to_handler(void);
396
397 extern int
398 ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
399                          unsigned long frame_pointer);
400
401 /*
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.
405  */
406 #define __notrace_funcgraph             notrace
407
408 /*
409  * We want to which function is an entrypoint of a hardirq.
410  * That will help us to put a signal on output.
411  */
412 #define __irq_entry              __attribute__((__section__(".irqentry.text")))
413
414 /* Limits of hardirq entrypoints */
415 extern char __irqentry_text_start[];
416 extern char __irqentry_text_end[];
417
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);
422
423 extern void ftrace_graph_stop(void);
424
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;
428
429 extern void unregister_ftrace_graph(void);
430
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);
434
435 static inline int task_curr_ret_stack(struct task_struct *t)
436 {
437         return t->curr_ret_stack;
438 }
439
440 static inline void pause_graph_tracing(void)
441 {
442         atomic_inc(&current->tracing_graph_pause);
443 }
444
445 static inline void unpause_graph_tracing(void)
446 {
447         atomic_dec(&current->tracing_graph_pause);
448 }
449 #else /* !CONFIG_FUNCTION_GRAPH_TRACER */
450
451 #define __notrace_funcgraph
452 #define __irq_entry
453 #define INIT_FTRACE_GRAPH
454
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) { }
458
459 static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
460                           trace_func_graph_ent_t entryfunc)
461 {
462         return -1;
463 }
464 static inline void unregister_ftrace_graph(void) { }
465
466 static inline int task_curr_ret_stack(struct task_struct *tsk)
467 {
468         return -1;
469 }
470
471 static inline void pause_graph_tracing(void) { }
472 static inline void unpause_graph_tracing(void) { }
473 #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
474
475 #ifdef CONFIG_TRACING
476
477 /* flags for current->trace */
478 enum {
479         TSK_TRACE_FL_TRACE_BIT  = 0,
480         TSK_TRACE_FL_GRAPH_BIT  = 1,
481 };
482 enum {
483         TSK_TRACE_FL_TRACE      = 1 << TSK_TRACE_FL_TRACE_BIT,
484         TSK_TRACE_FL_GRAPH      = 1 << TSK_TRACE_FL_GRAPH_BIT,
485 };
486
487 static inline void set_tsk_trace_trace(struct task_struct *tsk)
488 {
489         set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
490 }
491
492 static inline void clear_tsk_trace_trace(struct task_struct *tsk)
493 {
494         clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
495 }
496
497 static inline int test_tsk_trace_trace(struct task_struct *tsk)
498 {
499         return tsk->trace & TSK_TRACE_FL_TRACE;
500 }
501
502 static inline void set_tsk_trace_graph(struct task_struct *tsk)
503 {
504         set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
505 }
506
507 static inline void clear_tsk_trace_graph(struct task_struct *tsk)
508 {
509         clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
510 }
511
512 static inline int test_tsk_trace_graph(struct task_struct *tsk)
513 {
514         return tsk->trace & TSK_TRACE_FL_GRAPH;
515 }
516
517 enum ftrace_dump_mode;
518
519 extern enum ftrace_dump_mode ftrace_dump_on_oops;
520
521 #ifdef CONFIG_PREEMPT
522 #define INIT_TRACE_RECURSION            .trace_recursion = 0,
523 #endif
524
525 #endif /* CONFIG_TRACING */
526
527 #ifndef INIT_TRACE_RECURSION
528 #define INIT_TRACE_RECURSION
529 #endif
530
531 #ifdef CONFIG_FTRACE_SYSCALLS
532
533 unsigned long arch_syscall_addr(int nr);
534
535 #endif /* CONFIG_FTRACE_SYSCALLS */
536
537 #endif /* _LINUX_FTRACE_H */