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