diff options
Diffstat (limited to 'include/linux/ftrace.h')
-rw-r--r-- | include/linux/ftrace.h | 253 |
1 files changed, 146 insertions, 107 deletions
diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 677432b9cb7e..db3fed630db3 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h | |||
@@ -1,15 +1,18 @@ | |||
1 | #ifndef _LINUX_FTRACE_H | 1 | #ifndef _LINUX_FTRACE_H |
2 | #define _LINUX_FTRACE_H | 2 | #define _LINUX_FTRACE_H |
3 | 3 | ||
4 | #include <linux/linkage.h> | 4 | #include <linux/trace_clock.h> |
5 | #include <linux/fs.h> | ||
6 | #include <linux/ktime.h> | ||
7 | #include <linux/init.h> | ||
8 | #include <linux/types.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <linux/kallsyms.h> | 5 | #include <linux/kallsyms.h> |
6 | #include <linux/linkage.h> | ||
11 | #include <linux/bitops.h> | 7 | #include <linux/bitops.h> |
8 | #include <linux/module.h> | ||
9 | #include <linux/ktime.h> | ||
12 | #include <linux/sched.h> | 10 | #include <linux/sched.h> |
11 | #include <linux/types.h> | ||
12 | #include <linux/init.h> | ||
13 | #include <linux/fs.h> | ||
14 | |||
15 | #include <asm/ftrace.h> | ||
13 | 16 | ||
14 | #ifdef CONFIG_FUNCTION_TRACER | 17 | #ifdef CONFIG_FUNCTION_TRACER |
15 | 18 | ||
@@ -95,9 +98,41 @@ stack_trace_sysctl(struct ctl_table *table, int write, | |||
95 | loff_t *ppos); | 98 | loff_t *ppos); |
96 | #endif | 99 | #endif |
97 | 100 | ||
101 | struct ftrace_func_command { | ||
102 | struct list_head list; | ||
103 | char *name; | ||
104 | int (*func)(char *func, char *cmd, | ||
105 | char *params, int enable); | ||
106 | }; | ||
107 | |||
98 | #ifdef CONFIG_DYNAMIC_FTRACE | 108 | #ifdef CONFIG_DYNAMIC_FTRACE |
99 | /* asm/ftrace.h must be defined for archs supporting dynamic ftrace */ | 109 | |
100 | #include <asm/ftrace.h> | 110 | int ftrace_arch_code_modify_prepare(void); |
111 | int ftrace_arch_code_modify_post_process(void); | ||
112 | |||
113 | struct seq_file; | ||
114 | |||
115 | struct ftrace_probe_ops { | ||
116 | void (*func)(unsigned long ip, | ||
117 | unsigned long parent_ip, | ||
118 | void **data); | ||
119 | int (*callback)(unsigned long ip, void **data); | ||
120 | void (*free)(void **data); | ||
121 | int (*print)(struct seq_file *m, | ||
122 | unsigned long ip, | ||
123 | struct ftrace_probe_ops *ops, | ||
124 | void *data); | ||
125 | }; | ||
126 | |||
127 | extern int | ||
128 | register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | ||
129 | void *data); | ||
130 | extern void | ||
131 | unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, | ||
132 | void *data); | ||
133 | extern void | ||
134 | unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops); | ||
135 | extern void unregister_ftrace_function_probe_all(char *glob); | ||
101 | 136 | ||
102 | enum { | 137 | enum { |
103 | FTRACE_FL_FREE = (1 << 0), | 138 | FTRACE_FL_FREE = (1 << 0), |
@@ -110,7 +145,6 @@ enum { | |||
110 | }; | 145 | }; |
111 | 146 | ||
112 | struct dyn_ftrace { | 147 | struct dyn_ftrace { |
113 | struct list_head list; | ||
114 | unsigned long ip; /* address of mcount call-site */ | 148 | unsigned long ip; /* address of mcount call-site */ |
115 | unsigned long flags; | 149 | unsigned long flags; |
116 | struct dyn_arch_ftrace arch; | 150 | struct dyn_arch_ftrace arch; |
@@ -119,6 +153,9 @@ struct dyn_ftrace { | |||
119 | int ftrace_force_update(void); | 153 | int ftrace_force_update(void); |
120 | void ftrace_set_filter(unsigned char *buf, int len, int reset); | 154 | void ftrace_set_filter(unsigned char *buf, int len, int reset); |
121 | 155 | ||
156 | int register_ftrace_command(struct ftrace_func_command *cmd); | ||
157 | int unregister_ftrace_command(struct ftrace_func_command *cmd); | ||
158 | |||
122 | /* defined in arch */ | 159 | /* defined in arch */ |
123 | extern int ftrace_ip_converted(unsigned long ip); | 160 | extern int ftrace_ip_converted(unsigned long ip); |
124 | extern int ftrace_dyn_arch_init(void *data); | 161 | extern int ftrace_dyn_arch_init(void *data); |
@@ -126,6 +163,10 @@ extern int ftrace_update_ftrace_func(ftrace_func_t func); | |||
126 | extern void ftrace_caller(void); | 163 | extern void ftrace_caller(void); |
127 | extern void ftrace_call(void); | 164 | extern void ftrace_call(void); |
128 | extern void mcount_call(void); | 165 | extern void mcount_call(void); |
166 | |||
167 | #ifndef FTRACE_ADDR | ||
168 | #define FTRACE_ADDR ((unsigned long)ftrace_caller) | ||
169 | #endif | ||
129 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 170 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
130 | extern void ftrace_graph_caller(void); | 171 | extern void ftrace_graph_caller(void); |
131 | extern int ftrace_enable_ftrace_graph_caller(void); | 172 | extern int ftrace_enable_ftrace_graph_caller(void); |
@@ -136,7 +177,7 @@ static inline int ftrace_disable_ftrace_graph_caller(void) { return 0; } | |||
136 | #endif | 177 | #endif |
137 | 178 | ||
138 | /** | 179 | /** |
139 | * ftrace_make_nop - convert code into top | 180 | * ftrace_make_nop - convert code into nop |
140 | * @mod: module structure if called by module load initialization | 181 | * @mod: module structure if called by module load initialization |
141 | * @rec: the mcount call site record | 182 | * @rec: the mcount call site record |
142 | * @addr: the address that the call site should be calling | 183 | * @addr: the address that the call site should be calling |
@@ -181,7 +222,6 @@ extern int ftrace_make_nop(struct module *mod, | |||
181 | */ | 222 | */ |
182 | extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr); | 223 | extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr); |
183 | 224 | ||
184 | |||
185 | /* May be defined in arch */ | 225 | /* May be defined in arch */ |
186 | extern int ftrace_arch_read_dyn_info(char *buf, int size); | 226 | extern int ftrace_arch_read_dyn_info(char *buf, int size); |
187 | 227 | ||
@@ -198,6 +238,14 @@ extern void ftrace_enable_daemon(void); | |||
198 | # define ftrace_disable_daemon() do { } while (0) | 238 | # define ftrace_disable_daemon() do { } while (0) |
199 | # define ftrace_enable_daemon() do { } while (0) | 239 | # define ftrace_enable_daemon() do { } while (0) |
200 | static inline void ftrace_release(void *start, unsigned long size) { } | 240 | static inline void ftrace_release(void *start, unsigned long size) { } |
241 | static inline int register_ftrace_command(struct ftrace_func_command *cmd) | ||
242 | { | ||
243 | return -EINVAL; | ||
244 | } | ||
245 | static inline int unregister_ftrace_command(char *cmd_name) | ||
246 | { | ||
247 | return -EINVAL; | ||
248 | } | ||
201 | #endif /* CONFIG_DYNAMIC_FTRACE */ | 249 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
202 | 250 | ||
203 | /* totally disable ftrace - can not re-enable after this */ | 251 | /* totally disable ftrace - can not re-enable after this */ |
@@ -233,24 +281,25 @@ static inline void __ftrace_enabled_restore(int enabled) | |||
233 | #endif | 281 | #endif |
234 | } | 282 | } |
235 | 283 | ||
236 | #ifdef CONFIG_FRAME_POINTER | 284 | #ifndef HAVE_ARCH_CALLER_ADDR |
237 | /* TODO: need to fix this for ARM */ | 285 | # ifdef CONFIG_FRAME_POINTER |
238 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) | 286 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
239 | # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1)) | 287 | # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1)) |
240 | # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2)) | 288 | # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2)) |
241 | # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3)) | 289 | # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3)) |
242 | # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4)) | 290 | # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4)) |
243 | # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5)) | 291 | # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5)) |
244 | # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6)) | 292 | # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6)) |
245 | #else | 293 | # else |
246 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) | 294 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
247 | # define CALLER_ADDR1 0UL | 295 | # define CALLER_ADDR1 0UL |
248 | # define CALLER_ADDR2 0UL | 296 | # define CALLER_ADDR2 0UL |
249 | # define CALLER_ADDR3 0UL | 297 | # define CALLER_ADDR3 0UL |
250 | # define CALLER_ADDR4 0UL | 298 | # define CALLER_ADDR4 0UL |
251 | # define CALLER_ADDR5 0UL | 299 | # define CALLER_ADDR5 0UL |
252 | # define CALLER_ADDR6 0UL | 300 | # define CALLER_ADDR6 0UL |
253 | #endif | 301 | # endif |
302 | #endif /* ifndef HAVE_ARCH_CALLER_ADDR */ | ||
254 | 303 | ||
255 | #ifdef CONFIG_IRQSOFF_TRACER | 304 | #ifdef CONFIG_IRQSOFF_TRACER |
256 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); | 305 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); |
@@ -268,54 +317,6 @@ static inline void __ftrace_enabled_restore(int enabled) | |||
268 | # define trace_preempt_off(a0, a1) do { } while (0) | 317 | # define trace_preempt_off(a0, a1) do { } while (0) |
269 | #endif | 318 | #endif |
270 | 319 | ||
271 | #ifdef CONFIG_TRACING | ||
272 | extern int ftrace_dump_on_oops; | ||
273 | |||
274 | extern void tracing_start(void); | ||
275 | extern void tracing_stop(void); | ||
276 | extern void ftrace_off_permanent(void); | ||
277 | |||
278 | extern void | ||
279 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3); | ||
280 | |||
281 | /** | ||
282 | * ftrace_printk - printf formatting in the ftrace buffer | ||
283 | * @fmt: the printf format for printing | ||
284 | * | ||
285 | * Note: __ftrace_printk is an internal function for ftrace_printk and | ||
286 | * the @ip is passed in via the ftrace_printk macro. | ||
287 | * | ||
288 | * This function allows a kernel developer to debug fast path sections | ||
289 | * that printk is not appropriate for. By scattering in various | ||
290 | * printk like tracing in the code, a developer can quickly see | ||
291 | * where problems are occurring. | ||
292 | * | ||
293 | * This is intended as a debugging tool for the developer only. | ||
294 | * Please refrain from leaving ftrace_printks scattered around in | ||
295 | * your code. | ||
296 | */ | ||
297 | # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt) | ||
298 | extern int | ||
299 | __ftrace_printk(unsigned long ip, const char *fmt, ...) | ||
300 | __attribute__ ((format (printf, 2, 3))); | ||
301 | extern void ftrace_dump(void); | ||
302 | #else | ||
303 | static inline void | ||
304 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } | ||
305 | static inline int | ||
306 | ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); | ||
307 | |||
308 | static inline void tracing_start(void) { } | ||
309 | static inline void tracing_stop(void) { } | ||
310 | static inline void ftrace_off_permanent(void) { } | ||
311 | static inline int | ||
312 | ftrace_printk(const char *fmt, ...) | ||
313 | { | ||
314 | return 0; | ||
315 | } | ||
316 | static inline void ftrace_dump(void) { } | ||
317 | #endif | ||
318 | |||
319 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | 320 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
320 | extern void ftrace_init(void); | 321 | extern void ftrace_init(void); |
321 | extern void ftrace_init_module(struct module *mod, | 322 | extern void ftrace_init_module(struct module *mod, |
@@ -327,36 +328,6 @@ ftrace_init_module(struct module *mod, | |||
327 | unsigned long *start, unsigned long *end) { } | 328 | unsigned long *start, unsigned long *end) { } |
328 | #endif | 329 | #endif |
329 | 330 | ||
330 | enum { | ||
331 | POWER_NONE = 0, | ||
332 | POWER_CSTATE = 1, | ||
333 | POWER_PSTATE = 2, | ||
334 | }; | ||
335 | |||
336 | struct power_trace { | ||
337 | #ifdef CONFIG_POWER_TRACER | ||
338 | ktime_t stamp; | ||
339 | ktime_t end; | ||
340 | int type; | ||
341 | int state; | ||
342 | #endif | ||
343 | }; | ||
344 | |||
345 | #ifdef CONFIG_POWER_TRACER | ||
346 | extern void trace_power_start(struct power_trace *it, unsigned int type, | ||
347 | unsigned int state); | ||
348 | extern void trace_power_mark(struct power_trace *it, unsigned int type, | ||
349 | unsigned int state); | ||
350 | extern void trace_power_end(struct power_trace *it); | ||
351 | #else | ||
352 | static inline void trace_power_start(struct power_trace *it, unsigned int type, | ||
353 | unsigned int state) { } | ||
354 | static inline void trace_power_mark(struct power_trace *it, unsigned int type, | ||
355 | unsigned int state) { } | ||
356 | static inline void trace_power_end(struct power_trace *it) { } | ||
357 | #endif | ||
358 | |||
359 | |||
360 | /* | 331 | /* |
361 | * Structure that defines an entry function trace. | 332 | * Structure that defines an entry function trace. |
362 | */ | 333 | */ |
@@ -380,6 +351,30 @@ struct ftrace_graph_ret { | |||
380 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | 351 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
381 | 352 | ||
382 | /* | 353 | /* |
354 | * Stack of return addresses for functions | ||
355 | * of a thread. | ||
356 | * Used in struct thread_info | ||
357 | */ | ||
358 | struct ftrace_ret_stack { | ||
359 | unsigned long ret; | ||
360 | unsigned long func; | ||
361 | unsigned long long calltime; | ||
362 | }; | ||
363 | |||
364 | /* | ||
365 | * Primary handler of a function return. | ||
366 | * It relays on ftrace_return_to_handler. | ||
367 | * Defined in entry_32/64.S | ||
368 | */ | ||
369 | extern void return_to_handler(void); | ||
370 | |||
371 | extern int | ||
372 | ftrace_push_return_trace(unsigned long ret, unsigned long long time, | ||
373 | unsigned long func, int *depth); | ||
374 | extern void | ||
375 | ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret); | ||
376 | |||
377 | /* | ||
383 | * Sometimes we don't want to trace a function with the function | 378 | * Sometimes we don't want to trace a function with the function |
384 | * graph tracer but we want them to keep traced by the usual function | 379 | * graph tracer but we want them to keep traced by the usual function |
385 | * tracer if the function graph tracer is not configured. | 380 | * tracer if the function graph tracer is not configured. |
@@ -490,6 +485,50 @@ static inline int test_tsk_trace_graph(struct task_struct *tsk) | |||
490 | return tsk->trace & TSK_TRACE_FL_GRAPH; | 485 | return tsk->trace & TSK_TRACE_FL_GRAPH; |
491 | } | 486 | } |
492 | 487 | ||
488 | extern int ftrace_dump_on_oops; | ||
489 | |||
493 | #endif /* CONFIG_TRACING */ | 490 | #endif /* CONFIG_TRACING */ |
494 | 491 | ||
492 | |||
493 | #ifdef CONFIG_HW_BRANCH_TRACER | ||
494 | |||
495 | void trace_hw_branch(u64 from, u64 to); | ||
496 | void trace_hw_branch_oops(void); | ||
497 | |||
498 | #else /* CONFIG_HW_BRANCH_TRACER */ | ||
499 | |||
500 | static inline void trace_hw_branch(u64 from, u64 to) {} | ||
501 | static inline void trace_hw_branch_oops(void) {} | ||
502 | |||
503 | #endif /* CONFIG_HW_BRANCH_TRACER */ | ||
504 | |||
505 | /* | ||
506 | * A syscall entry in the ftrace syscalls array. | ||
507 | * | ||
508 | * @name: name of the syscall | ||
509 | * @nb_args: number of parameters it takes | ||
510 | * @types: list of types as strings | ||
511 | * @args: list of args as strings (args[i] matches types[i]) | ||
512 | */ | ||
513 | struct syscall_metadata { | ||
514 | const char *name; | ||
515 | int nb_args; | ||
516 | const char **types; | ||
517 | const char **args; | ||
518 | }; | ||
519 | |||
520 | #ifdef CONFIG_FTRACE_SYSCALLS | ||
521 | extern void arch_init_ftrace_syscalls(void); | ||
522 | extern struct syscall_metadata *syscall_nr_to_meta(int nr); | ||
523 | extern void start_ftrace_syscalls(void); | ||
524 | extern void stop_ftrace_syscalls(void); | ||
525 | extern void ftrace_syscall_enter(struct pt_regs *regs); | ||
526 | extern void ftrace_syscall_exit(struct pt_regs *regs); | ||
527 | #else | ||
528 | static inline void start_ftrace_syscalls(void) { } | ||
529 | static inline void stop_ftrace_syscalls(void) { } | ||
530 | static inline void ftrace_syscall_enter(struct pt_regs *regs) { } | ||
531 | static inline void ftrace_syscall_exit(struct pt_regs *regs) { } | ||
532 | #endif | ||
533 | |||
495 | #endif /* _LINUX_FTRACE_H */ | 534 | #endif /* _LINUX_FTRACE_H */ |