Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | #ifndef _LINUX_FTRACE_H |
| 2 | #define _LINUX_FTRACE_H |
| 3 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 4 | #include <linux/linkage.h> |
Ingo Molnar | d49dbf3 | 2008-05-16 10:41:53 +0200 | [diff] [blame] | 5 | #include <linux/fs.h> |
Steven Noonan | eb7fa935 | 2008-10-02 12:00:07 -0700 | [diff] [blame] | 6 | #include <linux/ktime.h> |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 7 | #include <linux/init.h> |
| 8 | #include <linux/types.h> |
Frederic Weisbecker | 5601020 | 2008-10-02 13:26:05 +0200 | [diff] [blame] | 9 | #include <linux/kallsyms.h> |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 10 | |
Ingo Molnar | 3e1932a | 2008-10-02 17:45:47 +0200 | [diff] [blame] | 11 | #ifdef CONFIG_FTRACE |
| 12 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 13 | extern int ftrace_enabled; |
| 14 | extern int |
| 15 | ftrace_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 Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 19 | typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip); |
| 20 | |
| 21 | struct 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 | */ |
| 33 | int register_ftrace_function(struct ftrace_ops *ops); |
| 34 | int unregister_ftrace_function(struct ftrace_ops *ops); |
| 35 | void clear_ftrace_function(void); |
| 36 | |
| 37 | extern void ftrace_stub(unsigned long a0, unsigned long a1); |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 38 | |
| 39 | #else /* !CONFIG_FTRACE */ |
| 40 | # 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 Molnar | c5131ad | 2008-08-15 18:22:09 +0200 | [diff] [blame] | 43 | static inline void ftrace_kill_atomic(void) { } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 44 | #endif /* CONFIG_FTRACE */ |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 45 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 47 | # define FTRACE_HASHBITS 10 |
| 48 | # define FTRACE_HASHSIZE (1<<FTRACE_HASHBITS) |
| 49 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 50 | enum { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 51 | FTRACE_FL_FREE = (1 << 0), |
| 52 | FTRACE_FL_FAILED = (1 << 1), |
| 53 | FTRACE_FL_FILTER = (1 << 2), |
| 54 | FTRACE_FL_ENABLED = (1 << 3), |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 55 | FTRACE_FL_NOTRACE = (1 << 4), |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 56 | FTRACE_FL_CONVERTED = (1 << 5), |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 57 | FTRACE_FL_FROZEN = (1 << 6), |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 60 | struct dyn_ftrace { |
| 61 | struct hlist_node node; |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 62 | unsigned long ip; /* address of mcount call-site */ |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 63 | unsigned long flags; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 64 | }; |
| 65 | |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 66 | int ftrace_force_update(void); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 67 | void ftrace_set_filter(unsigned char *buf, int len, int reset); |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 68 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 69 | /* defined in arch */ |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 70 | extern int ftrace_ip_converted(unsigned long ip); |
| 71 | extern unsigned char *ftrace_nop_replace(void); |
| 72 | extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 73 | extern int ftrace_dyn_arch_init(void *data); |
| 74 | extern int ftrace_mcount_set(unsigned long *data); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 75 | extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code, |
| 76 | unsigned char *new_code); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 77 | extern int ftrace_update_ftrace_func(ftrace_func_t func); |
| 78 | extern void ftrace_caller(void); |
| 79 | extern void ftrace_call(void); |
| 80 | extern void mcount_call(void); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 81 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 82 | extern int skip_trace(unsigned long ip); |
| 83 | |
Steven Rostedt | c0719e5 | 2008-09-06 01:06:03 -0400 | [diff] [blame] | 84 | extern void ftrace_release(void *start, unsigned long size); |
| 85 | |
| 86 | extern void ftrace_disable_daemon(void); |
| 87 | extern void ftrace_enable_daemon(void); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 88 | |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 89 | #else |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 90 | # define skip_trace(ip) ({ 0; }) |
Ingo Molnar | aeaee8a | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 91 | # define ftrace_force_update() ({ 0; }) |
| 92 | # define ftrace_set_filter(buf, len, reset) do { } while (0) |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 93 | # define ftrace_disable_daemon() do { } while (0) |
| 94 | # define ftrace_enable_daemon() do { } while (0) |
Steven Rostedt | c0719e5 | 2008-09-06 01:06:03 -0400 | [diff] [blame] | 95 | static inline void ftrace_release(void *start, unsigned long size) { } |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 96 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 97 | |
Ingo Molnar | aeaee8a | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 98 | /* totally disable ftrace - can not re-enable after this */ |
| 99 | void ftrace_kill(void); |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 100 | void ftrace_kill_atomic(void); |
Ingo Molnar | aeaee8a | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 101 | |
Ingo Molnar | f43fdad | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 102 | static inline void tracer_disable(void) |
| 103 | { |
| 104 | #ifdef CONFIG_FTRACE |
| 105 | ftrace_enabled = 0; |
| 106 | #endif |
| 107 | } |
| 108 | |
Huang Ying | 3700273 | 2008-08-18 16:24:56 +0800 | [diff] [blame] | 109 | /* |
| 110 | * Ftrace disable/restore without lock. Some synchronization mechanism |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 111 | * must be used to prevent ftrace_enabled to be changed between |
Huang Ying | 3700273 | 2008-08-18 16:24:56 +0800 | [diff] [blame] | 112 | * disable/restore. |
| 113 | */ |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 114 | static inline int __ftrace_enabled_save(void) |
| 115 | { |
| 116 | #ifdef CONFIG_FTRACE |
| 117 | int saved_ftrace_enabled = ftrace_enabled; |
| 118 | ftrace_enabled = 0; |
| 119 | return saved_ftrace_enabled; |
| 120 | #else |
| 121 | return 0; |
| 122 | #endif |
| 123 | } |
| 124 | |
| 125 | static inline void __ftrace_enabled_restore(int enabled) |
| 126 | { |
| 127 | #ifdef CONFIG_FTRACE |
| 128 | ftrace_enabled = enabled; |
| 129 | #endif |
| 130 | } |
| 131 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_FRAME_POINTER |
| 133 | /* TODO: need to fix this for ARM */ |
| 134 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
| 135 | # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1)) |
| 136 | # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2)) |
| 137 | # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3)) |
| 138 | # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4)) |
| 139 | # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5)) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 140 | # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6)) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 141 | #else |
| 142 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
| 143 | # define CALLER_ADDR1 0UL |
| 144 | # define CALLER_ADDR2 0UL |
| 145 | # define CALLER_ADDR3 0UL |
| 146 | # define CALLER_ADDR4 0UL |
| 147 | # define CALLER_ADDR5 0UL |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 148 | # define CALLER_ADDR6 0UL |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 149 | #endif |
| 150 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_IRQSOFF_TRACER |
Ingo Molnar | 489f139 | 2008-02-25 13:38:05 +0100 | [diff] [blame] | 152 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); |
| 153 | extern void time_hardirqs_off(unsigned long a0, unsigned long a1); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 154 | #else |
| 155 | # define time_hardirqs_on(a0, a1) do { } while (0) |
| 156 | # define time_hardirqs_off(a0, a1) do { } while (0) |
| 157 | #endif |
| 158 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 159 | #ifdef CONFIG_PREEMPT_TRACER |
Ingo Molnar | 489f139 | 2008-02-25 13:38:05 +0100 | [diff] [blame] | 160 | extern void trace_preempt_on(unsigned long a0, unsigned long a1); |
| 161 | extern void trace_preempt_off(unsigned long a0, unsigned long a1); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 162 | #else |
| 163 | # define trace_preempt_on(a0, a1) do { } while (0) |
| 164 | # define trace_preempt_off(a0, a1) do { } while (0) |
| 165 | #endif |
| 166 | |
Ingo Molnar | b1829d2 | 2008-05-28 01:22:08 +0200 | [diff] [blame] | 167 | #ifdef CONFIG_TRACING |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 168 | extern void |
| 169 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3); |
Steven Rostedt | 2f2c99d | 2008-08-01 16:45:49 -0400 | [diff] [blame] | 170 | |
| 171 | /** |
| 172 | * ftrace_printk - printf formatting in the ftrace buffer |
| 173 | * @fmt: the printf format for printing |
| 174 | * |
| 175 | * Note: __ftrace_printk is an internal function for ftrace_printk and |
| 176 | * the @ip is passed in via the ftrace_printk macro. |
| 177 | * |
| 178 | * This function allows a kernel developer to debug fast path sections |
| 179 | * that printk is not appropriate for. By scattering in various |
| 180 | * printk like tracing in the code, a developer can quickly see |
| 181 | * where problems are occurring. |
| 182 | * |
| 183 | * This is intended as a debugging tool for the developer only. |
| 184 | * Please refrain from leaving ftrace_printks scattered around in |
| 185 | * your code. |
| 186 | */ |
| 187 | # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 188 | extern int |
| 189 | __ftrace_printk(unsigned long ip, const char *fmt, ...) |
| 190 | __attribute__ ((format (printf, 2, 3))); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 191 | extern void ftrace_dump(void); |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 192 | #else |
| 193 | static inline void |
| 194 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 195 | static inline int |
Ingo Molnar | 7b928c2 | 2008-08-15 17:48:02 +0200 | [diff] [blame] | 196 | ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0))); |
| 197 | |
| 198 | static inline int |
| 199 | ftrace_printk(const char *fmt, ...) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 200 | { |
| 201 | return 0; |
| 202 | } |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 203 | static inline void ftrace_dump(void) { } |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 204 | #endif |
| 205 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 206 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
| 207 | extern void ftrace_init(void); |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 208 | extern void ftrace_init_module(unsigned long *start, unsigned long *end); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 209 | #else |
| 210 | static inline void ftrace_init(void) { } |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 211 | static inline void |
| 212 | ftrace_init_module(unsigned long *start, unsigned long *end) { } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 213 | #endif |
| 214 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 215 | |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 216 | struct boot_trace { |
| 217 | pid_t caller; |
Tim Bird | ca538f6 | 2008-10-09 15:23:05 -0700 | [diff] [blame^] | 218 | char func[KSYM_NAME_LEN]; |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 219 | int result; |
Tim Bird | ca538f6 | 2008-10-09 15:23:05 -0700 | [diff] [blame^] | 220 | unsigned long long duration; /* usecs */ |
Frederic Weisbecker | cb5ab74 | 2008-10-02 12:59:20 +0200 | [diff] [blame] | 221 | ktime_t calltime; |
| 222 | ktime_t rettime; |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | #ifdef CONFIG_BOOT_TRACER |
Frederic Weisbecker | 5601020 | 2008-10-02 13:26:05 +0200 | [diff] [blame] | 226 | extern void trace_boot(struct boot_trace *it, initcall_t fn); |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 227 | extern void start_boot_trace(void); |
Frederic Weisbecker | 097d036 | 2008-10-03 15:39:21 +0200 | [diff] [blame] | 228 | extern void stop_boot_trace(void); |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 229 | #else |
Frederic Weisbecker | 5601020 | 2008-10-02 13:26:05 +0200 | [diff] [blame] | 230 | static inline void trace_boot(struct boot_trace *it, initcall_t fn) { } |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 231 | static inline void start_boot_trace(void) { } |
Frederic Weisbecker | 097d036 | 2008-10-03 15:39:21 +0200 | [diff] [blame] | 232 | static inline void stop_boot_trace(void) { } |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 233 | #endif |
| 234 | |
| 235 | |
| 236 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 237 | #endif /* _LINUX_FTRACE_H */ |