Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ring buffer based function tracer |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 5 | * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com> |
| 6 | * |
| 7 | * Based on code from the latency_tracer, that is: |
| 8 | * |
| 9 | * Copyright (C) 2004-2006 Ingo Molnar |
| 10 | * Copyright (C) 2004 William Lee Irwin III |
| 11 | */ |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 12 | #include <linux/ring_buffer.h> |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 13 | #include <linux/debugfs.h> |
| 14 | #include <linux/uaccess.h> |
| 15 | #include <linux/ftrace.h> |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 16 | #include <linux/fs.h> |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 17 | |
| 18 | #include "trace.h" |
| 19 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 20 | /* function tracing enabled */ |
| 21 | static int ftrace_function_enabled; |
| 22 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 23 | static struct trace_array *func_trace; |
| 24 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 25 | static void tracing_start_function_trace(void); |
| 26 | static void tracing_stop_function_trace(void); |
| 27 | |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 28 | static int function_trace_init(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 29 | { |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 30 | func_trace = tr; |
Steven Rostedt | 26bc83f | 2008-07-10 20:58:14 -0400 | [diff] [blame] | 31 | tr->cpu = get_cpu(); |
Steven Rostedt | 26bc83f | 2008-07-10 20:58:14 -0400 | [diff] [blame] | 32 | put_cpu(); |
| 33 | |
Steven Rostedt | 41bc814 | 2008-05-22 11:49:22 -0400 | [diff] [blame] | 34 | tracing_start_cmdline_record(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 35 | tracing_start_function_trace(); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 36 | return 0; |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 37 | } |
| 38 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 39 | static void function_trace_reset(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 40 | { |
Arnaldo Carvalho de Melo | b6f11df | 2009-02-05 18:02:00 -0200 | [diff] [blame] | 41 | tracing_stop_function_trace(); |
| 42 | tracing_stop_cmdline_record(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 45 | static void function_trace_start(struct trace_array *tr) |
| 46 | { |
Pekka J Enberg | 213cc06 | 2008-12-19 12:08:39 +0200 | [diff] [blame] | 47 | tracing_reset_online_cpus(tr); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 50 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 51 | function_trace_call_preempt_only(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame^] | 52 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 53 | { |
| 54 | struct trace_array *tr = func_trace; |
| 55 | struct trace_array_cpu *data; |
| 56 | unsigned long flags; |
| 57 | long disabled; |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 58 | int cpu; |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 59 | int pc; |
| 60 | |
| 61 | if (unlikely(!ftrace_function_enabled)) |
| 62 | return; |
| 63 | |
| 64 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 65 | preempt_disable_notrace(); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 66 | local_save_flags(flags); |
| 67 | cpu = raw_smp_processor_id(); |
| 68 | data = tr->data[cpu]; |
| 69 | disabled = atomic_inc_return(&data->disabled); |
| 70 | |
| 71 | if (likely(disabled == 1)) |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 72 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 73 | |
| 74 | atomic_dec(&data->disabled); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 75 | preempt_enable_notrace(); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 79 | function_trace_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame^] | 80 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
| 81 | |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 82 | { |
| 83 | struct trace_array *tr = func_trace; |
| 84 | struct trace_array_cpu *data; |
| 85 | unsigned long flags; |
| 86 | long disabled; |
| 87 | int cpu; |
| 88 | int pc; |
| 89 | |
| 90 | if (unlikely(!ftrace_function_enabled)) |
| 91 | return; |
| 92 | |
| 93 | /* |
| 94 | * Need to use raw, since this must be called before the |
| 95 | * recursive protection is performed. |
| 96 | */ |
| 97 | local_irq_save(flags); |
| 98 | cpu = raw_smp_processor_id(); |
| 99 | data = tr->data[cpu]; |
| 100 | disabled = atomic_inc_return(&data->disabled); |
| 101 | |
| 102 | if (likely(disabled == 1)) { |
| 103 | pc = preempt_count(); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 104 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | atomic_dec(&data->disabled); |
| 108 | local_irq_restore(flags); |
| 109 | } |
| 110 | |
| 111 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 112 | function_stack_trace_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame^] | 113 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 114 | { |
| 115 | struct trace_array *tr = func_trace; |
| 116 | struct trace_array_cpu *data; |
| 117 | unsigned long flags; |
| 118 | long disabled; |
| 119 | int cpu; |
| 120 | int pc; |
| 121 | |
| 122 | if (unlikely(!ftrace_function_enabled)) |
| 123 | return; |
| 124 | |
| 125 | /* |
| 126 | * Need to use raw, since this must be called before the |
| 127 | * recursive protection is performed. |
| 128 | */ |
| 129 | local_irq_save(flags); |
| 130 | cpu = raw_smp_processor_id(); |
| 131 | data = tr->data[cpu]; |
| 132 | disabled = atomic_inc_return(&data->disabled); |
| 133 | |
| 134 | if (likely(disabled == 1)) { |
| 135 | pc = preempt_count(); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 136 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 137 | /* |
| 138 | * skip over 5 funcs: |
| 139 | * __ftrace_trace_stack, |
| 140 | * __trace_stack, |
| 141 | * function_stack_trace_call |
| 142 | * ftrace_list_func |
| 143 | * ftrace_call |
| 144 | */ |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 145 | __trace_stack(tr, flags, 5, pc); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | atomic_dec(&data->disabled); |
| 149 | local_irq_restore(flags); |
| 150 | } |
| 151 | |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 152 | |
| 153 | static struct ftrace_ops trace_ops __read_mostly = |
| 154 | { |
| 155 | .func = function_trace_call, |
Steven Rostedt | b848914 | 2011-05-04 09:27:52 -0400 | [diff] [blame] | 156 | .flags = FTRACE_OPS_FL_GLOBAL, |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 157 | }; |
| 158 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 159 | static struct ftrace_ops trace_stack_ops __read_mostly = |
| 160 | { |
| 161 | .func = function_stack_trace_call, |
Steven Rostedt | b848914 | 2011-05-04 09:27:52 -0400 | [diff] [blame] | 162 | .flags = FTRACE_OPS_FL_GLOBAL, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | /* Our two options */ |
| 166 | enum { |
| 167 | TRACE_FUNC_OPT_STACK = 0x1, |
| 168 | }; |
| 169 | |
| 170 | static struct tracer_opt func_opts[] = { |
| 171 | #ifdef CONFIG_STACKTRACE |
| 172 | { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) }, |
| 173 | #endif |
| 174 | { } /* Always set a last empty entry */ |
| 175 | }; |
| 176 | |
| 177 | static struct tracer_flags func_flags = { |
| 178 | .val = 0, /* By default: all flags disabled */ |
| 179 | .opts = func_opts |
| 180 | }; |
| 181 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 182 | static void tracing_start_function_trace(void) |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 183 | { |
| 184 | ftrace_function_enabled = 0; |
| 185 | |
| 186 | if (trace_flags & TRACE_ITER_PREEMPTONLY) |
| 187 | trace_ops.func = function_trace_call_preempt_only; |
| 188 | else |
| 189 | trace_ops.func = function_trace_call; |
| 190 | |
| 191 | if (func_flags.val & TRACE_FUNC_OPT_STACK) |
| 192 | register_ftrace_function(&trace_stack_ops); |
| 193 | else |
| 194 | register_ftrace_function(&trace_ops); |
| 195 | |
| 196 | ftrace_function_enabled = 1; |
| 197 | } |
| 198 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 199 | static void tracing_stop_function_trace(void) |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 200 | { |
| 201 | ftrace_function_enabled = 0; |
Frederic Weisbecker | c85a17e | 2009-06-20 05:45:14 +0200 | [diff] [blame] | 202 | |
| 203 | if (func_flags.val & TRACE_FUNC_OPT_STACK) |
| 204 | unregister_ftrace_function(&trace_stack_ops); |
| 205 | else |
| 206 | unregister_ftrace_function(&trace_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 207 | } |
| 208 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 209 | static int func_set_flag(u32 old_flags, u32 bit, int set) |
| 210 | { |
| 211 | if (bit == TRACE_FUNC_OPT_STACK) { |
| 212 | /* do nothing if already set */ |
| 213 | if (!!set == !!(func_flags.val & TRACE_FUNC_OPT_STACK)) |
| 214 | return 0; |
| 215 | |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 216 | if (set) { |
| 217 | unregister_ftrace_function(&trace_ops); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 218 | register_ftrace_function(&trace_stack_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 219 | } else { |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 220 | unregister_ftrace_function(&trace_stack_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 221 | register_ftrace_function(&trace_ops); |
| 222 | } |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | return -EINVAL; |
| 228 | } |
| 229 | |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 230 | static struct tracer function_trace __read_mostly = |
| 231 | { |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 232 | .name = "function", |
| 233 | .init = function_trace_init, |
| 234 | .reset = function_trace_reset, |
| 235 | .start = function_trace_start, |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 236 | .wait_pipe = poll_wait_pipe, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 237 | .flags = &func_flags, |
| 238 | .set_flag = func_set_flag, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 239 | #ifdef CONFIG_FTRACE_SELFTEST |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 240 | .selftest = trace_selftest_startup_function, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 241 | #endif |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 244 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 245 | static void |
| 246 | ftrace_traceon(unsigned long ip, unsigned long parent_ip, void **data) |
| 247 | { |
| 248 | long *count = (long *)data; |
| 249 | |
| 250 | if (tracing_is_on()) |
| 251 | return; |
| 252 | |
| 253 | if (!*count) |
| 254 | return; |
| 255 | |
| 256 | if (*count != -1) |
| 257 | (*count)--; |
| 258 | |
| 259 | tracing_on(); |
| 260 | } |
| 261 | |
| 262 | static void |
| 263 | ftrace_traceoff(unsigned long ip, unsigned long parent_ip, void **data) |
| 264 | { |
| 265 | long *count = (long *)data; |
| 266 | |
| 267 | if (!tracing_is_on()) |
| 268 | return; |
| 269 | |
| 270 | if (!*count) |
| 271 | return; |
| 272 | |
| 273 | if (*count != -1) |
| 274 | (*count)--; |
| 275 | |
| 276 | tracing_off(); |
| 277 | } |
| 278 | |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 279 | static int |
| 280 | ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip, |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 281 | struct ftrace_probe_ops *ops, void *data); |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 282 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 283 | static struct ftrace_probe_ops traceon_probe_ops = { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 284 | .func = ftrace_traceon, |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 285 | .print = ftrace_trace_onoff_print, |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 286 | }; |
| 287 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 288 | static struct ftrace_probe_ops traceoff_probe_ops = { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 289 | .func = ftrace_traceoff, |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 290 | .print = ftrace_trace_onoff_print, |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | static int |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 294 | ftrace_trace_onoff_print(struct seq_file *m, unsigned long ip, |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 295 | struct ftrace_probe_ops *ops, void *data) |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 296 | { |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 297 | long count = (long)data; |
| 298 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 299 | seq_printf(m, "%ps:", (void *)ip); |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 300 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 301 | if (ops == &traceon_probe_ops) |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 302 | seq_printf(m, "traceon"); |
| 303 | else |
| 304 | seq_printf(m, "traceoff"); |
| 305 | |
Steven Rostedt | 35ebf1c | 2009-02-17 13:12:12 -0500 | [diff] [blame] | 306 | if (count == -1) |
| 307 | seq_printf(m, ":unlimited\n"); |
| 308 | else |
Li Zefan | 00e54d0 | 2009-06-25 14:05:27 +0800 | [diff] [blame] | 309 | seq_printf(m, ":count=%ld\n", count); |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static int |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 315 | ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param) |
| 316 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 317 | struct ftrace_probe_ops *ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 318 | |
| 319 | /* we register both traceon and traceoff to this callback */ |
| 320 | if (strcmp(cmd, "traceon") == 0) |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 321 | ops = &traceon_probe_ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 322 | else |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 323 | ops = &traceoff_probe_ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 324 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 325 | unregister_ftrace_function_probe_func(glob, ops); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int |
Steven Rostedt | 43dd61c | 2011-07-07 11:09:22 -0400 | [diff] [blame] | 331 | ftrace_trace_onoff_callback(struct ftrace_hash *hash, |
| 332 | char *glob, char *cmd, char *param, int enable) |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 333 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 334 | struct ftrace_probe_ops *ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 335 | void *count = (void *)-1; |
| 336 | char *number; |
| 337 | int ret; |
| 338 | |
| 339 | /* hash funcs only work with set_ftrace_filter */ |
| 340 | if (!enable) |
| 341 | return -EINVAL; |
| 342 | |
| 343 | if (glob[0] == '!') |
| 344 | return ftrace_trace_onoff_unreg(glob+1, cmd, param); |
| 345 | |
| 346 | /* we register both traceon and traceoff to this callback */ |
| 347 | if (strcmp(cmd, "traceon") == 0) |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 348 | ops = &traceon_probe_ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 349 | else |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 350 | ops = &traceoff_probe_ops; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 351 | |
| 352 | if (!param) |
| 353 | goto out_reg; |
| 354 | |
| 355 | number = strsep(¶m, ":"); |
| 356 | |
| 357 | if (!strlen(number)) |
| 358 | goto out_reg; |
| 359 | |
| 360 | /* |
| 361 | * We use the callback data field (which is a pointer) |
| 362 | * as our counter. |
| 363 | */ |
| 364 | ret = strict_strtoul(number, 0, (unsigned long *)&count); |
| 365 | if (ret) |
| 366 | return ret; |
| 367 | |
| 368 | out_reg: |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 369 | ret = register_ftrace_function_probe(glob, ops, count); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 370 | |
Xiao Guangrong | 04aef32 | 2009-07-15 12:29:06 +0800 | [diff] [blame] | 371 | return ret < 0 ? ret : 0; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static struct ftrace_func_command ftrace_traceon_cmd = { |
| 375 | .name = "traceon", |
| 376 | .func = ftrace_trace_onoff_callback, |
| 377 | }; |
| 378 | |
| 379 | static struct ftrace_func_command ftrace_traceoff_cmd = { |
| 380 | .name = "traceoff", |
| 381 | .func = ftrace_trace_onoff_callback, |
| 382 | }; |
| 383 | |
| 384 | static int __init init_func_cmd_traceon(void) |
| 385 | { |
| 386 | int ret; |
| 387 | |
| 388 | ret = register_ftrace_command(&ftrace_traceoff_cmd); |
| 389 | if (ret) |
| 390 | return ret; |
| 391 | |
| 392 | ret = register_ftrace_command(&ftrace_traceon_cmd); |
| 393 | if (ret) |
| 394 | unregister_ftrace_command(&ftrace_traceoff_cmd); |
| 395 | return ret; |
| 396 | } |
| 397 | #else |
| 398 | static inline int init_func_cmd_traceon(void) |
| 399 | { |
| 400 | return 0; |
| 401 | } |
| 402 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 403 | |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 404 | static __init int init_function_trace(void) |
| 405 | { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 406 | init_func_cmd_traceon(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 407 | return register_tracer(&function_trace); |
| 408 | } |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 409 | device_initcall(init_function_trace); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 410 | |