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 |
Nadia Yvette Chambers | 6d49e35 | 2012-12-06 10:39:54 +0100 | [diff] [blame] | 10 | * Copyright (C) 2004 Nadia Yvette Chambers |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 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 (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 31 | tr->trace_buffer.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 | { |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 47 | tracing_reset_online_cpus(&tr->trace_buffer); |
Steven Rostedt | 9036990 | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Anton Vorontsov | 65f8c95 | 2012-07-17 14:26:15 -0700 | [diff] [blame] | 50 | /* Our option */ |
Anton Vorontsov | 21f6794 | 2012-07-09 17:10:42 -0700 | [diff] [blame] | 51 | enum { |
| 52 | TRACE_FUNC_OPT_STACK = 0x1, |
Anton Vorontsov | 21f6794 | 2012-07-09 17:10:42 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | static struct tracer_flags func_flags; |
| 56 | |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 57 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 58 | function_trace_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame] | 59 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 60 | { |
| 61 | struct trace_array *tr = func_trace; |
| 62 | struct trace_array_cpu *data; |
| 63 | unsigned long flags; |
Steven Rostedt | d41032a | 2013-01-24 07:52:34 -0500 | [diff] [blame] | 64 | int bit; |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 65 | int cpu; |
| 66 | int pc; |
| 67 | |
| 68 | if (unlikely(!ftrace_function_enabled)) |
| 69 | return; |
| 70 | |
Steven Rostedt | 897f68a | 2012-11-02 17:52:35 -0400 | [diff] [blame] | 71 | pc = preempt_count(); |
| 72 | preempt_disable_notrace(); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 73 | |
Steven Rostedt | 897f68a | 2012-11-02 17:52:35 -0400 | [diff] [blame] | 74 | bit = trace_test_and_set_recursion(TRACE_FTRACE_START, TRACE_FTRACE_MAX); |
| 75 | if (bit < 0) |
| 76 | goto out; |
| 77 | |
| 78 | cpu = smp_processor_id(); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 79 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 897f68a | 2012-11-02 17:52:35 -0400 | [diff] [blame] | 80 | if (!atomic_read(&data->disabled)) { |
| 81 | local_save_flags(flags); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 82 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 83 | } |
Steven Rostedt | 897f68a | 2012-11-02 17:52:35 -0400 | [diff] [blame] | 84 | trace_clear_recursion(bit); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 85 | |
Steven Rostedt | 897f68a | 2012-11-02 17:52:35 -0400 | [diff] [blame] | 86 | out: |
| 87 | preempt_enable_notrace(); |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static void |
Steven Rostedt | 2f5f6ad | 2011-08-08 16:57:47 -0400 | [diff] [blame] | 91 | function_stack_trace_call(unsigned long ip, unsigned long parent_ip, |
Steven Rostedt | a1e2e31 | 2011-08-09 12:50:46 -0400 | [diff] [blame] | 92 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 93 | { |
| 94 | struct trace_array *tr = func_trace; |
| 95 | struct trace_array_cpu *data; |
| 96 | unsigned long flags; |
| 97 | long disabled; |
| 98 | int cpu; |
| 99 | int pc; |
| 100 | |
| 101 | if (unlikely(!ftrace_function_enabled)) |
| 102 | return; |
| 103 | |
| 104 | /* |
| 105 | * Need to use raw, since this must be called before the |
| 106 | * recursive protection is performed. |
| 107 | */ |
| 108 | local_irq_save(flags); |
| 109 | cpu = raw_smp_processor_id(); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 110 | data = per_cpu_ptr(tr->trace_buffer.data, cpu); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 111 | disabled = atomic_inc_return(&data->disabled); |
| 112 | |
| 113 | if (likely(disabled == 1)) { |
| 114 | pc = preempt_count(); |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 115 | trace_function(tr, ip, parent_ip, flags, pc); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 116 | /* |
| 117 | * skip over 5 funcs: |
| 118 | * __ftrace_trace_stack, |
| 119 | * __trace_stack, |
| 120 | * function_stack_trace_call |
| 121 | * ftrace_list_func |
| 122 | * ftrace_call |
| 123 | */ |
Arnaldo Carvalho de Melo | 7be4215 | 2009-02-05 01:13:37 -0500 | [diff] [blame] | 124 | __trace_stack(tr, flags, 5, pc); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | atomic_dec(&data->disabled); |
| 128 | local_irq_restore(flags); |
| 129 | } |
| 130 | |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 131 | |
| 132 | static struct ftrace_ops trace_ops __read_mostly = |
| 133 | { |
| 134 | .func = function_trace_call, |
Steven Rostedt | 4740974 | 2012-07-20 11:04:44 -0400 | [diff] [blame] | 135 | .flags = FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_RECURSION_SAFE, |
Steven Rostedt | bb3c3c9 | 2009-01-15 20:40:23 -0500 | [diff] [blame] | 136 | }; |
| 137 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 138 | static struct ftrace_ops trace_stack_ops __read_mostly = |
| 139 | { |
| 140 | .func = function_stack_trace_call, |
Steven Rostedt | 4740974 | 2012-07-20 11:04:44 -0400 | [diff] [blame] | 141 | .flags = FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_RECURSION_SAFE, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 142 | }; |
| 143 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 144 | static struct tracer_opt func_opts[] = { |
| 145 | #ifdef CONFIG_STACKTRACE |
| 146 | { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) }, |
| 147 | #endif |
| 148 | { } /* Always set a last empty entry */ |
| 149 | }; |
| 150 | |
| 151 | static struct tracer_flags func_flags = { |
| 152 | .val = 0, /* By default: all flags disabled */ |
| 153 | .opts = func_opts |
| 154 | }; |
| 155 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 156 | static void tracing_start_function_trace(void) |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 157 | { |
| 158 | ftrace_function_enabled = 0; |
| 159 | |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 160 | if (func_flags.val & TRACE_FUNC_OPT_STACK) |
| 161 | register_ftrace_function(&trace_stack_ops); |
| 162 | else |
| 163 | register_ftrace_function(&trace_ops); |
| 164 | |
| 165 | ftrace_function_enabled = 1; |
| 166 | } |
| 167 | |
Steven Rostedt | a225cdd | 2009-01-15 23:06:03 -0500 | [diff] [blame] | 168 | static void tracing_stop_function_trace(void) |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 169 | { |
| 170 | ftrace_function_enabled = 0; |
Frederic Weisbecker | c85a17e | 2009-06-20 05:45:14 +0200 | [diff] [blame] | 171 | |
| 172 | if (func_flags.val & TRACE_FUNC_OPT_STACK) |
| 173 | unregister_ftrace_function(&trace_stack_ops); |
| 174 | else |
| 175 | unregister_ftrace_function(&trace_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 176 | } |
| 177 | |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 178 | static int func_set_flag(u32 old_flags, u32 bit, int set) |
| 179 | { |
Anton Vorontsov | f555f12 | 2012-07-09 17:10:46 -0700 | [diff] [blame] | 180 | switch (bit) { |
| 181 | case TRACE_FUNC_OPT_STACK: |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 182 | /* do nothing if already set */ |
| 183 | if (!!set == !!(func_flags.val & TRACE_FUNC_OPT_STACK)) |
Anton Vorontsov | f555f12 | 2012-07-09 17:10:46 -0700 | [diff] [blame] | 184 | break; |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 185 | |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 186 | if (set) { |
| 187 | unregister_ftrace_function(&trace_ops); |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 188 | register_ftrace_function(&trace_stack_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 189 | } else { |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 190 | unregister_ftrace_function(&trace_stack_ops); |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 191 | register_ftrace_function(&trace_ops); |
| 192 | } |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 193 | |
Anton Vorontsov | f555f12 | 2012-07-09 17:10:46 -0700 | [diff] [blame] | 194 | break; |
Anton Vorontsov | f555f12 | 2012-07-09 17:10:46 -0700 | [diff] [blame] | 195 | default: |
| 196 | return -EINVAL; |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Anton Vorontsov | f555f12 | 2012-07-09 17:10:46 -0700 | [diff] [blame] | 199 | return 0; |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 200 | } |
| 201 | |
Steven Rostedt (Red Hat) | 8f76899 | 2013-07-18 14:41:51 -0400 | [diff] [blame] | 202 | static struct tracer function_trace __tracer_data = |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 203 | { |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 204 | .name = "function", |
| 205 | .init = function_trace_init, |
| 206 | .reset = function_trace_reset, |
| 207 | .start = function_trace_start, |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 208 | .wait_pipe = poll_wait_pipe, |
Steven Rostedt | 5361499 | 2009-01-15 19:12:40 -0500 | [diff] [blame] | 209 | .flags = &func_flags, |
| 210 | .set_flag = func_set_flag, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 211 | #ifdef CONFIG_FTRACE_SELFTEST |
Steven Rostedt | 3eb36aa | 2009-01-15 22:21:43 -0500 | [diff] [blame] | 212 | .selftest = trace_selftest_startup_function, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 213 | #endif |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 216 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 217 | static int update_count(void **data) |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 218 | { |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 219 | unsigned long *count = (long *)data; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 220 | |
| 221 | if (!*count) |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 222 | return 0; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 223 | |
| 224 | if (*count != -1) |
| 225 | (*count)--; |
| 226 | |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 227 | return 1; |
| 228 | } |
| 229 | |
| 230 | static void |
Steven Rostedt (Red Hat) | 8380d24 | 2013-03-09 08:56:43 -0500 | [diff] [blame] | 231 | ftrace_traceon_count(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 232 | { |
| 233 | if (tracing_is_on()) |
| 234 | return; |
| 235 | |
| 236 | if (update_count(data)) |
| 237 | tracing_on(); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | static void |
Steven Rostedt (Red Hat) | 8380d24 | 2013-03-09 08:56:43 -0500 | [diff] [blame] | 241 | ftrace_traceoff_count(unsigned long ip, unsigned long parent_ip, void **data) |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 242 | { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 243 | if (!tracing_is_on()) |
| 244 | return; |
| 245 | |
Steven Rostedt (Red Hat) | 1c31714 | 2013-03-09 08:36:53 -0500 | [diff] [blame] | 246 | if (update_count(data)) |
| 247 | tracing_off(); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 248 | } |
| 249 | |
Steven Rostedt (Red Hat) | 8380d24 | 2013-03-09 08:56:43 -0500 | [diff] [blame] | 250 | static void |
| 251 | ftrace_traceon(unsigned long ip, unsigned long parent_ip, void **data) |
| 252 | { |
| 253 | if (tracing_is_on()) |
| 254 | return; |
| 255 | |
| 256 | tracing_on(); |
| 257 | } |
| 258 | |
| 259 | static void |
| 260 | ftrace_traceoff(unsigned long ip, unsigned long parent_ip, void **data) |
| 261 | { |
| 262 | if (!tracing_is_on()) |
| 263 | return; |
| 264 | |
| 265 | tracing_off(); |
| 266 | } |
| 267 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 268 | /* |
| 269 | * Skip 4: |
| 270 | * ftrace_stacktrace() |
| 271 | * function_trace_probe_call() |
| 272 | * ftrace_ops_list_func() |
| 273 | * ftrace_call() |
| 274 | */ |
| 275 | #define STACK_SKIP 4 |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 276 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 277 | static void |
| 278 | ftrace_stacktrace(unsigned long ip, unsigned long parent_ip, void **data) |
| 279 | { |
| 280 | trace_dump_stack(STACK_SKIP); |
| 281 | } |
Steven Rostedt (Red Hat) | 8380d24 | 2013-03-09 08:56:43 -0500 | [diff] [blame] | 282 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 283 | static void |
| 284 | ftrace_stacktrace_count(unsigned long ip, unsigned long parent_ip, void **data) |
| 285 | { |
| 286 | if (!tracing_is_on()) |
| 287 | return; |
Steven Rostedt (Red Hat) | 8380d24 | 2013-03-09 08:56:43 -0500 | [diff] [blame] | 288 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 289 | if (update_count(data)) |
| 290 | trace_dump_stack(STACK_SKIP); |
| 291 | } |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 292 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 293 | static void |
| 294 | ftrace_dump_probe(unsigned long ip, unsigned long parent_ip, void **data) |
| 295 | { |
| 296 | if (update_count(data)) |
| 297 | ftrace_dump(DUMP_ALL); |
| 298 | } |
| 299 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 300 | /* Only dump the current CPU buffer. */ |
| 301 | static void |
| 302 | ftrace_cpudump_probe(unsigned long ip, unsigned long parent_ip, void **data) |
| 303 | { |
| 304 | if (update_count(data)) |
| 305 | ftrace_dump(DUMP_ORIG); |
| 306 | } |
| 307 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 308 | static int |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 309 | ftrace_probe_print(const char *name, struct seq_file *m, |
| 310 | unsigned long ip, void *data) |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 311 | { |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 312 | long count = (long)data; |
| 313 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 314 | seq_printf(m, "%ps:%s", (void *)ip, name); |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 315 | |
Steven Rostedt | 35ebf1c | 2009-02-17 13:12:12 -0500 | [diff] [blame] | 316 | if (count == -1) |
| 317 | seq_printf(m, ":unlimited\n"); |
| 318 | else |
Li Zefan | 00e54d0 | 2009-06-25 14:05:27 +0800 | [diff] [blame] | 319 | seq_printf(m, ":count=%ld\n", count); |
Steven Rostedt | e110e3d | 2009-02-16 23:38:13 -0500 | [diff] [blame] | 320 | |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | static int |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 325 | ftrace_traceon_print(struct seq_file *m, unsigned long ip, |
| 326 | struct ftrace_probe_ops *ops, void *data) |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 327 | { |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 328 | return ftrace_probe_print("traceon", m, ip, data); |
| 329 | } |
| 330 | |
| 331 | static int |
| 332 | ftrace_traceoff_print(struct seq_file *m, unsigned long ip, |
| 333 | struct ftrace_probe_ops *ops, void *data) |
| 334 | { |
| 335 | return ftrace_probe_print("traceoff", m, ip, data); |
| 336 | } |
| 337 | |
| 338 | static int |
| 339 | ftrace_stacktrace_print(struct seq_file *m, unsigned long ip, |
| 340 | struct ftrace_probe_ops *ops, void *data) |
| 341 | { |
| 342 | return ftrace_probe_print("stacktrace", m, ip, data); |
| 343 | } |
| 344 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 345 | static int |
| 346 | ftrace_dump_print(struct seq_file *m, unsigned long ip, |
| 347 | struct ftrace_probe_ops *ops, void *data) |
| 348 | { |
| 349 | return ftrace_probe_print("dump", m, ip, data); |
| 350 | } |
| 351 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 352 | static int |
| 353 | ftrace_cpudump_print(struct seq_file *m, unsigned long ip, |
| 354 | struct ftrace_probe_ops *ops, void *data) |
| 355 | { |
| 356 | return ftrace_probe_print("cpudump", m, ip, data); |
| 357 | } |
| 358 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 359 | static struct ftrace_probe_ops traceon_count_probe_ops = { |
| 360 | .func = ftrace_traceon_count, |
| 361 | .print = ftrace_traceon_print, |
| 362 | }; |
| 363 | |
| 364 | static struct ftrace_probe_ops traceoff_count_probe_ops = { |
| 365 | .func = ftrace_traceoff_count, |
| 366 | .print = ftrace_traceoff_print, |
| 367 | }; |
| 368 | |
| 369 | static struct ftrace_probe_ops stacktrace_count_probe_ops = { |
| 370 | .func = ftrace_stacktrace_count, |
| 371 | .print = ftrace_stacktrace_print, |
| 372 | }; |
| 373 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 374 | static struct ftrace_probe_ops dump_probe_ops = { |
| 375 | .func = ftrace_dump_probe, |
| 376 | .print = ftrace_dump_print, |
| 377 | }; |
| 378 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 379 | static struct ftrace_probe_ops cpudump_probe_ops = { |
| 380 | .func = ftrace_cpudump_probe, |
| 381 | .print = ftrace_cpudump_print, |
| 382 | }; |
| 383 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 384 | static struct ftrace_probe_ops traceon_probe_ops = { |
| 385 | .func = ftrace_traceon, |
| 386 | .print = ftrace_traceon_print, |
| 387 | }; |
| 388 | |
| 389 | static struct ftrace_probe_ops traceoff_probe_ops = { |
| 390 | .func = ftrace_traceoff, |
| 391 | .print = ftrace_traceoff_print, |
| 392 | }; |
| 393 | |
| 394 | static struct ftrace_probe_ops stacktrace_probe_ops = { |
| 395 | .func = ftrace_stacktrace, |
| 396 | .print = ftrace_stacktrace_print, |
| 397 | }; |
| 398 | |
| 399 | static int |
| 400 | ftrace_trace_probe_callback(struct ftrace_probe_ops *ops, |
| 401 | struct ftrace_hash *hash, char *glob, |
| 402 | char *cmd, char *param, int enable) |
| 403 | { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 404 | void *count = (void *)-1; |
| 405 | char *number; |
| 406 | int ret; |
| 407 | |
| 408 | /* hash funcs only work with set_ftrace_filter */ |
| 409 | if (!enable) |
| 410 | return -EINVAL; |
| 411 | |
Steven Rostedt (Red Hat) | 8b8fa62 | 2013-03-12 09:25:00 -0400 | [diff] [blame] | 412 | if (glob[0] == '!') { |
| 413 | unregister_ftrace_function_probe_func(glob+1, ops); |
| 414 | return 0; |
| 415 | } |
| 416 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 417 | if (!param) |
| 418 | goto out_reg; |
| 419 | |
| 420 | number = strsep(¶m, ":"); |
| 421 | |
| 422 | if (!strlen(number)) |
| 423 | goto out_reg; |
| 424 | |
| 425 | /* |
| 426 | * We use the callback data field (which is a pointer) |
| 427 | * as our counter. |
| 428 | */ |
Daniel Walter | bcd83ea | 2012-09-26 22:08:38 +0200 | [diff] [blame] | 429 | ret = kstrtoul(number, 0, (unsigned long *)&count); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 430 | if (ret) |
| 431 | return ret; |
| 432 | |
| 433 | out_reg: |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 434 | ret = register_ftrace_function_probe(glob, ops, count); |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 435 | |
Xiao Guangrong | 04aef32 | 2009-07-15 12:29:06 +0800 | [diff] [blame] | 436 | return ret < 0 ? ret : 0; |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 437 | } |
| 438 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 439 | static int |
| 440 | ftrace_trace_onoff_callback(struct ftrace_hash *hash, |
| 441 | char *glob, char *cmd, char *param, int enable) |
| 442 | { |
| 443 | struct ftrace_probe_ops *ops; |
| 444 | |
| 445 | /* we register both traceon and traceoff to this callback */ |
| 446 | if (strcmp(cmd, "traceon") == 0) |
| 447 | ops = param ? &traceon_count_probe_ops : &traceon_probe_ops; |
| 448 | else |
| 449 | ops = param ? &traceoff_count_probe_ops : &traceoff_probe_ops; |
| 450 | |
| 451 | return ftrace_trace_probe_callback(ops, hash, glob, cmd, |
| 452 | param, enable); |
| 453 | } |
| 454 | |
| 455 | static int |
| 456 | ftrace_stacktrace_callback(struct ftrace_hash *hash, |
| 457 | char *glob, char *cmd, char *param, int enable) |
| 458 | { |
| 459 | struct ftrace_probe_ops *ops; |
| 460 | |
| 461 | ops = param ? &stacktrace_count_probe_ops : &stacktrace_probe_ops; |
| 462 | |
| 463 | return ftrace_trace_probe_callback(ops, hash, glob, cmd, |
| 464 | param, enable); |
| 465 | } |
| 466 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 467 | static int |
| 468 | ftrace_dump_callback(struct ftrace_hash *hash, |
| 469 | char *glob, char *cmd, char *param, int enable) |
| 470 | { |
| 471 | struct ftrace_probe_ops *ops; |
| 472 | |
| 473 | ops = &dump_probe_ops; |
| 474 | |
| 475 | /* Only dump once. */ |
| 476 | return ftrace_trace_probe_callback(ops, hash, glob, cmd, |
| 477 | "1", enable); |
| 478 | } |
| 479 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 480 | static int |
| 481 | ftrace_cpudump_callback(struct ftrace_hash *hash, |
| 482 | char *glob, char *cmd, char *param, int enable) |
| 483 | { |
| 484 | struct ftrace_probe_ops *ops; |
| 485 | |
| 486 | ops = &cpudump_probe_ops; |
| 487 | |
| 488 | /* Only dump once. */ |
| 489 | return ftrace_trace_probe_callback(ops, hash, glob, cmd, |
| 490 | "1", enable); |
| 491 | } |
| 492 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 493 | static struct ftrace_func_command ftrace_traceon_cmd = { |
| 494 | .name = "traceon", |
| 495 | .func = ftrace_trace_onoff_callback, |
| 496 | }; |
| 497 | |
| 498 | static struct ftrace_func_command ftrace_traceoff_cmd = { |
| 499 | .name = "traceoff", |
| 500 | .func = ftrace_trace_onoff_callback, |
| 501 | }; |
| 502 | |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 503 | static struct ftrace_func_command ftrace_stacktrace_cmd = { |
| 504 | .name = "stacktrace", |
| 505 | .func = ftrace_stacktrace_callback, |
| 506 | }; |
| 507 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 508 | static struct ftrace_func_command ftrace_dump_cmd = { |
| 509 | .name = "dump", |
| 510 | .func = ftrace_dump_callback, |
| 511 | }; |
| 512 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 513 | static struct ftrace_func_command ftrace_cpudump_cmd = { |
| 514 | .name = "cpudump", |
| 515 | .func = ftrace_cpudump_callback, |
| 516 | }; |
| 517 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 518 | static int __init init_func_cmd_traceon(void) |
| 519 | { |
| 520 | int ret; |
| 521 | |
| 522 | ret = register_ftrace_command(&ftrace_traceoff_cmd); |
| 523 | if (ret) |
| 524 | return ret; |
| 525 | |
| 526 | ret = register_ftrace_command(&ftrace_traceon_cmd); |
| 527 | if (ret) |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 528 | goto out_free_traceoff; |
Steven Rostedt (Red Hat) | dd42cd3 | 2013-03-13 10:17:50 -0400 | [diff] [blame] | 529 | |
| 530 | ret = register_ftrace_command(&ftrace_stacktrace_cmd); |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 531 | if (ret) |
| 532 | goto out_free_traceon; |
| 533 | |
| 534 | ret = register_ftrace_command(&ftrace_dump_cmd); |
| 535 | if (ret) |
| 536 | goto out_free_stacktrace; |
| 537 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 538 | ret = register_ftrace_command(&ftrace_cpudump_cmd); |
| 539 | if (ret) |
| 540 | goto out_free_dump; |
| 541 | |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 542 | return 0; |
| 543 | |
Steven Rostedt (Red Hat) | 90e3c03 | 2013-04-30 19:00:46 -0400 | [diff] [blame] | 544 | out_free_dump: |
| 545 | unregister_ftrace_command(&ftrace_dump_cmd); |
Steven Rostedt (Red Hat) | ad71d88 | 2013-04-30 15:46:14 -0400 | [diff] [blame] | 546 | out_free_stacktrace: |
| 547 | unregister_ftrace_command(&ftrace_stacktrace_cmd); |
| 548 | out_free_traceon: |
| 549 | unregister_ftrace_command(&ftrace_traceon_cmd); |
| 550 | out_free_traceoff: |
| 551 | unregister_ftrace_command(&ftrace_traceoff_cmd); |
| 552 | |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 553 | return ret; |
| 554 | } |
| 555 | #else |
| 556 | static inline int init_func_cmd_traceon(void) |
| 557 | { |
| 558 | return 0; |
| 559 | } |
| 560 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 561 | |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 562 | static __init int init_function_trace(void) |
| 563 | { |
Steven Rostedt | 23b4ff3 | 2009-02-14 19:04:24 -0500 | [diff] [blame] | 564 | init_func_cmd_traceon(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 565 | return register_tracer(&function_trace); |
| 566 | } |
Steven Rostedt | 6f41567 | 2012-10-05 12:13:07 -0400 | [diff] [blame] | 567 | core_initcall(init_function_trace); |