blob: 9c5bc6be2b091274b37b14046f03ebf3db70c194 [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>
Hugh Dickins9c246242008-12-09 13:14:27 -08009#include <linux/module.h>
Frederic Weisbecker56010202008-10-02 13:26:05 +020010#include <linux/kallsyms.h>
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020011
Steven Rostedt606576c2008-10-06 19:06:12 -040012#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnar3e1932a2008-10-02 17:45:47 +020013
Steven Rostedtb0fc4942008-05-12 21:20:43 +020014extern int ftrace_enabled;
15extern int
16ftrace_enable_sysctl(struct ctl_table *table, int write,
17 struct file *filp, void __user *buffer, size_t *lenp,
18 loff_t *ppos);
19
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020020typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
21
22struct ftrace_ops {
23 ftrace_func_t func;
24 struct ftrace_ops *next;
25};
26
27/*
28 * The ftrace_ops must be a static and should also
29 * be read_mostly. These functions do modify read_mostly variables
30 * so use them sparely. Never free an ftrace_op or modify the
31 * next pointer after it has been registered. Even after unregistering
32 * it, the next pointer may still be used internally.
33 */
34int register_ftrace_function(struct ftrace_ops *ops);
35int unregister_ftrace_function(struct ftrace_ops *ops);
36void clear_ftrace_function(void);
37
38extern void ftrace_stub(unsigned long a0, unsigned long a1);
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020039
Steven Rostedt606576c2008-10-06 19:06:12 -040040#else /* !CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020041# define register_ftrace_function(ops) do { } while (0)
42# define unregister_ftrace_function(ops) do { } while (0)
43# define clear_ftrace_function(ops) do { } while (0)
Steven Rostedt81adbdc2008-10-23 09:33:02 -040044static inline void ftrace_kill(void) { }
Steven Rostedt606576c2008-10-06 19:06:12 -040045#endif /* CONFIG_FUNCTION_TRACER */
Steven Rostedt352ad252008-05-12 21:20:42 +020046
Steven Rostedt3d083392008-05-12 21:20:42 +020047#ifdef CONFIG_DYNAMIC_FTRACE
Steven Rostedt3d083392008-05-12 21:20:42 +020048
Steven Rostedt3c1720f2008-05-12 21:20:43 +020049enum {
Steven Rostedt37ad5082008-05-12 21:20:48 +020050 FTRACE_FL_FREE = (1 << 0),
51 FTRACE_FL_FAILED = (1 << 1),
52 FTRACE_FL_FILTER = (1 << 2),
53 FTRACE_FL_ENABLED = (1 << 3),
Steven Rostedt41c52c02008-05-22 11:46:33 -040054 FTRACE_FL_NOTRACE = (1 << 4),
Abhishek Sagar0eb96702008-06-01 21:47:30 +053055 FTRACE_FL_CONVERTED = (1 << 5),
Abhishek Sagarecea6562008-06-21 23:47:53 +053056 FTRACE_FL_FROZEN = (1 << 6),
Steven Rostedt3c1720f2008-05-12 21:20:43 +020057};
58
Steven Rostedt3d083392008-05-12 21:20:42 +020059struct dyn_ftrace {
Steven Rostedt08f5ac902008-10-23 09:33:07 -040060 struct list_head list;
61 unsigned long ip; /* address of mcount call-site */
62 unsigned long flags;
Steven Rostedt3d083392008-05-12 21:20:42 +020063};
64
Steven Rostedte1c08bd2008-05-12 21:20:44 +020065int ftrace_force_update(void);
Steven Rostedt77a2b372008-05-12 21:20:45 +020066void ftrace_set_filter(unsigned char *buf, int len, int reset);
Steven Rostedte1c08bd2008-05-12 21:20:44 +020067
Steven Rostedt3d083392008-05-12 21:20:42 +020068/* defined in arch */
Steven Rostedt3c1720f2008-05-12 21:20:43 +020069extern int ftrace_ip_converted(unsigned long ip);
70extern unsigned char *ftrace_nop_replace(void);
71extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
Steven Rostedtd61f82d2008-05-12 21:20:43 +020072extern int ftrace_dyn_arch_init(void *data);
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
Steven Rostedt593eb8a2008-10-23 09:32:59 -040078/**
79 * ftrace_modify_code - modify code segment
80 * @ip: the address of the code segment
81 * @old_code: the contents of what is expected to be there
82 * @new_code: the code to patch in
83 *
84 * This is a very sensitive operation and great care needs
85 * to be taken by the arch. The operation should carefully
86 * read the location, check to see if what is read is indeed
87 * what we expect it to be, and then on success of the compare,
88 * it should write to the location.
89 *
90 * Return must be:
91 * 0 on success
92 * -EFAULT on error reading the location
93 * -EINVAL on a failed compare of the contents
94 * -EPERM on error writing to the location
95 * Any other value will be considered a failure.
96 */
97extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
98 unsigned char *new_code);
99
Abhishek Sagarecea6562008-06-21 23:47:53 +0530100extern int skip_trace(unsigned long ip);
101
Steven Rostedtc0719e52008-09-06 01:06:03 -0400102extern void ftrace_release(void *start, unsigned long size);
103
104extern void ftrace_disable_daemon(void);
105extern void ftrace_enable_daemon(void);
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400106
Steven Rostedte1c08bd2008-05-12 21:20:44 +0200107#else
Abhishek Sagarecea6562008-06-21 23:47:53 +0530108# define skip_trace(ip) ({ 0; })
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200109# define ftrace_force_update() ({ 0; })
110# define ftrace_set_filter(buf, len, reset) do { } while (0)
Steven Rostedtad90c0e2008-05-27 20:48:37 -0400111# define ftrace_disable_daemon() do { } while (0)
112# define ftrace_enable_daemon() do { } while (0)
Steven Rostedtc0719e52008-09-06 01:06:03 -0400113static inline void ftrace_release(void *start, unsigned long size) { }
Abhishek Sagarecea6562008-06-21 23:47:53 +0530114#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt352ad252008-05-12 21:20:42 +0200115
Ingo Molnaraeaee8a2008-05-12 21:20:49 +0200116/* totally disable ftrace - can not re-enable after this */
117void ftrace_kill(void);
118
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200119static inline void tracer_disable(void)
120{
Steven Rostedt606576c2008-10-06 19:06:12 -0400121#ifdef CONFIG_FUNCTION_TRACER
Ingo Molnarf43fdad2008-05-12 21:20:43 +0200122 ftrace_enabled = 0;
123#endif
124}
125
Huang Ying37002732008-08-18 16:24:56 +0800126/*
127 * Ftrace disable/restore without lock. Some synchronization mechanism
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700128 * must be used to prevent ftrace_enabled to be changed between
Huang Ying37002732008-08-18 16:24:56 +0800129 * disable/restore.
130 */
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700131static inline int __ftrace_enabled_save(void)
132{
Steven Rostedt606576c2008-10-06 19:06:12 -0400133#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700134 int saved_ftrace_enabled = ftrace_enabled;
135 ftrace_enabled = 0;
136 return saved_ftrace_enabled;
137#else
138 return 0;
139#endif
140}
141
142static inline void __ftrace_enabled_restore(int enabled)
143{
Steven Rostedt606576c2008-10-06 19:06:12 -0400144#ifdef CONFIG_FUNCTION_TRACER
Huang Ying9bdeb7b2008-08-15 00:40:25 -0700145 ftrace_enabled = enabled;
146#endif
147}
148
Steven Rostedt352ad252008-05-12 21:20:42 +0200149#ifdef CONFIG_FRAME_POINTER
150/* TODO: need to fix this for ARM */
151# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
152# define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
153# define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
154# define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
155# define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
156# define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
Ingo Molnar86387f72008-05-12 21:20:51 +0200157# define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
Steven Rostedt352ad252008-05-12 21:20:42 +0200158#else
159# define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
160# define CALLER_ADDR1 0UL
161# define CALLER_ADDR2 0UL
162# define CALLER_ADDR3 0UL
163# define CALLER_ADDR4 0UL
164# define CALLER_ADDR5 0UL
Ingo Molnar86387f72008-05-12 21:20:51 +0200165# define CALLER_ADDR6 0UL
Steven Rostedt352ad252008-05-12 21:20:42 +0200166#endif
167
Steven Rostedt81d68a92008-05-12 21:20:42 +0200168#ifdef CONFIG_IRQSOFF_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100169 extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
170 extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
Steven Rostedt81d68a92008-05-12 21:20:42 +0200171#else
172# define time_hardirqs_on(a0, a1) do { } while (0)
173# define time_hardirqs_off(a0, a1) do { } while (0)
174#endif
175
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200176#ifdef CONFIG_PREEMPT_TRACER
Ingo Molnar489f1392008-02-25 13:38:05 +0100177 extern void trace_preempt_on(unsigned long a0, unsigned long a1);
178 extern void trace_preempt_off(unsigned long a0, unsigned long a1);
Steven Rostedt6cd8a4b2008-05-12 21:20:42 +0200179#else
180# define trace_preempt_on(a0, a1) do { } while (0)
181# define trace_preempt_off(a0, a1) do { } while (0)
182#endif
183
Ingo Molnarb1829d22008-05-28 01:22:08 +0200184#ifdef CONFIG_TRACING
Ingo Molnar74f4e362008-05-12 21:21:15 +0200185extern void
186ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
Steven Rostedt2f2c99d2008-08-01 16:45:49 -0400187
188/**
189 * ftrace_printk - printf formatting in the ftrace buffer
190 * @fmt: the printf format for printing
191 *
192 * Note: __ftrace_printk is an internal function for ftrace_printk and
193 * the @ip is passed in via the ftrace_printk macro.
194 *
195 * This function allows a kernel developer to debug fast path sections
196 * that printk is not appropriate for. By scattering in various
197 * printk like tracing in the code, a developer can quickly see
198 * where problems are occurring.
199 *
200 * This is intended as a debugging tool for the developer only.
201 * Please refrain from leaving ftrace_printks scattered around in
202 * your code.
203 */
204# define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400205extern int
206__ftrace_printk(unsigned long ip, const char *fmt, ...)
207 __attribute__ ((format (printf, 2, 3)));
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400208extern void ftrace_dump(void);
Ingo Molnar74f4e362008-05-12 21:21:15 +0200209#else
210static inline void
211ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400212static inline int
Ingo Molnar7b928c22008-08-15 17:48:02 +0200213ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
214
215static inline int
216ftrace_printk(const char *fmt, ...)
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400217{
218 return 0;
219}
Steven Rostedt3f5a54e2008-07-30 22:36:46 -0400220static inline void ftrace_dump(void) { }
Ingo Molnar74f4e362008-05-12 21:21:15 +0200221#endif
222
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400223#ifdef CONFIG_FTRACE_MCOUNT_RECORD
224extern void ftrace_init(void);
Steven Rostedt90d595f2008-08-14 15:45:09 -0400225extern void ftrace_init_module(unsigned long *start, unsigned long *end);
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400226#else
227static inline void ftrace_init(void) { }
Steven Rostedt90d595f2008-08-14 15:45:09 -0400228static inline void
229ftrace_init_module(unsigned long *start, unsigned long *end) { }
Steven Rostedt68bf21a2008-08-14 15:45:08 -0400230#endif
231
Steven Rostedtdd0e5452008-08-01 12:26:41 -0400232
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100233struct boot_trace {
234 pid_t caller;
Hugh Dickins9c246242008-12-09 13:14:27 -0800235 char func[KSYM_SYMBOL_LEN];
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100236 int result;
Tim Birdca538f62008-10-09 15:23:05 -0700237 unsigned long long duration; /* usecs */
Frederic Weisbeckercb5ab742008-10-02 12:59:20 +0200238 ktime_t calltime;
239 ktime_t rettime;
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100240};
241
242#ifdef CONFIG_BOOT_TRACER
Frederic Weisbecker56010202008-10-02 13:26:05 +0200243extern void trace_boot(struct boot_trace *it, initcall_t fn);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100244extern void start_boot_trace(void);
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200245extern void stop_boot_trace(void);
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100246#else
Frederic Weisbecker56010202008-10-02 13:26:05 +0200247static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100248static inline void start_boot_trace(void) { }
Frederic Weisbecker097d0362008-10-03 15:39:21 +0200249static inline void stop_boot_trace(void) { }
Frédéric Weisbeckerd13744c2008-09-23 11:32:08 +0100250#endif
251
252
253
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200254#endif /* _LINUX_FTRACE_H */