Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Infrastructure for profiling code inserted by 'gcc -pg'. |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com> |
| 5 | * Copyright (C) 2004-2008 Ingo Molnar <mingo@redhat.com> |
| 6 | * |
| 7 | * Originally ported from the -rt patch by: |
| 8 | * Copyright (C) 2007 Arnaldo Carvalho de Melo <acme@redhat.com> |
| 9 | * |
| 10 | * Based on code in the latency_tracer, that is: |
| 11 | * |
| 12 | * Copyright (C) 2004-2006 Ingo Molnar |
| 13 | * Copyright (C) 2004 William Lee Irwin III |
| 14 | */ |
| 15 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 16 | #include <linux/stop_machine.h> |
| 17 | #include <linux/clocksource.h> |
| 18 | #include <linux/kallsyms.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 19 | #include <linux/seq_file.h> |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 20 | #include <linux/suspend.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 21 | #include <linux/debugfs.h> |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 22 | #include <linux/hardirq.h> |
Ingo Molnar | 2d8b820 | 2008-02-23 16:55:50 +0100 | [diff] [blame] | 23 | #include <linux/kthread.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 24 | #include <linux/uaccess.h> |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 25 | #include <linux/kprobes.h> |
Ingo Molnar | 2d8b820 | 2008-02-23 16:55:50 +0100 | [diff] [blame] | 26 | #include <linux/ftrace.h> |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 27 | #include <linux/sysctl.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 28 | #include <linux/ctype.h> |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 29 | #include <linux/list.h> |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 30 | #include <linux/hash.h> |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 31 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame^] | 32 | #include <trace/sched.h> |
| 33 | |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 34 | #include <asm/ftrace.h> |
| 35 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 36 | #include "trace.h" |
| 37 | |
Steven Rostedt | 6912896 | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 38 | #define FTRACE_WARN_ON(cond) \ |
| 39 | do { \ |
| 40 | if (WARN_ON(cond)) \ |
| 41 | ftrace_kill(); \ |
| 42 | } while (0) |
| 43 | |
| 44 | #define FTRACE_WARN_ON_ONCE(cond) \ |
| 45 | do { \ |
| 46 | if (WARN_ON_ONCE(cond)) \ |
| 47 | ftrace_kill(); \ |
| 48 | } while (0) |
| 49 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 50 | /* hash bits for specific function selection */ |
| 51 | #define FTRACE_HASH_BITS 7 |
| 52 | #define FTRACE_FUNC_HASHSIZE (1 << FTRACE_HASH_BITS) |
| 53 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 54 | /* ftrace_enabled is a method to turn ftrace on or off */ |
| 55 | int ftrace_enabled __read_mostly; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 56 | static int last_ftrace_enabled; |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 57 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 58 | /* Quick disabling of function tracer. */ |
| 59 | int function_trace_stop; |
| 60 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 61 | /* |
| 62 | * ftrace_disabled is set when an anomaly is discovered. |
| 63 | * ftrace_disabled is much stronger than ftrace_enabled. |
| 64 | */ |
| 65 | static int ftrace_disabled __read_mostly; |
| 66 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 67 | static DEFINE_MUTEX(ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 68 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 69 | static struct ftrace_ops ftrace_list_end __read_mostly = |
| 70 | { |
| 71 | .func = ftrace_stub, |
| 72 | }; |
| 73 | |
| 74 | static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end; |
| 75 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 76 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 77 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 78 | |
Ingo Molnar | f225293 | 2008-05-22 10:37:48 +0200 | [diff] [blame] | 79 | static void ftrace_list_func(unsigned long ip, unsigned long parent_ip) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 80 | { |
| 81 | struct ftrace_ops *op = ftrace_list; |
| 82 | |
| 83 | /* in case someone actually ports this to alpha! */ |
| 84 | read_barrier_depends(); |
| 85 | |
| 86 | while (op != &ftrace_list_end) { |
| 87 | /* silly alpha */ |
| 88 | read_barrier_depends(); |
| 89 | op->func(ip, parent_ip); |
| 90 | op = op->next; |
| 91 | }; |
| 92 | } |
| 93 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 94 | static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip) |
| 95 | { |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 96 | if (!test_tsk_trace_trace(current)) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 97 | return; |
| 98 | |
| 99 | ftrace_pid_function(ip, parent_ip); |
| 100 | } |
| 101 | |
| 102 | static void set_ftrace_pid_function(ftrace_func_t func) |
| 103 | { |
| 104 | /* do not set ftrace_pid_function to itself! */ |
| 105 | if (func != ftrace_pid_func) |
| 106 | ftrace_pid_function = func; |
| 107 | } |
| 108 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 109 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 110 | * clear_ftrace_function - reset the ftrace function |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 111 | * |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 112 | * This NULLs the ftrace function and in essence stops |
| 113 | * tracing. There may be lag |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 114 | */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 115 | void clear_ftrace_function(void) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 116 | { |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 117 | ftrace_trace_function = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 118 | __ftrace_trace_function = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 119 | ftrace_pid_function = ftrace_stub; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 120 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 121 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 122 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 123 | /* |
| 124 | * For those archs that do not test ftrace_trace_stop in their |
| 125 | * mcount call site, we need to do it from C. |
| 126 | */ |
| 127 | static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip) |
| 128 | { |
| 129 | if (function_trace_stop) |
| 130 | return; |
| 131 | |
| 132 | __ftrace_trace_function(ip, parent_ip); |
| 133 | } |
| 134 | #endif |
| 135 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 136 | static int __register_ftrace_function(struct ftrace_ops *ops) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 137 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 138 | ops->next = ftrace_list; |
| 139 | /* |
| 140 | * We are entering ops into the ftrace_list but another |
| 141 | * CPU might be walking that list. We need to make sure |
| 142 | * the ops->next pointer is valid before another CPU sees |
| 143 | * the ops pointer included into the ftrace_list. |
| 144 | */ |
| 145 | smp_wmb(); |
| 146 | ftrace_list = ops; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 147 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 148 | if (ftrace_enabled) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 149 | ftrace_func_t func; |
| 150 | |
| 151 | if (ops->next == &ftrace_list_end) |
| 152 | func = ops->func; |
| 153 | else |
| 154 | func = ftrace_list_func; |
| 155 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 156 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 157 | set_ftrace_pid_function(func); |
| 158 | func = ftrace_pid_func; |
| 159 | } |
| 160 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 161 | /* |
| 162 | * For one func, simply call it directly. |
| 163 | * For more than one func, call the chain. |
| 164 | */ |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 165 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 166 | ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 167 | #else |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 168 | __ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 169 | ftrace_trace_function = ftrace_test_stop_func; |
| 170 | #endif |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 171 | } |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 172 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 176 | static int __unregister_ftrace_function(struct ftrace_ops *ops) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 177 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 178 | struct ftrace_ops **p; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 179 | |
| 180 | /* |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 181 | * If we are removing the last function, then simply point |
| 182 | * to the ftrace_stub. |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 183 | */ |
| 184 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { |
| 185 | ftrace_trace_function = ftrace_stub; |
| 186 | ftrace_list = &ftrace_list_end; |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 187 | return 0; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) |
| 191 | if (*p == ops) |
| 192 | break; |
| 193 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 194 | if (*p != ops) |
| 195 | return -1; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 196 | |
| 197 | *p = (*p)->next; |
| 198 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 199 | if (ftrace_enabled) { |
| 200 | /* If we only have one func left, then call that directly */ |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 201 | if (ftrace_list->next == &ftrace_list_end) { |
| 202 | ftrace_func_t func = ftrace_list->func; |
| 203 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 204 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 205 | set_ftrace_pid_function(func); |
| 206 | func = ftrace_pid_func; |
| 207 | } |
| 208 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 209 | ftrace_trace_function = func; |
| 210 | #else |
| 211 | __ftrace_trace_function = func; |
| 212 | #endif |
| 213 | } |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 214 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 215 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 216 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 219 | static void ftrace_update_pid_func(void) |
| 220 | { |
| 221 | ftrace_func_t func; |
| 222 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 223 | if (ftrace_trace_function == ftrace_stub) |
KOSAKI Motohiro | 10dd3eb | 2009-03-06 15:29:04 +0900 | [diff] [blame] | 224 | return; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 225 | |
| 226 | func = ftrace_trace_function; |
| 227 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 228 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 229 | set_ftrace_pid_function(func); |
| 230 | func = ftrace_pid_func; |
| 231 | } else { |
Liming Wang | 66eafeb | 2008-12-02 10:33:08 +0800 | [diff] [blame] | 232 | if (func == ftrace_pid_func) |
| 233 | func = ftrace_pid_function; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 237 | ftrace_trace_function = func; |
| 238 | #else |
| 239 | __ftrace_trace_function = func; |
| 240 | #endif |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 241 | } |
| 242 | |
Ingo Molnar | 73d3fd9 | 2009-02-17 11:48:18 +0100 | [diff] [blame] | 243 | /* set when tracing only a pid */ |
| 244 | struct pid *ftrace_pid_trace; |
| 245 | static struct pid * const ftrace_swapper_pid = &init_struct_pid; |
| 246 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 247 | #ifdef CONFIG_DYNAMIC_FTRACE |
Ingo Molnar | 73d3fd9 | 2009-02-17 11:48:18 +0100 | [diff] [blame] | 248 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 249 | #ifndef CONFIG_FTRACE_MCOUNT_RECORD |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 250 | # error Dynamic ftrace depends on MCOUNT_RECORD |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 251 | #endif |
| 252 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 253 | static struct hlist_head ftrace_func_hash[FTRACE_FUNC_HASHSIZE] __read_mostly; |
| 254 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 255 | struct ftrace_func_probe { |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 256 | struct hlist_node node; |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 257 | struct ftrace_probe_ops *ops; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 258 | unsigned long flags; |
| 259 | unsigned long ip; |
| 260 | void *data; |
| 261 | struct rcu_head rcu; |
| 262 | }; |
| 263 | |
| 264 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 265 | enum { |
| 266 | FTRACE_ENABLE_CALLS = (1 << 0), |
| 267 | FTRACE_DISABLE_CALLS = (1 << 1), |
| 268 | FTRACE_UPDATE_TRACE_FUNC = (1 << 2), |
| 269 | FTRACE_ENABLE_MCOUNT = (1 << 3), |
| 270 | FTRACE_DISABLE_MCOUNT = (1 << 4), |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 271 | FTRACE_START_FUNC_RET = (1 << 5), |
| 272 | FTRACE_STOP_FUNC_RET = (1 << 6), |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 273 | }; |
| 274 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 275 | static int ftrace_filtered; |
| 276 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 277 | static struct dyn_ftrace *ftrace_new_addrs; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 278 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 279 | static DEFINE_MUTEX(ftrace_regex_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 280 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 281 | struct ftrace_page { |
| 282 | struct ftrace_page *next; |
Steven Rostedt | 431aa3f | 2009-01-06 12:43:01 -0500 | [diff] [blame] | 283 | int index; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 284 | struct dyn_ftrace records[]; |
David Miller | aa5e5ce | 2008-05-13 22:06:56 -0700 | [diff] [blame] | 285 | }; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 286 | |
| 287 | #define ENTRIES_PER_PAGE \ |
| 288 | ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace)) |
| 289 | |
| 290 | /* estimate from running different kernels */ |
| 291 | #define NR_TO_INIT 10000 |
| 292 | |
| 293 | static struct ftrace_page *ftrace_pages_start; |
| 294 | static struct ftrace_page *ftrace_pages; |
| 295 | |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 296 | static struct dyn_ftrace *ftrace_free_records; |
| 297 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 298 | /* |
| 299 | * This is a double for. Do not use 'break' to break out of the loop, |
| 300 | * you must use a goto. |
| 301 | */ |
| 302 | #define do_for_each_ftrace_rec(pg, rec) \ |
| 303 | for (pg = ftrace_pages_start; pg; pg = pg->next) { \ |
| 304 | int _____i; \ |
| 305 | for (_____i = 0; _____i < pg->index; _____i++) { \ |
| 306 | rec = &pg->records[_____i]; |
| 307 | |
| 308 | #define while_for_each_ftrace_rec() \ |
| 309 | } \ |
| 310 | } |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 311 | |
| 312 | #ifdef CONFIG_KPROBES |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 313 | |
| 314 | static int frozen_record_count; |
| 315 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 316 | static inline void freeze_record(struct dyn_ftrace *rec) |
| 317 | { |
| 318 | if (!(rec->flags & FTRACE_FL_FROZEN)) { |
| 319 | rec->flags |= FTRACE_FL_FROZEN; |
| 320 | frozen_record_count++; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | static inline void unfreeze_record(struct dyn_ftrace *rec) |
| 325 | { |
| 326 | if (rec->flags & FTRACE_FL_FROZEN) { |
| 327 | rec->flags &= ~FTRACE_FL_FROZEN; |
| 328 | frozen_record_count--; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | static inline int record_frozen(struct dyn_ftrace *rec) |
| 333 | { |
| 334 | return rec->flags & FTRACE_FL_FROZEN; |
| 335 | } |
| 336 | #else |
| 337 | # define freeze_record(rec) ({ 0; }) |
| 338 | # define unfreeze_record(rec) ({ 0; }) |
| 339 | # define record_frozen(rec) ({ 0; }) |
| 340 | #endif /* CONFIG_KPROBES */ |
| 341 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 342 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 343 | { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 344 | rec->ip = (unsigned long)ftrace_free_records; |
| 345 | ftrace_free_records = rec; |
| 346 | rec->flags |= FTRACE_FL_FREE; |
| 347 | } |
| 348 | |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 349 | void ftrace_release(void *start, unsigned long size) |
| 350 | { |
| 351 | struct dyn_ftrace *rec; |
| 352 | struct ftrace_page *pg; |
| 353 | unsigned long s = (unsigned long)start; |
| 354 | unsigned long e = s + size; |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 355 | |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 356 | if (ftrace_disabled || !start) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 357 | return; |
| 358 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 359 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 360 | do_for_each_ftrace_rec(pg, rec) { |
Zhaolei | b00f0b6 | 2009-03-13 17:14:01 +0800 | [diff] [blame] | 361 | if ((rec->ip >= s) && (rec->ip < e) && |
| 362 | !(rec->flags & FTRACE_FL_FREE)) |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 363 | ftrace_free_rec(rec); |
| 364 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 365 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 368 | static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 369 | { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 370 | struct dyn_ftrace *rec; |
| 371 | |
| 372 | /* First check for freed records */ |
| 373 | if (ftrace_free_records) { |
| 374 | rec = ftrace_free_records; |
| 375 | |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 376 | if (unlikely(!(rec->flags & FTRACE_FL_FREE))) { |
Steven Rostedt | 6912896 | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 377 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 378 | ftrace_free_records = NULL; |
| 379 | return NULL; |
| 380 | } |
| 381 | |
| 382 | ftrace_free_records = (void *)rec->ip; |
| 383 | memset(rec, 0, sizeof(*rec)); |
| 384 | return rec; |
| 385 | } |
| 386 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 387 | if (ftrace_pages->index == ENTRIES_PER_PAGE) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 388 | if (!ftrace_pages->next) { |
| 389 | /* allocate another page */ |
| 390 | ftrace_pages->next = |
| 391 | (void *)get_zeroed_page(GFP_KERNEL); |
| 392 | if (!ftrace_pages->next) |
| 393 | return NULL; |
| 394 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 395 | ftrace_pages = ftrace_pages->next; |
| 396 | } |
| 397 | |
| 398 | return &ftrace_pages->records[ftrace_pages->index++]; |
| 399 | } |
| 400 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 401 | static struct dyn_ftrace * |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 402 | ftrace_record_ip(unsigned long ip) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 403 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 404 | struct dyn_ftrace *rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 405 | |
Steven Rostedt | f3c7ac4 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 406 | if (ftrace_disabled) |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 407 | return NULL; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 408 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 409 | rec = ftrace_alloc_dyn_node(ip); |
| 410 | if (!rec) |
| 411 | return NULL; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 412 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 413 | rec->ip = ip; |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 414 | rec->flags = (unsigned long)ftrace_new_addrs; |
| 415 | ftrace_new_addrs = rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 416 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 417 | return rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 418 | } |
| 419 | |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 420 | static void print_ip_ins(const char *fmt, unsigned char *p) |
| 421 | { |
| 422 | int i; |
| 423 | |
| 424 | printk(KERN_CONT "%s", fmt); |
| 425 | |
| 426 | for (i = 0; i < MCOUNT_INSN_SIZE; i++) |
| 427 | printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); |
| 428 | } |
| 429 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 430 | static void ftrace_bug(int failed, unsigned long ip) |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 431 | { |
| 432 | switch (failed) { |
| 433 | case -EFAULT: |
| 434 | FTRACE_WARN_ON_ONCE(1); |
| 435 | pr_info("ftrace faulted on modifying "); |
| 436 | print_ip_sym(ip); |
| 437 | break; |
| 438 | case -EINVAL: |
| 439 | FTRACE_WARN_ON_ONCE(1); |
| 440 | pr_info("ftrace failed to modify "); |
| 441 | print_ip_sym(ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 442 | print_ip_ins(" actual: ", (unsigned char *)ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 443 | printk(KERN_CONT "\n"); |
| 444 | break; |
| 445 | case -EPERM: |
| 446 | FTRACE_WARN_ON_ONCE(1); |
| 447 | pr_info("ftrace faulted on writing "); |
| 448 | print_ip_sym(ip); |
| 449 | break; |
| 450 | default: |
| 451 | FTRACE_WARN_ON_ONCE(1); |
| 452 | pr_info("ftrace faulted on unknown error "); |
| 453 | print_ip_sym(ip); |
| 454 | } |
| 455 | } |
| 456 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 457 | |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 458 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 459 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 460 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 461 | unsigned long ftrace_addr; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 462 | unsigned long ip, fl; |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 463 | |
Shaohua Li | f000120 | 2009-01-09 11:29:42 +0800 | [diff] [blame] | 464 | ftrace_addr = (unsigned long)FTRACE_ADDR; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 465 | |
| 466 | ip = rec->ip; |
| 467 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 468 | /* |
| 469 | * If this record is not to be traced and |
| 470 | * it is not enabled then do nothing. |
| 471 | * |
| 472 | * If this record is not to be traced and |
Wenji Huang | 57794a9 | 2009-02-06 17:33:27 +0800 | [diff] [blame] | 473 | * it is enabled then disable it. |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 474 | * |
| 475 | */ |
| 476 | if (rec->flags & FTRACE_FL_NOTRACE) { |
| 477 | if (rec->flags & FTRACE_FL_ENABLED) |
| 478 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 479 | else |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 480 | return 0; |
| 481 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 482 | } else if (ftrace_filtered && enable) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 483 | /* |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 484 | * Filtering is on: |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 485 | */ |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 486 | |
| 487 | fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED); |
| 488 | |
| 489 | /* Record is filtered and enabled, do nothing */ |
| 490 | if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) |
| 491 | return 0; |
| 492 | |
Wenji Huang | 57794a9 | 2009-02-06 17:33:27 +0800 | [diff] [blame] | 493 | /* Record is not filtered or enabled, do nothing */ |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 494 | if (!fl) |
| 495 | return 0; |
| 496 | |
| 497 | /* Record is not filtered but enabled, disable it */ |
| 498 | if (fl == FTRACE_FL_ENABLED) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 499 | rec->flags &= ~FTRACE_FL_ENABLED; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 500 | else |
| 501 | /* Otherwise record is filtered but not enabled, enable it */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 502 | rec->flags |= FTRACE_FL_ENABLED; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 503 | } else { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 504 | /* Disable or not filtered */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 505 | |
| 506 | if (enable) { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 507 | /* if record is enabled, do nothing */ |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 508 | if (rec->flags & FTRACE_FL_ENABLED) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 509 | return 0; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 510 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 511 | rec->flags |= FTRACE_FL_ENABLED; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 512 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 513 | } else { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 514 | |
Wenji Huang | 57794a9 | 2009-02-06 17:33:27 +0800 | [diff] [blame] | 515 | /* if record is not enabled, do nothing */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 516 | if (!(rec->flags & FTRACE_FL_ENABLED)) |
| 517 | return 0; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 518 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 519 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 520 | } |
| 521 | } |
| 522 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 523 | if (rec->flags & FTRACE_FL_ENABLED) |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 524 | return ftrace_make_call(rec, ftrace_addr); |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 525 | else |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 526 | return ftrace_make_nop(NULL, rec, ftrace_addr); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void ftrace_replace_code(int enable) |
| 530 | { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 531 | struct dyn_ftrace *rec; |
| 532 | struct ftrace_page *pg; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 533 | int failed; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 534 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 535 | do_for_each_ftrace_rec(pg, rec) { |
| 536 | /* |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 537 | * Skip over free records, records that have |
| 538 | * failed and not converted. |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 539 | */ |
| 540 | if (rec->flags & FTRACE_FL_FREE || |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 541 | rec->flags & FTRACE_FL_FAILED || |
Frederic Weisbecker | 0330354 | 2009-03-16 22:41:00 +0100 | [diff] [blame] | 542 | !(rec->flags & FTRACE_FL_CONVERTED)) |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 543 | continue; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 544 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 545 | /* ignore updates to this record's mcount site */ |
| 546 | if (get_kprobe((void *)rec->ip)) { |
| 547 | freeze_record(rec); |
| 548 | continue; |
| 549 | } else { |
| 550 | unfreeze_record(rec); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 551 | } |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 552 | |
| 553 | failed = __ftrace_replace_code(rec, enable); |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 554 | if (failed) { |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 555 | rec->flags |= FTRACE_FL_FAILED; |
| 556 | if ((system_state == SYSTEM_BOOTING) || |
| 557 | !core_kernel_text(rec->ip)) { |
| 558 | ftrace_free_rec(rec); |
Steven Rostedt | 4377245 | 2009-02-19 13:41:27 -0500 | [diff] [blame] | 559 | } else { |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 560 | ftrace_bug(failed, rec->ip); |
Steven Rostedt | 4377245 | 2009-02-19 13:41:27 -0500 | [diff] [blame] | 561 | /* Stop processing */ |
| 562 | return; |
| 563 | } |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 564 | } |
| 565 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 566 | } |
| 567 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 568 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 569 | ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 570 | { |
| 571 | unsigned long ip; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 572 | int ret; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 573 | |
| 574 | ip = rec->ip; |
| 575 | |
Shaohua Li | 25aac9d | 2009-01-09 11:29:40 +0800 | [diff] [blame] | 576 | ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR); |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 577 | if (ret) { |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 578 | ftrace_bug(ret, ip); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 579 | rec->flags |= FTRACE_FL_FAILED; |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 580 | return 0; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 581 | } |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 582 | return 1; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 583 | } |
| 584 | |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 585 | /* |
| 586 | * archs can override this function if they must do something |
| 587 | * before the modifying code is performed. |
| 588 | */ |
| 589 | int __weak ftrace_arch_code_modify_prepare(void) |
| 590 | { |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * archs can override this function if they must do something |
| 596 | * after the modifying code is performed. |
| 597 | */ |
| 598 | int __weak ftrace_arch_code_modify_post_process(void) |
| 599 | { |
| 600 | return 0; |
| 601 | } |
| 602 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 603 | static int __ftrace_modify_code(void *data) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 604 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 605 | int *command = data; |
| 606 | |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 607 | if (*command & FTRACE_ENABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 608 | ftrace_replace_code(1); |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 609 | else if (*command & FTRACE_DISABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 610 | ftrace_replace_code(0); |
| 611 | |
| 612 | if (*command & FTRACE_UPDATE_TRACE_FUNC) |
| 613 | ftrace_update_ftrace_func(ftrace_trace_function); |
| 614 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 615 | if (*command & FTRACE_START_FUNC_RET) |
| 616 | ftrace_enable_ftrace_graph_caller(); |
| 617 | else if (*command & FTRACE_STOP_FUNC_RET) |
| 618 | ftrace_disable_ftrace_graph_caller(); |
| 619 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 620 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 623 | static void ftrace_run_update_code(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 624 | { |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 625 | int ret; |
| 626 | |
| 627 | ret = ftrace_arch_code_modify_prepare(); |
| 628 | FTRACE_WARN_ON(ret); |
| 629 | if (ret) |
| 630 | return; |
| 631 | |
Rusty Russell | 784e2d7 | 2008-07-28 12:16:31 -0500 | [diff] [blame] | 632 | stop_machine(__ftrace_modify_code, &command, NULL); |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 633 | |
| 634 | ret = ftrace_arch_code_modify_post_process(); |
| 635 | FTRACE_WARN_ON(ret); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 636 | } |
| 637 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 638 | static ftrace_func_t saved_ftrace_func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 639 | static int ftrace_start_up; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 640 | |
| 641 | static void ftrace_startup_enable(int command) |
| 642 | { |
| 643 | if (saved_ftrace_func != ftrace_trace_function) { |
| 644 | saved_ftrace_func = ftrace_trace_function; |
| 645 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 646 | } |
| 647 | |
| 648 | if (!command || !ftrace_enabled) |
| 649 | return; |
| 650 | |
| 651 | ftrace_run_update_code(command); |
| 652 | } |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 653 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 654 | static void ftrace_startup(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 655 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 656 | if (unlikely(ftrace_disabled)) |
| 657 | return; |
| 658 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 659 | ftrace_start_up++; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 660 | command |= FTRACE_ENABLE_CALLS; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 661 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 662 | ftrace_startup_enable(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 665 | static void ftrace_shutdown(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 666 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 667 | if (unlikely(ftrace_disabled)) |
| 668 | return; |
| 669 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 670 | ftrace_start_up--; |
| 671 | if (!ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 672 | command |= FTRACE_DISABLE_CALLS; |
| 673 | |
| 674 | if (saved_ftrace_func != ftrace_trace_function) { |
| 675 | saved_ftrace_func = ftrace_trace_function; |
| 676 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 677 | } |
| 678 | |
| 679 | if (!command || !ftrace_enabled) |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 680 | return; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 681 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 682 | ftrace_run_update_code(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 683 | } |
| 684 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 685 | static void ftrace_startup_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 686 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 687 | int command = FTRACE_ENABLE_MCOUNT; |
| 688 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 689 | if (unlikely(ftrace_disabled)) |
| 690 | return; |
| 691 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 692 | /* Force update next time */ |
| 693 | saved_ftrace_func = NULL; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 694 | /* ftrace_start_up is true if we want ftrace running */ |
| 695 | if (ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 696 | command |= FTRACE_ENABLE_CALLS; |
| 697 | |
| 698 | ftrace_run_update_code(command); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 701 | static void ftrace_shutdown_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 702 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 703 | int command = FTRACE_DISABLE_MCOUNT; |
| 704 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 705 | if (unlikely(ftrace_disabled)) |
| 706 | return; |
| 707 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 708 | /* ftrace_start_up is true if ftrace is running */ |
| 709 | if (ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 710 | command |= FTRACE_DISABLE_CALLS; |
| 711 | |
| 712 | ftrace_run_update_code(command); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 713 | } |
| 714 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 715 | static cycle_t ftrace_update_time; |
| 716 | static unsigned long ftrace_update_cnt; |
| 717 | unsigned long ftrace_update_tot_cnt; |
| 718 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 719 | static int ftrace_update_code(struct module *mod) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 720 | { |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 721 | struct dyn_ftrace *p; |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 722 | cycle_t start, stop; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 723 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 724 | start = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 725 | ftrace_update_cnt = 0; |
| 726 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 727 | while (ftrace_new_addrs) { |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 728 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 729 | /* If something went wrong, bail without enabling anything */ |
| 730 | if (unlikely(ftrace_disabled)) |
| 731 | return -1; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 732 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 733 | p = ftrace_new_addrs; |
| 734 | ftrace_new_addrs = (struct dyn_ftrace *)p->flags; |
| 735 | p->flags = 0L; |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 736 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 737 | /* convert record (i.e, patch mcount-call with NOP) */ |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 738 | if (ftrace_code_disable(mod, p)) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 739 | p->flags |= FTRACE_FL_CONVERTED; |
| 740 | ftrace_update_cnt++; |
| 741 | } else |
| 742 | ftrace_free_rec(p); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 743 | } |
| 744 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 745 | stop = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 746 | ftrace_update_time = stop - start; |
| 747 | ftrace_update_tot_cnt += ftrace_update_cnt; |
| 748 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 749 | return 0; |
| 750 | } |
| 751 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 752 | static int __init ftrace_dyn_table_alloc(unsigned long num_to_init) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 753 | { |
| 754 | struct ftrace_page *pg; |
| 755 | int cnt; |
| 756 | int i; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 757 | |
| 758 | /* allocate a few pages */ |
| 759 | ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL); |
| 760 | if (!ftrace_pages_start) |
| 761 | return -1; |
| 762 | |
| 763 | /* |
| 764 | * Allocate a few more pages. |
| 765 | * |
| 766 | * TODO: have some parser search vmlinux before |
| 767 | * final linking to find all calls to ftrace. |
| 768 | * Then we can: |
| 769 | * a) know how many pages to allocate. |
| 770 | * and/or |
| 771 | * b) set up the table then. |
| 772 | * |
| 773 | * The dynamic code is still necessary for |
| 774 | * modules. |
| 775 | */ |
| 776 | |
| 777 | pg = ftrace_pages = ftrace_pages_start; |
| 778 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 779 | cnt = num_to_init / ENTRIES_PER_PAGE; |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 780 | pr_info("ftrace: allocating %ld entries in %d pages\n", |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 781 | num_to_init, cnt + 1); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 782 | |
| 783 | for (i = 0; i < cnt; i++) { |
| 784 | pg->next = (void *)get_zeroed_page(GFP_KERNEL); |
| 785 | |
| 786 | /* If we fail, we'll try later anyway */ |
| 787 | if (!pg->next) |
| 788 | break; |
| 789 | |
| 790 | pg = pg->next; |
| 791 | } |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 796 | enum { |
| 797 | FTRACE_ITER_FILTER = (1 << 0), |
| 798 | FTRACE_ITER_CONT = (1 << 1), |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 799 | FTRACE_ITER_NOTRACE = (1 << 2), |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 800 | FTRACE_ITER_FAILURES = (1 << 3), |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 801 | FTRACE_ITER_PRINTALL = (1 << 4), |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 802 | FTRACE_ITER_HASH = (1 << 5), |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 803 | }; |
| 804 | |
| 805 | #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */ |
| 806 | |
| 807 | struct ftrace_iterator { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 808 | struct ftrace_page *pg; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 809 | int hidx; |
Steven Rostedt | 431aa3f | 2009-01-06 12:43:01 -0500 | [diff] [blame] | 810 | int idx; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 811 | unsigned flags; |
| 812 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 813 | unsigned buffer_idx; |
| 814 | unsigned filtered; |
| 815 | }; |
| 816 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 817 | static void * |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 818 | t_hash_next(struct seq_file *m, void *v, loff_t *pos) |
| 819 | { |
| 820 | struct ftrace_iterator *iter = m->private; |
| 821 | struct hlist_node *hnd = v; |
| 822 | struct hlist_head *hhd; |
| 823 | |
| 824 | WARN_ON(!(iter->flags & FTRACE_ITER_HASH)); |
| 825 | |
| 826 | (*pos)++; |
| 827 | |
| 828 | retry: |
| 829 | if (iter->hidx >= FTRACE_FUNC_HASHSIZE) |
| 830 | return NULL; |
| 831 | |
| 832 | hhd = &ftrace_func_hash[iter->hidx]; |
| 833 | |
| 834 | if (hlist_empty(hhd)) { |
| 835 | iter->hidx++; |
| 836 | hnd = NULL; |
| 837 | goto retry; |
| 838 | } |
| 839 | |
| 840 | if (!hnd) |
| 841 | hnd = hhd->first; |
| 842 | else { |
| 843 | hnd = hnd->next; |
| 844 | if (!hnd) { |
| 845 | iter->hidx++; |
| 846 | goto retry; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | return hnd; |
| 851 | } |
| 852 | |
| 853 | static void *t_hash_start(struct seq_file *m, loff_t *pos) |
| 854 | { |
| 855 | struct ftrace_iterator *iter = m->private; |
| 856 | void *p = NULL; |
| 857 | |
| 858 | iter->flags |= FTRACE_ITER_HASH; |
| 859 | |
| 860 | return t_hash_next(m, p, pos); |
| 861 | } |
| 862 | |
| 863 | static int t_hash_show(struct seq_file *m, void *v) |
| 864 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 865 | struct ftrace_func_probe *rec; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 866 | struct hlist_node *hnd = v; |
| 867 | char str[KSYM_SYMBOL_LEN]; |
| 868 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 869 | rec = hlist_entry(hnd, struct ftrace_func_probe, node); |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 870 | |
Steven Rostedt | 809dcf2 | 2009-02-16 23:06:01 -0500 | [diff] [blame] | 871 | if (rec->ops->print) |
| 872 | return rec->ops->print(m, rec->ip, rec->ops, rec->data); |
| 873 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 874 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 875 | seq_printf(m, "%s:", str); |
| 876 | |
| 877 | kallsyms_lookup((unsigned long)rec->ops->func, NULL, NULL, NULL, str); |
| 878 | seq_printf(m, "%s", str); |
| 879 | |
| 880 | if (rec->data) |
| 881 | seq_printf(m, ":%p", rec->data); |
| 882 | seq_putc(m, '\n'); |
| 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | static void * |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 888 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 889 | { |
| 890 | struct ftrace_iterator *iter = m->private; |
| 891 | struct dyn_ftrace *rec = NULL; |
| 892 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 893 | if (iter->flags & FTRACE_ITER_HASH) |
| 894 | return t_hash_next(m, v, pos); |
| 895 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 896 | (*pos)++; |
| 897 | |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 898 | if (iter->flags & FTRACE_ITER_PRINTALL) |
| 899 | return NULL; |
| 900 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 901 | retry: |
| 902 | if (iter->idx >= iter->pg->index) { |
| 903 | if (iter->pg->next) { |
| 904 | iter->pg = iter->pg->next; |
| 905 | iter->idx = 0; |
| 906 | goto retry; |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 907 | } else { |
| 908 | iter->idx = -1; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 909 | } |
| 910 | } else { |
| 911 | rec = &iter->pg->records[iter->idx++]; |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 912 | if ((rec->flags & FTRACE_FL_FREE) || |
| 913 | |
| 914 | (!(iter->flags & FTRACE_ITER_FAILURES) && |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 915 | (rec->flags & FTRACE_FL_FAILED)) || |
| 916 | |
| 917 | ((iter->flags & FTRACE_ITER_FAILURES) && |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 918 | !(rec->flags & FTRACE_FL_FAILED)) || |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 919 | |
Steven Rostedt | 0183fb1 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 920 | ((iter->flags & FTRACE_ITER_FILTER) && |
| 921 | !(rec->flags & FTRACE_FL_FILTER)) || |
| 922 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 923 | ((iter->flags & FTRACE_ITER_NOTRACE) && |
| 924 | !(rec->flags & FTRACE_FL_NOTRACE))) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 925 | rec = NULL; |
| 926 | goto retry; |
| 927 | } |
| 928 | } |
| 929 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 930 | return rec; |
| 931 | } |
| 932 | |
| 933 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 934 | { |
| 935 | struct ftrace_iterator *iter = m->private; |
| 936 | void *p = NULL; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 937 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 938 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 939 | /* |
| 940 | * For set_ftrace_filter reading, if we have the filter |
| 941 | * off, we can short cut and just print out that all |
| 942 | * functions are enabled. |
| 943 | */ |
| 944 | if (iter->flags & FTRACE_ITER_FILTER && !ftrace_filtered) { |
| 945 | if (*pos > 0) |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 946 | return t_hash_start(m, pos); |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 947 | iter->flags |= FTRACE_ITER_PRINTALL; |
| 948 | (*pos)++; |
| 949 | return iter; |
| 950 | } |
| 951 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 952 | if (iter->flags & FTRACE_ITER_HASH) |
| 953 | return t_hash_start(m, pos); |
| 954 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 955 | if (*pos > 0) { |
| 956 | if (iter->idx < 0) |
| 957 | return p; |
| 958 | (*pos)--; |
| 959 | iter->idx--; |
| 960 | } |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 961 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 962 | p = t_next(m, p, pos); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 963 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 964 | if (!p) |
| 965 | return t_hash_start(m, pos); |
| 966 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 967 | return p; |
| 968 | } |
| 969 | |
| 970 | static void t_stop(struct seq_file *m, void *p) |
| 971 | { |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 972 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | static int t_show(struct seq_file *m, void *v) |
| 976 | { |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 977 | struct ftrace_iterator *iter = m->private; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 978 | struct dyn_ftrace *rec = v; |
| 979 | char str[KSYM_SYMBOL_LEN]; |
| 980 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 981 | if (iter->flags & FTRACE_ITER_HASH) |
| 982 | return t_hash_show(m, v); |
| 983 | |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 984 | if (iter->flags & FTRACE_ITER_PRINTALL) { |
| 985 | seq_printf(m, "#### all functions enabled ####\n"); |
| 986 | return 0; |
| 987 | } |
| 988 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 989 | if (!rec) |
| 990 | return 0; |
| 991 | |
| 992 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 993 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 994 | seq_printf(m, "%s\n", str); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 995 | |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | static struct seq_operations show_ftrace_seq_ops = { |
| 1000 | .start = t_start, |
| 1001 | .next = t_next, |
| 1002 | .stop = t_stop, |
| 1003 | .show = t_show, |
| 1004 | }; |
| 1005 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1006 | static int |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1007 | ftrace_avail_open(struct inode *inode, struct file *file) |
| 1008 | { |
| 1009 | struct ftrace_iterator *iter; |
| 1010 | int ret; |
| 1011 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1012 | if (unlikely(ftrace_disabled)) |
| 1013 | return -ENODEV; |
| 1014 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1015 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 1016 | if (!iter) |
| 1017 | return -ENOMEM; |
| 1018 | |
| 1019 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1020 | |
| 1021 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 1022 | if (!ret) { |
| 1023 | struct seq_file *m = file->private_data; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1024 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1025 | m->private = iter; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1026 | } else { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1027 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1028 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | int ftrace_avail_release(struct inode *inode, struct file *file) |
| 1034 | { |
| 1035 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1036 | struct ftrace_iterator *iter = m->private; |
| 1037 | |
| 1038 | seq_release(inode, file); |
| 1039 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1040 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1041 | return 0; |
| 1042 | } |
| 1043 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1044 | static int |
| 1045 | ftrace_failures_open(struct inode *inode, struct file *file) |
| 1046 | { |
| 1047 | int ret; |
| 1048 | struct seq_file *m; |
| 1049 | struct ftrace_iterator *iter; |
| 1050 | |
| 1051 | ret = ftrace_avail_open(inode, file); |
| 1052 | if (!ret) { |
| 1053 | m = (struct seq_file *)file->private_data; |
| 1054 | iter = (struct ftrace_iterator *)m->private; |
| 1055 | iter->flags = FTRACE_ITER_FAILURES; |
| 1056 | } |
| 1057 | |
| 1058 | return ret; |
| 1059 | } |
| 1060 | |
| 1061 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1062 | static void ftrace_filter_reset(int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1063 | { |
| 1064 | struct ftrace_page *pg; |
| 1065 | struct dyn_ftrace *rec; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1066 | unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1067 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1068 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1069 | if (enable) |
| 1070 | ftrace_filtered = 0; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1071 | do_for_each_ftrace_rec(pg, rec) { |
| 1072 | if (rec->flags & FTRACE_FL_FAILED) |
| 1073 | continue; |
| 1074 | rec->flags &= ~type; |
| 1075 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1076 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1077 | } |
| 1078 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1079 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1080 | ftrace_regex_open(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1081 | { |
| 1082 | struct ftrace_iterator *iter; |
| 1083 | int ret = 0; |
| 1084 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1085 | if (unlikely(ftrace_disabled)) |
| 1086 | return -ENODEV; |
| 1087 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1088 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 1089 | if (!iter) |
| 1090 | return -ENOMEM; |
| 1091 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1092 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1093 | if ((file->f_mode & FMODE_WRITE) && |
| 1094 | !(file->f_flags & O_APPEND)) |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1095 | ftrace_filter_reset(enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1096 | |
| 1097 | if (file->f_mode & FMODE_READ) { |
| 1098 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1099 | iter->flags = enable ? FTRACE_ITER_FILTER : |
| 1100 | FTRACE_ITER_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1101 | |
| 1102 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 1103 | if (!ret) { |
| 1104 | struct seq_file *m = file->private_data; |
| 1105 | m->private = iter; |
| 1106 | } else |
| 1107 | kfree(iter); |
| 1108 | } else |
| 1109 | file->private_data = iter; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1110 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1111 | |
| 1112 | return ret; |
| 1113 | } |
| 1114 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1115 | static int |
| 1116 | ftrace_filter_open(struct inode *inode, struct file *file) |
| 1117 | { |
| 1118 | return ftrace_regex_open(inode, file, 1); |
| 1119 | } |
| 1120 | |
| 1121 | static int |
| 1122 | ftrace_notrace_open(struct inode *inode, struct file *file) |
| 1123 | { |
| 1124 | return ftrace_regex_open(inode, file, 0); |
| 1125 | } |
| 1126 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1127 | static loff_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1128 | ftrace_regex_lseek(struct file *file, loff_t offset, int origin) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1129 | { |
| 1130 | loff_t ret; |
| 1131 | |
| 1132 | if (file->f_mode & FMODE_READ) |
| 1133 | ret = seq_lseek(file, offset, origin); |
| 1134 | else |
| 1135 | file->f_pos = ret = 1; |
| 1136 | |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
| 1140 | enum { |
| 1141 | MATCH_FULL, |
| 1142 | MATCH_FRONT_ONLY, |
| 1143 | MATCH_MIDDLE_ONLY, |
| 1144 | MATCH_END_ONLY, |
| 1145 | }; |
| 1146 | |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1147 | /* |
| 1148 | * (static function - no need for kernel doc) |
| 1149 | * |
| 1150 | * Pass in a buffer containing a glob and this function will |
| 1151 | * set search to point to the search part of the buffer and |
| 1152 | * return the type of search it is (see enum above). |
| 1153 | * This does modify buff. |
| 1154 | * |
| 1155 | * Returns enum type. |
| 1156 | * search returns the pointer to use for comparison. |
| 1157 | * not returns 1 if buff started with a '!' |
| 1158 | * 0 otherwise. |
| 1159 | */ |
| 1160 | static int |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1161 | ftrace_setup_glob(char *buff, int len, char **search, int *not) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1162 | { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1163 | int type = MATCH_FULL; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1164 | int i; |
Steven Rostedt | ea3a6d6 | 2008-12-17 15:05:36 -0500 | [diff] [blame] | 1165 | |
| 1166 | if (buff[0] == '!') { |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1167 | *not = 1; |
Steven Rostedt | ea3a6d6 | 2008-12-17 15:05:36 -0500 | [diff] [blame] | 1168 | buff++; |
| 1169 | len--; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1170 | } else |
| 1171 | *not = 0; |
| 1172 | |
| 1173 | *search = buff; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1174 | |
| 1175 | for (i = 0; i < len; i++) { |
| 1176 | if (buff[i] == '*') { |
| 1177 | if (!i) { |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1178 | *search = buff + 1; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1179 | type = MATCH_END_ONLY; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1180 | } else { |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1181 | if (type == MATCH_END_ONLY) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1182 | type = MATCH_MIDDLE_ONLY; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1183 | else |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1184 | type = MATCH_FRONT_ONLY; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1185 | buff[i] = 0; |
| 1186 | break; |
| 1187 | } |
| 1188 | } |
| 1189 | } |
| 1190 | |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1191 | return type; |
| 1192 | } |
| 1193 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1194 | static int ftrace_match(char *str, char *regex, int len, int type) |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1195 | { |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1196 | int matched = 0; |
| 1197 | char *ptr; |
| 1198 | |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1199 | switch (type) { |
| 1200 | case MATCH_FULL: |
| 1201 | if (strcmp(str, regex) == 0) |
| 1202 | matched = 1; |
| 1203 | break; |
| 1204 | case MATCH_FRONT_ONLY: |
| 1205 | if (strncmp(str, regex, len) == 0) |
| 1206 | matched = 1; |
| 1207 | break; |
| 1208 | case MATCH_MIDDLE_ONLY: |
| 1209 | if (strstr(str, regex)) |
| 1210 | matched = 1; |
| 1211 | break; |
| 1212 | case MATCH_END_ONLY: |
| 1213 | ptr = strstr(str, regex); |
| 1214 | if (ptr && (ptr[len] == 0)) |
| 1215 | matched = 1; |
| 1216 | break; |
| 1217 | } |
| 1218 | |
| 1219 | return matched; |
| 1220 | } |
| 1221 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1222 | static int |
| 1223 | ftrace_match_record(struct dyn_ftrace *rec, char *regex, int len, int type) |
| 1224 | { |
| 1225 | char str[KSYM_SYMBOL_LEN]; |
| 1226 | |
| 1227 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 1228 | return ftrace_match(str, regex, len, type); |
| 1229 | } |
| 1230 | |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1231 | static void ftrace_match_records(char *buff, int len, int enable) |
| 1232 | { |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1233 | unsigned int search_len; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1234 | struct ftrace_page *pg; |
| 1235 | struct dyn_ftrace *rec; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1236 | unsigned long flag; |
| 1237 | char *search; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1238 | int type; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1239 | int not; |
| 1240 | |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1241 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1242 | type = ftrace_setup_glob(buff, len, &search, ¬); |
| 1243 | |
| 1244 | search_len = strlen(search); |
| 1245 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1246 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1247 | do_for_each_ftrace_rec(pg, rec) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1248 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1249 | if (rec->flags & FTRACE_FL_FAILED) |
| 1250 | continue; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1251 | |
| 1252 | if (ftrace_match_record(rec, search, search_len, type)) { |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1253 | if (not) |
| 1254 | rec->flags &= ~flag; |
| 1255 | else |
| 1256 | rec->flags |= flag; |
| 1257 | } |
Steven Rostedt | e68746a | 2009-02-13 20:53:42 -0500 | [diff] [blame] | 1258 | /* |
| 1259 | * Only enable filtering if we have a function that |
| 1260 | * is filtered on. |
| 1261 | */ |
| 1262 | if (enable && (rec->flags & FTRACE_FL_FILTER)) |
| 1263 | ftrace_filtered = 1; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1264 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1265 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1266 | } |
| 1267 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1268 | static int |
| 1269 | ftrace_match_module_record(struct dyn_ftrace *rec, char *mod, |
| 1270 | char *regex, int len, int type) |
| 1271 | { |
| 1272 | char str[KSYM_SYMBOL_LEN]; |
| 1273 | char *modname; |
| 1274 | |
| 1275 | kallsyms_lookup(rec->ip, NULL, NULL, &modname, str); |
| 1276 | |
| 1277 | if (!modname || strcmp(modname, mod)) |
| 1278 | return 0; |
| 1279 | |
| 1280 | /* blank search means to match all funcs in the mod */ |
| 1281 | if (len) |
| 1282 | return ftrace_match(str, regex, len, type); |
| 1283 | else |
| 1284 | return 1; |
| 1285 | } |
| 1286 | |
| 1287 | static void ftrace_match_module_records(char *buff, char *mod, int enable) |
| 1288 | { |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1289 | unsigned search_len = 0; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1290 | struct ftrace_page *pg; |
| 1291 | struct dyn_ftrace *rec; |
| 1292 | int type = MATCH_FULL; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1293 | char *search = buff; |
| 1294 | unsigned long flag; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1295 | int not = 0; |
| 1296 | |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1297 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
| 1298 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1299 | /* blank or '*' mean the same */ |
| 1300 | if (strcmp(buff, "*") == 0) |
| 1301 | buff[0] = 0; |
| 1302 | |
| 1303 | /* handle the case of 'dont filter this module' */ |
| 1304 | if (strcmp(buff, "!") == 0 || strcmp(buff, "!*") == 0) { |
| 1305 | buff[0] = 0; |
| 1306 | not = 1; |
| 1307 | } |
| 1308 | |
| 1309 | if (strlen(buff)) { |
| 1310 | type = ftrace_setup_glob(buff, strlen(buff), &search, ¬); |
| 1311 | search_len = strlen(search); |
| 1312 | } |
| 1313 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1314 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1315 | do_for_each_ftrace_rec(pg, rec) { |
| 1316 | |
| 1317 | if (rec->flags & FTRACE_FL_FAILED) |
| 1318 | continue; |
| 1319 | |
| 1320 | if (ftrace_match_module_record(rec, mod, |
| 1321 | search, search_len, type)) { |
| 1322 | if (not) |
| 1323 | rec->flags &= ~flag; |
| 1324 | else |
| 1325 | rec->flags |= flag; |
| 1326 | } |
Steven Rostedt | e68746a | 2009-02-13 20:53:42 -0500 | [diff] [blame] | 1327 | if (enable && (rec->flags & FTRACE_FL_FILTER)) |
| 1328 | ftrace_filtered = 1; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1329 | |
| 1330 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1331 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1334 | /* |
| 1335 | * We register the module command as a template to show others how |
| 1336 | * to register the a command as well. |
| 1337 | */ |
| 1338 | |
| 1339 | static int |
| 1340 | ftrace_mod_callback(char *func, char *cmd, char *param, int enable) |
| 1341 | { |
| 1342 | char *mod; |
| 1343 | |
| 1344 | /* |
| 1345 | * cmd == 'mod' because we only registered this func |
| 1346 | * for the 'mod' ftrace_func_command. |
| 1347 | * But if you register one func with multiple commands, |
| 1348 | * you can tell which command was used by the cmd |
| 1349 | * parameter. |
| 1350 | */ |
| 1351 | |
| 1352 | /* we must have a module name */ |
| 1353 | if (!param) |
| 1354 | return -EINVAL; |
| 1355 | |
| 1356 | mod = strsep(¶m, ":"); |
| 1357 | if (!strlen(mod)) |
| 1358 | return -EINVAL; |
| 1359 | |
| 1360 | ftrace_match_module_records(func, mod, enable); |
| 1361 | return 0; |
| 1362 | } |
| 1363 | |
| 1364 | static struct ftrace_func_command ftrace_mod_cmd = { |
| 1365 | .name = "mod", |
| 1366 | .func = ftrace_mod_callback, |
| 1367 | }; |
| 1368 | |
| 1369 | static int __init ftrace_mod_cmd_init(void) |
| 1370 | { |
| 1371 | return register_ftrace_command(&ftrace_mod_cmd); |
| 1372 | } |
| 1373 | device_initcall(ftrace_mod_cmd_init); |
| 1374 | |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1375 | static void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1376 | function_trace_probe_call(unsigned long ip, unsigned long parent_ip) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1377 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1378 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1379 | struct hlist_head *hhd; |
| 1380 | struct hlist_node *n; |
| 1381 | unsigned long key; |
| 1382 | int resched; |
| 1383 | |
| 1384 | key = hash_long(ip, FTRACE_HASH_BITS); |
| 1385 | |
| 1386 | hhd = &ftrace_func_hash[key]; |
| 1387 | |
| 1388 | if (hlist_empty(hhd)) |
| 1389 | return; |
| 1390 | |
| 1391 | /* |
| 1392 | * Disable preemption for these calls to prevent a RCU grace |
| 1393 | * period. This syncs the hash iteration and freeing of items |
| 1394 | * on the hash. rcu_read_lock is too dangerous here. |
| 1395 | */ |
| 1396 | resched = ftrace_preempt_disable(); |
| 1397 | hlist_for_each_entry_rcu(entry, n, hhd, node) { |
| 1398 | if (entry->ip == ip) |
| 1399 | entry->ops->func(ip, parent_ip, &entry->data); |
| 1400 | } |
| 1401 | ftrace_preempt_enable(resched); |
| 1402 | } |
| 1403 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1404 | static struct ftrace_ops trace_probe_ops __read_mostly = |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1405 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1406 | .func = function_trace_probe_call, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1407 | }; |
| 1408 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1409 | static int ftrace_probe_registered; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1410 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1411 | static void __enable_ftrace_function_probe(void) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1412 | { |
| 1413 | int i; |
| 1414 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1415 | if (ftrace_probe_registered) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1416 | return; |
| 1417 | |
| 1418 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 1419 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 1420 | if (hhd->first) |
| 1421 | break; |
| 1422 | } |
| 1423 | /* Nothing registered? */ |
| 1424 | if (i == FTRACE_FUNC_HASHSIZE) |
| 1425 | return; |
| 1426 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1427 | __register_ftrace_function(&trace_probe_ops); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1428 | ftrace_startup(0); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1429 | ftrace_probe_registered = 1; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1430 | } |
| 1431 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1432 | static void __disable_ftrace_function_probe(void) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1433 | { |
| 1434 | int i; |
| 1435 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1436 | if (!ftrace_probe_registered) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1437 | return; |
| 1438 | |
| 1439 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 1440 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 1441 | if (hhd->first) |
| 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | /* no more funcs left */ |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1446 | __unregister_ftrace_function(&trace_probe_ops); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1447 | ftrace_shutdown(0); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1448 | ftrace_probe_registered = 0; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | static void ftrace_free_entry_rcu(struct rcu_head *rhp) |
| 1453 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1454 | struct ftrace_func_probe *entry = |
| 1455 | container_of(rhp, struct ftrace_func_probe, rcu); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1456 | |
| 1457 | if (entry->ops->free) |
| 1458 | entry->ops->free(&entry->data); |
| 1459 | kfree(entry); |
| 1460 | } |
| 1461 | |
| 1462 | |
| 1463 | int |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1464 | register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1465 | void *data) |
| 1466 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1467 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1468 | struct ftrace_page *pg; |
| 1469 | struct dyn_ftrace *rec; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1470 | int type, len, not; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1471 | unsigned long key; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1472 | int count = 0; |
| 1473 | char *search; |
| 1474 | |
| 1475 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); |
| 1476 | len = strlen(search); |
| 1477 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1478 | /* we do not support '!' for function probes */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1479 | if (WARN_ON(not)) |
| 1480 | return -EINVAL; |
| 1481 | |
| 1482 | mutex_lock(&ftrace_lock); |
| 1483 | do_for_each_ftrace_rec(pg, rec) { |
| 1484 | |
| 1485 | if (rec->flags & FTRACE_FL_FAILED) |
| 1486 | continue; |
| 1487 | |
| 1488 | if (!ftrace_match_record(rec, search, len, type)) |
| 1489 | continue; |
| 1490 | |
| 1491 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 1492 | if (!entry) { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1493 | /* If we did not process any, then return error */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1494 | if (!count) |
| 1495 | count = -ENOMEM; |
| 1496 | goto out_unlock; |
| 1497 | } |
| 1498 | |
| 1499 | count++; |
| 1500 | |
| 1501 | entry->data = data; |
| 1502 | |
| 1503 | /* |
| 1504 | * The caller might want to do something special |
| 1505 | * for each function we find. We call the callback |
| 1506 | * to give the caller an opportunity to do so. |
| 1507 | */ |
| 1508 | if (ops->callback) { |
| 1509 | if (ops->callback(rec->ip, &entry->data) < 0) { |
| 1510 | /* caller does not like this func */ |
| 1511 | kfree(entry); |
| 1512 | continue; |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | entry->ops = ops; |
| 1517 | entry->ip = rec->ip; |
| 1518 | |
| 1519 | key = hash_long(entry->ip, FTRACE_HASH_BITS); |
| 1520 | hlist_add_head_rcu(&entry->node, &ftrace_func_hash[key]); |
| 1521 | |
| 1522 | } while_for_each_ftrace_rec(); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1523 | __enable_ftrace_function_probe(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1524 | |
| 1525 | out_unlock: |
| 1526 | mutex_unlock(&ftrace_lock); |
| 1527 | |
| 1528 | return count; |
| 1529 | } |
| 1530 | |
| 1531 | enum { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1532 | PROBE_TEST_FUNC = 1, |
| 1533 | PROBE_TEST_DATA = 2 |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1534 | }; |
| 1535 | |
| 1536 | static void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1537 | __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1538 | void *data, int flags) |
| 1539 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1540 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1541 | struct hlist_node *n, *tmp; |
| 1542 | char str[KSYM_SYMBOL_LEN]; |
| 1543 | int type = MATCH_FULL; |
| 1544 | int i, len = 0; |
| 1545 | char *search; |
| 1546 | |
| 1547 | if (glob && (strcmp(glob, "*") || !strlen(glob))) |
| 1548 | glob = NULL; |
| 1549 | else { |
| 1550 | int not; |
| 1551 | |
| 1552 | type = ftrace_setup_glob(glob, strlen(glob), &search, ¬); |
| 1553 | len = strlen(search); |
| 1554 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1555 | /* we do not support '!' for function probes */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1556 | if (WARN_ON(not)) |
| 1557 | return; |
| 1558 | } |
| 1559 | |
| 1560 | mutex_lock(&ftrace_lock); |
| 1561 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 1562 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 1563 | |
| 1564 | hlist_for_each_entry_safe(entry, n, tmp, hhd, node) { |
| 1565 | |
| 1566 | /* break up if statements for readability */ |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1567 | if ((flags & PROBE_TEST_FUNC) && entry->ops != ops) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1568 | continue; |
| 1569 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1570 | if ((flags & PROBE_TEST_DATA) && entry->data != data) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1571 | continue; |
| 1572 | |
| 1573 | /* do this last, since it is the most expensive */ |
| 1574 | if (glob) { |
| 1575 | kallsyms_lookup(entry->ip, NULL, NULL, |
| 1576 | NULL, str); |
| 1577 | if (!ftrace_match(str, glob, len, type)) |
| 1578 | continue; |
| 1579 | } |
| 1580 | |
| 1581 | hlist_del(&entry->node); |
| 1582 | call_rcu(&entry->rcu, ftrace_free_entry_rcu); |
| 1583 | } |
| 1584 | } |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1585 | __disable_ftrace_function_probe(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1586 | mutex_unlock(&ftrace_lock); |
| 1587 | } |
| 1588 | |
| 1589 | void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1590 | unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1591 | void *data) |
| 1592 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1593 | __unregister_ftrace_function_probe(glob, ops, data, |
| 1594 | PROBE_TEST_FUNC | PROBE_TEST_DATA); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1598 | unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1599 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1600 | __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1601 | } |
| 1602 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1603 | void unregister_ftrace_function_probe_all(char *glob) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1604 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1605 | __unregister_ftrace_function_probe(glob, NULL, NULL, 0); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1606 | } |
| 1607 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1608 | static LIST_HEAD(ftrace_commands); |
| 1609 | static DEFINE_MUTEX(ftrace_cmd_mutex); |
| 1610 | |
| 1611 | int register_ftrace_command(struct ftrace_func_command *cmd) |
| 1612 | { |
| 1613 | struct ftrace_func_command *p; |
| 1614 | int ret = 0; |
| 1615 | |
| 1616 | mutex_lock(&ftrace_cmd_mutex); |
| 1617 | list_for_each_entry(p, &ftrace_commands, list) { |
| 1618 | if (strcmp(cmd->name, p->name) == 0) { |
| 1619 | ret = -EBUSY; |
| 1620 | goto out_unlock; |
| 1621 | } |
| 1622 | } |
| 1623 | list_add(&cmd->list, &ftrace_commands); |
| 1624 | out_unlock: |
| 1625 | mutex_unlock(&ftrace_cmd_mutex); |
| 1626 | |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | int unregister_ftrace_command(struct ftrace_func_command *cmd) |
| 1631 | { |
| 1632 | struct ftrace_func_command *p, *n; |
| 1633 | int ret = -ENODEV; |
| 1634 | |
| 1635 | mutex_lock(&ftrace_cmd_mutex); |
| 1636 | list_for_each_entry_safe(p, n, &ftrace_commands, list) { |
| 1637 | if (strcmp(cmd->name, p->name) == 0) { |
| 1638 | ret = 0; |
| 1639 | list_del_init(&p->list); |
| 1640 | goto out_unlock; |
| 1641 | } |
| 1642 | } |
| 1643 | out_unlock: |
| 1644 | mutex_unlock(&ftrace_cmd_mutex); |
| 1645 | |
| 1646 | return ret; |
| 1647 | } |
| 1648 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1649 | static int ftrace_process_regex(char *buff, int len, int enable) |
| 1650 | { |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1651 | char *func, *command, *next = buff; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1652 | struct ftrace_func_command *p; |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1653 | int ret = -EINVAL; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1654 | |
| 1655 | func = strsep(&next, ":"); |
| 1656 | |
| 1657 | if (!next) { |
| 1658 | ftrace_match_records(func, len, enable); |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1662 | /* command found */ |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1663 | |
| 1664 | command = strsep(&next, ":"); |
| 1665 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1666 | mutex_lock(&ftrace_cmd_mutex); |
| 1667 | list_for_each_entry(p, &ftrace_commands, list) { |
| 1668 | if (strcmp(p->name, command) == 0) { |
| 1669 | ret = p->func(func, command, next, enable); |
| 1670 | goto out_unlock; |
| 1671 | } |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1672 | } |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1673 | out_unlock: |
| 1674 | mutex_unlock(&ftrace_cmd_mutex); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1675 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1676 | return ret; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1677 | } |
| 1678 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1679 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1680 | ftrace_regex_write(struct file *file, const char __user *ubuf, |
| 1681 | size_t cnt, loff_t *ppos, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1682 | { |
| 1683 | struct ftrace_iterator *iter; |
| 1684 | char ch; |
| 1685 | size_t read = 0; |
| 1686 | ssize_t ret; |
| 1687 | |
| 1688 | if (!cnt || cnt < 0) |
| 1689 | return 0; |
| 1690 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1691 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1692 | |
| 1693 | if (file->f_mode & FMODE_READ) { |
| 1694 | struct seq_file *m = file->private_data; |
| 1695 | iter = m->private; |
| 1696 | } else |
| 1697 | iter = file->private_data; |
| 1698 | |
| 1699 | if (!*ppos) { |
| 1700 | iter->flags &= ~FTRACE_ITER_CONT; |
| 1701 | iter->buffer_idx = 0; |
| 1702 | } |
| 1703 | |
| 1704 | ret = get_user(ch, ubuf++); |
| 1705 | if (ret) |
| 1706 | goto out; |
| 1707 | read++; |
| 1708 | cnt--; |
| 1709 | |
| 1710 | if (!(iter->flags & ~FTRACE_ITER_CONT)) { |
| 1711 | /* skip white space */ |
| 1712 | while (cnt && isspace(ch)) { |
| 1713 | ret = get_user(ch, ubuf++); |
| 1714 | if (ret) |
| 1715 | goto out; |
| 1716 | read++; |
| 1717 | cnt--; |
| 1718 | } |
| 1719 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1720 | if (isspace(ch)) { |
| 1721 | file->f_pos += read; |
| 1722 | ret = read; |
| 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | iter->buffer_idx = 0; |
| 1727 | } |
| 1728 | |
| 1729 | while (cnt && !isspace(ch)) { |
| 1730 | if (iter->buffer_idx < FTRACE_BUFF_MAX) |
| 1731 | iter->buffer[iter->buffer_idx++] = ch; |
| 1732 | else { |
| 1733 | ret = -EINVAL; |
| 1734 | goto out; |
| 1735 | } |
| 1736 | ret = get_user(ch, ubuf++); |
| 1737 | if (ret) |
| 1738 | goto out; |
| 1739 | read++; |
| 1740 | cnt--; |
| 1741 | } |
| 1742 | |
| 1743 | if (isspace(ch)) { |
| 1744 | iter->filtered++; |
| 1745 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1746 | ret = ftrace_process_regex(iter->buffer, |
| 1747 | iter->buffer_idx, enable); |
| 1748 | if (ret) |
| 1749 | goto out; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1750 | iter->buffer_idx = 0; |
| 1751 | } else |
| 1752 | iter->flags |= FTRACE_ITER_CONT; |
| 1753 | |
| 1754 | |
| 1755 | file->f_pos += read; |
| 1756 | |
| 1757 | ret = read; |
| 1758 | out: |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1759 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1760 | |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1764 | static ssize_t |
| 1765 | ftrace_filter_write(struct file *file, const char __user *ubuf, |
| 1766 | size_t cnt, loff_t *ppos) |
| 1767 | { |
| 1768 | return ftrace_regex_write(file, ubuf, cnt, ppos, 1); |
| 1769 | } |
| 1770 | |
| 1771 | static ssize_t |
| 1772 | ftrace_notrace_write(struct file *file, const char __user *ubuf, |
| 1773 | size_t cnt, loff_t *ppos) |
| 1774 | { |
| 1775 | return ftrace_regex_write(file, ubuf, cnt, ppos, 0); |
| 1776 | } |
| 1777 | |
| 1778 | static void |
| 1779 | ftrace_set_regex(unsigned char *buf, int len, int reset, int enable) |
| 1780 | { |
| 1781 | if (unlikely(ftrace_disabled)) |
| 1782 | return; |
| 1783 | |
| 1784 | mutex_lock(&ftrace_regex_lock); |
| 1785 | if (reset) |
| 1786 | ftrace_filter_reset(enable); |
| 1787 | if (buf) |
Steven Rostedt | 7f24b31 | 2009-02-13 14:37:33 -0500 | [diff] [blame] | 1788 | ftrace_match_records(buf, len, enable); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1789 | mutex_unlock(&ftrace_regex_lock); |
| 1790 | } |
| 1791 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1792 | /** |
| 1793 | * ftrace_set_filter - set a function to filter on in ftrace |
| 1794 | * @buf - the string that holds the function filter text. |
| 1795 | * @len - the length of the string. |
| 1796 | * @reset - non zero to reset all filters before applying this filter. |
| 1797 | * |
| 1798 | * Filters denote which functions should be enabled when tracing is enabled. |
| 1799 | * If @buf is NULL and reset is set, all functions will be enabled for tracing. |
| 1800 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1801 | void ftrace_set_filter(unsigned char *buf, int len, int reset) |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1802 | { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1803 | ftrace_set_regex(buf, len, reset, 1); |
| 1804 | } |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1805 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1806 | /** |
| 1807 | * ftrace_set_notrace - set a function to not trace in ftrace |
| 1808 | * @buf - the string that holds the function notrace text. |
| 1809 | * @len - the length of the string. |
| 1810 | * @reset - non zero to reset all filters before applying this filter. |
| 1811 | * |
| 1812 | * Notrace Filters denote which functions should not be enabled when tracing |
| 1813 | * is enabled. If @buf is NULL and reset is set, all functions will be enabled |
| 1814 | * for tracing. |
| 1815 | */ |
| 1816 | void ftrace_set_notrace(unsigned char *buf, int len, int reset) |
| 1817 | { |
| 1818 | ftrace_set_regex(buf, len, reset, 0); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1819 | } |
| 1820 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1821 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1822 | ftrace_regex_release(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1823 | { |
| 1824 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1825 | struct ftrace_iterator *iter; |
| 1826 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1827 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1828 | if (file->f_mode & FMODE_READ) { |
| 1829 | iter = m->private; |
| 1830 | |
| 1831 | seq_release(inode, file); |
| 1832 | } else |
| 1833 | iter = file->private_data; |
| 1834 | |
| 1835 | if (iter->buffer_idx) { |
| 1836 | iter->filtered++; |
| 1837 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 7f24b31 | 2009-02-13 14:37:33 -0500 | [diff] [blame] | 1838 | ftrace_match_records(iter->buffer, iter->buffer_idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 1841 | mutex_lock(&ftrace_lock); |
Steven Rostedt | ee02a2e | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1842 | if (ftrace_start_up && ftrace_enabled) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1843 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 1844 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1845 | |
| 1846 | kfree(iter); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1847 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1848 | return 0; |
| 1849 | } |
| 1850 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1851 | static int |
| 1852 | ftrace_filter_release(struct inode *inode, struct file *file) |
| 1853 | { |
| 1854 | return ftrace_regex_release(inode, file, 1); |
| 1855 | } |
| 1856 | |
| 1857 | static int |
| 1858 | ftrace_notrace_release(struct inode *inode, struct file *file) |
| 1859 | { |
| 1860 | return ftrace_regex_release(inode, file, 0); |
| 1861 | } |
| 1862 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 1863 | static const struct file_operations ftrace_avail_fops = { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1864 | .open = ftrace_avail_open, |
| 1865 | .read = seq_read, |
| 1866 | .llseek = seq_lseek, |
| 1867 | .release = ftrace_avail_release, |
| 1868 | }; |
| 1869 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 1870 | static const struct file_operations ftrace_failures_fops = { |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1871 | .open = ftrace_failures_open, |
| 1872 | .read = seq_read, |
| 1873 | .llseek = seq_lseek, |
| 1874 | .release = ftrace_avail_release, |
| 1875 | }; |
| 1876 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 1877 | static const struct file_operations ftrace_filter_fops = { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1878 | .open = ftrace_filter_open, |
Lai Jiangshan | 850a80c | 2009-03-13 17:47:23 +0800 | [diff] [blame] | 1879 | .read = seq_read, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1880 | .write = ftrace_filter_write, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1881 | .llseek = ftrace_regex_lseek, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1882 | .release = ftrace_filter_release, |
| 1883 | }; |
| 1884 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 1885 | static const struct file_operations ftrace_notrace_fops = { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1886 | .open = ftrace_notrace_open, |
Lai Jiangshan | 850a80c | 2009-03-13 17:47:23 +0800 | [diff] [blame] | 1887 | .read = seq_read, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1888 | .write = ftrace_notrace_write, |
| 1889 | .llseek = ftrace_regex_lseek, |
| 1890 | .release = ftrace_notrace_release, |
| 1891 | }; |
| 1892 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1893 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1894 | |
| 1895 | static DEFINE_MUTEX(graph_lock); |
| 1896 | |
| 1897 | int ftrace_graph_count; |
| 1898 | unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; |
| 1899 | |
| 1900 | static void * |
| 1901 | g_next(struct seq_file *m, void *v, loff_t *pos) |
| 1902 | { |
| 1903 | unsigned long *array = m->private; |
| 1904 | int index = *pos; |
| 1905 | |
| 1906 | (*pos)++; |
| 1907 | |
| 1908 | if (index >= ftrace_graph_count) |
| 1909 | return NULL; |
| 1910 | |
| 1911 | return &array[index]; |
| 1912 | } |
| 1913 | |
| 1914 | static void *g_start(struct seq_file *m, loff_t *pos) |
| 1915 | { |
| 1916 | void *p = NULL; |
| 1917 | |
| 1918 | mutex_lock(&graph_lock); |
| 1919 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 1920 | /* Nothing, tell g_show to print all functions are enabled */ |
| 1921 | if (!ftrace_graph_count && !*pos) |
| 1922 | return (void *)1; |
| 1923 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1924 | p = g_next(m, p, pos); |
| 1925 | |
| 1926 | return p; |
| 1927 | } |
| 1928 | |
| 1929 | static void g_stop(struct seq_file *m, void *p) |
| 1930 | { |
| 1931 | mutex_unlock(&graph_lock); |
| 1932 | } |
| 1933 | |
| 1934 | static int g_show(struct seq_file *m, void *v) |
| 1935 | { |
| 1936 | unsigned long *ptr = v; |
| 1937 | char str[KSYM_SYMBOL_LEN]; |
| 1938 | |
| 1939 | if (!ptr) |
| 1940 | return 0; |
| 1941 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 1942 | if (ptr == (unsigned long *)1) { |
| 1943 | seq_printf(m, "#### all functions enabled ####\n"); |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1947 | kallsyms_lookup(*ptr, NULL, NULL, NULL, str); |
| 1948 | |
| 1949 | seq_printf(m, "%s\n", str); |
| 1950 | |
| 1951 | return 0; |
| 1952 | } |
| 1953 | |
| 1954 | static struct seq_operations ftrace_graph_seq_ops = { |
| 1955 | .start = g_start, |
| 1956 | .next = g_next, |
| 1957 | .stop = g_stop, |
| 1958 | .show = g_show, |
| 1959 | }; |
| 1960 | |
| 1961 | static int |
| 1962 | ftrace_graph_open(struct inode *inode, struct file *file) |
| 1963 | { |
| 1964 | int ret = 0; |
| 1965 | |
| 1966 | if (unlikely(ftrace_disabled)) |
| 1967 | return -ENODEV; |
| 1968 | |
| 1969 | mutex_lock(&graph_lock); |
| 1970 | if ((file->f_mode & FMODE_WRITE) && |
| 1971 | !(file->f_flags & O_APPEND)) { |
| 1972 | ftrace_graph_count = 0; |
| 1973 | memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); |
| 1974 | } |
| 1975 | |
| 1976 | if (file->f_mode & FMODE_READ) { |
| 1977 | ret = seq_open(file, &ftrace_graph_seq_ops); |
| 1978 | if (!ret) { |
| 1979 | struct seq_file *m = file->private_data; |
| 1980 | m->private = ftrace_graph_funcs; |
| 1981 | } |
| 1982 | } else |
| 1983 | file->private_data = ftrace_graph_funcs; |
| 1984 | mutex_unlock(&graph_lock); |
| 1985 | |
| 1986 | return ret; |
| 1987 | } |
| 1988 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1989 | static int |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 1990 | ftrace_set_func(unsigned long *array, int *idx, char *buffer) |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1991 | { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1992 | struct dyn_ftrace *rec; |
| 1993 | struct ftrace_page *pg; |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 1994 | int search_len; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1995 | int found = 0; |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 1996 | int type, not; |
| 1997 | char *search; |
| 1998 | bool exists; |
| 1999 | int i; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2000 | |
| 2001 | if (ftrace_disabled) |
| 2002 | return -ENODEV; |
| 2003 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2004 | /* decode regex */ |
| 2005 | type = ftrace_setup_glob(buffer, strlen(buffer), &search, ¬); |
| 2006 | if (not) |
| 2007 | return -EINVAL; |
| 2008 | |
| 2009 | search_len = strlen(search); |
| 2010 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 2011 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2012 | do_for_each_ftrace_rec(pg, rec) { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2013 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2014 | if (*idx >= FTRACE_GRAPH_MAX_FUNCS) |
| 2015 | break; |
| 2016 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2017 | if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) |
| 2018 | continue; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2019 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2020 | if (ftrace_match_record(rec, search, search_len, type)) { |
| 2021 | /* ensure it is not already in the array */ |
| 2022 | exists = false; |
| 2023 | for (i = 0; i < *idx; i++) |
| 2024 | if (array[i] == rec->ip) { |
| 2025 | exists = true; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2026 | break; |
| 2027 | } |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2028 | if (!exists) { |
| 2029 | array[(*idx)++] = rec->ip; |
| 2030 | found = 1; |
| 2031 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2032 | } |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2033 | } while_for_each_ftrace_rec(); |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2034 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 2035 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2036 | |
| 2037 | return found ? 0 : -EINVAL; |
| 2038 | } |
| 2039 | |
| 2040 | static ssize_t |
| 2041 | ftrace_graph_write(struct file *file, const char __user *ubuf, |
| 2042 | size_t cnt, loff_t *ppos) |
| 2043 | { |
| 2044 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 2045 | unsigned long *array; |
| 2046 | size_t read = 0; |
| 2047 | ssize_t ret; |
| 2048 | int index = 0; |
| 2049 | char ch; |
| 2050 | |
| 2051 | if (!cnt || cnt < 0) |
| 2052 | return 0; |
| 2053 | |
| 2054 | mutex_lock(&graph_lock); |
| 2055 | |
| 2056 | if (ftrace_graph_count >= FTRACE_GRAPH_MAX_FUNCS) { |
| 2057 | ret = -EBUSY; |
| 2058 | goto out; |
| 2059 | } |
| 2060 | |
| 2061 | if (file->f_mode & FMODE_READ) { |
| 2062 | struct seq_file *m = file->private_data; |
| 2063 | array = m->private; |
| 2064 | } else |
| 2065 | array = file->private_data; |
| 2066 | |
| 2067 | ret = get_user(ch, ubuf++); |
| 2068 | if (ret) |
| 2069 | goto out; |
| 2070 | read++; |
| 2071 | cnt--; |
| 2072 | |
| 2073 | /* skip white space */ |
| 2074 | while (cnt && isspace(ch)) { |
| 2075 | ret = get_user(ch, ubuf++); |
| 2076 | if (ret) |
| 2077 | goto out; |
| 2078 | read++; |
| 2079 | cnt--; |
| 2080 | } |
| 2081 | |
| 2082 | if (isspace(ch)) { |
| 2083 | *ppos += read; |
| 2084 | ret = read; |
| 2085 | goto out; |
| 2086 | } |
| 2087 | |
| 2088 | while (cnt && !isspace(ch)) { |
| 2089 | if (index < FTRACE_BUFF_MAX) |
| 2090 | buffer[index++] = ch; |
| 2091 | else { |
| 2092 | ret = -EINVAL; |
| 2093 | goto out; |
| 2094 | } |
| 2095 | ret = get_user(ch, ubuf++); |
| 2096 | if (ret) |
| 2097 | goto out; |
| 2098 | read++; |
| 2099 | cnt--; |
| 2100 | } |
| 2101 | buffer[index] = 0; |
| 2102 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2103 | /* we allow only one expression at a time */ |
| 2104 | ret = ftrace_set_func(array, &ftrace_graph_count, buffer); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2105 | if (ret) |
| 2106 | goto out; |
| 2107 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2108 | file->f_pos += read; |
| 2109 | |
| 2110 | ret = read; |
| 2111 | out: |
| 2112 | mutex_unlock(&graph_lock); |
| 2113 | |
| 2114 | return ret; |
| 2115 | } |
| 2116 | |
| 2117 | static const struct file_operations ftrace_graph_fops = { |
| 2118 | .open = ftrace_graph_open, |
Lai Jiangshan | 850a80c | 2009-03-13 17:47:23 +0800 | [diff] [blame] | 2119 | .read = seq_read, |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2120 | .write = ftrace_graph_write, |
| 2121 | }; |
| 2122 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 2123 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2124 | static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2125 | { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2126 | struct dentry *entry; |
| 2127 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2128 | entry = debugfs_create_file("available_filter_functions", 0444, |
| 2129 | d_tracer, NULL, &ftrace_avail_fops); |
| 2130 | if (!entry) |
| 2131 | pr_warning("Could not create debugfs " |
| 2132 | "'available_filter_functions' entry\n"); |
| 2133 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 2134 | entry = debugfs_create_file("failures", 0444, |
| 2135 | d_tracer, NULL, &ftrace_failures_fops); |
| 2136 | if (!entry) |
| 2137 | pr_warning("Could not create debugfs 'failures' entry\n"); |
| 2138 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2139 | entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer, |
| 2140 | NULL, &ftrace_filter_fops); |
| 2141 | if (!entry) |
| 2142 | pr_warning("Could not create debugfs " |
| 2143 | "'set_ftrace_filter' entry\n"); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2144 | |
| 2145 | entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer, |
| 2146 | NULL, &ftrace_notrace_fops); |
| 2147 | if (!entry) |
| 2148 | pr_warning("Could not create debugfs " |
| 2149 | "'set_ftrace_notrace' entry\n"); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 2150 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2151 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 2152 | entry = debugfs_create_file("set_graph_function", 0444, d_tracer, |
| 2153 | NULL, |
| 2154 | &ftrace_graph_fops); |
| 2155 | if (!entry) |
| 2156 | pr_warning("Could not create debugfs " |
| 2157 | "'set_graph_function' entry\n"); |
| 2158 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 2159 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2160 | return 0; |
| 2161 | } |
| 2162 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2163 | static int ftrace_convert_nops(struct module *mod, |
| 2164 | unsigned long *start, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2165 | unsigned long *end) |
| 2166 | { |
| 2167 | unsigned long *p; |
| 2168 | unsigned long addr; |
| 2169 | unsigned long flags; |
| 2170 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2171 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2172 | p = start; |
| 2173 | while (p < end) { |
| 2174 | addr = ftrace_call_adjust(*p++); |
Steven Rostedt | 20e5227 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2175 | /* |
| 2176 | * Some architecture linkers will pad between |
| 2177 | * the different mcount_loc sections of different |
| 2178 | * object files to satisfy alignments. |
| 2179 | * Skip any NULL pointers. |
| 2180 | */ |
| 2181 | if (!addr) |
| 2182 | continue; |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2183 | ftrace_record_ip(addr); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2184 | } |
| 2185 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 2186 | /* disable interrupts to prevent kstop machine */ |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2187 | local_irq_save(flags); |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2188 | ftrace_update_code(mod); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2189 | local_irq_restore(flags); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2190 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2191 | |
| 2192 | return 0; |
| 2193 | } |
| 2194 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2195 | void ftrace_init_module(struct module *mod, |
| 2196 | unsigned long *start, unsigned long *end) |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 2197 | { |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 2198 | if (ftrace_disabled || start == end) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 2199 | return; |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2200 | ftrace_convert_nops(mod, start, end); |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2203 | extern unsigned long __start_mcount_loc[]; |
| 2204 | extern unsigned long __stop_mcount_loc[]; |
| 2205 | |
| 2206 | void __init ftrace_init(void) |
| 2207 | { |
| 2208 | unsigned long count, addr, flags; |
| 2209 | int ret; |
| 2210 | |
| 2211 | /* Keep the ftrace pointer to the stub */ |
| 2212 | addr = (unsigned long)ftrace_stub; |
| 2213 | |
| 2214 | local_irq_save(flags); |
| 2215 | ftrace_dyn_arch_init(&addr); |
| 2216 | local_irq_restore(flags); |
| 2217 | |
| 2218 | /* ftrace_dyn_arch_init places the return code in addr */ |
| 2219 | if (addr) |
| 2220 | goto failed; |
| 2221 | |
| 2222 | count = __stop_mcount_loc - __start_mcount_loc; |
| 2223 | |
| 2224 | ret = ftrace_dyn_table_alloc(count); |
| 2225 | if (ret) |
| 2226 | goto failed; |
| 2227 | |
| 2228 | last_ftrace_enabled = ftrace_enabled = 1; |
| 2229 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2230 | ret = ftrace_convert_nops(NULL, |
| 2231 | __start_mcount_loc, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2232 | __stop_mcount_loc); |
| 2233 | |
| 2234 | return; |
| 2235 | failed: |
| 2236 | ftrace_disabled = 1; |
| 2237 | } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2238 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2239 | #else |
Frederic Weisbecker | 0b6e4d5 | 2008-10-28 20:17:38 +0100 | [diff] [blame] | 2240 | |
| 2241 | static int __init ftrace_nodyn_init(void) |
| 2242 | { |
| 2243 | ftrace_enabled = 1; |
| 2244 | return 0; |
| 2245 | } |
| 2246 | device_initcall(ftrace_nodyn_init); |
| 2247 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2248 | static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; } |
| 2249 | static inline void ftrace_startup_enable(int command) { } |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2250 | /* Keep as macros so we do not need to define the commands */ |
| 2251 | # define ftrace_startup(command) do { } while (0) |
| 2252 | # define ftrace_shutdown(command) do { } while (0) |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2253 | # define ftrace_startup_sysctl() do { } while (0) |
| 2254 | # define ftrace_shutdown_sysctl() do { } while (0) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2255 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 2256 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2257 | static ssize_t |
| 2258 | ftrace_pid_read(struct file *file, char __user *ubuf, |
| 2259 | size_t cnt, loff_t *ppos) |
| 2260 | { |
| 2261 | char buf[64]; |
| 2262 | int r; |
| 2263 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2264 | if (ftrace_pid_trace == ftrace_swapper_pid) |
| 2265 | r = sprintf(buf, "swapper tasks\n"); |
| 2266 | else if (ftrace_pid_trace) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2267 | r = sprintf(buf, "%u\n", pid_nr(ftrace_pid_trace)); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2268 | else |
| 2269 | r = sprintf(buf, "no pid\n"); |
| 2270 | |
| 2271 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 2272 | } |
| 2273 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2274 | static void clear_ftrace_swapper(void) |
| 2275 | { |
| 2276 | struct task_struct *p; |
| 2277 | int cpu; |
| 2278 | |
| 2279 | get_online_cpus(); |
| 2280 | for_each_online_cpu(cpu) { |
| 2281 | p = idle_task(cpu); |
| 2282 | clear_tsk_trace_trace(p); |
| 2283 | } |
| 2284 | put_online_cpus(); |
| 2285 | } |
| 2286 | |
| 2287 | static void set_ftrace_swapper(void) |
| 2288 | { |
| 2289 | struct task_struct *p; |
| 2290 | int cpu; |
| 2291 | |
| 2292 | get_online_cpus(); |
| 2293 | for_each_online_cpu(cpu) { |
| 2294 | p = idle_task(cpu); |
| 2295 | set_tsk_trace_trace(p); |
| 2296 | } |
| 2297 | put_online_cpus(); |
| 2298 | } |
| 2299 | |
| 2300 | static void clear_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2301 | { |
| 2302 | struct task_struct *p; |
| 2303 | |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2304 | rcu_read_lock(); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2305 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2306 | clear_tsk_trace_trace(p); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2307 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2308 | rcu_read_unlock(); |
| 2309 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2310 | put_pid(pid); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2311 | } |
| 2312 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2313 | static void set_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2314 | { |
| 2315 | struct task_struct *p; |
| 2316 | |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2317 | rcu_read_lock(); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2318 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
| 2319 | set_tsk_trace_trace(p); |
| 2320 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2321 | rcu_read_unlock(); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2322 | } |
| 2323 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2324 | static void clear_ftrace_pid_task(struct pid **pid) |
| 2325 | { |
| 2326 | if (*pid == ftrace_swapper_pid) |
| 2327 | clear_ftrace_swapper(); |
| 2328 | else |
| 2329 | clear_ftrace_pid(*pid); |
| 2330 | |
| 2331 | *pid = NULL; |
| 2332 | } |
| 2333 | |
| 2334 | static void set_ftrace_pid_task(struct pid *pid) |
| 2335 | { |
| 2336 | if (pid == ftrace_swapper_pid) |
| 2337 | set_ftrace_swapper(); |
| 2338 | else |
| 2339 | set_ftrace_pid(pid); |
| 2340 | } |
| 2341 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2342 | static ssize_t |
| 2343 | ftrace_pid_write(struct file *filp, const char __user *ubuf, |
| 2344 | size_t cnt, loff_t *ppos) |
| 2345 | { |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2346 | struct pid *pid; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2347 | char buf[64]; |
| 2348 | long val; |
| 2349 | int ret; |
| 2350 | |
| 2351 | if (cnt >= sizeof(buf)) |
| 2352 | return -EINVAL; |
| 2353 | |
| 2354 | if (copy_from_user(&buf, ubuf, cnt)) |
| 2355 | return -EFAULT; |
| 2356 | |
| 2357 | buf[cnt] = 0; |
| 2358 | |
| 2359 | ret = strict_strtol(buf, 10, &val); |
| 2360 | if (ret < 0) |
| 2361 | return ret; |
| 2362 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2363 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2364 | if (val < 0) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2365 | /* disable pid tracing */ |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2366 | if (!ftrace_pid_trace) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2367 | goto out; |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2368 | |
| 2369 | clear_ftrace_pid_task(&ftrace_pid_trace); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2370 | |
| 2371 | } else { |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2372 | /* swapper task is special */ |
| 2373 | if (!val) { |
| 2374 | pid = ftrace_swapper_pid; |
| 2375 | if (pid == ftrace_pid_trace) |
| 2376 | goto out; |
| 2377 | } else { |
| 2378 | pid = find_get_pid(val); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2379 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2380 | if (pid == ftrace_pid_trace) { |
| 2381 | put_pid(pid); |
| 2382 | goto out; |
| 2383 | } |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | if (ftrace_pid_trace) |
| 2387 | clear_ftrace_pid_task(&ftrace_pid_trace); |
| 2388 | |
| 2389 | if (!pid) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2390 | goto out; |
| 2391 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2392 | ftrace_pid_trace = pid; |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 2393 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2394 | set_ftrace_pid_task(ftrace_pid_trace); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | /* update the function call */ |
| 2398 | ftrace_update_pid_func(); |
| 2399 | ftrace_startup_enable(0); |
| 2400 | |
| 2401 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2402 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2403 | |
| 2404 | return cnt; |
| 2405 | } |
| 2406 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2407 | static const struct file_operations ftrace_pid_fops = { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2408 | .read = ftrace_pid_read, |
| 2409 | .write = ftrace_pid_write, |
| 2410 | }; |
| 2411 | |
| 2412 | static __init int ftrace_init_debugfs(void) |
| 2413 | { |
| 2414 | struct dentry *d_tracer; |
| 2415 | struct dentry *entry; |
| 2416 | |
| 2417 | d_tracer = tracing_init_dentry(); |
| 2418 | if (!d_tracer) |
| 2419 | return 0; |
| 2420 | |
| 2421 | ftrace_init_dyn_debugfs(d_tracer); |
| 2422 | |
| 2423 | entry = debugfs_create_file("set_ftrace_pid", 0644, d_tracer, |
| 2424 | NULL, &ftrace_pid_fops); |
| 2425 | if (!entry) |
| 2426 | pr_warning("Could not create debugfs " |
| 2427 | "'set_ftrace_pid' entry\n"); |
| 2428 | return 0; |
| 2429 | } |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2430 | fs_initcall(ftrace_init_debugfs); |
| 2431 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2432 | /** |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 2433 | * ftrace_kill - kill ftrace |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 2434 | * |
| 2435 | * This function should be used by panic code. It stops ftrace |
| 2436 | * but in a not so nice way. If you need to simply kill ftrace |
| 2437 | * from a non-atomic section, use ftrace_kill. |
| 2438 | */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 2439 | void ftrace_kill(void) |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 2440 | { |
| 2441 | ftrace_disabled = 1; |
| 2442 | ftrace_enabled = 0; |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 2443 | clear_ftrace_function(); |
| 2444 | } |
| 2445 | |
| 2446 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2447 | * register_ftrace_function - register a function for profiling |
| 2448 | * @ops - ops structure that holds the function for profiling. |
| 2449 | * |
| 2450 | * Register a function to be called by all functions in the |
| 2451 | * kernel. |
| 2452 | * |
| 2453 | * Note: @ops->func and all the functions it calls must be labeled |
| 2454 | * with "notrace", otherwise it will go into a |
| 2455 | * recursive loop. |
| 2456 | */ |
| 2457 | int register_ftrace_function(struct ftrace_ops *ops) |
| 2458 | { |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2459 | int ret; |
| 2460 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2461 | if (unlikely(ftrace_disabled)) |
| 2462 | return -1; |
| 2463 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2464 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2465 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2466 | ret = __register_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2467 | ftrace_startup(0); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2468 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2469 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2470 | return ret; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | /** |
Uwe Kleine-Koenig | 3263292 | 2009-01-12 23:35:50 +0100 | [diff] [blame] | 2474 | * unregister_ftrace_function - unregister a function for profiling. |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2475 | * @ops - ops structure that holds the function to unregister |
| 2476 | * |
| 2477 | * Unregister a function that was added to be called by ftrace profiling. |
| 2478 | */ |
| 2479 | int unregister_ftrace_function(struct ftrace_ops *ops) |
| 2480 | { |
| 2481 | int ret; |
| 2482 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2483 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2484 | ret = __unregister_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2485 | ftrace_shutdown(0); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2486 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2487 | |
| 2488 | return ret; |
| 2489 | } |
| 2490 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2491 | int |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2492 | ftrace_enable_sysctl(struct ctl_table *table, int write, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2493 | struct file *file, void __user *buffer, size_t *lenp, |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2494 | loff_t *ppos) |
| 2495 | { |
| 2496 | int ret; |
| 2497 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2498 | if (unlikely(ftrace_disabled)) |
| 2499 | return -ENODEV; |
| 2500 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2501 | mutex_lock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2502 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2503 | ret = proc_dointvec(table, write, file, buffer, lenp, ppos); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2504 | |
| 2505 | if (ret || !write || (last_ftrace_enabled == ftrace_enabled)) |
| 2506 | goto out; |
| 2507 | |
| 2508 | last_ftrace_enabled = ftrace_enabled; |
| 2509 | |
| 2510 | if (ftrace_enabled) { |
| 2511 | |
| 2512 | ftrace_startup_sysctl(); |
| 2513 | |
| 2514 | /* we are starting ftrace again */ |
| 2515 | if (ftrace_list != &ftrace_list_end) { |
| 2516 | if (ftrace_list->next == &ftrace_list_end) |
| 2517 | ftrace_trace_function = ftrace_list->func; |
| 2518 | else |
| 2519 | ftrace_trace_function = ftrace_list_func; |
| 2520 | } |
| 2521 | |
| 2522 | } else { |
| 2523 | /* stopping ftrace calls (just send to ftrace_stub) */ |
| 2524 | ftrace_trace_function = ftrace_stub; |
| 2525 | |
| 2526 | ftrace_shutdown_sysctl(); |
| 2527 | } |
| 2528 | |
| 2529 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2530 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2531 | return ret; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2532 | } |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 2533 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2534 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2535 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2536 | static atomic_t ftrace_graph_active; |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 2537 | static struct notifier_block ftrace_suspend_notifier; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2538 | |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 2539 | int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) |
| 2540 | { |
| 2541 | return 0; |
| 2542 | } |
| 2543 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2544 | /* The callbacks that hook a function */ |
| 2545 | trace_func_graph_ret_t ftrace_graph_return = |
| 2546 | (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 2547 | trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2548 | |
| 2549 | /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */ |
| 2550 | static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) |
| 2551 | { |
| 2552 | int i; |
| 2553 | int ret = 0; |
| 2554 | unsigned long flags; |
| 2555 | int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE; |
| 2556 | struct task_struct *g, *t; |
| 2557 | |
| 2558 | for (i = 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) { |
| 2559 | ret_stack_list[i] = kmalloc(FTRACE_RETFUNC_DEPTH |
| 2560 | * sizeof(struct ftrace_ret_stack), |
| 2561 | GFP_KERNEL); |
| 2562 | if (!ret_stack_list[i]) { |
| 2563 | start = 0; |
| 2564 | end = i; |
| 2565 | ret = -ENOMEM; |
| 2566 | goto free; |
| 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | read_lock_irqsave(&tasklist_lock, flags); |
| 2571 | do_each_thread(g, t) { |
| 2572 | if (start == end) { |
| 2573 | ret = -EAGAIN; |
| 2574 | goto unlock; |
| 2575 | } |
| 2576 | |
| 2577 | if (t->ret_stack == NULL) { |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2578 | t->curr_ret_stack = -1; |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 2579 | /* Make sure IRQs see the -1 first: */ |
| 2580 | barrier(); |
| 2581 | t->ret_stack = ret_stack_list[start++]; |
Frederic Weisbecker | 380c4b1 | 2008-12-06 03:43:41 +0100 | [diff] [blame] | 2582 | atomic_set(&t->tracing_graph_pause, 0); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2583 | atomic_set(&t->trace_overrun, 0); |
| 2584 | } |
| 2585 | } while_each_thread(g, t); |
| 2586 | |
| 2587 | unlock: |
| 2588 | read_unlock_irqrestore(&tasklist_lock, flags); |
| 2589 | free: |
| 2590 | for (i = start; i < end; i++) |
| 2591 | kfree(ret_stack_list[i]); |
| 2592 | return ret; |
| 2593 | } |
| 2594 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame^] | 2595 | static void |
| 2596 | ftrace_graph_probe_sched_switch(struct rq *__rq, struct task_struct *prev, |
| 2597 | struct task_struct *next) |
| 2598 | { |
| 2599 | unsigned long long timestamp; |
| 2600 | int index; |
| 2601 | |
| 2602 | timestamp = trace_clock_local(); |
| 2603 | |
| 2604 | prev->ftrace_timestamp = timestamp; |
| 2605 | |
| 2606 | /* only process tasks that we timestamped */ |
| 2607 | if (!next->ftrace_timestamp) |
| 2608 | return; |
| 2609 | |
| 2610 | /* |
| 2611 | * Update all the counters in next to make up for the |
| 2612 | * time next was sleeping. |
| 2613 | */ |
| 2614 | timestamp -= next->ftrace_timestamp; |
| 2615 | |
| 2616 | for (index = next->curr_ret_stack; index >= 0; index--) |
| 2617 | next->ret_stack[index].calltime += timestamp; |
| 2618 | } |
| 2619 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2620 | /* Allocate a return stack for each task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2621 | static int start_graph_tracing(void) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2622 | { |
| 2623 | struct ftrace_ret_stack **ret_stack_list; |
Frederic Weisbecker | 5b058bc | 2009-02-17 18:35:34 +0100 | [diff] [blame] | 2624 | int ret, cpu; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2625 | |
| 2626 | ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE * |
| 2627 | sizeof(struct ftrace_ret_stack *), |
| 2628 | GFP_KERNEL); |
| 2629 | |
| 2630 | if (!ret_stack_list) |
| 2631 | return -ENOMEM; |
| 2632 | |
Frederic Weisbecker | 5b058bc | 2009-02-17 18:35:34 +0100 | [diff] [blame] | 2633 | /* The cpu_boot init_task->ret_stack will never be freed */ |
| 2634 | for_each_online_cpu(cpu) |
| 2635 | ftrace_graph_init_task(idle_task(cpu)); |
| 2636 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2637 | do { |
| 2638 | ret = alloc_retstack_tasklist(ret_stack_list); |
| 2639 | } while (ret == -EAGAIN); |
| 2640 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame^] | 2641 | if (!ret) { |
| 2642 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch); |
| 2643 | if (ret) |
| 2644 | pr_info("ftrace_graph: Couldn't activate tracepoint" |
| 2645 | " probe to kernel_sched_switch\n"); |
| 2646 | } |
| 2647 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2648 | kfree(ret_stack_list); |
| 2649 | return ret; |
| 2650 | } |
| 2651 | |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 2652 | /* |
| 2653 | * Hibernation protection. |
| 2654 | * The state of the current task is too much unstable during |
| 2655 | * suspend/restore to disk. We want to protect against that. |
| 2656 | */ |
| 2657 | static int |
| 2658 | ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state, |
| 2659 | void *unused) |
| 2660 | { |
| 2661 | switch (state) { |
| 2662 | case PM_HIBERNATION_PREPARE: |
| 2663 | pause_graph_tracing(); |
| 2664 | break; |
| 2665 | |
| 2666 | case PM_POST_HIBERNATION: |
| 2667 | unpause_graph_tracing(); |
| 2668 | break; |
| 2669 | } |
| 2670 | return NOTIFY_DONE; |
| 2671 | } |
| 2672 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2673 | int register_ftrace_graph(trace_func_graph_ret_t retfunc, |
| 2674 | trace_func_graph_ent_t entryfunc) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2675 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2676 | int ret = 0; |
| 2677 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2678 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2679 | |
Steven Rostedt | 05ce581 | 2009-03-24 00:18:31 -0400 | [diff] [blame] | 2680 | /* we currently allow only one tracer registered at a time */ |
| 2681 | if (atomic_read(&ftrace_graph_active)) { |
| 2682 | ret = -EBUSY; |
| 2683 | goto out; |
| 2684 | } |
| 2685 | |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 2686 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; |
| 2687 | register_pm_notifier(&ftrace_suspend_notifier); |
| 2688 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2689 | atomic_inc(&ftrace_graph_active); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2690 | ret = start_graph_tracing(); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2691 | if (ret) { |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2692 | atomic_dec(&ftrace_graph_active); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2693 | goto out; |
| 2694 | } |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 2695 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2696 | ftrace_graph_return = retfunc; |
| 2697 | ftrace_graph_entry = entryfunc; |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 2698 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2699 | ftrace_startup(FTRACE_START_FUNC_RET); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2700 | |
| 2701 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2702 | mutex_unlock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2703 | return ret; |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2706 | void unregister_ftrace_graph(void) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2707 | { |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2708 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2709 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2710 | atomic_dec(&ftrace_graph_active); |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame^] | 2711 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2712 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 2713 | ftrace_graph_entry = ftrace_graph_entry_stub; |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2714 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 2715 | unregister_pm_notifier(&ftrace_suspend_notifier); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2716 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2717 | mutex_unlock(&ftrace_lock); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2718 | } |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2719 | |
| 2720 | /* Allocate a return stack for newly created task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2721 | void ftrace_graph_init_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2722 | { |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2723 | if (atomic_read(&ftrace_graph_active)) { |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2724 | t->ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH |
| 2725 | * sizeof(struct ftrace_ret_stack), |
| 2726 | GFP_KERNEL); |
| 2727 | if (!t->ret_stack) |
| 2728 | return; |
| 2729 | t->curr_ret_stack = -1; |
Frederic Weisbecker | 380c4b1 | 2008-12-06 03:43:41 +0100 | [diff] [blame] | 2730 | atomic_set(&t->tracing_graph_pause, 0); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2731 | atomic_set(&t->trace_overrun, 0); |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame^] | 2732 | t->ftrace_timestamp = 0; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2733 | } else |
| 2734 | t->ret_stack = NULL; |
| 2735 | } |
| 2736 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2737 | void ftrace_graph_exit_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2738 | { |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 2739 | struct ftrace_ret_stack *ret_stack = t->ret_stack; |
| 2740 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2741 | t->ret_stack = NULL; |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 2742 | /* NULL must become visible to IRQs before we free it: */ |
| 2743 | barrier(); |
| 2744 | |
| 2745 | kfree(ret_stack); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2746 | } |
Steven Rostedt | 14a866c | 2008-12-02 23:50:02 -0500 | [diff] [blame] | 2747 | |
| 2748 | void ftrace_graph_stop(void) |
| 2749 | { |
| 2750 | ftrace_stop(); |
| 2751 | } |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2752 | #endif |
| 2753 | |