blob: 794ab907dbfea5520adc19fdf177d8178edbf4c8 [file] [log] [blame]
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001#ifndef _LINUX_FTRACE_H
2#define _LINUX_FTRACE_H
3
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02004#include <linux/linkage.h>
Ingo Molnard49dbf32008-05-16 10:41:53 +02005#include <linux/fs.h>
Steven Noonaneb7fa932008-10-02 12:00:07 -07006#include <linux/ktime.h>
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +01007#include <linux/init.h>
8#include <linux/types.h>
Frederic Weisbecker56010202008-10-02 13:26:05 +02009#include <linux/kallsyms.h>
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020010
Steven Rostedt606576c2008-10-06 19:06:12 -040011#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnar3e1932a2008-10-02 17:45:47 +020012
Steven Rostedtb0fc4942008-05-12 21:20:43 +020013extern 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
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020019typedef 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
Steven Rostedt60a7ecf2008-11-05 16:05:44 -050026extern int function_trace_stop;
27
28/**
29 * ftrace_stop - stop function tracer.
30 *
31 * A quick way to stop the function tracer. Note this an on off switch,
32 * it is not something that is recursive like preempt_disable.
33 * This does not disable the calling of mcount, it only stops the
34 * calling of functions from mcount.
35 */
36static inline void ftrace_stop(void)
37{
38 function_trace_stop = 1;
39}
40
41/**
42 * ftrace_start - start the function tracer.
43 *
44 * This function is the inverse of ftrace_stop. This does not enable
45 * the function tracing if the function tracer is disabled. This only
46 * sets the function tracer flag to continue calling the functions
47 * from mcount.
48 */
49static inline void ftrace_start(void)
50{
51 function_trace_stop = 0;
52}
53
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020054/*
55 * The ftrace_ops must be a static and should also
56 * be read_mostly. These functions do modify read_mostly variables
57 * so use them sparely. Never free an ftrace_op or modify the
58 * next pointer after it has been registered. Even after unregistering
59 * it, the next pointer may still be used internally.
60 */
61int register_ftrace_function(struct ftrace_ops *ops);
62int unregister_ftrace_function(struct ftrace_ops *ops);
63void clear_ftrace_function(void);
64
65extern void ftrace_stub(unsigned long a0, unsigned long a1);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020066
Steven Rostedt606576c2008-10-06 19:06:12 -040067#else /* !CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020068# define register_ftrace_function(ops) do { } while (0)
69# define unregister_ftrace_function(ops) do { } while (0)
70# define clear_ftrace_function(ops) do { } while (0)
Steven Rostedt81adbdc2008-10-23 09:33:02 -040071static inline void ftrace_kill(void) { }
Steven Rostedt60a7ecf2008-11-05 16:05:44 -050072static inline void ftrace_stop(void) { }
73static inline void ftrace_start(void) { }
Steven Rostedt606576c2008-10-06 19:06:12 -040074#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt352ad252008-05-12 21:20:42 +020075
Steven Rostedt3d083392008-05-12 21:20:42 +020076#ifdef CONFIG_DYNAMIC_FTRACE
Steven Rostedt3d083392008-05-12 21:20:42 +020077
Steven Rostedt3c1720f2008-05-12 21:20:43 +020078enum {
Steven Rostedt37ad5082008-05-12 21:20:48 +020079 FTRACE_FL_FREE = (1 << 0),
80 FTRACE_FL_FAILED = (1 << 1),
81 FTRACE_FL_FILTER = (1 << 2),
82 FTRACE_FL_ENABLED = (1 << 3),
Steven Rostedt41c52c02008-05-22 11:46:33 -040083 FTRACE_FL_NOTRACE = (1 << 4),
Abhishek Sagar0eb96702008-06-01 21:47:30 +053084 FTRACE_FL_CONVERTED = (1 << 5),
Abhishek Sagarecea6562008-06-21 23:47:53 +053085 FTRACE_FL_FROZEN = (1 << 6),
Steven Rostedt3c1720f2008-05-12 21:20:43 +020086};
87
Steven Rostedt3d083392008-05-12 21:20:42 +020088struct dyn_ftrace {
Steven Rostedt08f5ac902008-10-23 09:33:07 -040089 struct list_head list;
90 unsigned long ip; /* address of mcount call-site */
91 unsigned long flags;
Steven Rostedt3d083392008-05-12 21:20:42 +020092};
93
Steven Rostedte1c08bd2008-05-12 21:20:44 +020094int ftrace_force_update(void);
Steven Rostedt77a2b372008-05-12 21:20:45 +020095void ftrace_set_filter(unsigned char *buf, int len, int reset);
Steven Rostedte1c08bd2008-05-12 21:20:44 +020096
Steven Rostedt3d083392008-05-12 21:20:42 +020097/* defined in arch */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020098extern int ftrace_ip_converted(unsigned long ip);
99extern unsigned char *ftrace_nop_replace(void);
100extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200101extern int ftrace_dyn_arch_init(void *data);
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200102extern int ftrace_update_ftrace_func(ftrace_func_t func);
103extern void ftrace_caller(void);
104extern void ftrace_call(void);
105extern void mcount_call(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400106
Steven Rostedta26a2a22008-10-31 00:03:22 -0400107/* May be defined in arch */
108extern int ftrace_arch_read_dyn_info(char *buf, int size);
109
Steven Rostedt593eb8a2008-10-23 09:32:59 -0400110/**
111 * ftrace_modify_code - modify code segment
112 * @ip: the address of the code segment
113 * @old_code: the contents of what is expected to be there
114 * @new_code: the code to patch in
115 *
116 * This is a very sensitive operation and great care needs
117 * to be taken by the arch. The operation should carefully
118 * read the location, check to see if what is read is indeed
119 * what we expect it to be, and then on success of the compare,
120 * it should write to the location.
121 *
122 * Return must be:
123 * 0 on success
124 * -EFAULT on error reading the location
125 * -EINVAL on a failed compare of the contents
126 * -EPERM on error writing to the location
127 * Any other value will be considered a failure.
128 */
129extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
130 unsigned char *new_code);
131
Abhishek Sagarecea6562008-06-21 23:47:53 +0530132extern int skip_trace(unsigned long ip);
133
Steven Rostedtc0719e52008-09-06 01:06:03 -0400134extern void ftrace_release(void *start, unsigned long size);
135
136extern void ftrace_disable_daemon(void);
137extern void ftrace_enable_daemon(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400138
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200139#else
Abhishek Sagarecea6562008-06-21 23:47:53 +0530140# define skip_trace(ip) ({ 0; })
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200141# define ftrace_force_update() ({ 0; })
142# define ftrace_set_filter(buf, len, reset) do { } while (0)
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400143# define ftrace_disable_daemon() do { } while (0)
144# define ftrace_enable_daemon() do { } while (0)
Steven Rostedtc0719e52008-09-06 01:06:03 -0400145static inline void ftrace_release(void *start, unsigned long size) { }
Abhishek Sagarecea6562008-06-21 23:47:53 +0530146#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +0200147
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200148/* totally disable ftrace - can not re-enable after this */
149void ftrace_kill(void);
150
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200151static inline void tracer_disable(void)
152{
Steven Rostedt606576c2008-10-06 19:06:12 -0400153#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200154 ftrace_enabled = 0;
155#endif
156}
157
Huang Ying37002732008-08-18 16:24:56 +0800158/*
159 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700160 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800161 * disable/restore.
162 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700163static inline int __ftrace_enabled_save(void)
164{
Steven Rostedt606576c2008-10-06 19:06:12 -0400165#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700166 int saved_ftrace_enabled = ftrace_enabled;
167 ftrace_enabled = 0;
168 return saved_ftrace_enabled;
169#else
170 return 0;
171#endif
172}
173
174static inline void __ftrace_enabled_restore(int enabled)
175{
Steven Rostedt606576c2008-10-06 19:06:12 -0400176#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700177 ftrace_enabled = enabled;
178#endif
179}
180
Steven Rostedt352ad252008-05-12 21:20:42 +0200181#ifdef CONFIG_FRAME_POINTER
182/* TODO: need to fix this for ARM */
183# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
184# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
185# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
186# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
187# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
188# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
Ingo Molnar86387f72008-05-12 21:20:51 +0200189# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
Steven Rostedt352ad252008-05-12 21:20:42 +0200190#else
191# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
192# define CALLER_ADDR1 0UL
193# define CALLER_ADDR2 0UL
194# define CALLER_ADDR3 0UL
195# define CALLER_ADDR4 0UL
196# define CALLER_ADDR5 0UL
Ingo Molnar86387f72008-05-12 21:20:51 +0200197# define CALLER_ADDR6 0UL
Steven Rostedt352ad252008-05-12 21:20:42 +0200198#endif
199
Steven Rostedt81d68a92008-05-12 21:20:42 +0200200#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100201 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
202 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200203#else
204# define time_hardirqs_on(a0, a1) do { } while (0)
205# define time_hardirqs_off(a0, a1) do { } while (0)
206#endif
207
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200208#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100209 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
210 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200211#else
212# define trace_preempt_on(a0, a1) do { } while (0)
213# define trace_preempt_off(a0, a1) do { } while (0)
214#endif
215
Ingo Molnarb1829d22008-05-28 01:22:08 +0200216#ifdef CONFIG_TRACING
Steven Rostedt944ac422008-10-23 19:26:08 -0400217extern int ftrace_dump_on_oops;
218
Ingo Molnar74f4e362008-05-12 21:21:15 +0200219extern void
220ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
Steven Rostedt2f2c99d2008-08-01 16:45:49 -0400221
222/**
223 * ftrace_printk - printf formatting in the ftrace buffer
224 * @fmt: the printf format for printing
225 *
226 * Note: __ftrace_printk is an internal function for ftrace_printk and
227 * the @ip is passed in via the ftrace_printk macro.
228 *
229 * This function allows a kernel developer to debug fast path sections
230 * that printk is not appropriate for. By scattering in various
231 * printk like tracing in the code, a developer can quickly see
232 * where problems are occurring.
233 *
234 * This is intended as a debugging tool for the developer only.
235 * Please refrain from leaving ftrace_printks scattered around in
236 * your code.
237 */
238# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400239extern int
240__ftrace_printk(unsigned long ip, const char *fmt, ...)
241 __attribute__ ((format (printf, 2, 3)));
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400242extern void ftrace_dump(void);
Ingo Molnar74f4e362008-05-12 21:21:15 +0200243#else
244static inline void
245ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400246static inline int
Ingo Molnar7b928c22008-08-15 17:48:02 +0200247ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
248
249static inline int
250ftrace_printk(const char *fmt, ...)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400251{
252 return 0;
253}
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400254static inline void ftrace_dump(void) { }
Ingo Molnar74f4e362008-05-12 21:21:15 +0200255#endif
256
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400257#ifdef CONFIG_FTRACE_MCOUNT_RECORD
258extern void ftrace_init(void);
Steven Rostedt90d595f2008-08-14 15:45:09 -0400259extern void ftrace_init_module(unsigned long *start, unsigned long *end);
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400260#else
261static inline void ftrace_init(void) { }
Steven Rostedt90d595f2008-08-14 15:45:09 -0400262static inline void
263ftrace_init_module(unsigned long *start, unsigned long *end) { }
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400264#endif
265
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400266
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100267/*
268 * Structure which defines the trace of an initcall.
269 * You don't have to fill the func field since it is
270 * only used internally by the tracer.
271 */
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100272struct boot_trace {
273 pid_t caller;
Tim Birdca538f62008-10-09 15:23:05 -0700274 char func[KSYM_NAME_LEN];
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100275 int result;
Tim Birdca538f62008-10-09 15:23:05 -0700276 unsigned long long duration; /* usecs */
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +0200277 ktime_t calltime;
278 ktime_t rettime;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100279};
280
281#ifdef CONFIG_BOOT_TRACER
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100282/* Append the trace on the ring-buffer */
Frederic Weisbecker56010202008-10-02 13:26:05 +0200283extern void trace_boot(struct boot_trace *it, initcall_t fn);
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100284
285/* Tells the tracer that smp_pre_initcall is finished.
286 * So we can start the tracing
287 */
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100288extern void start_boot_trace(void);
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100289
290/* Resume the tracing of other necessary events
291 * such as sched switches
292 */
293extern void enable_boot_trace(void);
294
295/* Suspend this tracing. Actually, only sched_switches tracing have
296 * to be suspended. Initcalls doesn't need it.)
297 */
298extern void disable_boot_trace(void);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100299#else
Frederic Weisbecker56010202008-10-02 13:26:05 +0200300static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100301static inline void start_boot_trace(void) { }
Frederic Weisbecker71566a02008-10-31 12:57:20 +0100302static inline void enable_boot_trace(void) { }
303static inline void disable_boot_trace(void) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100304#endif
305
306
307
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200308#endif /* _LINUX_FTRACE_H */