blob: 79fa10cbdcfb686ab47409279815aae75d53fe71 [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
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)
Ingo Molnarc5131ad2008-08-15 18:22:09 +020043static inline void ftrace_kill_atomic(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 Rostedt37ad5082008-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);
74extern int ftrace_mcount_set(unsigned long *data);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020075extern int ftrace_update_ftrace_func(ftrace_func_t func);
76extern void ftrace_caller(void);
77extern void ftrace_call(void);
78extern void mcount_call(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -040079
Steven Rostedt593eb8a2008-10-23 09:32:59 -040080/**
81 * ftrace_modify_code - modify code segment
82 * @ip: the address of the code segment
83 * @old_code: the contents of what is expected to be there
84 * @new_code: the code to patch in
85 *
86 * This is a very sensitive operation and great care needs
87 * to be taken by the arch. The operation should carefully
88 * read the location, check to see if what is read is indeed
89 * what we expect it to be, and then on success of the compare,
90 * it should write to the location.
91 *
92 * Return must be:
93 * 0 on success
94 * -EFAULT on error reading the location
95 * -EINVAL on a failed compare of the contents
96 * -EPERM on error writing to the location
97 * Any other value will be considered a failure.
98 */
99extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
100 unsigned char *new_code);
101
Abhishek Sagarecea6562008-06-21 23:47:53 +0530102extern int skip_trace(unsigned long ip);
103
Steven Rostedtc0719e52008-09-06 01:06:03 -0400104extern void ftrace_release(void *start, unsigned long size);
105
106extern void ftrace_disable_daemon(void);
107extern void ftrace_enable_daemon(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400108
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200109#else
Abhishek Sagarecea6562008-06-21 23:47:53 +0530110# define skip_trace(ip) ({ 0; })
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200111# define ftrace_force_update() ({ 0; })
112# define ftrace_set_filter(buf, len, reset) do { } while (0)
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400113# define ftrace_disable_daemon() do { } while (0)
114# define ftrace_enable_daemon() do { } while (0)
Steven Rostedtc0719e52008-09-06 01:06:03 -0400115static inline void ftrace_release(void *start, unsigned long size) { }
Abhishek Sagarecea6562008-06-21 23:47:53 +0530116#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +0200117
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200118/* totally disable ftrace - can not re-enable after this */
119void ftrace_kill(void);
Steven Rostedta2bb6a32008-07-10 20:58:15 -0400120void ftrace_kill_atomic(void);
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200121
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200122static inline void tracer_disable(void)
123{
Steven Rostedt606576c2008-10-06 19:06:12 -0400124#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200125 ftrace_enabled = 0;
126#endif
127}
128
Huang Ying37002732008-08-18 16:24:56 +0800129/*
130 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700131 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800132 * disable/restore.
133 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700134static inline int __ftrace_enabled_save(void)
135{
Steven Rostedt606576c2008-10-06 19:06:12 -0400136#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700137 int saved_ftrace_enabled = ftrace_enabled;
138 ftrace_enabled = 0;
139 return saved_ftrace_enabled;
140#else
141 return 0;
142#endif
143}
144
145static inline void __ftrace_enabled_restore(int enabled)
146{
Steven Rostedt606576c2008-10-06 19:06:12 -0400147#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700148 ftrace_enabled = enabled;
149#endif
150}
151
Steven Rostedt352ad252008-05-12 21:20:42 +0200152#ifdef CONFIG_FRAME_POINTER
153/* TODO: need to fix this for ARM */
154# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
155# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
156# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
157# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
158# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
159# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
Ingo Molnar86387f72008-05-12 21:20:51 +0200160# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
Steven Rostedt352ad252008-05-12 21:20:42 +0200161#else
162# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
163# define CALLER_ADDR1 0UL
164# define CALLER_ADDR2 0UL
165# define CALLER_ADDR3 0UL
166# define CALLER_ADDR4 0UL
167# define CALLER_ADDR5 0UL
Ingo Molnar86387f72008-05-12 21:20:51 +0200168# define CALLER_ADDR6 0UL
Steven Rostedt352ad252008-05-12 21:20:42 +0200169#endif
170
Steven Rostedt81d68a92008-05-12 21:20:42 +0200171#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100172 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
173 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200174#else
175# define time_hardirqs_on(a0, a1) do { } while (0)
176# define time_hardirqs_off(a0, a1) do { } while (0)
177#endif
178
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200179#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100180 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
181 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200182#else
183# define trace_preempt_on(a0, a1) do { } while (0)
184# define trace_preempt_off(a0, a1) do { } while (0)
185#endif
186
Ingo Molnarb1829d22008-05-28 01:22:08 +0200187#ifdef CONFIG_TRACING
Ingo Molnar74f4e362008-05-12 21:21:15 +0200188extern void
189ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
Steven Rostedt2f2c99d2008-08-01 16:45:49 -0400190
191/**
192 * ftrace_printk - printf formatting in the ftrace buffer
193 * @fmt: the printf format for printing
194 *
195 * Note: __ftrace_printk is an internal function for ftrace_printk and
196 * the @ip is passed in via the ftrace_printk macro.
197 *
198 * This function allows a kernel developer to debug fast path sections
199 * that printk is not appropriate for. By scattering in various
200 * printk like tracing in the code, a developer can quickly see
201 * where problems are occurring.
202 *
203 * This is intended as a debugging tool for the developer only.
204 * Please refrain from leaving ftrace_printks scattered around in
205 * your code.
206 */
207# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400208extern int
209__ftrace_printk(unsigned long ip, const char *fmt, ...)
210 __attribute__ ((format (printf, 2, 3)));
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400211extern void ftrace_dump(void);
Ingo Molnar74f4e362008-05-12 21:21:15 +0200212#else
213static inline void
214ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400215static inline int
Ingo Molnar7b928c22008-08-15 17:48:02 +0200216ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
217
218static inline int
219ftrace_printk(const char *fmt, ...)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400220{
221 return 0;
222}
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400223static inline void ftrace_dump(void) { }
Ingo Molnar74f4e362008-05-12 21:21:15 +0200224#endif
225
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400226#ifdef CONFIG_FTRACE_MCOUNT_RECORD
227extern void ftrace_init(void);
Steven Rostedt90d595f2008-08-14 15:45:09 -0400228extern void ftrace_init_module(unsigned long *start, unsigned long *end);
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400229#else
230static inline void ftrace_init(void) { }
Steven Rostedt90d595f2008-08-14 15:45:09 -0400231static inline void
232ftrace_init_module(unsigned long *start, unsigned long *end) { }
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400233#endif
234
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400235
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100236struct boot_trace {
237 pid_t caller;
Tim Birdca538f62008-10-09 15:23:05 -0700238 char func[KSYM_NAME_LEN];
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100239 int result;
Tim Birdca538f62008-10-09 15:23:05 -0700240 unsigned long long duration; /* usecs */
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +0200241 ktime_t calltime;
242 ktime_t rettime;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100243};
244
245#ifdef CONFIG_BOOT_TRACER
Frederic Weisbecker56010202008-10-02 13:26:05 +0200246extern void trace_boot(struct boot_trace *it, initcall_t fn);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100247extern void start_boot_trace(void);
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200248extern void stop_boot_trace(void);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100249#else
Frederic Weisbecker56010202008-10-02 13:26:05 +0200250static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100251static inline void start_boot_trace(void) { }
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200252static inline void stop_boot_trace(void) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100253#endif
254
255
256
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200257#endif /* _LINUX_FTRACE_H */