]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/ftrace.h
ftrace/x86_32: Push ftrace_ops in as 3rd parameter to function tracer
[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>
a1e2e31d 13#include <linux/ptrace.h>
0012693a 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
2f5f6ad9
SR
22/*
23 * If the arch supports passing the variable contents of
24 * function_trace_op as the third parameter back from the
25 * mcount call, then the arch should define this as 1.
26 */
27#ifndef ARCH_SUPPORTS_FTRACE_OPS
28#define ARCH_SUPPORTS_FTRACE_OPS 0
29#endif
30
ccf3672d
SR
31/*
32 * If the arch's mcount caller does not support all of ftrace's
33 * features, then it must call an indirect function that
34 * does. Or at least does enough to prevent any unwelcomed side effects.
35 */
36#if !defined(CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST) || \
37 !ARCH_SUPPORTS_FTRACE_OPS
38# define FTRACE_FORCE_LIST_FUNC 1
39#else
40# define FTRACE_FORCE_LIST_FUNC 0
41#endif
42
43
de477254 44struct module;
04da85b8
SR
45struct ftrace_hash;
46
606576ce 47#ifdef CONFIG_FUNCTION_TRACER
3e1932ad 48
b0fc494f
SR
49extern int ftrace_enabled;
50extern int
51ftrace_enable_sysctl(struct ctl_table *table, int write,
8d65af78 52 void __user *buffer, size_t *lenp,
b0fc494f
SR
53 loff_t *ppos);
54
2f5f6ad9
SR
55struct ftrace_ops;
56
57typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
a1e2e31d 58 struct ftrace_ops *op, struct pt_regs *regs);
16444a8a 59
e248491a
JO
60/*
61 * FTRACE_OPS_FL_* bits denote the state of ftrace_ops struct and are
62 * set in the flags member.
63 *
64 * ENABLED - set/unset when ftrace_ops is registered/unregistered
65 * GLOBAL - set manualy by ftrace_ops user to denote the ftrace_ops
66 * is part of the global tracers sharing the same filter
67 * via set_ftrace_* debugfs files.
68 * DYNAMIC - set when ftrace_ops is registered to denote dynamically
69 * allocated ftrace_ops which need special care
70 * CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
71 * could be controled by following calls:
72 * ftrace_function_local_enable
73 * ftrace_function_local_disable
74 */
b848914c
SR
75enum {
76 FTRACE_OPS_FL_ENABLED = 1 << 0,
77 FTRACE_OPS_FL_GLOBAL = 1 << 1,
cdbe61bf 78 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
e248491a 79 FTRACE_OPS_FL_CONTROL = 1 << 3,
b848914c
SR
80};
81
16444a8a 82struct ftrace_ops {
f45948e8
SR
83 ftrace_func_t func;
84 struct ftrace_ops *next;
b848914c 85 unsigned long flags;
e248491a 86 int __percpu *disabled;
f45948e8
SR
87#ifdef CONFIG_DYNAMIC_FTRACE
88 struct ftrace_hash *notrace_hash;
89 struct ftrace_hash *filter_hash;
90#endif
16444a8a
ACM
91};
92
60a7ecf4
SR
93extern int function_trace_stop;
94
e7d3737e
FW
95/*
96 * Type of the current tracing.
97 */
98enum ftrace_tracing_type_t {
99 FTRACE_TYPE_ENTER = 0, /* Hook the call of the function */
100 FTRACE_TYPE_RETURN, /* Hook the return of the function */
101};
102
103/* Current tracing type, default is FTRACE_TYPE_ENTER */
104extern enum ftrace_tracing_type_t ftrace_tracing_type;
105
60a7ecf4
SR
106/**
107 * ftrace_stop - stop function tracer.
108 *
109 * A quick way to stop the function tracer. Note this an on off switch,
110 * it is not something that is recursive like preempt_disable.
111 * This does not disable the calling of mcount, it only stops the
112 * calling of functions from mcount.
113 */
114static inline void ftrace_stop(void)
115{
116 function_trace_stop = 1;
117}
118
119/**
120 * ftrace_start - start the function tracer.
121 *
122 * This function is the inverse of ftrace_stop. This does not enable
123 * the function tracing if the function tracer is disabled. This only
124 * sets the function tracer flag to continue calling the functions
125 * from mcount.
126 */
127static inline void ftrace_start(void)
128{
129 function_trace_stop = 0;
130}
131
16444a8a
ACM
132/*
133 * The ftrace_ops must be a static and should also
134 * be read_mostly. These functions do modify read_mostly variables
135 * so use them sparely. Never free an ftrace_op or modify the
136 * next pointer after it has been registered. Even after unregistering
137 * it, the next pointer may still be used internally.
138 */
139int register_ftrace_function(struct ftrace_ops *ops);
140int unregister_ftrace_function(struct ftrace_ops *ops);
141void clear_ftrace_function(void);
142
e248491a
JO
143/**
144 * ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
145 *
146 * This function enables tracing on current cpu by decreasing
147 * the per cpu control variable.
148 * It must be called with preemption disabled and only on ftrace_ops
149 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
150 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
151 */
152static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
153{
154 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
155 return;
156
157 (*this_cpu_ptr(ops->disabled))--;
158}
159
160/**
161 * ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
162 *
163 * This function enables tracing on current cpu by decreasing
164 * the per cpu control variable.
165 * It must be called with preemption disabled and only on ftrace_ops
166 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
167 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
168 */
169static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
170{
171 if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
172 return;
173
174 (*this_cpu_ptr(ops->disabled))++;
175}
176
177/**
178 * ftrace_function_local_disabled - returns ftrace_ops disabled value
179 * on current cpu
180 *
181 * This function returns value of ftrace_ops::disabled on current cpu.
182 * It must be called with preemption disabled and only on ftrace_ops
183 * registered with FTRACE_OPS_FL_CONTROL. If called without preemption
184 * disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
185 */
186static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
187{
188 WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
189 return *this_cpu_ptr(ops->disabled);
190}
191
a1e2e31d
SR
192extern void ftrace_stub(unsigned long a0, unsigned long a1,
193 struct ftrace_ops *op, struct pt_regs *regs);
16444a8a 194
606576ce 195#else /* !CONFIG_FUNCTION_TRACER */
4dbf6bc2
SR
196/*
197 * (un)register_ftrace_function must be a macro since the ops parameter
198 * must not be evaluated.
199 */
200#define register_ftrace_function(ops) ({ 0; })
201#define unregister_ftrace_function(ops) ({ 0; })
202static inline void clear_ftrace_function(void) { }
81adbdc0 203static inline void ftrace_kill(void) { }
60a7ecf4
SR
204static inline void ftrace_stop(void) { }
205static inline void ftrace_start(void) { }
606576ce 206#endif /* CONFIG_FUNCTION_TRACER */
352ad25a 207
f38f1d2a
SR
208#ifdef CONFIG_STACK_TRACER
209extern int stack_tracer_enabled;
210int
211stack_trace_sysctl(struct ctl_table *table, int write,
8d65af78 212 void __user *buffer, size_t *lenp,
f38f1d2a
SR
213 loff_t *ppos);
214#endif
215
f6180773
SR
216struct ftrace_func_command {
217 struct list_head list;
218 char *name;
43dd61c9
SR
219 int (*func)(struct ftrace_hash *hash,
220 char *func, char *cmd,
f6180773
SR
221 char *params, int enable);
222};
223
3d083395 224#ifdef CONFIG_DYNAMIC_FTRACE
31e88909 225
000ab691
SR
226int ftrace_arch_code_modify_prepare(void);
227int ftrace_arch_code_modify_post_process(void);
228
c88fd863
SR
229void ftrace_bug(int err, unsigned long ip);
230
809dcf29
SR
231struct seq_file;
232
b6887d79 233struct ftrace_probe_ops {
59df055f
SR
234 void (*func)(unsigned long ip,
235 unsigned long parent_ip,
236 void **data);
237 int (*callback)(unsigned long ip, void **data);
238 void (*free)(void **data);
809dcf29
SR
239 int (*print)(struct seq_file *m,
240 unsigned long ip,
b6887d79 241 struct ftrace_probe_ops *ops,
809dcf29 242 void *data);
59df055f
SR
243};
244
245extern int
b6887d79 246register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
59df055f
SR
247 void *data);
248extern void
b6887d79 249unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
59df055f
SR
250 void *data);
251extern void
b6887d79
SR
252unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
253extern void unregister_ftrace_function_probe_all(char *glob);
59df055f 254
2cfa1978
MH
255extern int ftrace_text_reserved(void *start, void *end);
256
3c1720f0 257enum {
ed926f9b 258 FTRACE_FL_ENABLED = (1 << 30),
3c1720f0
SR
259};
260
ed926f9b
SR
261#define FTRACE_FL_MASK (0x3UL << 30)
262#define FTRACE_REF_MAX ((1 << 30) - 1)
263
3d083395 264struct dyn_ftrace {
ee000b7f
LJ
265 union {
266 unsigned long ip; /* address of mcount call-site */
267 struct dyn_ftrace *freelist;
268 };
85ae32ae 269 unsigned long flags;
ee000b7f 270 struct dyn_arch_ftrace arch;
3d083395
SR
271};
272
e1c08bdd 273int ftrace_force_update(void);
ac483c44 274int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
936e074b 275 int len, int reset);
ac483c44 276int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
936e074b
SR
277 int len, int reset);
278void ftrace_set_global_filter(unsigned char *buf, int len, int reset);
279void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
5500fa51 280void ftrace_free_filter(struct ftrace_ops *ops);
e1c08bdd 281
f6180773
SR
282int register_ftrace_command(struct ftrace_func_command *cmd);
283int unregister_ftrace_command(struct ftrace_func_command *cmd);
284
c88fd863
SR
285enum {
286 FTRACE_UPDATE_CALLS = (1 << 0),
287 FTRACE_DISABLE_CALLS = (1 << 1),
288 FTRACE_UPDATE_TRACE_FUNC = (1 << 2),
289 FTRACE_START_FUNC_RET = (1 << 3),
290 FTRACE_STOP_FUNC_RET = (1 << 4),
291};
292
293enum {
294 FTRACE_UPDATE_IGNORE,
295 FTRACE_UPDATE_MAKE_CALL,
296 FTRACE_UPDATE_MAKE_NOP,
297};
298
fc13cb0c
SR
299enum {
300 FTRACE_ITER_FILTER = (1 << 0),
301 FTRACE_ITER_NOTRACE = (1 << 1),
302 FTRACE_ITER_PRINTALL = (1 << 2),
69a3083c
SR
303 FTRACE_ITER_DO_HASH = (1 << 3),
304 FTRACE_ITER_HASH = (1 << 4),
305 FTRACE_ITER_ENABLED = (1 << 5),
fc13cb0c
SR
306};
307
c88fd863
SR
308void arch_ftrace_update_code(int command);
309
310struct ftrace_rec_iter;
311
312struct ftrace_rec_iter *ftrace_rec_iter_start(void);
313struct ftrace_rec_iter *ftrace_rec_iter_next(struct ftrace_rec_iter *iter);
314struct dyn_ftrace *ftrace_rec_iter_record(struct ftrace_rec_iter *iter);
315
08d636b6
SR
316#define for_ftrace_rec_iter(iter) \
317 for (iter = ftrace_rec_iter_start(); \
318 iter; \
319 iter = ftrace_rec_iter_next(iter))
320
321
c88fd863
SR
322int ftrace_update_record(struct dyn_ftrace *rec, int enable);
323int ftrace_test_record(struct dyn_ftrace *rec, int enable);
324void ftrace_run_stop_machine(int command);
f0cf973a 325unsigned long ftrace_location(unsigned long ip);
c88fd863
SR
326
327extern ftrace_func_t ftrace_trace_function;
328
fc13cb0c
SR
329int ftrace_regex_open(struct ftrace_ops *ops, int flag,
330 struct inode *inode, struct file *file);
331ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
332 size_t cnt, loff_t *ppos);
333ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
334 size_t cnt, loff_t *ppos);
335loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin);
336int ftrace_regex_release(struct inode *inode, struct file *file);
337
2a85a37f
SR
338void __init
339ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
340
3d083395 341/* defined in arch */
3c1720f0 342extern int ftrace_ip_converted(unsigned long ip);
d61f82d0 343extern int ftrace_dyn_arch_init(void *data);
e4f5d544 344extern void ftrace_replace_code(int enable);
d61f82d0
SR
345extern int ftrace_update_ftrace_func(ftrace_func_t func);
346extern void ftrace_caller(void);
347extern void ftrace_call(void);
348extern void mcount_call(void);
f0001207 349
8ed3e2cf
SR
350void ftrace_modify_all_code(int command);
351
f0001207
SL
352#ifndef FTRACE_ADDR
353#define FTRACE_ADDR ((unsigned long)ftrace_caller)
354#endif
fb52607a
FW
355#ifdef CONFIG_FUNCTION_GRAPH_TRACER
356extern void ftrace_graph_caller(void);
5a45cfe1
SR
357extern int ftrace_enable_ftrace_graph_caller(void);
358extern int ftrace_disable_ftrace_graph_caller(void);
359#else
360static inline int ftrace_enable_ftrace_graph_caller(void) { return 0; }
361static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; }
e7d3737e 362#endif
ad90c0e3 363
31e88909 364/**
57794a9d 365 * ftrace_make_nop - convert code into nop
31e88909
SR
366 * @mod: module structure if called by module load initialization
367 * @rec: the mcount call site record
368 * @addr: the address that the call site should be calling
369 *
370 * This is a very sensitive operation and great care needs
371 * to be taken by the arch. The operation should carefully
372 * read the location, check to see if what is read is indeed
373 * what we expect it to be, and then on success of the compare,
374 * it should write to the location.
375 *
376 * The code segment at @rec->ip should be a caller to @addr
377 *
378 * Return must be:
379 * 0 on success
380 * -EFAULT on error reading the location
381 * -EINVAL on a failed compare of the contents
382 * -EPERM on error writing to the location
383 * Any other value will be considered a failure.
384 */
385extern int ftrace_make_nop(struct module *mod,
386 struct dyn_ftrace *rec, unsigned long addr);
a26a2a27 387
593eb8a2 388/**
31e88909
SR
389 * ftrace_make_call - convert a nop call site into a call to addr
390 * @rec: the mcount call site record
391 * @addr: the address that the call site should call
593eb8a2
SR
392 *
393 * This is a very sensitive operation and great care needs
394 * to be taken by the arch. The operation should carefully
395 * read the location, check to see if what is read is indeed
396 * what we expect it to be, and then on success of the compare,
397 * it should write to the location.
398 *
31e88909
SR
399 * The code segment at @rec->ip should be a nop
400 *
593eb8a2
SR
401 * Return must be:
402 * 0 on success
403 * -EFAULT on error reading the location
404 * -EINVAL on a failed compare of the contents
405 * -EPERM on error writing to the location
406 * Any other value will be considered a failure.
407 */
31e88909
SR
408extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
409
31e88909
SR
410/* May be defined in arch */
411extern int ftrace_arch_read_dyn_info(char *buf, int size);
593eb8a2 412
ecea656d
AS
413extern int skip_trace(unsigned long ip);
414
c0719e5a
SR
415extern void ftrace_disable_daemon(void);
416extern void ftrace_enable_daemon(void);
e1c08bdd 417#else
4dbf6bc2
SR
418static inline int skip_trace(unsigned long ip) { return 0; }
419static inline int ftrace_force_update(void) { return 0; }
4dbf6bc2
SR
420static inline void ftrace_disable_daemon(void) { }
421static inline void ftrace_enable_daemon(void) { }
e7247a15 422static inline void ftrace_release_mod(struct module *mod) {}
f6180773
SR
423static inline int register_ftrace_command(struct ftrace_func_command *cmd)
424{
97d0bb8d 425 return -EINVAL;
f6180773
SR
426}
427static inline int unregister_ftrace_command(char *cmd_name)
428{
97d0bb8d 429 return -EINVAL;
f6180773 430}
2cfa1978
MH
431static inline int ftrace_text_reserved(void *start, void *end)
432{
433 return 0;
434}
fc13cb0c
SR
435
436/*
437 * Again users of functions that have ftrace_ops may not
438 * have them defined when ftrace is not enabled, but these
439 * functions may still be called. Use a macro instead of inline.
440 */
441#define ftrace_regex_open(ops, flag, inod, file) ({ -ENODEV; })
96de37b6 442#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
5500fa51
JO
443#define ftrace_set_filter(ops, buf, len, reset) ({ -ENODEV; })
444#define ftrace_set_notrace(ops, buf, len, reset) ({ -ENODEV; })
445#define ftrace_free_filter(ops) do { } while (0)
fc13cb0c
SR
446
447static inline ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
448 size_t cnt, loff_t *ppos) { return -ENODEV; }
449static inline ssize_t ftrace_notrace_write(struct file *file, const char __user *ubuf,
450 size_t cnt, loff_t *ppos) { return -ENODEV; }
451static inline loff_t ftrace_regex_lseek(struct file *file, loff_t offset, int origin)
452{
453 return -ENODEV;
454}
455static inline int
456ftrace_regex_release(struct inode *inode, struct file *file) { return -ENODEV; }
ecea656d 457#endif /* CONFIG_DYNAMIC_FTRACE */
352ad25a 458
aeaee8a2
IM
459/* totally disable ftrace - can not re-enable after this */
460void ftrace_kill(void);
461
f43fdad8
IM
462static inline void tracer_disable(void)
463{
606576ce 464#ifdef CONFIG_FUNCTION_TRACER
f43fdad8
IM
465 ftrace_enabled = 0;
466#endif
467}
468
37002735
HY
469/*
470 * Ftrace disable/restore without lock. Some synchronization mechanism
9bdeb7b5 471 * must be used to prevent ftrace_enabled to be changed between
37002735
HY
472 * disable/restore.
473 */
9bdeb7b5
HY
474static inline int __ftrace_enabled_save(void)
475{
606576ce 476#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
477 int saved_ftrace_enabled = ftrace_enabled;
478 ftrace_enabled = 0;
479 return saved_ftrace_enabled;
480#else
481 return 0;
482#endif
483}
484
485static inline void __ftrace_enabled_restore(int enabled)
486{
606576ce 487#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
488 ftrace_enabled = enabled;
489#endif
490}
491
c79a61f5
UKK
492#ifndef HAVE_ARCH_CALLER_ADDR
493# ifdef CONFIG_FRAME_POINTER
494# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
495# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
496# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
497# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
498# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
499# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
500# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
501# else
502# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
503# define CALLER_ADDR1 0UL
504# define CALLER_ADDR2 0UL
505# define CALLER_ADDR3 0UL
506# define CALLER_ADDR4 0UL
507# define CALLER_ADDR5 0UL
508# define CALLER_ADDR6 0UL
509# endif
510#endif /* ifndef HAVE_ARCH_CALLER_ADDR */
352ad25a 511
81d68a96 512#ifdef CONFIG_IRQSOFF_TRACER
489f1396
IM
513 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
514 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
81d68a96 515#else
4dbf6bc2
SR
516 static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
517 static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
81d68a96
SR
518#endif
519
6cd8a4bb 520#ifdef CONFIG_PREEMPT_TRACER
489f1396
IM
521 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
522 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb 523#else
b02ee9a3
MB
524/*
525 * Use defines instead of static inlines because some arches will make code out
526 * of the CALLER_ADDR, when we really want these to be a real nop.
527 */
528# define trace_preempt_on(a0, a1) do { } while (0)
529# define trace_preempt_off(a0, a1) do { } while (0)
6cd8a4bb
SR
530#endif
531
68bf21aa
SR
532#ifdef CONFIG_FTRACE_MCOUNT_RECORD
533extern void ftrace_init(void);
534#else
535static inline void ftrace_init(void) { }
536#endif
537
287b6e68
FW
538/*
539 * Structure that defines an entry function trace.
540 */
541struct ftrace_graph_ent {
542 unsigned long func; /* Current function */
543 int depth;
544};
dd0e545f 545
caf4b323
FW
546/*
547 * Structure that defines a return function trace.
548 */
fb52607a 549struct ftrace_graph_ret {
caf4b323
FW
550 unsigned long func; /* Current function */
551 unsigned long long calltime;
552 unsigned long long rettime;
0231022c
FW
553 /* Number of functions that overran the depth limit for current task */
554 unsigned long overrun;
287b6e68 555 int depth;
caf4b323
FW
556};
557
62b915f1
JO
558/* Type of the callback handlers for tracing function graph*/
559typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
560typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
561
fb52607a 562#ifdef CONFIG_FUNCTION_GRAPH_TRACER
8b96f011 563
5ac9f622 564/* for init task */
f876d346 565#define INIT_FTRACE_GRAPH .ret_stack = NULL,
5ac9f622 566
712406a6
SR
567/*
568 * Stack of return addresses for functions
569 * of a thread.
570 * Used in struct thread_info
571 */
572struct ftrace_ret_stack {
573 unsigned long ret;
574 unsigned long func;
575 unsigned long long calltime;
a2a16d6a 576 unsigned long long subtime;
71e308a2 577 unsigned long fp;
712406a6
SR
578};
579
580/*
581 * Primary handler of a function return.
582 * It relays on ftrace_return_to_handler.
583 * Defined in entry_32/64.S
584 */
585extern void return_to_handler(void);
586
587extern int
71e308a2
SR
588ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
589 unsigned long frame_pointer);
712406a6 590
8b96f011
FW
591/*
592 * Sometimes we don't want to trace a function with the function
593 * graph tracer but we want them to keep traced by the usual function
594 * tracer if the function graph tracer is not configured.
595 */
596#define __notrace_funcgraph notrace
597
bcbc4f20
FW
598/*
599 * We want to which function is an entrypoint of a hardirq.
600 * That will help us to put a signal on output.
601 */
602#define __irq_entry __attribute__((__section__(".irqentry.text")))
603
604/* Limits of hardirq entrypoints */
605extern char __irqentry_text_start[];
606extern char __irqentry_text_end[];
607
f201ae23
FW
608#define FTRACE_RETFUNC_DEPTH 50
609#define FTRACE_RETSTACK_ALLOC_SIZE 32
287b6e68
FW
610extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
611 trace_func_graph_ent_t entryfunc);
612
14a866c5
SR
613extern void ftrace_graph_stop(void);
614
287b6e68
FW
615/* The current handlers in use */
616extern trace_func_graph_ret_t ftrace_graph_return;
617extern trace_func_graph_ent_t ftrace_graph_entry;
caf4b323 618
fb52607a 619extern void unregister_ftrace_graph(void);
f201ae23 620
fb52607a
FW
621extern void ftrace_graph_init_task(struct task_struct *t);
622extern void ftrace_graph_exit_task(struct task_struct *t);
868baf07 623extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
21a8c466
FW
624
625static inline int task_curr_ret_stack(struct task_struct *t)
626{
627 return t->curr_ret_stack;
628}
380c4b14
FW
629
630static inline void pause_graph_tracing(void)
631{
632 atomic_inc(&current->tracing_graph_pause);
633}
634
635static inline void unpause_graph_tracing(void)
636{
637 atomic_dec(&current->tracing_graph_pause);
638}
5ac9f622 639#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
8b96f011
FW
640
641#define __notrace_funcgraph
bcbc4f20 642#define __irq_entry
5ac9f622 643#define INIT_FTRACE_GRAPH
8b96f011 644
fb52607a
FW
645static inline void ftrace_graph_init_task(struct task_struct *t) { }
646static inline void ftrace_graph_exit_task(struct task_struct *t) { }
868baf07 647static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
21a8c466 648
62b915f1
JO
649static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
650 trace_func_graph_ent_t entryfunc)
651{
652 return -1;
653}
654static inline void unregister_ftrace_graph(void) { }
655
21a8c466
FW
656static inline int task_curr_ret_stack(struct task_struct *tsk)
657{
658 return -1;
659}
380c4b14
FW
660
661static inline void pause_graph_tracing(void) { }
662static inline void unpause_graph_tracing(void) { }
5ac9f622 663#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
caf4b323 664
ea4e2bc4 665#ifdef CONFIG_TRACING
ea4e2bc4
SR
666
667/* flags for current->trace */
668enum {
669 TSK_TRACE_FL_TRACE_BIT = 0,
670 TSK_TRACE_FL_GRAPH_BIT = 1,
671};
672enum {
673 TSK_TRACE_FL_TRACE = 1 << TSK_TRACE_FL_TRACE_BIT,
674 TSK_TRACE_FL_GRAPH = 1 << TSK_TRACE_FL_GRAPH_BIT,
675};
676
677static inline void set_tsk_trace_trace(struct task_struct *tsk)
678{
679 set_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
680}
681
682static inline void clear_tsk_trace_trace(struct task_struct *tsk)
683{
684 clear_bit(TSK_TRACE_FL_TRACE_BIT, &tsk->trace);
685}
686
687static inline int test_tsk_trace_trace(struct task_struct *tsk)
688{
689 return tsk->trace & TSK_TRACE_FL_TRACE;
690}
691
692static inline void set_tsk_trace_graph(struct task_struct *tsk)
693{
694 set_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
695}
696
697static inline void clear_tsk_trace_graph(struct task_struct *tsk)
698{
699 clear_bit(TSK_TRACE_FL_GRAPH_BIT, &tsk->trace);
700}
701
702static inline int test_tsk_trace_graph(struct task_struct *tsk)
703{
704 return tsk->trace & TSK_TRACE_FL_GRAPH;
705}
706
cecbca96
FW
707enum ftrace_dump_mode;
708
709extern enum ftrace_dump_mode ftrace_dump_on_oops;
526211bc 710
261842b7
SR
711#ifdef CONFIG_PREEMPT
712#define INIT_TRACE_RECURSION .trace_recursion = 0,
713#endif
714
ea4e2bc4
SR
715#endif /* CONFIG_TRACING */
716
261842b7
SR
717#ifndef INIT_TRACE_RECURSION
718#define INIT_TRACE_RECURSION
719#endif
b1818748 720
e7b8e675
MF
721#ifdef CONFIG_FTRACE_SYSCALLS
722
723unsigned long arch_syscall_addr(int nr);
724
725#endif /* CONFIG_FTRACE_SYSCALLS */
726
16444a8a 727#endif /* _LINUX_FTRACE_H */