ftrace: nmi update statistics
[deliverable/linux.git] / include / linux / ftrace.h
CommitLineData
16444a8a
ACM
1#ifndef _LINUX_FTRACE_H
2#define _LINUX_FTRACE_H
3
16444a8a 4#include <linux/linkage.h>
d49dbf33 5#include <linux/fs.h>
eb7fa935 6#include <linux/ktime.h>
d13744cd
FW
7#include <linux/init.h>
8#include <linux/types.h>
5601020f 9#include <linux/kallsyms.h>
16444a8a 10
606576ce 11#ifdef CONFIG_FUNCTION_TRACER
3e1932ad 12
b0fc494f
SR
13extern int ftrace_enabled;
14extern int
15ftrace_enable_sysctl(struct ctl_table *table, int write,
16 struct file *filp, void __user *buffer, size_t *lenp,
17 loff_t *ppos);
18
16444a8a
ACM
19typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
20
21struct ftrace_ops {
22 ftrace_func_t func;
23 struct ftrace_ops *next;
24};
25
26/*
27 * The ftrace_ops must be a static and should also
28 * be read_mostly. These functions do modify read_mostly variables
29 * so use them sparely. Never free an ftrace_op or modify the
30 * next pointer after it has been registered. Even after unregistering
31 * it, the next pointer may still be used internally.
32 */
33int register_ftrace_function(struct ftrace_ops *ops);
34int unregister_ftrace_function(struct ftrace_ops *ops);
35void clear_ftrace_function(void);
36
37extern void ftrace_stub(unsigned long a0, unsigned long a1);
16444a8a 38
606576ce 39#else /* !CONFIG_FUNCTION_TRACER */
16444a8a
ACM
40# define register_ftrace_function(ops) do { } while (0)
41# define unregister_ftrace_function(ops) do { } while (0)
42# define clear_ftrace_function(ops) do { } while (0)
81adbdc0 43static inline void ftrace_kill(void) { }
606576ce 44#endif /* CONFIG_FUNCTION_TRACER */
352ad25a 45
3d083395 46#ifdef CONFIG_DYNAMIC_FTRACE
3d083395 47
3c1720f0 48enum {
37ad5084
SR
49 FTRACE_FL_FREE = (1 << 0),
50 FTRACE_FL_FAILED = (1 << 1),
51 FTRACE_FL_FILTER = (1 << 2),
52 FTRACE_FL_ENABLED = (1 << 3),
41c52c0d 53 FTRACE_FL_NOTRACE = (1 << 4),
0eb96701 54 FTRACE_FL_CONVERTED = (1 << 5),
ecea656d 55 FTRACE_FL_FROZEN = (1 << 6),
3c1720f0
SR
56};
57
3d083395 58struct dyn_ftrace {
08f5ac90
SR
59 struct list_head list;
60 unsigned long ip; /* address of mcount call-site */
61 unsigned long flags;
3d083395
SR
62};
63
e1c08bdd 64int ftrace_force_update(void);
77a2b37d 65void ftrace_set_filter(unsigned char *buf, int len, int reset);
e1c08bdd 66
3d083395 67/* defined in arch */
3c1720f0
SR
68extern int ftrace_ip_converted(unsigned long ip);
69extern unsigned char *ftrace_nop_replace(void);
70extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
d61f82d0 71extern int ftrace_dyn_arch_init(void *data);
d61f82d0
SR
72extern int ftrace_update_ftrace_func(ftrace_func_t func);
73extern void ftrace_caller(void);
74extern void ftrace_call(void);
75extern void mcount_call(void);
ad90c0e3 76
593eb8a2
SR
77/**
78 * ftrace_modify_code - modify code segment
79 * @ip: the address of the code segment
80 * @old_code: the contents of what is expected to be there
81 * @new_code: the code to patch in
82 *
83 * This is a very sensitive operation and great care needs
84 * to be taken by the arch. The operation should carefully
85 * read the location, check to see if what is read is indeed
86 * what we expect it to be, and then on success of the compare,
87 * it should write to the location.
88 *
89 * Return must be:
90 * 0 on success
91 * -EFAULT on error reading the location
92 * -EINVAL on a failed compare of the contents
93 * -EPERM on error writing to the location
94 * Any other value will be considered a failure.
95 */
96extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
97 unsigned char *new_code);
98
ecea656d
AS
99extern int skip_trace(unsigned long ip);
100
c0719e5a
SR
101extern void ftrace_release(void *start, unsigned long size);
102
103extern void ftrace_disable_daemon(void);
104extern void ftrace_enable_daemon(void);
ad90c0e3 105
e1c08bdd 106#else
ecea656d 107# define skip_trace(ip) ({ 0; })
aeaee8a2
IM
108# define ftrace_force_update() ({ 0; })
109# define ftrace_set_filter(buf, len, reset) do { } while (0)
ad90c0e3
SR
110# define ftrace_disable_daemon() do { } while (0)
111# define ftrace_enable_daemon() do { } while (0)
c0719e5a 112static inline void ftrace_release(void *start, unsigned long size) { }
ecea656d 113#endif /* CONFIG_DYNAMIC_FTRACE */
352ad25a 114
aeaee8a2
IM
115/* totally disable ftrace - can not re-enable after this */
116void ftrace_kill(void);
117
f43fdad8
IM
118static inline void tracer_disable(void)
119{
606576ce 120#ifdef CONFIG_FUNCTION_TRACER
f43fdad8
IM
121 ftrace_enabled = 0;
122#endif
123}
124
37002735
HY
125/*
126 * Ftrace disable/restore without lock. Some synchronization mechanism
9bdeb7b5 127 * must be used to prevent ftrace_enabled to be changed between
37002735
HY
128 * disable/restore.
129 */
9bdeb7b5
HY
130static inline int __ftrace_enabled_save(void)
131{
606576ce 132#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
133 int saved_ftrace_enabled = ftrace_enabled;
134 ftrace_enabled = 0;
135 return saved_ftrace_enabled;
136#else
137 return 0;
138#endif
139}
140
141static inline void __ftrace_enabled_restore(int enabled)
142{
606576ce 143#ifdef CONFIG_FUNCTION_TRACER
9bdeb7b5
HY
144 ftrace_enabled = enabled;
145#endif
146}
147
352ad25a
SR
148#ifdef CONFIG_FRAME_POINTER
149/* TODO: need to fix this for ARM */
150# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
151# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
152# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
153# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
154# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
155# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
86387f7e 156# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
352ad25a
SR
157#else
158# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
159# define CALLER_ADDR1 0UL
160# define CALLER_ADDR2 0UL
161# define CALLER_ADDR3 0UL
162# define CALLER_ADDR4 0UL
163# define CALLER_ADDR5 0UL
86387f7e 164# define CALLER_ADDR6 0UL
352ad25a
SR
165#endif
166
81d68a96 167#ifdef CONFIG_IRQSOFF_TRACER
489f1396
IM
168 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
169 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
81d68a96
SR
170#else
171# define time_hardirqs_on(a0, a1) do { } while (0)
172# define time_hardirqs_off(a0, a1) do { } while (0)
173#endif
174
6cd8a4bb 175#ifdef CONFIG_PREEMPT_TRACER
489f1396
IM
176 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
177 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb
SR
178#else
179# define trace_preempt_on(a0, a1) do { } while (0)
180# define trace_preempt_off(a0, a1) do { } while (0)
181#endif
182
b1829d27 183#ifdef CONFIG_TRACING
74f4e369
IM
184extern void
185ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
2f2c99db
SR
186
187/**
188 * ftrace_printk - printf formatting in the ftrace buffer
189 * @fmt: the printf format for printing
190 *
191 * Note: __ftrace_printk is an internal function for ftrace_printk and
192 * the @ip is passed in via the ftrace_printk macro.
193 *
194 * This function allows a kernel developer to debug fast path sections
195 * that printk is not appropriate for. By scattering in various
196 * printk like tracing in the code, a developer can quickly see
197 * where problems are occurring.
198 *
199 * This is intended as a debugging tool for the developer only.
200 * Please refrain from leaving ftrace_printks scattered around in
201 * your code.
202 */
203# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
dd0e545f
SR
204extern int
205__ftrace_printk(unsigned long ip, const char *fmt, ...)
206 __attribute__ ((format (printf, 2, 3)));
3f5a54e3 207extern void ftrace_dump(void);
74f4e369
IM
208#else
209static inline void
210ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
dd0e545f 211static inline int
7b928c23
IM
212ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
213
214static inline int
215ftrace_printk(const char *fmt, ...)
dd0e545f
SR
216{
217 return 0;
218}
3f5a54e3 219static inline void ftrace_dump(void) { }
74f4e369
IM
220#endif
221
68bf21aa
SR
222#ifdef CONFIG_FTRACE_MCOUNT_RECORD
223extern void ftrace_init(void);
90d595fe 224extern void ftrace_init_module(unsigned long *start, unsigned long *end);
68bf21aa
SR
225#else
226static inline void ftrace_init(void) { }
90d595fe
SR
227static inline void
228ftrace_init_module(unsigned long *start, unsigned long *end) { }
68bf21aa
SR
229#endif
230
dd0e545f 231
d13744cd
FW
232struct boot_trace {
233 pid_t caller;
ca538f6b 234 char func[KSYM_NAME_LEN];
d13744cd 235 int result;
ca538f6b 236 unsigned long long duration; /* usecs */
cb5ab742
FW
237 ktime_t calltime;
238 ktime_t rettime;
d13744cd
FW
239};
240
241#ifdef CONFIG_BOOT_TRACER
5601020f 242extern void trace_boot(struct boot_trace *it, initcall_t fn);
d13744cd 243extern void start_boot_trace(void);
097d036a 244extern void stop_boot_trace(void);
d13744cd 245#else
5601020f 246static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
d13744cd 247static inline void start_boot_trace(void) { }
097d036a 248static inline void stop_boot_trace(void) { }
d13744cd
FW
249#endif
250
251
252
16444a8a 253#endif /* _LINUX_FTRACE_H */
This page took 0.090682 seconds and 5 git commands to generate.