ftrace: add necessary locking for ftrace records
[deliverable/linux.git] / include / linux / ftrace.h
CommitLineData
16444a8a
ACM
1#ifndef _LINUX_FTRACE_H
2#define _LINUX_FTRACE_H
3
4#ifdef CONFIG_FTRACE
5
6#include <linux/linkage.h>
d49dbf33 7#include <linux/fs.h>
16444a8a 8
b0fc494f
SR
9extern int ftrace_enabled;
10extern int
11ftrace_enable_sysctl(struct ctl_table *table, int write,
12 struct file *filp, void __user *buffer, size_t *lenp,
13 loff_t *ppos);
14
16444a8a
ACM
15typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
16
17struct ftrace_ops {
18 ftrace_func_t func;
19 struct ftrace_ops *next;
20};
21
22/*
23 * The ftrace_ops must be a static and should also
24 * be read_mostly. These functions do modify read_mostly variables
25 * so use them sparely. Never free an ftrace_op or modify the
26 * next pointer after it has been registered. Even after unregistering
27 * it, the next pointer may still be used internally.
28 */
29int register_ftrace_function(struct ftrace_ops *ops);
30int unregister_ftrace_function(struct ftrace_ops *ops);
31void clear_ftrace_function(void);
32
33extern void ftrace_stub(unsigned long a0, unsigned long a1);
16444a8a
ACM
34
35#else /* !CONFIG_FTRACE */
36# define register_ftrace_function(ops) do { } while (0)
37# define unregister_ftrace_function(ops) do { } while (0)
38# define clear_ftrace_function(ops) do { } while (0)
c5131ad6 39static inline void ftrace_kill_atomic(void) { }
16444a8a 40#endif /* CONFIG_FTRACE */
352ad25a 41
3d083395
SR
42#ifdef CONFIG_DYNAMIC_FTRACE
43# define FTRACE_HASHBITS 10
44# define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
45
3c1720f0 46enum {
37ad5084
SR
47 FTRACE_FL_FREE = (1 << 0),
48 FTRACE_FL_FAILED = (1 << 1),
49 FTRACE_FL_FILTER = (1 << 2),
50 FTRACE_FL_ENABLED = (1 << 3),
41c52c0d 51 FTRACE_FL_NOTRACE = (1 << 4),
0eb96701 52 FTRACE_FL_CONVERTED = (1 << 5),
ecea656d 53 FTRACE_FL_FROZEN = (1 << 6),
3c1720f0
SR
54};
55
3d083395
SR
56struct dyn_ftrace {
57 struct hlist_node node;
395a59d0 58 unsigned long ip; /* address of mcount call-site */
3c1720f0 59 unsigned long flags;
3d083395
SR
60};
61
e1c08bdd 62int ftrace_force_update(void);
77a2b37d 63void ftrace_set_filter(unsigned char *buf, int len, int reset);
e1c08bdd 64
3d083395 65/* defined in arch */
3c1720f0
SR
66extern int ftrace_ip_converted(unsigned long ip);
67extern unsigned char *ftrace_nop_replace(void);
68extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
d61f82d0
SR
69extern int ftrace_dyn_arch_init(void *data);
70extern int ftrace_mcount_set(unsigned long *data);
3c1720f0
SR
71extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
72 unsigned char *new_code);
d61f82d0
SR
73extern int ftrace_update_ftrace_func(ftrace_func_t func);
74extern void ftrace_caller(void);
75extern void ftrace_call(void);
76extern void mcount_call(void);
ad90c0e3 77
ecea656d
AS
78extern int skip_trace(unsigned long ip);
79
ad90c0e3
SR
80void ftrace_disable_daemon(void);
81void ftrace_enable_daemon(void);
82
e1c08bdd 83#else
ecea656d 84# define skip_trace(ip) ({ 0; })
aeaee8a2
IM
85# define ftrace_force_update() ({ 0; })
86# define ftrace_set_filter(buf, len, reset) do { } while (0)
ad90c0e3
SR
87# define ftrace_disable_daemon() do { } while (0)
88# define ftrace_enable_daemon() do { } while (0)
ecea656d 89#endif /* CONFIG_DYNAMIC_FTRACE */
352ad25a 90
aeaee8a2
IM
91/* totally disable ftrace - can not re-enable after this */
92void ftrace_kill(void);
a2bb6a3d 93void ftrace_kill_atomic(void);
aeaee8a2 94
f43fdad8
IM
95static inline void tracer_disable(void)
96{
97#ifdef CONFIG_FTRACE
98 ftrace_enabled = 0;
99#endif
100}
101
9bdeb7b5
HY
102/* Ftrace disable/restore without lock. Some synchronization mechanism
103 * must be used to prevent ftrace_enabled to be changed between
104 * disable/restore. */
105static inline int __ftrace_enabled_save(void)
106{
107#ifdef CONFIG_FTRACE
108 int saved_ftrace_enabled = ftrace_enabled;
109 ftrace_enabled = 0;
110 return saved_ftrace_enabled;
111#else
112 return 0;
113#endif
114}
115
116static inline void __ftrace_enabled_restore(int enabled)
117{
118#ifdef CONFIG_FTRACE
119 ftrace_enabled = enabled;
120#endif
121}
122
352ad25a
SR
123#ifdef CONFIG_FRAME_POINTER
124/* TODO: need to fix this for ARM */
125# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
126# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
127# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
128# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
129# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
130# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
86387f7e 131# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
352ad25a
SR
132#else
133# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
134# define CALLER_ADDR1 0UL
135# define CALLER_ADDR2 0UL
136# define CALLER_ADDR3 0UL
137# define CALLER_ADDR4 0UL
138# define CALLER_ADDR5 0UL
86387f7e 139# define CALLER_ADDR6 0UL
352ad25a
SR
140#endif
141
81d68a96 142#ifdef CONFIG_IRQSOFF_TRACER
489f1396
IM
143 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
144 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
81d68a96
SR
145#else
146# define time_hardirqs_on(a0, a1) do { } while (0)
147# define time_hardirqs_off(a0, a1) do { } while (0)
148#endif
149
6cd8a4bb 150#ifdef CONFIG_PREEMPT_TRACER
489f1396
IM
151 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
152 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
6cd8a4bb
SR
153#else
154# define trace_preempt_on(a0, a1) do { } while (0)
155# define trace_preempt_off(a0, a1) do { } while (0)
156#endif
157
b1829d27 158#ifdef CONFIG_TRACING
74f4e369
IM
159extern void
160ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
2f2c99db
SR
161
162/**
163 * ftrace_printk - printf formatting in the ftrace buffer
164 * @fmt: the printf format for printing
165 *
166 * Note: __ftrace_printk is an internal function for ftrace_printk and
167 * the @ip is passed in via the ftrace_printk macro.
168 *
169 * This function allows a kernel developer to debug fast path sections
170 * that printk is not appropriate for. By scattering in various
171 * printk like tracing in the code, a developer can quickly see
172 * where problems are occurring.
173 *
174 * This is intended as a debugging tool for the developer only.
175 * Please refrain from leaving ftrace_printks scattered around in
176 * your code.
177 */
178# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
dd0e545f
SR
179extern int
180__ftrace_printk(unsigned long ip, const char *fmt, ...)
181 __attribute__ ((format (printf, 2, 3)));
3f5a54e3 182extern void ftrace_dump(void);
74f4e369
IM
183#else
184static inline void
185ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
dd0e545f 186static inline int
7b928c23
IM
187ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
188
189static inline int
190ftrace_printk(const char *fmt, ...)
dd0e545f
SR
191{
192 return 0;
193}
3f5a54e3 194static inline void ftrace_dump(void) { }
74f4e369
IM
195#endif
196
68bf21aa
SR
197#ifdef CONFIG_FTRACE_MCOUNT_RECORD
198extern void ftrace_init(void);
90d595fe 199extern void ftrace_init_module(unsigned long *start, unsigned long *end);
fed1939c 200extern void ftrace_release(void *start, unsigned long size);
68bf21aa
SR
201#else
202static inline void ftrace_init(void) { }
90d595fe
SR
203static inline void
204ftrace_init_module(unsigned long *start, unsigned long *end) { }
fed1939c 205static inline void ftrace_release(void *start, unsigned long size) { }
68bf21aa
SR
206#endif
207
dd0e545f 208
16444a8a 209#endif /* _LINUX_FTRACE_H */
This page took 0.093036 seconds and 5 git commands to generate.