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