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 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 11 | #ifdef CONFIG_FUNCTION_TRACER |
Ingo Molnar | 3e1932a | 2008-10-02 17:45:47 +0200 | [diff] [blame] | 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 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 39 | #else /* !CONFIG_FUNCTION_TRACER */ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 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) |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 43 | static inline void ftrace_kill(void) { } |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 44 | #endif /* CONFIG_FUNCTION_TRACER */ |
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 |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 47 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 48 | enum { |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 49 | FTRACE_FL_FREE = (1 << 0), |
| 50 | FTRACE_FL_FAILED = (1 << 1), |
| 51 | FTRACE_FL_FILTER = (1 << 2), |
| 52 | FTRACE_FL_ENABLED = (1 << 3), |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 53 | FTRACE_FL_NOTRACE = (1 << 4), |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 54 | FTRACE_FL_CONVERTED = (1 << 5), |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 55 | FTRACE_FL_FROZEN = (1 << 6), |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 56 | }; |
| 57 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 58 | struct dyn_ftrace { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 59 | struct list_head list; |
| 60 | unsigned long ip; /* address of mcount call-site */ |
| 61 | unsigned long flags; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 64 | int ftrace_force_update(void); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 65 | void ftrace_set_filter(unsigned char *buf, int len, int reset); |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 66 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 67 | /* defined in arch */ |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 68 | extern int ftrace_ip_converted(unsigned long ip); |
| 69 | extern unsigned char *ftrace_nop_replace(void); |
| 70 | extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 71 | extern int ftrace_dyn_arch_init(void *data); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 72 | extern int ftrace_update_ftrace_func(ftrace_func_t func); |
| 73 | extern void ftrace_caller(void); |
| 74 | extern void ftrace_call(void); |
| 75 | extern void mcount_call(void); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 76 | |
Steven Rostedt | a26a2a2 | 2008-10-31 00:03:22 -0400 | [diff] [blame] | 77 | /* May be defined in arch */ |
| 78 | extern int ftrace_arch_read_dyn_info(char *buf, int size); |
| 79 | |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 80 | /** |
| 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 | */ |
| 99 | extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code, |
| 100 | unsigned char *new_code); |
| 101 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 102 | extern int skip_trace(unsigned long ip); |
| 103 | |
Steven Rostedt | c0719e5 | 2008-09-06 01:06:03 -0400 | [diff] [blame] | 104 | extern void ftrace_release(void *start, unsigned long size); |
| 105 | |
| 106 | extern void ftrace_disable_daemon(void); |
| 107 | extern void ftrace_enable_daemon(void); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 108 | |
Steven Rostedt | e1c08bd | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 109 | #else |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 110 | # define skip_trace(ip) ({ 0; }) |
Ingo Molnar | aeaee8a | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 111 | # define ftrace_force_update() ({ 0; }) |
| 112 | # define ftrace_set_filter(buf, len, reset) do { } while (0) |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 113 | # define ftrace_disable_daemon() do { } while (0) |
| 114 | # define ftrace_enable_daemon() do { } while (0) |
Steven Rostedt | c0719e5 | 2008-09-06 01:06:03 -0400 | [diff] [blame] | 115 | static inline void ftrace_release(void *start, unsigned long size) { } |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 116 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 117 | |
Ingo Molnar | aeaee8a | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 118 | /* totally disable ftrace - can not re-enable after this */ |
| 119 | void ftrace_kill(void); |
| 120 | |
Ingo Molnar | f43fdad | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 121 | static inline void tracer_disable(void) |
| 122 | { |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 123 | #ifdef CONFIG_FUNCTION_TRACER |
Ingo Molnar | f43fdad | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 124 | ftrace_enabled = 0; |
| 125 | #endif |
| 126 | } |
| 127 | |
Huang Ying | 3700273 | 2008-08-18 16:24:56 +0800 | [diff] [blame] | 128 | /* |
| 129 | * Ftrace disable/restore without lock. Some synchronization mechanism |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 130 | * must be used to prevent ftrace_enabled to be changed between |
Huang Ying | 3700273 | 2008-08-18 16:24:56 +0800 | [diff] [blame] | 131 | * disable/restore. |
| 132 | */ |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 133 | static inline int __ftrace_enabled_save(void) |
| 134 | { |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 135 | #ifdef CONFIG_FUNCTION_TRACER |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 136 | int saved_ftrace_enabled = ftrace_enabled; |
| 137 | ftrace_enabled = 0; |
| 138 | return saved_ftrace_enabled; |
| 139 | #else |
| 140 | return 0; |
| 141 | #endif |
| 142 | } |
| 143 | |
| 144 | static inline void __ftrace_enabled_restore(int enabled) |
| 145 | { |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 146 | #ifdef CONFIG_FUNCTION_TRACER |
Huang Ying | 9bdeb7b | 2008-08-15 00:40:25 -0700 | [diff] [blame] | 147 | ftrace_enabled = enabled; |
| 148 | #endif |
| 149 | } |
| 150 | |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_FRAME_POINTER |
| 152 | /* TODO: need to fix this for ARM */ |
| 153 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
| 154 | # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1)) |
| 155 | # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2)) |
| 156 | # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3)) |
| 157 | # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4)) |
| 158 | # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5)) |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 159 | # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6)) |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 160 | #else |
| 161 | # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0)) |
| 162 | # define CALLER_ADDR1 0UL |
| 163 | # define CALLER_ADDR2 0UL |
| 164 | # define CALLER_ADDR3 0UL |
| 165 | # define CALLER_ADDR4 0UL |
| 166 | # define CALLER_ADDR5 0UL |
Ingo Molnar | 86387f7 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 167 | # define CALLER_ADDR6 0UL |
Steven Rostedt | 352ad25 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 168 | #endif |
| 169 | |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 170 | #ifdef CONFIG_IRQSOFF_TRACER |
Ingo Molnar | 489f139 | 2008-02-25 13:38:05 +0100 | [diff] [blame] | 171 | extern void time_hardirqs_on(unsigned long a0, unsigned long a1); |
| 172 | extern void time_hardirqs_off(unsigned long a0, unsigned long a1); |
Steven Rostedt | 81d68a9 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 173 | #else |
| 174 | # define time_hardirqs_on(a0, a1) do { } while (0) |
| 175 | # define time_hardirqs_off(a0, a1) do { } while (0) |
| 176 | #endif |
| 177 | |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 178 | #ifdef CONFIG_PREEMPT_TRACER |
Ingo Molnar | 489f139 | 2008-02-25 13:38:05 +0100 | [diff] [blame] | 179 | extern void trace_preempt_on(unsigned long a0, unsigned long a1); |
| 180 | extern void trace_preempt_off(unsigned long a0, unsigned long a1); |
Steven Rostedt | 6cd8a4b | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 181 | #else |
| 182 | # define trace_preempt_on(a0, a1) do { } while (0) |
| 183 | # define trace_preempt_off(a0, a1) do { } while (0) |
| 184 | #endif |
| 185 | |
Ingo Molnar | b1829d2 | 2008-05-28 01:22:08 +0200 | [diff] [blame] | 186 | #ifdef CONFIG_TRACING |
Steven Rostedt | 944ac42 | 2008-10-23 19:26:08 -0400 | [diff] [blame] | 187 | extern int ftrace_dump_on_oops; |
| 188 | |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 189 | extern void |
| 190 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3); |
Steven Rostedt | 2f2c99d | 2008-08-01 16:45:49 -0400 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * ftrace_printk - printf formatting in the ftrace buffer |
| 194 | * @fmt: the printf format for printing |
| 195 | * |
| 196 | * Note: __ftrace_printk is an internal function for ftrace_printk and |
| 197 | * the @ip is passed in via the ftrace_printk macro. |
| 198 | * |
| 199 | * This function allows a kernel developer to debug fast path sections |
| 200 | * that printk is not appropriate for. By scattering in various |
| 201 | * printk like tracing in the code, a developer can quickly see |
| 202 | * where problems are occurring. |
| 203 | * |
| 204 | * This is intended as a debugging tool for the developer only. |
| 205 | * Please refrain from leaving ftrace_printks scattered around in |
| 206 | * your code. |
| 207 | */ |
| 208 | # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 209 | extern int |
| 210 | __ftrace_printk(unsigned long ip, const char *fmt, ...) |
| 211 | __attribute__ ((format (printf, 2, 3))); |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 212 | extern void ftrace_dump(void); |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 213 | #else |
| 214 | static inline void |
| 215 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 216 | static inline int |
Ingo Molnar | 7b928c2 | 2008-08-15 17:48:02 +0200 | [diff] [blame] | 217 | ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0))); |
| 218 | |
| 219 | static inline int |
| 220 | ftrace_printk(const char *fmt, ...) |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 221 | { |
| 222 | return 0; |
| 223 | } |
Steven Rostedt | 3f5a54e | 2008-07-30 22:36:46 -0400 | [diff] [blame] | 224 | static inline void ftrace_dump(void) { } |
Ingo Molnar | 74f4e36 | 2008-05-12 21:21:15 +0200 | [diff] [blame] | 225 | #endif |
| 226 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 227 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
| 228 | extern void ftrace_init(void); |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 229 | extern void ftrace_init_module(unsigned long *start, unsigned long *end); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 230 | #else |
| 231 | static inline void ftrace_init(void) { } |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 232 | static inline void |
| 233 | ftrace_init_module(unsigned long *start, unsigned long *end) { } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 234 | #endif |
| 235 | |
Steven Rostedt | dd0e545 | 2008-08-01 12:26:41 -0400 | [diff] [blame] | 236 | |
Frederic Weisbecker | 71566a0 | 2008-10-31 12:57:20 +0100 | [diff] [blame^] | 237 | /* |
| 238 | * Structure which defines the trace of an initcall. |
| 239 | * You don't have to fill the func field since it is |
| 240 | * only used internally by the tracer. |
| 241 | */ |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 242 | struct boot_trace { |
| 243 | pid_t caller; |
Tim Bird | ca538f6 | 2008-10-09 15:23:05 -0700 | [diff] [blame] | 244 | char func[KSYM_NAME_LEN]; |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 245 | int result; |
Tim Bird | ca538f6 | 2008-10-09 15:23:05 -0700 | [diff] [blame] | 246 | unsigned long long duration; /* usecs */ |
Frederic Weisbecker | cb5ab74 | 2008-10-02 12:59:20 +0200 | [diff] [blame] | 247 | ktime_t calltime; |
| 248 | ktime_t rettime; |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | #ifdef CONFIG_BOOT_TRACER |
Frederic Weisbecker | 71566a0 | 2008-10-31 12:57:20 +0100 | [diff] [blame^] | 252 | /* Append the trace on the ring-buffer */ |
Frederic Weisbecker | 5601020 | 2008-10-02 13:26:05 +0200 | [diff] [blame] | 253 | extern void trace_boot(struct boot_trace *it, initcall_t fn); |
Frederic Weisbecker | 71566a0 | 2008-10-31 12:57:20 +0100 | [diff] [blame^] | 254 | |
| 255 | /* Tells the tracer that smp_pre_initcall is finished. |
| 256 | * So we can start the tracing |
| 257 | */ |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 258 | extern void start_boot_trace(void); |
Frederic Weisbecker | 71566a0 | 2008-10-31 12:57:20 +0100 | [diff] [blame^] | 259 | |
| 260 | /* Resume the tracing of other necessary events |
| 261 | * such as sched switches |
| 262 | */ |
| 263 | extern void enable_boot_trace(void); |
| 264 | |
| 265 | /* Suspend this tracing. Actually, only sched_switches tracing have |
| 266 | * to be suspended. Initcalls doesn't need it.) |
| 267 | */ |
| 268 | extern void disable_boot_trace(void); |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 269 | #else |
Frederic Weisbecker | 5601020 | 2008-10-02 13:26:05 +0200 | [diff] [blame] | 270 | 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] | 271 | static inline void start_boot_trace(void) { } |
Frederic Weisbecker | 71566a0 | 2008-10-31 12:57:20 +0100 | [diff] [blame^] | 272 | static inline void enable_boot_trace(void) { } |
| 273 | static inline void disable_boot_trace(void) { } |
Frédéric Weisbecker | d13744c | 2008-09-23 11:32:08 +0100 | [diff] [blame] | 274 | #endif |
| 275 | |
| 276 | |
| 277 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 278 | #endif /* _LINUX_FTRACE_H */ |