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