blob: 5de9903645d57b17aadc17646519d35a755402ae [file] [log] [blame]
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001#ifndef _LINUX_FTRACE_H
2#define _LINUX_FTRACE_H
3
4#ifdef CONFIG_FTRACE
5
6#include <linux/linkage.h>
Ingo Molnard49dbf32008-05-16 10:41:53 +02007#include <linux/fs.h>
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02008
Steven Rostedtb0fc4942008-05-12 21:20:43 +02009extern int ftrace_enabled;
10extern int
11ftrace_enable_sysctl(struct ctl_table *table, int write,
12 struct file *filp, void __user *buffer, size_t *lenp,
13 loff_t *ppos);
14
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020015typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
16
17struct ftrace_ops {
18 ftrace_func_t func;
19 struct ftrace_ops *next;
20};
21
22/*
23 * The ftrace_ops must be a static and should also
24 * be read_mostly. These functions do modify read_mostly variables
25 * so use them sparely. Never free an ftrace_op or modify the
26 * next pointer after it has been registered. Even after unregistering
27 * it, the next pointer may still be used internally.
28 */
29int register_ftrace_function(struct ftrace_ops *ops);
30int unregister_ftrace_function(struct ftrace_ops *ops);
31void clear_ftrace_function(void);
32
33extern void ftrace_stub(unsigned long a0, unsigned long a1);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020034
35#else /* !CONFIG_FTRACE */
36# define register_ftrace_function(ops) do { } while (0)
37# define unregister_ftrace_function(ops) do { } while (0)
38# define clear_ftrace_function(ops) do { } while (0)
Ingo Molnarc5131ad2008-08-15 18:22:09 +020039static inline void ftrace_kill_atomic(void) { }
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020040#endif /* CONFIG_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +020041
Steven Rostedt3d083392008-05-12 21:20:42 +020042#ifdef CONFIG_DYNAMIC_FTRACE
43# define FTRACE_HASHBITS 10
44# define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS)
45
Steven Rostedt3c1720f2008-05-12 21:20:43 +020046enum {
Steven Rostedt37ad5082008-05-12 21:20:48 +020047 FTRACE_FL_FREE = (1 << 0),
48 FTRACE_FL_FAILED = (1 << 1),
49 FTRACE_FL_FILTER = (1 << 2),
50 FTRACE_FL_ENABLED = (1 << 3),
Steven Rostedt41c52c02008-05-22 11:46:33 -040051 FTRACE_FL_NOTRACE = (1 << 4),
Abhishek Sagar0eb96702008-06-01 21:47:30 +053052 FTRACE_FL_CONVERTED = (1 << 5),
Abhishek Sagarecea6562008-06-21 23:47:53 +053053 FTRACE_FL_FROZEN = (1 << 6),
Steven Rostedt3c1720f2008-05-12 21:20:43 +020054};
55
Steven Rostedt3d083392008-05-12 21:20:42 +020056struct dyn_ftrace {
57 struct hlist_node node;
Abhishek Sagar395a59d2008-06-21 23:47:27 +053058 unsigned long ip; /* address of mcount call-site */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020059 unsigned long flags;
Steven Rostedt3d083392008-05-12 21:20:42 +020060};
61
Steven Rostedte1c08bd2008-05-12 21:20:44 +020062int ftrace_force_update(void);
Steven Rostedt77a2b372008-05-12 21:20:45 +020063void ftrace_set_filter(unsigned char *buf, int len, int reset);
Steven Rostedte1c08bd2008-05-12 21:20:44 +020064
Steven Rostedt3d083392008-05-12 21:20:42 +020065/* defined in arch */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020066extern int ftrace_ip_converted(unsigned long ip);
67extern unsigned char *ftrace_nop_replace(void);
68extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020069extern int ftrace_dyn_arch_init(void *data);
70extern int ftrace_mcount_set(unsigned long *data);
Steven Rostedt3c1720f2008-05-12 21:20:43 +020071extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
72 unsigned char *new_code);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020073extern int ftrace_update_ftrace_func(ftrace_func_t func);
74extern void ftrace_caller(void);
75extern void ftrace_call(void);
76extern void mcount_call(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -040077
Abhishek Sagarecea6562008-06-21 23:47:53 +053078extern int skip_trace(unsigned long ip);
79
Steven Rostedtc0719e52008-09-06 01:06:03 -040080extern void ftrace_release(void *start, unsigned long size);
81
82extern void ftrace_disable_daemon(void);
83extern void ftrace_enable_daemon(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -040084
Steven Rostedte1c08bd2008-05-12 21:20:44 +020085#else
Abhishek Sagarecea6562008-06-21 23:47:53 +053086# define skip_trace(ip) ({ 0; })
Ingo Molnaraeaee8a2008-05-12 21:20:49 +020087# define ftrace_force_update() ({ 0; })
88# define ftrace_set_filter(buf, len, reset) do { } while (0)
Steven Rostedtad90c0e2008-05-27 20:48:37 -040089# define ftrace_disable_daemon() do { } while (0)
90# define ftrace_enable_daemon() do { } while (0)
Steven Rostedtc0719e52008-09-06 01:06:03 -040091static inline void ftrace_release(void *start, unsigned long size) { }
Abhishek Sagarecea6562008-06-21 23:47:53 +053092#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +020093
Ingo Molnaraeaee8a2008-05-12 21:20:49 +020094/* totally disable ftrace - can not re-enable after this */
95void ftrace_kill(void);
Steven Rostedta2bb6a32008-07-10 20:58:15 -040096void ftrace_kill_atomic(void);
Ingo Molnaraeaee8a2008-05-12 21:20:49 +020097
Ingo Molnarf43fdad2008-05-12 21:20:43 +020098static inline void tracer_disable(void)
99{
100#ifdef CONFIG_FTRACE
101 ftrace_enabled = 0;
102#endif
103}
104
Huang Ying37002732008-08-18 16:24:56 +0800105/*
106 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700107 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800108 * disable/restore.
109 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700110static inline int __ftrace_enabled_save(void)
111{
112#ifdef CONFIG_FTRACE
113 int saved_ftrace_enabled = ftrace_enabled;
114 ftrace_enabled = 0;
115 return saved_ftrace_enabled;
116#else
117 return 0;
118#endif
119}
120
121static inline void __ftrace_enabled_restore(int enabled)
122{
123#ifdef CONFIG_FTRACE
124 ftrace_enabled = enabled;
125#endif
126}
127
Steven Rostedt352ad252008-05-12 21:20:42 +0200128#ifdef CONFIG_FRAME_POINTER
129/* TODO: need to fix this for ARM */
130# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
131# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
132# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
133# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
134# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
135# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
Ingo Molnar86387f72008-05-12 21:20:51 +0200136# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
Steven Rostedt352ad252008-05-12 21:20:42 +0200137#else
138# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
139# define CALLER_ADDR1 0UL
140# define CALLER_ADDR2 0UL
141# define CALLER_ADDR3 0UL
142# define CALLER_ADDR4 0UL
143# define CALLER_ADDR5 0UL
Ingo Molnar86387f72008-05-12 21:20:51 +0200144# define CALLER_ADDR6 0UL
Steven Rostedt352ad252008-05-12 21:20:42 +0200145#endif
146
Steven Rostedt81d68a92008-05-12 21:20:42 +0200147#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100148 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
149 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200150#else
151# define time_hardirqs_on(a0, a1) do { } while (0)
152# define time_hardirqs_off(a0, a1) do { } while (0)
153#endif
154
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200155#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100156 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
157 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200158#else
159# define trace_preempt_on(a0, a1) do { } while (0)
160# define trace_preempt_off(a0, a1) do { } while (0)
161#endif
162
Ingo Molnarb1829d22008-05-28 01:22:08 +0200163#ifdef CONFIG_TRACING
Ingo Molnar74f4e362008-05-12 21:21:15 +0200164extern void
165ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
Steven Rostedt2f2c99d2008-08-01 16:45:49 -0400166
167/**
168 * ftrace_printk - printf formatting in the ftrace buffer
169 * @fmt: the printf format for printing
170 *
171 * Note: __ftrace_printk is an internal function for ftrace_printk and
172 * the @ip is passed in via the ftrace_printk macro.
173 *
174 * This function allows a kernel developer to debug fast path sections
175 * that printk is not appropriate for. By scattering in various
176 * printk like tracing in the code, a developer can quickly see
177 * where problems are occurring.
178 *
179 * This is intended as a debugging tool for the developer only.
180 * Please refrain from leaving ftrace_printks scattered around in
181 * your code.
182 */
183# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400184extern int
185__ftrace_printk(unsigned long ip, const char *fmt, ...)
186 __attribute__ ((format (printf, 2, 3)));
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400187extern void ftrace_dump(void);
Ingo Molnar74f4e362008-05-12 21:21:15 +0200188#else
189static inline void
190ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400191static inline int
Ingo Molnar7b928c22008-08-15 17:48:02 +0200192ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
193
194static inline int
195ftrace_printk(const char *fmt, ...)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400196{
197 return 0;
198}
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400199static inline void ftrace_dump(void) { }
Ingo Molnar74f4e362008-05-12 21:21:15 +0200200#endif
201
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400202#ifdef CONFIG_FTRACE_MCOUNT_RECORD
203extern void ftrace_init(void);
Steven Rostedt90d595f2008-08-14 15:45:09 -0400204extern void ftrace_init_module(unsigned long *start, unsigned long *end);
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400205#else
206static inline void ftrace_init(void) { }
Steven Rostedt90d595f2008-08-14 15:45:09 -0400207static inline void
208ftrace_init_module(unsigned long *start, unsigned long *end) { }
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400209#endif
210
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400211
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200212#endif /* _LINUX_FTRACE_H */