blob: e4202881fb003843fbb98a5d957df8a052e195d7 [file] [log] [blame]
Mike Frysinger9849ed42010-07-20 03:13:35 -04001/*
2 * Ftrace header. For implementation details beyond the random comments
3 * scattered below, see: Documentation/trace/ftrace-design.txt
4 */
5
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02006#ifndef _LINUX_FTRACE_H
7#define _LINUX_FTRACE_H
8
Frederic Weisbecker00126932009-03-05 01:49:22 +01009#include <linux/trace_clock.h>
Frederic Weisbecker56010202008-10-02 13:26:05 +020010#include <linux/kallsyms.h>
Frederic Weisbecker00126932009-03-05 01:49:22 +010011#include <linux/linkage.h>
Steven Rostedtea4e2bc2008-12-03 15:36:57 -050012#include <linux/bitops.h>
Steven Rostedta1e2e312011-08-09 12:50:46 -040013#include <linux/ptrace.h>
Frederic Weisbecker00126932009-03-05 01:49:22 +010014#include <linux/ktime.h>
Frederic Weisbecker21a8c462008-12-04 23:51:23 +010015#include <linux/sched.h>
Frederic Weisbecker00126932009-03-05 01:49:22 +010016#include <linux/types.h>
17#include <linux/init.h>
18#include <linux/fs.h>
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020019
Uwe Kleine-Koenigc79a61f2009-02-27 21:30:03 +010020#include <asm/ftrace.h>
21
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -040022/*
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
Steven Rostedtccf36722012-06-05 09:44:25 -040031/*
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
Paul Gortmakerde477252011-05-26 13:46:22 -040044struct module;
Steven Rostedt04da85b2011-07-11 10:12:59 -040045struct ftrace_hash;
46
Steven Rostedt606576c2008-10-06 19:06:12 -040047#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnar3e1932a2008-10-02 17:45:47 +020048
Steven Rostedtb0fc4942008-05-12 21:20:43 +020049extern int ftrace_enabled;
50extern int
51ftrace_enable_sysctl(struct ctl_table *table, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -070052 void __user *buffer, size_t *lenp,
Steven Rostedtb0fc4942008-05-12 21:20:43 +020053 loff_t *ppos);
54
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -040055struct ftrace_ops;
56
57typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip,
Steven Rostedta1e2e312011-08-09 12:50:46 -040058 struct ftrace_ops *op, struct pt_regs *regs);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020059
Jiri Olsae2484912012-02-15 15:51:48 +010060/*
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 */
Steven Rostedtb8489142011-05-04 09:27:52 -040075enum {
76 FTRACE_OPS_FL_ENABLED = 1 << 0,
77 FTRACE_OPS_FL_GLOBAL = 1 << 1,
Steven Rostedtcdbe61b2011-05-05 21:14:55 -040078 FTRACE_OPS_FL_DYNAMIC = 1 << 2,
Jiri Olsae2484912012-02-15 15:51:48 +010079 FTRACE_OPS_FL_CONTROL = 1 << 3,
Steven Rostedtb8489142011-05-04 09:27:52 -040080};
81
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020082struct ftrace_ops {
Steven Rostedtf45948e2011-05-02 12:29:25 -040083 ftrace_func_t func;
84 struct ftrace_ops *next;
Steven Rostedtb8489142011-05-04 09:27:52 -040085 unsigned long flags;
Jiri Olsae2484912012-02-15 15:51:48 +010086 int __percpu *disabled;
Steven Rostedtf45948e2011-05-02 12:29:25 -040087#ifdef CONFIG_DYNAMIC_FTRACE
88 struct ftrace_hash *notrace_hash;
89 struct ftrace_hash *filter_hash;
90#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020091};
92
Steven Rostedt60a7ecf2008-11-05 16:05:44 -050093extern int function_trace_stop;
94
Frederic Weisbeckere7d37372008-11-16 06:02:06 +010095/*
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
Steven Rostedt60a7ecf2008-11-05 16:05:44 -0500106/**
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
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200132/*
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
Jiri Olsae2484912012-02-15 15:51:48 +0100143/**
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
Steven Rostedta1e2e312011-08-09 12:50:46 -0400192extern void ftrace_stub(unsigned long a0, unsigned long a1,
193 struct ftrace_ops *op, struct pt_regs *regs);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200194
Steven Rostedt606576c2008-10-06 19:06:12 -0400195#else /* !CONFIG_FUNCTION_TRACER */
Steven Rostedt4dbf6bc2010-05-04 11:24:01 -0400196/*
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) { }
Steven Rostedt81adbdc2008-10-23 09:33:02 -0400203static inline void ftrace_kill(void) { }
Steven Rostedt60a7ecf2008-11-05 16:05:44 -0500204static inline void ftrace_stop(void) { }
205static inline void ftrace_start(void) { }
Steven Rostedt606576c2008-10-06 19:06:12 -0400206#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt352ad252008-05-12 21:20:42 +0200207
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500208#ifdef CONFIG_STACK_TRACER
209extern int stack_tracer_enabled;
210int
211stack_trace_sysctl(struct ctl_table *table, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700212 void __user *buffer, size_t *lenp,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500213 loff_t *ppos);
214#endif
215
Steven Rostedtf6180772009-02-14 00:40:25 -0500216struct ftrace_func_command {
217 struct list_head list;
218 char *name;
Steven Rostedt43dd61c2011-07-07 11:09:22 -0400219 int (*func)(struct ftrace_hash *hash,
220 char *func, char *cmd,
Steven Rostedtf6180772009-02-14 00:40:25 -0500221 char *params, int enable);
222};
223
Steven Rostedt3d083392008-05-12 21:20:42 +0200224#ifdef CONFIG_DYNAMIC_FTRACE
Steven Rostedt31e88902008-11-14 16:21:19 -0800225
Steven Rostedt000ab692009-02-17 13:35:06 -0500226int ftrace_arch_code_modify_prepare(void);
227int ftrace_arch_code_modify_post_process(void);
228
Steven Rostedtc88fd862011-08-16 09:53:39 -0400229void ftrace_bug(int err, unsigned long ip);
230
Steven Rostedt809dcf22009-02-16 23:06:01 -0500231struct seq_file;
232
Steven Rostedtb6887d72009-02-17 12:32:04 -0500233struct ftrace_probe_ops {
Steven Rostedt59df055f2009-02-14 15:29:06 -0500234 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);
Steven Rostedt809dcf22009-02-16 23:06:01 -0500239 int (*print)(struct seq_file *m,
240 unsigned long ip,
Steven Rostedtb6887d72009-02-17 12:32:04 -0500241 struct ftrace_probe_ops *ops,
Steven Rostedt809dcf22009-02-16 23:06:01 -0500242 void *data);
Steven Rostedt59df055f2009-02-14 15:29:06 -0500243};
244
245extern int
Steven Rostedtb6887d72009-02-17 12:32:04 -0500246register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
Steven Rostedt59df055f2009-02-14 15:29:06 -0500247 void *data);
248extern void
Steven Rostedtb6887d72009-02-17 12:32:04 -0500249unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
Steven Rostedt59df055f2009-02-14 15:29:06 -0500250 void *data);
251extern void
Steven Rostedtb6887d72009-02-17 12:32:04 -0500252unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
253extern void unregister_ftrace_function_probe_all(char *glob);
Steven Rostedt59df055f2009-02-14 15:29:06 -0500254
Masami Hiramatsu2cfa1972010-02-02 16:49:11 -0500255extern int ftrace_text_reserved(void *start, void *end);
256
Steven Rostedt3c1720f2008-05-12 21:20:43 +0200257enum {
Steven Rostedted926f92011-05-03 13:25:24 -0400258 FTRACE_FL_ENABLED = (1 << 30),
Steven Rostedt3c1720f2008-05-12 21:20:43 +0200259};
260
Steven Rostedted926f92011-05-03 13:25:24 -0400261#define FTRACE_FL_MASK (0x3UL << 30)
262#define FTRACE_REF_MAX ((1 << 30) - 1)
263
Steven Rostedt3d083392008-05-12 21:20:42 +0200264struct dyn_ftrace {
Lai Jiangshanee000b72009-03-24 13:38:06 +0800265 union {
266 unsigned long ip; /* address of mcount call-site */
267 struct dyn_ftrace *freelist;
268 };
Steven Rostedt85ae32a2011-12-16 16:30:31 -0500269 unsigned long flags;
Lai Jiangshanee000b72009-03-24 13:38:06 +0800270 struct dyn_arch_ftrace arch;
Steven Rostedt3d083392008-05-12 21:20:42 +0200271};
272
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200273int ftrace_force_update(void);
Jiri Olsaac483c42012-01-02 10:04:14 +0100274int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
Steven Rostedt936e0742011-05-05 22:54:01 -0400275 int len, int reset);
Jiri Olsaac483c42012-01-02 10:04:14 +0100276int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
Steven Rostedt936e0742011-05-05 22:54:01 -0400277 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);
Jiri Olsa5500fa52012-02-15 15:51:54 +0100280void ftrace_free_filter(struct ftrace_ops *ops);
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200281
Steven Rostedtf6180772009-02-14 00:40:25 -0500282int register_ftrace_command(struct ftrace_func_command *cmd);
283int unregister_ftrace_command(struct ftrace_func_command *cmd);
284
Steven Rostedtc88fd862011-08-16 09:53:39 -0400285enum {
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
Steven Rostedtfc13cb02011-12-19 14:41:25 -0500299enum {
300 FTRACE_ITER_FILTER = (1 << 0),
301 FTRACE_ITER_NOTRACE = (1 << 1),
302 FTRACE_ITER_PRINTALL = (1 << 2),
Steven Rostedt69a30832011-12-19 15:21:16 -0500303 FTRACE_ITER_DO_HASH = (1 << 3),
304 FTRACE_ITER_HASH = (1 << 4),
305 FTRACE_ITER_ENABLED = (1 << 5),
Steven Rostedtfc13cb02011-12-19 14:41:25 -0500306};
307
Steven Rostedtc88fd862011-08-16 09:53:39 -0400308void 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
Steven Rostedt08d636b2011-08-16 09:57:10 -0400316#define for_ftrace_rec_iter(iter) \
317 for (iter = ftrace_rec_iter_start(); \
318 iter; \
319 iter = ftrace_rec_iter_next(iter))
320
321
Steven Rostedtc88fd862011-08-16 09:53:39 -0400322int 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);
Steven Rostedtf0cf9732012-04-25 14:39:54 -0400325unsigned long ftrace_location(unsigned long ip);
Steven Rostedtc88fd862011-08-16 09:53:39 -0400326
327extern ftrace_func_t ftrace_trace_function;
328
Steven Rostedtfc13cb02011-12-19 14:41:25 -0500329int 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
Steven Rostedt2a85a372011-12-19 21:57:44 -0500338void __init
339ftrace_set_early_filter(struct ftrace_ops *ops, char *buf, int enable);
340
Steven Rostedt3d083392008-05-12 21:20:42 +0200341/* defined in arch */
Steven Rostedt3c1720f2008-05-12 21:20:43 +0200342extern int ftrace_ip_converted(unsigned long ip);
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200343extern int ftrace_dyn_arch_init(void *data);
Steven Rostedte4f5d542012-04-27 09:13:18 -0400344extern void ftrace_replace_code(int enable);
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200345extern int ftrace_update_ftrace_func(ftrace_func_t func);
346extern void ftrace_caller(void);
347extern void ftrace_call(void);
348extern void mcount_call(void);
Shaohua Lif0001202009-01-09 11:29:42 +0800349
Steven Rostedt8ed3e2c2012-04-26 14:59:43 -0400350void ftrace_modify_all_code(int command);
351
Shaohua Lif0001202009-01-09 11:29:42 +0800352#ifndef FTRACE_ADDR
353#define FTRACE_ADDR ((unsigned long)ftrace_caller)
354#endif
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100355#ifdef CONFIG_FUNCTION_GRAPH_TRACER
356extern void ftrace_graph_caller(void);
Steven Rostedt5a45cfe2008-11-26 00:16:24 -0500357extern 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; }
Frederic Weisbeckere7d37372008-11-16 06:02:06 +0100362#endif
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400363
Steven Rostedt593eb8a2008-10-23 09:32:59 -0400364/**
Wenji Huang57794a92009-02-06 17:33:27 +0800365 * ftrace_make_nop - convert code into nop
Steven Rostedt31e88902008-11-14 16:21:19 -0800366 * @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
Steven Rostedt593eb8a2008-10-23 09:32:59 -0400369 *
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 *
Steven Rostedt31e88902008-11-14 16:21:19 -0800376 * The code segment at @rec->ip should be a caller to @addr
377 *
Steven Rostedt593eb8a2008-10-23 09:32:59 -0400378 * 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 */
Steven Rostedt31e88902008-11-14 16:21:19 -0800385extern int ftrace_make_nop(struct module *mod,
386 struct dyn_ftrace *rec, unsigned long addr);
387
388/**
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
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 *
399 * The code segment at @rec->ip should be a nop
400 *
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 */
408extern int ftrace_make_call(struct dyn_ftrace *rec, unsigned long addr);
409
Steven Rostedt31e88902008-11-14 16:21:19 -0800410/* May be defined in arch */
411extern int ftrace_arch_read_dyn_info(char *buf, int size);
Steven Rostedt593eb8a2008-10-23 09:32:59 -0400412
Abhishek Sagarecea6562008-06-21 23:47:53 +0530413extern int skip_trace(unsigned long ip);
414
Steven Rostedtc0719e52008-09-06 01:06:03 -0400415extern void ftrace_disable_daemon(void);
416extern void ftrace_enable_daemon(void);
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200417#else
Steven Rostedt4dbf6bc2010-05-04 11:24:01 -0400418static inline int skip_trace(unsigned long ip) { return 0; }
419static inline int ftrace_force_update(void) { return 0; }
Steven Rostedt4dbf6bc2010-05-04 11:24:01 -0400420static inline void ftrace_disable_daemon(void) { }
421static inline void ftrace_enable_daemon(void) { }
jolsa@redhat.come7247a12009-10-07 19:00:35 +0200422static inline void ftrace_release_mod(struct module *mod) {}
Steven Rostedtf6180772009-02-14 00:40:25 -0500423static inline int register_ftrace_command(struct ftrace_func_command *cmd)
424{
Ingo Molnar97d0bb82009-02-17 11:47:39 +0100425 return -EINVAL;
Steven Rostedtf6180772009-02-14 00:40:25 -0500426}
427static inline int unregister_ftrace_command(char *cmd_name)
428{
Ingo Molnar97d0bb82009-02-17 11:47:39 +0100429 return -EINVAL;
Steven Rostedtf6180772009-02-14 00:40:25 -0500430}
Masami Hiramatsu2cfa1972010-02-02 16:49:11 -0500431static inline int ftrace_text_reserved(void *start, void *end)
432{
433 return 0;
434}
Steven Rostedtfc13cb02011-12-19 14:41:25 -0500435
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; })
Steven Rostedt96de37b2012-01-07 17:26:49 -0500442#define ftrace_set_early_filter(ops, buf, enable) do { } while (0)
Jiri Olsa5500fa52012-02-15 15:51:54 +0100443#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)
Steven Rostedtfc13cb02011-12-19 14:41:25 -0500446
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; }
Abhishek Sagarecea6562008-06-21 23:47:53 +0530457#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +0200458
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200459/* totally disable ftrace - can not re-enable after this */
460void ftrace_kill(void);
461
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200462static inline void tracer_disable(void)
463{
Steven Rostedt606576c2008-10-06 19:06:12 -0400464#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200465 ftrace_enabled = 0;
466#endif
467}
468
Huang Ying37002732008-08-18 16:24:56 +0800469/*
470 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700471 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800472 * disable/restore.
473 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700474static inline int __ftrace_enabled_save(void)
475{
Steven Rostedt606576c2008-10-06 19:06:12 -0400476#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700477 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{
Steven Rostedt606576c2008-10-06 19:06:12 -0400487#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700488 ftrace_enabled = enabled;
489#endif
490}
491
Uwe Kleine-Koenigc79a61f2009-02-27 21:30:03 +0100492#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 */
Steven Rostedt352ad252008-05-12 21:20:42 +0200511
Steven Rostedt81d68a92008-05-12 21:20:42 +0200512#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100513 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
514 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200515#else
Steven Rostedt4dbf6bc2010-05-04 11:24:01 -0400516 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) { }
Steven Rostedt81d68a92008-05-12 21:20:42 +0200518#endif
519
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200520#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100521 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
522 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200523#else
Minho Banb02ee9a2012-05-07 11:36:00 +0900524/*
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)
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200530#endif
531
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400532#ifdef CONFIG_FTRACE_MCOUNT_RECORD
533extern void ftrace_init(void);
534#else
535static inline void ftrace_init(void) { }
536#endif
537
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100538/*
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100539 * Structure that defines an entry function trace.
540 */
541struct ftrace_graph_ent {
542 unsigned long func; /* Current function */
543 int depth;
544};
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400545
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100546/*
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +0100547 * Structure that defines a return function trace.
548 */
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100549struct ftrace_graph_ret {
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +0100550 unsigned long func; /* Current function */
551 unsigned long long calltime;
552 unsigned long long rettime;
Frederic Weisbecker02310222008-11-17 03:22:41 +0100553 /* Number of functions that overran the depth limit for current task */
554 unsigned long overrun;
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100555 int depth;
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +0100556};
557
Jiri Olsa62b915f2010-04-02 19:01:22 +0200558/* 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
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100562#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Frederic Weisbecker8b96f012008-12-06 03:40:00 +0100563
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400564/* for init task */
Tetsuo Handaf876d342009-04-08 14:05:43 +0900565#define INIT_FTRACE_GRAPH .ret_stack = NULL,
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400566
Frederic Weisbecker8b96f012008-12-06 03:40:00 +0100567/*
Steven Rostedt712406a2009-02-09 10:54:03 -0800568 * 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;
Steven Rostedta2a16d62009-03-24 23:17:58 -0400576 unsigned long long subtime;
Steven Rostedt71e308a2009-06-18 12:45:08 -0400577 unsigned long fp;
Steven Rostedt712406a2009-02-09 10:54:03 -0800578};
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
Steven Rostedt71e308a2009-06-18 12:45:08 -0400588ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
589 unsigned long frame_pointer);
Steven Rostedt712406a2009-02-09 10:54:03 -0800590
591/*
Frederic Weisbecker8b96f012008-12-06 03:40:00 +0100592 * 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
Frederic Weisbeckerbcbc4f22008-12-09 23:54:20 +0100598/*
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
Frederic Weisbeckerf201ae22008-11-23 06:22:56 +0100608#define FTRACE_RETFUNC_DEPTH 50
609#define FTRACE_RETSTACK_ALLOC_SIZE 32
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100610extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
611 trace_func_graph_ent_t entryfunc);
Frederic Weisbeckerf201ae22008-11-23 06:22:56 +0100612
Steven Rostedt14a866c2008-12-02 23:50:02 -0500613extern void ftrace_graph_stop(void);
614
Frederic Weisbecker287b6e62008-11-26 00:57:25 +0100615/* The current handlers in use */
616extern trace_func_graph_ret_t ftrace_graph_return;
617extern trace_func_graph_ent_t ftrace_graph_entry;
618
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100619extern void unregister_ftrace_graph(void);
Frederic Weisbeckerf201ae22008-11-23 06:22:56 +0100620
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100621extern void ftrace_graph_init_task(struct task_struct *t);
622extern void ftrace_graph_exit_task(struct task_struct *t);
Steven Rostedt868baf02011-02-10 21:26:13 -0500623extern void ftrace_graph_init_idle_task(struct task_struct *t, int cpu);
Frederic Weisbecker21a8c462008-12-04 23:51:23 +0100624
625static inline int task_curr_ret_stack(struct task_struct *t)
626{
627 return t->curr_ret_stack;
628}
Frederic Weisbecker380c4b12008-12-06 03:43:41 +0100629
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}
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400639#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
Frederic Weisbecker8b96f012008-12-06 03:40:00 +0100640
641#define __notrace_funcgraph
Frederic Weisbeckerbcbc4f22008-12-09 23:54:20 +0100642#define __irq_entry
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400643#define INIT_FTRACE_GRAPH
Frederic Weisbecker8b96f012008-12-06 03:40:00 +0100644
Frederic Weisbeckerfb526072008-11-25 21:07:04 +0100645static inline void ftrace_graph_init_task(struct task_struct *t) { }
646static inline void ftrace_graph_exit_task(struct task_struct *t) { }
Steven Rostedt868baf02011-02-10 21:26:13 -0500647static inline void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) { }
Frederic Weisbecker21a8c462008-12-04 23:51:23 +0100648
Jiri Olsa62b915f2010-04-02 19:01:22 +0200649static 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
Frederic Weisbecker21a8c462008-12-04 23:51:23 +0100656static inline int task_curr_ret_stack(struct task_struct *tsk)
657{
658 return -1;
659}
Frederic Weisbecker380c4b12008-12-06 03:43:41 +0100660
661static inline void pause_graph_tracing(void) { }
662static inline void unpause_graph_tracing(void) { }
Steven Rostedt5ac9f622009-03-25 20:55:00 -0400663#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +0100664
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500665#ifdef CONFIG_TRACING
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500666
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
Frederic Weisbeckercecbca92010-04-18 19:08:41 +0200707enum ftrace_dump_mode;
708
709extern enum ftrace_dump_mode ftrace_dump_on_oops;
Ingo Molnar526211b2009-03-05 10:28:45 +0100710
Steven Rostedt261842b2009-04-16 21:41:52 -0400711#ifdef CONFIG_PREEMPT
712#define INIT_TRACE_RECURSION .trace_recursion = 0,
713#endif
714
Steven Rostedtea4e2bc2008-12-03 15:36:57 -0500715#endif /* CONFIG_TRACING */
716
Steven Rostedt261842b2009-04-16 21:41:52 -0400717#ifndef INIT_TRACE_RECURSION
718#define INIT_TRACE_RECURSION
719#endif
Markus Metzgerb1818742009-01-19 10:31:01 +0100720
Mike Frysingere7b8e672010-01-26 04:40:03 -0500721#ifdef CONFIG_FTRACE_SYSCALLS
722
723unsigned long arch_syscall_addr(int nr);
724
725#endif /* CONFIG_FTRACE_SYSCALLS */
726
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200727#endif /* _LINUX_FTRACE_H */