1
2
3
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/ktime.h>
14#include <linux/sched.h>
15#include <linux/types.h>
16#include <linux/init.h>
17#include <linux/fs.h>
18
19#include <asm/ftrace.h>
20
21struct module;
22struct ftrace_hash;
23
24#ifdef CONFIG_FUNCTION_TRACER
25
26extern int ftrace_enabled;
27extern int
28ftrace_enable_sysctl(struct ctl_table *table, int write,
29 void __user *buffer, size_t *lenp,
30 loff_t *ppos);
31
32typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49enum {
50 FTRACE_OPS_FL_ENABLED = 1 << 0,
51 FTRACE_OPS_FL_GLOBAL = 1 << 1,
52 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
53 FTRACE_OPS_FL_CONTROL = 1 << 3,
54};
55
56struct ftrace_ops {
57 ftrace_func_t func;
58 struct ftrace_ops *next;
59 unsigned long flags;
60 int __percpu *disabled;
61#ifdef CONFIG_DYNAMIC_FTRACE
62 struct ftrace_hash *notrace_hash;
63 struct ftrace_hash *filter_hash;
64#endif
65};
66
67extern int function_trace_stop;
68
69
70
71
72enum ftrace_tracing_type_t {
73 FTRACE_TYPE_ENTER = 0,
74 FTRACE_TYPE_RETURN,
75};
76
77
78extern enum ftrace_tracing_type_t ftrace_tracing_type;
79
80
81
82
83
84
85
86
87
88static inline void ftrace_stop(void)
89{
90 function_trace_stop = 1;
91}
92
93
94
95
96
97
98
99
100
101static inline void ftrace_start(void)
102{
103 function_trace_stop = 0;
104}
105
106
107
108
109
110
111
112
113int register_ftrace_function(struct ftrace_ops *ops);
114int unregister_ftrace_function(struct ftrace_ops *ops);
115void clear_ftrace_function(void);
116
117
118
119
120
121
122
123
124
125
126static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
127{
128 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
129 return;
130
131 (*this_cpu_ptr(ops->disabled))--;
132}
133
134
135
136
137
138
139
140
141
142
143static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
144{
145 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
146 return;
147
148 (*this_cpu_ptr(ops->disabled))++;
149}
150
151
152
153
154
155
156
157
158
159
160static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
161{
162 WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
163 return *this_cpu_ptr(ops->disabled);
164}
165
166extern void ftrace_stub(unsigned long a0, unsigned long a1);
167
168#else
169
170
171
172
173#define register_ftrace_function(ops) ({ 0; })
174#define unregister_ftrace_function(ops) ({ 0; })
175static inline void clear_ftrace_function(void) { }
176static inline void ftrace_kill(void) { }
177static inline void ftrace_stop(void) { }
178static inline void ftrace_start(void) { }
179#endif
180
181#ifdef CONFIG_STACK_TRACER
182extern int stack_tracer_enabled;
183int
184stack_trace_sysctl(struct ctl_table *table, int write,
185 void __user *buffer, size_t *lenp,
186 loff_t *ppos);
187#endif
188
189struct ftrace_func_command {
190 struct list_head list;
191 char *name;
192 int (*func)(struct ftrace_hash *hash,
193 char *func, char *cmd,
194 char *params, int enable);
195};
196
197#ifdef CONFIG_DYNAMIC_FTRACE
198
199int ftrace_arch_code_modify_prepare(void);
200int ftrace_arch_code_modify_post_process(void);
201
202void ftrace_bug(int err, unsigned long ip);
203
204struct seq_file;
205
206struct ftrace_probe_ops {
207 void (*func)(unsigned long ip,
208 unsigned long parent_ip,
209 void **data);
210 int (*callback)(unsigned long ip, void **data);
211 void (*free)(void **data);
212 int (*print)(struct seq_file *m,
213 unsigned long ip,
214 struct ftrace_probe_ops *ops,
215 void *data);
216};
217
218extern int
219register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
220 void *data);
221extern void
222unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
223 void *data);
224extern void
225unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
226extern void unregister_ftrace_function_probe_all(char *glob);
227
228extern int ftrace_text_reserved(void *start, void *end);
229
230enum {
231 FTRACE_FL_ENABLED = (1 << 30),
232};
233
234#define FTRACE_FL_MASK (0x3UL << 30)
235#define FTRACE_REF_MAX ((1 << 30) - 1)
236
237struct dyn_ftrace {
238 union {
239 unsigned long ip;
240 struct dyn_ftrace *freelist;
241 };
242 unsigned long flags;
243 struct dyn_arch_ftrace arch;
244};
245
246int ftrace_force_update(void);
247int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
248 int len, int reset);
249int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
250 int len, int reset);
251void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
252void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
253void ftrace_free_filter(struct ftrace_ops *ops);
254
255int register_ftrace_command(struct ftrace_func_command *cmd);
256int unregister_ftrace_command(struct ftrace_func_command *cmd);
257
258enum {
259 FTRACE_UPDATE_CALLS = (1 << 0),
260 FTRACE_DISABLE_CALLS = (1 << 1),
261 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
262 FTRACE_START_FUNC_RET = (1 << 3),
263 FTRACE_STOP_FUNC_RET = (1 << 4),
264};
265
266enum {
267 FTRACE_UPDATE_IGNORE,
268 FTRACE_UPDATE_MAKE_CALL,
269 FTRACE_UPDATE_MAKE_NOP,
270};
271
272enum {
273 FTRACE_ITER_FILTER = (1 << 0),
274 FTRACE_ITER_NOTRACE = (1 << 1),
275 FTRACE_ITER_PRINTALL = (1 << 2),
276 FTRACE_ITER_DO_HASH = (1 << 3),
277 FTRACE_ITER_HASH = (1 << 4),
278 FTRACE_ITER_ENABLED = (1 << 5),
279};
280
281void arch_ftrace_update_code(int command);
282
283struct ftrace_rec_iter;
284
285struct ftrace_rec_iter *ftrace_rec_iter_start(void);
286struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
287struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
288
289#define for_ftrace_rec_iter(iter) \
290 for (iter = ftrace_rec_iter_start(); \
291 iter; \
292 iter = ftrace_rec_iter_next(iter))
293
294
295int ftrace_update_record(struct dyn_ftrace *rec, int enable);
296int ftrace_test_record(struct dyn_ftrace *rec, int enable);
297void ftrace_run_stop_machine(int command);
298unsigned long ftrace_location(unsigned long ip);
299
300extern ftrace_func_t ftrace_trace_function;
301
302int ftrace_regex_open(struct ftrace_ops *ops, int flag,
303 struct inode *inode, struct file *file);
304ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
305 size_t cnt, loff_t *ppos);
306ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
307 size_t cnt, loff_t *ppos);
308loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
309int ftrace_regex_release(struct inode *inode, struct file *file);
310
311void __init
312ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
313
314
315extern int ftrace_ip_converted(unsigned long ip);
316extern int ftrace_dyn_arch_init(void *data);
317extern void ftrace_replace_code(int enable);
318extern int ftrace_update_ftrace_func(ftrace_func_t func);
319extern void ftrace_caller(void);
320extern void ftrace_call(void);
321extern void mcount_call(void);
322
323void ftrace_modify_all_code(int command);
324
325#ifndef FTRACE_ADDR
326#define FTRACE_ADDR ((unsigned long)ftrace_caller)
327#endif
328#ifdef CONFIG_FUNCTION_GRAPH_TRACER
329extern void ftrace_graph_caller(void);
330extern int ftrace_enable_ftrace_graph_caller(void);
331extern int ftrace_disable_ftrace_graph_caller(void);
332#else
333static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
334static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
335#endif
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358extern int ftrace_make_nop(struct module *mod,
359 struct dyn_ftrace *rec, unsigned long addr);
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
382
383
384extern int ftrace_arch_read_dyn_info(char *buf, int size);
385
386extern int skip_trace(unsigned long ip);
387
388extern void ftrace_disable_daemon(void);
389extern void ftrace_enable_daemon(void);
390#else
391static inline int skip_trace(unsigned long ip) { return 0; }
392static inline int ftrace_force_update(void) { return 0; }
393static inline void ftrace_disable_daemon(void) { }
394static inline void ftrace_enable_daemon(void) { }
395static inline void ftrace_release_mod(struct module *mod) {}
396static inline int register_ftrace_command(struct ftrace_func_command *cmd)
397{
398 return -EINVAL;
399}
400static inline int unregister_ftrace_command(char *cmd_name)
401{
402 return -EINVAL;
403}
404static inline int ftrace_text_reserved(void *start, void *end)
405{
406 return 0;
407}
408
409
410
411
412
413
414#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
415#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
416#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
417#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
418#define ftrace_free_filter(ops) do { } while (0)
419
420static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
421 size_t cnt, loff_t *ppos) { return -ENODEV; }
422static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
423 size_t cnt, loff_t *ppos) { return -ENODEV; }
424static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
425{
426 return -ENODEV;
427}
428static inline int
429ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
430#endif
431
432
433void ftrace_kill(void);
434
435static inline void tracer_disable(void)
436{
437#ifdef CONFIG_FUNCTION_TRACER
438 ftrace_enabled = 0;
439#endif
440}
441
442
443
444
445
446
447static inline int __ftrace_enabled_save(void)
448{
449#ifdef CONFIG_FUNCTION_TRACER
450 int saved_ftrace_enabled = ftrace_enabled;
451 ftrace_enabled = 0;
452 return saved_ftrace_enabled;
453#else
454 return 0;
455#endif
456}
457
458static inline void __ftrace_enabled_restore(int enabled)
459{
460#ifdef CONFIG_FUNCTION_TRACER
461 ftrace_enabled = enabled;
462#endif
463}
464
465#ifndef HAVE_ARCH_CALLER_ADDR
466# ifdef CONFIG_FRAME_POINTER
467# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
468# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
469# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
470# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
471# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
472# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
473# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
474# else
475# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
476# define CALLER_ADDR1 0UL
477# define CALLER_ADDR2 0UL
478# define CALLER_ADDR3 0UL
479# define CALLER_ADDR4 0UL
480# define CALLER_ADDR5 0UL
481# define CALLER_ADDR6 0UL
482# endif
483#endif
484
485#ifdef CONFIG_IRQSOFF_TRACER
486 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
487 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
488#else
489 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
490 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
491#endif
492
493#ifdef CONFIG_PREEMPT_TRACER
494 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
495 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
496#else
497
498
499
500
501# define trace_preempt_on(a0, a1) do { } while (0)
502# define trace_preempt_off(a0, a1) do { } while (0)
503#endif
504
505#ifdef CONFIG_FTRACE_MCOUNT_RECORD
506extern void ftrace_init(void);
507#else
508static inline void ftrace_init(void) { }
509#endif
510
511
512
513
514struct ftrace_graph_ent {
515 unsigned long func;
516 int depth;
517};
518
519
520
521
522struct ftrace_graph_ret {
523 unsigned long func;
524 unsigned long long calltime;
525 unsigned long long rettime;
526
527 unsigned long overrun;
528 int depth;
529};
530
531
532typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *);
533typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *);
534
535#ifdef CONFIG_FUNCTION_GRAPH_TRACER
536
537
538#define INIT_FTRACE_GRAPH .ret_stack = NULL,
539
540
541
542
543
544
545struct ftrace_ret_stack {
546 unsigned long ret;
547 unsigned long func;
548 unsigned long long calltime;
549 unsigned long long subtime;
550 unsigned long fp;
551};
552
553
554
555
556
557
558extern void return_to_handler(void);
559
560extern int
561ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
562 unsigned long frame_pointer);
563
564
565
566
567
568
569#define __notrace_funcgraph notrace
570
571
572
573
574
575#define __irq_entry __attribute__((__section__(".irqentry.text")))
576
577
578extern char __irqentry_text_start[];
579extern char __irqentry_text_end[];
580
581#define FTRACE_RETFUNC_DEPTH 50
582#define FTRACE_RETSTACK_ALLOC_SIZE 32
583extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
584 trace_func_graph_ent_t entryfunc);
585
586extern void ftrace_graph_stop(void);
587
588
589extern trace_func_graph_ret_t ftrace_graph_return;
590extern trace_func_graph_ent_t ftrace_graph_entry;
591
592extern void unregister_ftrace_graph(void);
593
594extern void ftrace_graph_init_task(struct task_struct *t);
595extern void ftrace_graph_exit_task(struct task_struct *t);
596extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
597
598static inline int task_curr_ret_stack(struct task_struct *t)
599{
600 return t->curr_ret_stack;
601}
602
603static inline void pause_graph_tracing(void)
604{
605 atomic_inc(¤t->tracing_graph_pause);
606}
607
608static inline void unpause_graph_tracing(void)
609{
610 atomic_dec(¤t->tracing_graph_pause);
611}
612#else
613
614#define __notrace_funcgraph
615#define __irq_entry
616#define INIT_FTRACE_GRAPH
617
618static inline void ftrace_graph_init_task(struct task_struct *t) { }
619static inline void ftrace_graph_exit_task(struct task_struct *t) { }
620static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
621
622static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
623 trace_func_graph_ent_t entryfunc)
624{
625 return -1;
626}
627static inline void unregister_ftrace_graph(void) { }
628
629static inline int task_curr_ret_stack(struct task_struct *tsk)
630{
631 return -1;
632}
633
634static inline void pause_graph_tracing(void) { }
635static inline void unpause_graph_tracing(void) { }
636#endif
637
638#ifdef CONFIG_TRACING
639
640
641enum {
642 TSK_TRACE_FL_TRACE_BIT = 0,
643 TSK_TRACE_FL_GRAPH_BIT = 1,
644};
645enum {
646 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
647 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
648};
649
650static inline void set_tsk_trace_trace(struct task_struct *tsk)
651{
652 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
653}
654
655static inline void clear_tsk_trace_trace(struct task_struct *tsk)
656{
657 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
658}
659
660static inline int test_tsk_trace_trace(struct task_struct *tsk)
661{
662 return tsk->trace & TSK_TRACE_FL_TRACE;
663}
664
665static inline void set_tsk_trace_graph(struct task_struct *tsk)
666{
667 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
668}
669
670static inline void clear_tsk_trace_graph(struct task_struct *tsk)
671{
672 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
673}
674
675static inline int test_tsk_trace_graph(struct task_struct *tsk)
676{
677 return tsk->trace & TSK_TRACE_FL_GRAPH;
678}
679
680enum ftrace_dump_mode;
681
682extern enum ftrace_dump_mode ftrace_dump_on_oops;
683
684#ifdef CONFIG_PREEMPT
685#define INIT_TRACE_RECURSION .trace_recursion = 0,
686#endif
687
688#endif
689
690#ifndef INIT_TRACE_RECURSION
691#define INIT_TRACE_RECURSION
692#endif
693
694#ifdef CONFIG_FTRACE_SYSCALLS
695
696unsigned long arch_syscall_addr(int nr);
697
698#endif
699
700#endif
701