blob: 1c4835f86911bc5457ae81b383724fc046c88cec [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 Noonaneb7fa9352008-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
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 */
33int register_ftrace_function(struct ftrace_ops *ops);
34int unregister_ftrace_function(struct ftrace_ops *ops);
35void clear_ftrace_function(void);
36
37extern void ftrace_stub(unsigned long a0, unsigned long a1);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020038
Steven Rostedt606576c2008-10-06 19:06:12 -040039#else /* !CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020040# 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)
Steven Rostedt81adbdc2008-10-23 09:33:02 -040043static inline void ftrace_kill(void) { }
Steven Rostedt606576c2008-10-06 19:06:12 -040044#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt352ad252008-05-12 21:20:42 +020045
Steven Rostedt3d083392008-05-12 21:20:42 +020046#ifdef CONFIG_DYNAMIC_FTRACE
47# define FTRACE_HASHBITS 10
48# define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
49
Steven Rostedt3c1720f2008-05-12 21:20:43 +020050enum {
Steven Rostedt37ad50842008-05-12 21:20:48 +020051 FTRACE_FL_FREE = (1 << 0),
52 FTRACE_FL_FAILED = (1 << 1),
53 FTRACE_FL_FILTER = (1 << 2),
54 FTRACE_FL_ENABLED = (1 << 3),
Steven Rostedt41c52c02008-05-22 11:46:33 -040055 FTRACE_FL_NOTRACE = (1 << 4),
Abhishek Sagar0eb96702008-06-01 21:47:30 +053056 FTRACE_FL_CONVERTED = (1 << 5),
Abhishek Sagarecea6562008-06-21 23:47:53 +053057 FTRACE_FL_FROZEN = (1 << 6),
Steven Rostedt3c1720f2008-05-12 21:20:43 +020058};
59
Steven Rostedt3d083392008-05-12 21:20:42 +020060struct dyn_ftrace {
61 struct hlist_node node;
Abhishek Sagar395a59d2008-06-21 23:47:27 +053062 unsigned long ip; /* address of mcount call-site */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020063 unsigned long flags;
Steven Rostedt3d083392008-05-12 21:20:42 +020064};
65
Steven Rostedte1c08bd2008-05-12 21:20:44 +020066int ftrace_force_update(void);
Steven Rostedt77a2b372008-05-12 21:20:45 +020067void ftrace_set_filter(unsigned char *buf, int len, int reset);
Steven Rostedte1c08bd2008-05-12 21:20:44 +020068
Steven Rostedt3d083392008-05-12 21:20:42 +020069/* defined in arch */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020070extern int ftrace_ip_converted(unsigned long ip);
71extern unsigned char *ftrace_nop_replace(void);
72extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020073extern int ftrace_dyn_arch_init(void *data);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020074extern int ftrace_update_ftrace_func(ftrace_func_t func);
75extern void ftrace_caller(void);
76extern void ftrace_call(void);
77extern void mcount_call(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -040078
Steven Rostedt593eb8a2008-10-23 09:32:59 -040079/**
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 */
98extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
99 unsigned char *new_code);
100
Abhishek Sagarecea6562008-06-21 23:47:53 +0530101extern int skip_trace(unsigned long ip);
102
Steven Rostedtc0719e52008-09-06 01:06:03 -0400103extern void ftrace_release(void *start, unsigned long size);
104
105extern void ftrace_disable_daemon(void);
106extern void ftrace_enable_daemon(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400107
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200108#else
Abhishek Sagarecea6562008-06-21 23:47:53 +0530109# define skip_trace(ip) ({ 0; })
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200110# define ftrace_force_update() ({ 0; })
111# define ftrace_set_filter(buf, len, reset) do { } while (0)
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400112# define ftrace_disable_daemon() do { } while (0)
113# define ftrace_enable_daemon() do { } while (0)
Steven Rostedtc0719e52008-09-06 01:06:03 -0400114static inline void ftrace_release(void *start, unsigned long size) { }
Abhishek Sagarecea6562008-06-21 23:47:53 +0530115#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +0200116
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200117/* totally disable ftrace - can not re-enable after this */
118void ftrace_kill(void);
119
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200120static inline void tracer_disable(void)
121{
Steven Rostedt606576c2008-10-06 19:06:12 -0400122#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200123 ftrace_enabled = 0;
124#endif
125}
126
Huang Ying37002732008-08-18 16:24:56 +0800127/*
128 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700129 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800130 * disable/restore.
131 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700132static inline int __ftrace_enabled_save(void)
133{
Steven Rostedt606576c2008-10-06 19:06:12 -0400134#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700135 int saved_ftrace_enabled = ftrace_enabled;
136 ftrace_enabled = 0;
137 return saved_ftrace_enabled;
138#else
139 return 0;
140#endif
141}
142
143static inline void __ftrace_enabled_restore(int enabled)
144{
Steven Rostedt606576c2008-10-06 19:06:12 -0400145#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700146 ftrace_enabled = enabled;
147#endif
148}
149
Steven Rostedt352ad252008-05-12 21:20:42 +0200150#ifdef CONFIG_FRAME_POINTER
151/* TODO: need to fix this for ARM */
152# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
153# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
154# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
155# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
156# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
157# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
Ingo Molnar86387f72008-05-12 21:20:51 +0200158# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
Steven Rostedt352ad252008-05-12 21:20:42 +0200159#else
160# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
161# define CALLER_ADDR1 0UL
162# define CALLER_ADDR2 0UL
163# define CALLER_ADDR3 0UL
164# define CALLER_ADDR4 0UL
165# define CALLER_ADDR5 0UL
Ingo Molnar86387f72008-05-12 21:20:51 +0200166# define CALLER_ADDR6 0UL
Steven Rostedt352ad252008-05-12 21:20:42 +0200167#endif
168
Steven Rostedt81d68a92008-05-12 21:20:42 +0200169#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100170 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
171 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200172#else
173# define time_hardirqs_on(a0, a1) do { } while (0)
174# define time_hardirqs_off(a0, a1) do { } while (0)
175#endif
176
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200177#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100178 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
179 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200180#else
181# define trace_preempt_on(a0, a1) do { } while (0)
182# define trace_preempt_off(a0, a1) do { } while (0)
183#endif
184
Ingo Molnarb1829d22008-05-28 01:22:08 +0200185#ifdef CONFIG_TRACING
Ingo Molnar74f4e362008-05-12 21:21:15 +0200186extern void
187ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
Steven Rostedt2f2c99d2008-08-01 16:45:49 -0400188
189/**
190 * ftrace_printk - printf formatting in the ftrace buffer
191 * @fmt: the printf format for printing
192 *
193 * Note: __ftrace_printk is an internal function for ftrace_printk and
194 * the @ip is passed in via the ftrace_printk macro.
195 *
196 * This function allows a kernel developer to debug fast path sections
197 * that printk is not appropriate for. By scattering in various
198 * printk like tracing in the code, a developer can quickly see
199 * where problems are occurring.
200 *
201 * This is intended as a debugging tool for the developer only.
202 * Please refrain from leaving ftrace_printks scattered around in
203 * your code.
204 */
205# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400206extern int
207__ftrace_printk(unsigned long ip, const char *fmt, ...)
208 __attribute__ ((format (printf, 2, 3)));
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400209extern void ftrace_dump(void);
Ingo Molnar74f4e362008-05-12 21:21:15 +0200210#else
211static inline void
212ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400213static inline int
Ingo Molnar7b928c22008-08-15 17:48:02 +0200214ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
215
216static inline int
217ftrace_printk(const char *fmt, ...)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400218{
219 return 0;
220}
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400221static inline void ftrace_dump(void) { }
Ingo Molnar74f4e362008-05-12 21:21:15 +0200222#endif
223
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400224#ifdef CONFIG_FTRACE_MCOUNT_RECORD
225extern void ftrace_init(void);
Steven Rostedt90d595f2008-08-14 15:45:09 -0400226extern void ftrace_init_module(unsigned long *start, unsigned long *end);
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400227#else
228static inline void ftrace_init(void) { }
Steven Rostedt90d595f2008-08-14 15:45:09 -0400229static inline void
230ftrace_init_module(unsigned long *start, unsigned long *end) { }
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400231#endif
232
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400233
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100234struct boot_trace {
235 pid_t caller;
Tim Birdca538f62008-10-09 15:23:05 -0700236 char func[KSYM_NAME_LEN];
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100237 int result;
Tim Birdca538f62008-10-09 15:23:05 -0700238 unsigned long long duration; /* usecs */
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +0200239 ktime_t calltime;
240 ktime_t rettime;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100241};
242
243#ifdef CONFIG_BOOT_TRACER
Frederic Weisbecker56010202008-10-02 13:26:05 +0200244extern void trace_boot(struct boot_trace *it, initcall_t fn);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100245extern void start_boot_trace(void);
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200246extern void stop_boot_trace(void);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100247#else
Frederic Weisbecker56010202008-10-02 13:26:05 +0200248static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100249static inline void start_boot_trace(void) { }
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200250static inline void stop_boot_trace(void) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100251#endif
252
253
254
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200255#endif /* _LINUX_FTRACE_H */