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> |
Ingo Molnar | 2d8b820 | 2008-02-23 16:55:50 +0100 | [diff] [blame] | 25 | #include <linux/ftrace.h> |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 26 | #include <linux/sysctl.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.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> |
Paul E. McKenney | 3f379b0 | 2010-03-05 15:03:25 -0800 | [diff] [blame] | 31 | #include <linux/rcupdate.h> |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 32 | |
Steven Rostedt | ad8d75f | 2009-04-14 19:39:12 -0400 | [diff] [blame] | 33 | #include <trace/events/sched.h> |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 34 | |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 35 | #include <asm/ftrace.h> |
Steven Rostedt | 2af15d6 | 2009-05-28 13:37:24 -0400 | [diff] [blame] | 36 | #include <asm/setup.h> |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 37 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 38 | #include "trace_output.h" |
Steven Rostedt | bac429f | 2009-03-20 12:50:56 -0400 | [diff] [blame] | 39 | #include "trace_stat.h" |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 40 | |
Steven Rostedt | 6912896 | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 41 | #define FTRACE_WARN_ON(cond) \ |
| 42 | do { \ |
| 43 | if (WARN_ON(cond)) \ |
| 44 | ftrace_kill(); \ |
| 45 | } while (0) |
| 46 | |
| 47 | #define FTRACE_WARN_ON_ONCE(cond) \ |
| 48 | do { \ |
| 49 | if (WARN_ON_ONCE(cond)) \ |
| 50 | ftrace_kill(); \ |
| 51 | } while (0) |
| 52 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 53 | /* hash bits for specific function selection */ |
| 54 | #define FTRACE_HASH_BITS 7 |
| 55 | #define FTRACE_FUNC_HASHSIZE (1 << FTRACE_HASH_BITS) |
| 56 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 57 | /* ftrace_enabled is a method to turn ftrace on or off */ |
| 58 | int ftrace_enabled __read_mostly; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 59 | static int last_ftrace_enabled; |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 60 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 61 | /* Quick disabling of function tracer. */ |
| 62 | int function_trace_stop; |
| 63 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 64 | /* List for set_ftrace_pid's pids. */ |
| 65 | LIST_HEAD(ftrace_pids); |
| 66 | struct ftrace_pid { |
| 67 | struct list_head list; |
| 68 | struct pid *pid; |
| 69 | }; |
| 70 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 71 | /* |
| 72 | * ftrace_disabled is set when an anomaly is discovered. |
| 73 | * ftrace_disabled is much stronger than ftrace_enabled. |
| 74 | */ |
| 75 | static int ftrace_disabled __read_mostly; |
| 76 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 77 | static DEFINE_MUTEX(ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 78 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 79 | static struct ftrace_ops ftrace_list_end __read_mostly = |
| 80 | { |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 81 | .func = ftrace_stub, |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end; |
| 85 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 86 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 87 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 88 | |
Paul E. McKenney | 3f379b0 | 2010-03-05 15:03:25 -0800 | [diff] [blame] | 89 | /* |
| 90 | * Traverse the ftrace_list, invoking all entries. The reason that we |
| 91 | * can use rcu_dereference_raw() is that elements removed from this list |
| 92 | * are simply leaked, so there is no need to interact with a grace-period |
| 93 | * mechanism. The rcu_dereference_raw() calls are needed to handle |
| 94 | * concurrent insertions into the ftrace_list. |
| 95 | * |
| 96 | * Silly Alpha and silly pointer-speculation compiler optimizations! |
| 97 | */ |
Ingo Molnar | f225293 | 2008-05-22 10:37:48 +0200 | [diff] [blame] | 98 | 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] | 99 | { |
Paul E. McKenney | 3f379b0 | 2010-03-05 15:03:25 -0800 | [diff] [blame] | 100 | struct ftrace_ops *op = rcu_dereference_raw(ftrace_list); /*see above*/ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 101 | |
| 102 | while (op != &ftrace_list_end) { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 103 | op->func(ip, parent_ip); |
Paul E. McKenney | 3f379b0 | 2010-03-05 15:03:25 -0800 | [diff] [blame] | 104 | op = rcu_dereference_raw(op->next); /*see above*/ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 105 | }; |
| 106 | } |
| 107 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 108 | static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip) |
| 109 | { |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 110 | if (!test_tsk_trace_trace(current)) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 111 | return; |
| 112 | |
| 113 | ftrace_pid_function(ip, parent_ip); |
| 114 | } |
| 115 | |
| 116 | static void set_ftrace_pid_function(ftrace_func_t func) |
| 117 | { |
| 118 | /* do not set ftrace_pid_function to itself! */ |
| 119 | if (func != ftrace_pid_func) |
| 120 | ftrace_pid_function = func; |
| 121 | } |
| 122 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 123 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 124 | * clear_ftrace_function - reset the ftrace function |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 125 | * |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 126 | * This NULLs the ftrace function and in essence stops |
| 127 | * tracing. There may be lag |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 128 | */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 129 | void clear_ftrace_function(void) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 130 | { |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 131 | ftrace_trace_function = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 132 | __ftrace_trace_function = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 133 | ftrace_pid_function = ftrace_stub; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 134 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 135 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 136 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 137 | /* |
| 138 | * For those archs that do not test ftrace_trace_stop in their |
| 139 | * mcount call site, we need to do it from C. |
| 140 | */ |
| 141 | static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip) |
| 142 | { |
| 143 | if (function_trace_stop) |
| 144 | return; |
| 145 | |
| 146 | __ftrace_trace_function(ip, parent_ip); |
| 147 | } |
| 148 | #endif |
| 149 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 150 | static int __register_ftrace_function(struct ftrace_ops *ops) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 151 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 152 | ops->next = ftrace_list; |
| 153 | /* |
| 154 | * We are entering ops into the ftrace_list but another |
| 155 | * CPU might be walking that list. We need to make sure |
| 156 | * the ops->next pointer is valid before another CPU sees |
| 157 | * the ops pointer included into the ftrace_list. |
| 158 | */ |
Paul E. McKenney | 3f379b0 | 2010-03-05 15:03:25 -0800 | [diff] [blame] | 159 | rcu_assign_pointer(ftrace_list, ops); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 160 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 161 | if (ftrace_enabled) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 162 | ftrace_func_t func; |
| 163 | |
| 164 | if (ops->next == &ftrace_list_end) |
| 165 | func = ops->func; |
| 166 | else |
| 167 | func = ftrace_list_func; |
| 168 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 169 | if (!list_empty(&ftrace_pids)) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 170 | set_ftrace_pid_function(func); |
| 171 | func = ftrace_pid_func; |
| 172 | } |
| 173 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 174 | /* |
| 175 | * For one func, simply call it directly. |
| 176 | * For more than one func, call the chain. |
| 177 | */ |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 178 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 179 | ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 180 | #else |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 181 | __ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 182 | ftrace_trace_function = ftrace_test_stop_func; |
| 183 | #endif |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 184 | } |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 185 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 189 | static int __unregister_ftrace_function(struct ftrace_ops *ops) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 190 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 191 | struct ftrace_ops **p; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 192 | |
| 193 | /* |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 194 | * If we are removing the last function, then simply point |
| 195 | * to the ftrace_stub. |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 196 | */ |
| 197 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { |
| 198 | ftrace_trace_function = ftrace_stub; |
| 199 | ftrace_list = &ftrace_list_end; |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 200 | return 0; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) |
| 204 | if (*p == ops) |
| 205 | break; |
| 206 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 207 | if (*p != ops) |
| 208 | return -1; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 209 | |
| 210 | *p = (*p)->next; |
| 211 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 212 | if (ftrace_enabled) { |
| 213 | /* If we only have one func left, then call that directly */ |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 214 | if (ftrace_list->next == &ftrace_list_end) { |
| 215 | ftrace_func_t func = ftrace_list->func; |
| 216 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 217 | if (!list_empty(&ftrace_pids)) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 218 | set_ftrace_pid_function(func); |
| 219 | func = ftrace_pid_func; |
| 220 | } |
| 221 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 222 | ftrace_trace_function = func; |
| 223 | #else |
| 224 | __ftrace_trace_function = func; |
| 225 | #endif |
| 226 | } |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 227 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 228 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 229 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 232 | static void ftrace_update_pid_func(void) |
| 233 | { |
| 234 | ftrace_func_t func; |
| 235 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 236 | if (ftrace_trace_function == ftrace_stub) |
KOSAKI Motohiro | 10dd3eb | 2009-03-06 15:29:04 +0900 | [diff] [blame] | 237 | return; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 238 | |
Matt Fleming | 3397409 | 2009-09-28 16:43:01 +0100 | [diff] [blame] | 239 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 240 | func = ftrace_trace_function; |
Matt Fleming | 3397409 | 2009-09-28 16:43:01 +0100 | [diff] [blame] | 241 | #else |
| 242 | func = __ftrace_trace_function; |
| 243 | #endif |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 244 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 245 | if (!list_empty(&ftrace_pids)) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 246 | set_ftrace_pid_function(func); |
| 247 | func = ftrace_pid_func; |
| 248 | } else { |
Liming Wang | 66eafeb | 2008-12-02 10:33:08 +0800 | [diff] [blame] | 249 | if (func == ftrace_pid_func) |
| 250 | func = ftrace_pid_function; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 254 | ftrace_trace_function = func; |
| 255 | #else |
| 256 | __ftrace_trace_function = func; |
| 257 | #endif |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 258 | } |
| 259 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 260 | #ifdef CONFIG_FUNCTION_PROFILER |
| 261 | struct ftrace_profile { |
| 262 | struct hlist_node node; |
| 263 | unsigned long ip; |
| 264 | unsigned long counter; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 265 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 266 | unsigned long long time; |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 267 | unsigned long long time_squared; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 268 | #endif |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | struct ftrace_profile_page { |
| 272 | struct ftrace_profile_page *next; |
| 273 | unsigned long index; |
| 274 | struct ftrace_profile records[]; |
| 275 | }; |
| 276 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 277 | struct ftrace_profile_stat { |
| 278 | atomic_t disabled; |
| 279 | struct hlist_head *hash; |
| 280 | struct ftrace_profile_page *pages; |
| 281 | struct ftrace_profile_page *start; |
| 282 | struct tracer_stat stat; |
| 283 | }; |
| 284 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 285 | #define PROFILE_RECORDS_SIZE \ |
| 286 | (PAGE_SIZE - offsetof(struct ftrace_profile_page, records)) |
| 287 | |
| 288 | #define PROFILES_PER_PAGE \ |
| 289 | (PROFILE_RECORDS_SIZE / sizeof(struct ftrace_profile)) |
| 290 | |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 291 | static int ftrace_profile_bits __read_mostly; |
| 292 | static int ftrace_profile_enabled __read_mostly; |
| 293 | |
| 294 | /* ftrace_profile_lock - synchronize the enable and disable of the profiler */ |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 295 | static DEFINE_MUTEX(ftrace_profile_lock); |
| 296 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 297 | static DEFINE_PER_CPU(struct ftrace_profile_stat, ftrace_profile_stats); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 298 | |
| 299 | #define FTRACE_PROFILE_HASH_SIZE 1024 /* must be power of 2 */ |
| 300 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 301 | static void * |
| 302 | function_stat_next(void *v, int idx) |
| 303 | { |
| 304 | struct ftrace_profile *rec = v; |
| 305 | struct ftrace_profile_page *pg; |
| 306 | |
| 307 | pg = (struct ftrace_profile_page *)((unsigned long)rec & PAGE_MASK); |
| 308 | |
| 309 | again: |
Li Zefan | 0296e42 | 2009-06-26 11:15:37 +0800 | [diff] [blame] | 310 | if (idx != 0) |
| 311 | rec++; |
| 312 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 313 | if ((void *)rec >= (void *)&pg->records[pg->index]) { |
| 314 | pg = pg->next; |
| 315 | if (!pg) |
| 316 | return NULL; |
| 317 | rec = &pg->records[0]; |
| 318 | if (!rec->counter) |
| 319 | goto again; |
| 320 | } |
| 321 | |
| 322 | return rec; |
| 323 | } |
| 324 | |
| 325 | static void *function_stat_start(struct tracer_stat *trace) |
| 326 | { |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 327 | struct ftrace_profile_stat *stat = |
| 328 | container_of(trace, struct ftrace_profile_stat, stat); |
| 329 | |
| 330 | if (!stat || !stat->start) |
| 331 | return NULL; |
| 332 | |
| 333 | return function_stat_next(&stat->start->records[0], 0); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 336 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 337 | /* function graph compares on total time */ |
| 338 | static int function_stat_cmp(void *p1, void *p2) |
| 339 | { |
| 340 | struct ftrace_profile *a = p1; |
| 341 | struct ftrace_profile *b = p2; |
| 342 | |
| 343 | if (a->time < b->time) |
| 344 | return -1; |
| 345 | if (a->time > b->time) |
| 346 | return 1; |
| 347 | else |
| 348 | return 0; |
| 349 | } |
| 350 | #else |
| 351 | /* not function graph compares against hits */ |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 352 | static int function_stat_cmp(void *p1, void *p2) |
| 353 | { |
| 354 | struct ftrace_profile *a = p1; |
| 355 | struct ftrace_profile *b = p2; |
| 356 | |
| 357 | if (a->counter < b->counter) |
| 358 | return -1; |
| 359 | if (a->counter > b->counter) |
| 360 | return 1; |
| 361 | else |
| 362 | return 0; |
| 363 | } |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 364 | #endif |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 365 | |
| 366 | static int function_stat_headers(struct seq_file *m) |
| 367 | { |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 368 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt | 34886c8 | 2009-03-25 21:00:47 -0400 | [diff] [blame] | 369 | seq_printf(m, " Function " |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 370 | "Hit Time Avg s^2\n" |
Steven Rostedt | 34886c8 | 2009-03-25 21:00:47 -0400 | [diff] [blame] | 371 | " -------- " |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 372 | "--- ---- --- ---\n"); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 373 | #else |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 374 | seq_printf(m, " Function Hit\n" |
| 375 | " -------- ---\n"); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 376 | #endif |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int function_stat_show(struct seq_file *m, void *v) |
| 381 | { |
| 382 | struct ftrace_profile *rec = v; |
| 383 | char str[KSYM_SYMBOL_LEN]; |
Li Zefan | 3aaba20 | 2010-08-23 16:50:12 +0800 | [diff] [blame] | 384 | int ret = 0; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 385 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt | 34886c8 | 2009-03-25 21:00:47 -0400 | [diff] [blame] | 386 | static struct trace_seq s; |
| 387 | unsigned long long avg; |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 388 | unsigned long long stddev; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 389 | #endif |
Li Zefan | 3aaba20 | 2010-08-23 16:50:12 +0800 | [diff] [blame] | 390 | mutex_lock(&ftrace_profile_lock); |
| 391 | |
| 392 | /* we raced with function_profile_reset() */ |
| 393 | if (unlikely(rec->counter == 0)) { |
| 394 | ret = -EBUSY; |
| 395 | goto out; |
| 396 | } |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 397 | |
| 398 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 399 | seq_printf(m, " %-30.30s %10lu", str, rec->counter); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 400 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 401 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 402 | seq_printf(m, " "); |
Steven Rostedt | 34886c8 | 2009-03-25 21:00:47 -0400 | [diff] [blame] | 403 | avg = rec->time; |
| 404 | do_div(avg, rec->counter); |
| 405 | |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 406 | /* Sample standard deviation (s^2) */ |
| 407 | if (rec->counter <= 1) |
| 408 | stddev = 0; |
| 409 | else { |
| 410 | stddev = rec->time_squared - rec->counter * avg * avg; |
| 411 | /* |
| 412 | * Divide only 1000 for ns^2 -> us^2 conversion. |
| 413 | * trace_print_graph_duration will divide 1000 again. |
| 414 | */ |
| 415 | do_div(stddev, (rec->counter - 1) * 1000); |
| 416 | } |
| 417 | |
Steven Rostedt | 34886c8 | 2009-03-25 21:00:47 -0400 | [diff] [blame] | 418 | trace_seq_init(&s); |
| 419 | trace_print_graph_duration(rec->time, &s); |
| 420 | trace_seq_puts(&s, " "); |
| 421 | trace_print_graph_duration(avg, &s); |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 422 | trace_seq_puts(&s, " "); |
| 423 | trace_print_graph_duration(stddev, &s); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 424 | trace_print_seq(m, &s); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 425 | #endif |
| 426 | seq_putc(m, '\n'); |
Li Zefan | 3aaba20 | 2010-08-23 16:50:12 +0800 | [diff] [blame] | 427 | out: |
| 428 | mutex_unlock(&ftrace_profile_lock); |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 429 | |
Li Zefan | 3aaba20 | 2010-08-23 16:50:12 +0800 | [diff] [blame] | 430 | return ret; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 433 | static void ftrace_profile_reset(struct ftrace_profile_stat *stat) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 434 | { |
| 435 | struct ftrace_profile_page *pg; |
| 436 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 437 | pg = stat->pages = stat->start; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 438 | |
| 439 | while (pg) { |
| 440 | memset(pg->records, 0, PROFILE_RECORDS_SIZE); |
| 441 | pg->index = 0; |
| 442 | pg = pg->next; |
| 443 | } |
| 444 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 445 | memset(stat->hash, 0, |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 446 | FTRACE_PROFILE_HASH_SIZE * sizeof(struct hlist_head)); |
| 447 | } |
| 448 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 449 | int ftrace_profile_pages_init(struct ftrace_profile_stat *stat) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 450 | { |
| 451 | struct ftrace_profile_page *pg; |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 452 | int functions; |
| 453 | int pages; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 454 | int i; |
| 455 | |
| 456 | /* If we already allocated, do nothing */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 457 | if (stat->pages) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 458 | return 0; |
| 459 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 460 | stat->pages = (void *)get_zeroed_page(GFP_KERNEL); |
| 461 | if (!stat->pages) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 462 | return -ENOMEM; |
| 463 | |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 464 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 465 | functions = ftrace_update_tot_cnt; |
| 466 | #else |
| 467 | /* |
| 468 | * We do not know the number of functions that exist because |
| 469 | * dynamic tracing is what counts them. With past experience |
| 470 | * we have around 20K functions. That should be more than enough. |
| 471 | * It is highly unlikely we will execute every function in |
| 472 | * the kernel. |
| 473 | */ |
| 474 | functions = 20000; |
| 475 | #endif |
| 476 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 477 | pg = stat->start = stat->pages; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 478 | |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 479 | pages = DIV_ROUND_UP(functions, PROFILES_PER_PAGE); |
| 480 | |
| 481 | for (i = 0; i < pages; i++) { |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 482 | pg->next = (void *)get_zeroed_page(GFP_KERNEL); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 483 | if (!pg->next) |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 484 | goto out_free; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 485 | pg = pg->next; |
| 486 | } |
| 487 | |
| 488 | return 0; |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 489 | |
| 490 | out_free: |
| 491 | pg = stat->start; |
| 492 | while (pg) { |
| 493 | unsigned long tmp = (unsigned long)pg; |
| 494 | |
| 495 | pg = pg->next; |
| 496 | free_page(tmp); |
| 497 | } |
| 498 | |
| 499 | free_page((unsigned long)stat->pages); |
| 500 | stat->pages = NULL; |
| 501 | stat->start = NULL; |
| 502 | |
| 503 | return -ENOMEM; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 504 | } |
| 505 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 506 | static int ftrace_profile_init_cpu(int cpu) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 507 | { |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 508 | struct ftrace_profile_stat *stat; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 509 | int size; |
| 510 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 511 | stat = &per_cpu(ftrace_profile_stats, cpu); |
| 512 | |
| 513 | if (stat->hash) { |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 514 | /* If the profile is already created, simply reset it */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 515 | ftrace_profile_reset(stat); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * We are profiling all functions, but usually only a few thousand |
| 521 | * functions are hit. We'll make a hash of 1024 items. |
| 522 | */ |
| 523 | size = FTRACE_PROFILE_HASH_SIZE; |
| 524 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 525 | stat->hash = kzalloc(sizeof(struct hlist_head) * size, GFP_KERNEL); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 526 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 527 | if (!stat->hash) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 528 | return -ENOMEM; |
| 529 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 530 | if (!ftrace_profile_bits) { |
| 531 | size--; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 532 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 533 | for (; size; size >>= 1) |
| 534 | ftrace_profile_bits++; |
| 535 | } |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 536 | |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 537 | /* Preallocate the function profiling pages */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 538 | if (ftrace_profile_pages_init(stat) < 0) { |
| 539 | kfree(stat->hash); |
| 540 | stat->hash = NULL; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 541 | return -ENOMEM; |
| 542 | } |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 547 | static int ftrace_profile_init(void) |
| 548 | { |
| 549 | int cpu; |
| 550 | int ret = 0; |
| 551 | |
| 552 | for_each_online_cpu(cpu) { |
| 553 | ret = ftrace_profile_init_cpu(cpu); |
| 554 | if (ret) |
| 555 | break; |
| 556 | } |
| 557 | |
| 558 | return ret; |
| 559 | } |
| 560 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 561 | /* interrupts must be disabled */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 562 | static struct ftrace_profile * |
| 563 | ftrace_find_profiled_func(struct ftrace_profile_stat *stat, unsigned long ip) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 564 | { |
| 565 | struct ftrace_profile *rec; |
| 566 | struct hlist_head *hhd; |
| 567 | struct hlist_node *n; |
| 568 | unsigned long key; |
| 569 | |
| 570 | key = hash_long(ip, ftrace_profile_bits); |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 571 | hhd = &stat->hash[key]; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 572 | |
| 573 | if (hlist_empty(hhd)) |
| 574 | return NULL; |
| 575 | |
| 576 | hlist_for_each_entry_rcu(rec, n, hhd, node) { |
| 577 | if (rec->ip == ip) |
| 578 | return rec; |
| 579 | } |
| 580 | |
| 581 | return NULL; |
| 582 | } |
| 583 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 584 | static void ftrace_add_profile(struct ftrace_profile_stat *stat, |
| 585 | struct ftrace_profile *rec) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 586 | { |
| 587 | unsigned long key; |
| 588 | |
| 589 | key = hash_long(rec->ip, ftrace_profile_bits); |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 590 | hlist_add_head_rcu(&rec->node, &stat->hash[key]); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 591 | } |
| 592 | |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 593 | /* |
| 594 | * The memory is already allocated, this simply finds a new record to use. |
| 595 | */ |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 596 | static struct ftrace_profile * |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 597 | ftrace_profile_alloc(struct ftrace_profile_stat *stat, unsigned long ip) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 598 | { |
| 599 | struct ftrace_profile *rec = NULL; |
| 600 | |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 601 | /* prevent recursion (from NMIs) */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 602 | if (atomic_inc_return(&stat->disabled) != 1) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 603 | goto out; |
| 604 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 605 | /* |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 606 | * Try to find the function again since an NMI |
| 607 | * could have added it |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 608 | */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 609 | rec = ftrace_find_profiled_func(stat, ip); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 610 | if (rec) |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 611 | goto out; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 612 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 613 | if (stat->pages->index == PROFILES_PER_PAGE) { |
| 614 | if (!stat->pages->next) |
| 615 | goto out; |
| 616 | stat->pages = stat->pages->next; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 619 | rec = &stat->pages->records[stat->pages->index++]; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 620 | rec->ip = ip; |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 621 | ftrace_add_profile(stat, rec); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 622 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 623 | out: |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 624 | atomic_dec(&stat->disabled); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 625 | |
| 626 | return rec; |
| 627 | } |
| 628 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 629 | static void |
| 630 | function_profile_call(unsigned long ip, unsigned long parent_ip) |
| 631 | { |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 632 | struct ftrace_profile_stat *stat; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 633 | struct ftrace_profile *rec; |
| 634 | unsigned long flags; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 635 | |
| 636 | if (!ftrace_profile_enabled) |
| 637 | return; |
| 638 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 639 | local_irq_save(flags); |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 640 | |
| 641 | stat = &__get_cpu_var(ftrace_profile_stats); |
Steven Rostedt | 0f6ce3d | 2009-06-01 21:51:28 -0400 | [diff] [blame] | 642 | if (!stat->hash || !ftrace_profile_enabled) |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 643 | goto out; |
| 644 | |
| 645 | rec = ftrace_find_profiled_func(stat, ip); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 646 | if (!rec) { |
Steven Rostedt | 318e0a7 | 2009-03-25 20:06:34 -0400 | [diff] [blame] | 647 | rec = ftrace_profile_alloc(stat, ip); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 648 | if (!rec) |
| 649 | goto out; |
| 650 | } |
| 651 | |
| 652 | rec->counter++; |
| 653 | out: |
| 654 | local_irq_restore(flags); |
| 655 | } |
| 656 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 657 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 658 | static int profile_graph_entry(struct ftrace_graph_ent *trace) |
| 659 | { |
| 660 | function_profile_call(trace->func, 0); |
| 661 | return 1; |
| 662 | } |
| 663 | |
| 664 | static void profile_graph_return(struct ftrace_graph_ret *trace) |
| 665 | { |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 666 | struct ftrace_profile_stat *stat; |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 667 | unsigned long long calltime; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 668 | struct ftrace_profile *rec; |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 669 | unsigned long flags; |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 670 | |
| 671 | local_irq_save(flags); |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 672 | stat = &__get_cpu_var(ftrace_profile_stats); |
Steven Rostedt | 0f6ce3d | 2009-06-01 21:51:28 -0400 | [diff] [blame] | 673 | if (!stat->hash || !ftrace_profile_enabled) |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 674 | goto out; |
| 675 | |
Steven Rostedt | 37e44bc | 2010-04-27 21:04:24 -0400 | [diff] [blame] | 676 | /* If the calltime was zero'd ignore it */ |
| 677 | if (!trace->calltime) |
| 678 | goto out; |
| 679 | |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 680 | calltime = trace->rettime - trace->calltime; |
| 681 | |
| 682 | if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) { |
| 683 | int index; |
| 684 | |
| 685 | index = trace->depth; |
| 686 | |
| 687 | /* Append this call time to the parent time to subtract */ |
| 688 | if (index) |
| 689 | current->ret_stack[index - 1].subtime += calltime; |
| 690 | |
| 691 | if (current->ret_stack[index].subtime < calltime) |
| 692 | calltime -= current->ret_stack[index].subtime; |
| 693 | else |
| 694 | calltime = 0; |
| 695 | } |
| 696 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 697 | rec = ftrace_find_profiled_func(stat, trace->func); |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 698 | if (rec) { |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 699 | rec->time += calltime; |
Chase Douglas | e330b3b | 2010-04-26 14:02:05 -0400 | [diff] [blame] | 700 | rec->time_squared += calltime * calltime; |
| 701 | } |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 702 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 703 | out: |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 704 | local_irq_restore(flags); |
| 705 | } |
| 706 | |
| 707 | static int register_ftrace_profiler(void) |
| 708 | { |
| 709 | return register_ftrace_graph(&profile_graph_return, |
| 710 | &profile_graph_entry); |
| 711 | } |
| 712 | |
| 713 | static void unregister_ftrace_profiler(void) |
| 714 | { |
| 715 | unregister_ftrace_graph(); |
| 716 | } |
| 717 | #else |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 718 | static struct ftrace_ops ftrace_profile_ops __read_mostly = |
| 719 | { |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 720 | .func = function_profile_call, |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 721 | }; |
| 722 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 723 | static int register_ftrace_profiler(void) |
| 724 | { |
| 725 | return register_ftrace_function(&ftrace_profile_ops); |
| 726 | } |
| 727 | |
| 728 | static void unregister_ftrace_profiler(void) |
| 729 | { |
| 730 | unregister_ftrace_function(&ftrace_profile_ops); |
| 731 | } |
| 732 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 733 | |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 734 | static ssize_t |
| 735 | ftrace_profile_write(struct file *filp, const char __user *ubuf, |
| 736 | size_t cnt, loff_t *ppos) |
| 737 | { |
| 738 | unsigned long val; |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 739 | char buf[64]; /* big enough to hold a number */ |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 740 | int ret; |
| 741 | |
| 742 | if (cnt >= sizeof(buf)) |
| 743 | return -EINVAL; |
| 744 | |
| 745 | if (copy_from_user(&buf, ubuf, cnt)) |
| 746 | return -EFAULT; |
| 747 | |
| 748 | buf[cnt] = 0; |
| 749 | |
| 750 | ret = strict_strtoul(buf, 10, &val); |
| 751 | if (ret < 0) |
| 752 | return ret; |
| 753 | |
| 754 | val = !!val; |
| 755 | |
| 756 | mutex_lock(&ftrace_profile_lock); |
| 757 | if (ftrace_profile_enabled ^ val) { |
| 758 | if (val) { |
| 759 | ret = ftrace_profile_init(); |
| 760 | if (ret < 0) { |
| 761 | cnt = ret; |
| 762 | goto out; |
| 763 | } |
| 764 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 765 | ret = register_ftrace_profiler(); |
| 766 | if (ret < 0) { |
| 767 | cnt = ret; |
| 768 | goto out; |
| 769 | } |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 770 | ftrace_profile_enabled = 1; |
| 771 | } else { |
| 772 | ftrace_profile_enabled = 0; |
Steven Rostedt | 0f6ce3d | 2009-06-01 21:51:28 -0400 | [diff] [blame] | 773 | /* |
| 774 | * unregister_ftrace_profiler calls stop_machine |
| 775 | * so this acts like an synchronize_sched. |
| 776 | */ |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 777 | unregister_ftrace_profiler(); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | out: |
| 781 | mutex_unlock(&ftrace_profile_lock); |
| 782 | |
Jiri Olsa | cf8517c | 2009-10-23 19:36:16 -0400 | [diff] [blame] | 783 | *ppos += cnt; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 784 | |
| 785 | return cnt; |
| 786 | } |
| 787 | |
| 788 | static ssize_t |
| 789 | ftrace_profile_read(struct file *filp, char __user *ubuf, |
| 790 | size_t cnt, loff_t *ppos) |
| 791 | { |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 792 | char buf[64]; /* big enough to hold a number */ |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 793 | int r; |
| 794 | |
| 795 | r = sprintf(buf, "%u\n", ftrace_profile_enabled); |
| 796 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 797 | } |
| 798 | |
| 799 | static const struct file_operations ftrace_profile_fops = { |
| 800 | .open = tracing_open_generic, |
| 801 | .read = ftrace_profile_read, |
| 802 | .write = ftrace_profile_write, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 803 | .llseek = default_llseek, |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 804 | }; |
| 805 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 806 | /* used to initialize the real stat files */ |
| 807 | static struct tracer_stat function_stats __initdata = { |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 808 | .name = "functions", |
| 809 | .stat_start = function_stat_start, |
| 810 | .stat_next = function_stat_next, |
| 811 | .stat_cmp = function_stat_cmp, |
| 812 | .stat_headers = function_stat_headers, |
| 813 | .stat_show = function_stat_show |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 814 | }; |
| 815 | |
Steven Rostedt | 6ab5d66 | 2009-06-04 00:55:45 -0400 | [diff] [blame] | 816 | static __init void ftrace_profile_debugfs(struct dentry *d_tracer) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 817 | { |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 818 | struct ftrace_profile_stat *stat; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 819 | struct dentry *entry; |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 820 | char *name; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 821 | int ret; |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 822 | int cpu; |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 823 | |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 824 | for_each_possible_cpu(cpu) { |
| 825 | stat = &per_cpu(ftrace_profile_stats, cpu); |
| 826 | |
| 827 | /* allocate enough for function name + cpu number */ |
| 828 | name = kmalloc(32, GFP_KERNEL); |
| 829 | if (!name) { |
| 830 | /* |
| 831 | * The files created are permanent, if something happens |
| 832 | * we still do not free memory. |
| 833 | */ |
Steven Rostedt | cafb168 | 2009-03-24 20:50:39 -0400 | [diff] [blame] | 834 | WARN(1, |
| 835 | "Could not allocate stat file for cpu %d\n", |
| 836 | cpu); |
| 837 | return; |
| 838 | } |
| 839 | stat->stat = function_stats; |
| 840 | snprintf(name, 32, "function%d", cpu); |
| 841 | stat->stat.name = name; |
| 842 | ret = register_stat_tracer(&stat->stat); |
| 843 | if (ret) { |
| 844 | WARN(1, |
| 845 | "Could not register function stat for cpu %d\n", |
| 846 | cpu); |
| 847 | kfree(name); |
| 848 | return; |
| 849 | } |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | entry = debugfs_create_file("function_profile_enabled", 0644, |
| 853 | d_tracer, NULL, &ftrace_profile_fops); |
| 854 | if (!entry) |
| 855 | pr_warning("Could not create debugfs " |
| 856 | "'function_profile_enabled' entry\n"); |
| 857 | } |
| 858 | |
| 859 | #else /* CONFIG_FUNCTION_PROFILER */ |
Steven Rostedt | 6ab5d66 | 2009-06-04 00:55:45 -0400 | [diff] [blame] | 860 | static __init void ftrace_profile_debugfs(struct dentry *d_tracer) |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 861 | { |
| 862 | } |
| 863 | #endif /* CONFIG_FUNCTION_PROFILER */ |
| 864 | |
Ingo Molnar | 73d3fd9 | 2009-02-17 11:48:18 +0100 | [diff] [blame] | 865 | static struct pid * const ftrace_swapper_pid = &init_struct_pid; |
| 866 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 867 | #ifdef CONFIG_DYNAMIC_FTRACE |
Ingo Molnar | 73d3fd9 | 2009-02-17 11:48:18 +0100 | [diff] [blame] | 868 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 869 | #ifndef CONFIG_FTRACE_MCOUNT_RECORD |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 870 | # error Dynamic ftrace depends on MCOUNT_RECORD |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 871 | #endif |
| 872 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 873 | static struct hlist_head ftrace_func_hash[FTRACE_FUNC_HASHSIZE] __read_mostly; |
| 874 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 875 | struct ftrace_func_probe { |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 876 | struct hlist_node node; |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 877 | struct ftrace_probe_ops *ops; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 878 | unsigned long flags; |
| 879 | unsigned long ip; |
| 880 | void *data; |
| 881 | struct rcu_head rcu; |
| 882 | }; |
| 883 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 884 | enum { |
| 885 | FTRACE_ENABLE_CALLS = (1 << 0), |
| 886 | FTRACE_DISABLE_CALLS = (1 << 1), |
| 887 | FTRACE_UPDATE_TRACE_FUNC = (1 << 2), |
Steven Rostedt | 79e406d | 2010-09-14 22:19:46 -0400 | [diff] [blame] | 888 | FTRACE_START_FUNC_RET = (1 << 3), |
| 889 | FTRACE_STOP_FUNC_RET = (1 << 4), |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 890 | }; |
| 891 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 892 | static int ftrace_filtered; |
| 893 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 894 | static struct dyn_ftrace *ftrace_new_addrs; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 895 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 896 | static DEFINE_MUTEX(ftrace_regex_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 897 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 898 | struct ftrace_page { |
| 899 | struct ftrace_page *next; |
Steven Rostedt | 431aa3f | 2009-01-06 12:43:01 -0500 | [diff] [blame] | 900 | int index; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 901 | struct dyn_ftrace records[]; |
David Miller | aa5e5ce | 2008-05-13 22:06:56 -0700 | [diff] [blame] | 902 | }; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 903 | |
| 904 | #define ENTRIES_PER_PAGE \ |
| 905 | ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace)) |
| 906 | |
| 907 | /* estimate from running different kernels */ |
| 908 | #define NR_TO_INIT 10000 |
| 909 | |
| 910 | static struct ftrace_page *ftrace_pages_start; |
| 911 | static struct ftrace_page *ftrace_pages; |
| 912 | |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 913 | static struct dyn_ftrace *ftrace_free_records; |
| 914 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 915 | /* |
| 916 | * This is a double for. Do not use 'break' to break out of the loop, |
| 917 | * you must use a goto. |
| 918 | */ |
| 919 | #define do_for_each_ftrace_rec(pg, rec) \ |
| 920 | for (pg = ftrace_pages_start; pg; pg = pg->next) { \ |
| 921 | int _____i; \ |
| 922 | for (_____i = 0; _____i < pg->index; _____i++) { \ |
| 923 | rec = &pg->records[_____i]; |
| 924 | |
| 925 | #define while_for_each_ftrace_rec() \ |
| 926 | } \ |
| 927 | } |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 928 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 929 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 930 | { |
Lai Jiangshan | ee000b7 | 2009-03-24 13:38:06 +0800 | [diff] [blame] | 931 | rec->freelist = ftrace_free_records; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 932 | ftrace_free_records = rec; |
| 933 | rec->flags |= FTRACE_FL_FREE; |
| 934 | } |
| 935 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 936 | static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 937 | { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 938 | struct dyn_ftrace *rec; |
| 939 | |
| 940 | /* First check for freed records */ |
| 941 | if (ftrace_free_records) { |
| 942 | rec = ftrace_free_records; |
| 943 | |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 944 | if (unlikely(!(rec->flags & FTRACE_FL_FREE))) { |
Steven Rostedt | 6912896 | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 945 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 946 | ftrace_free_records = NULL; |
| 947 | return NULL; |
| 948 | } |
| 949 | |
Lai Jiangshan | ee000b7 | 2009-03-24 13:38:06 +0800 | [diff] [blame] | 950 | ftrace_free_records = rec->freelist; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 951 | memset(rec, 0, sizeof(*rec)); |
| 952 | return rec; |
| 953 | } |
| 954 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 955 | if (ftrace_pages->index == ENTRIES_PER_PAGE) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 956 | if (!ftrace_pages->next) { |
| 957 | /* allocate another page */ |
| 958 | ftrace_pages->next = |
| 959 | (void *)get_zeroed_page(GFP_KERNEL); |
| 960 | if (!ftrace_pages->next) |
| 961 | return NULL; |
| 962 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 963 | ftrace_pages = ftrace_pages->next; |
| 964 | } |
| 965 | |
| 966 | return &ftrace_pages->records[ftrace_pages->index++]; |
| 967 | } |
| 968 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 969 | static struct dyn_ftrace * |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 970 | ftrace_record_ip(unsigned long ip) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 971 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 972 | struct dyn_ftrace *rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 973 | |
Steven Rostedt | f3c7ac4 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 974 | if (ftrace_disabled) |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 975 | return NULL; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 976 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 977 | rec = ftrace_alloc_dyn_node(ip); |
| 978 | if (!rec) |
| 979 | return NULL; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 980 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 981 | rec->ip = ip; |
Lai Jiangshan | ee000b7 | 2009-03-24 13:38:06 +0800 | [diff] [blame] | 982 | rec->newlist = ftrace_new_addrs; |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 983 | ftrace_new_addrs = rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 984 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 985 | return rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 986 | } |
| 987 | |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 988 | static void print_ip_ins(const char *fmt, unsigned char *p) |
| 989 | { |
| 990 | int i; |
| 991 | |
| 992 | printk(KERN_CONT "%s", fmt); |
| 993 | |
| 994 | for (i = 0; i < MCOUNT_INSN_SIZE; i++) |
| 995 | printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); |
| 996 | } |
| 997 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 998 | static void ftrace_bug(int failed, unsigned long ip) |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 999 | { |
| 1000 | switch (failed) { |
| 1001 | case -EFAULT: |
| 1002 | FTRACE_WARN_ON_ONCE(1); |
| 1003 | pr_info("ftrace faulted on modifying "); |
| 1004 | print_ip_sym(ip); |
| 1005 | break; |
| 1006 | case -EINVAL: |
| 1007 | FTRACE_WARN_ON_ONCE(1); |
| 1008 | pr_info("ftrace failed to modify "); |
| 1009 | print_ip_sym(ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1010 | print_ip_ins(" actual: ", (unsigned char *)ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1011 | printk(KERN_CONT "\n"); |
| 1012 | break; |
| 1013 | case -EPERM: |
| 1014 | FTRACE_WARN_ON_ONCE(1); |
| 1015 | pr_info("ftrace faulted on writing "); |
| 1016 | print_ip_sym(ip); |
| 1017 | break; |
| 1018 | default: |
| 1019 | FTRACE_WARN_ON_ONCE(1); |
| 1020 | pr_info("ftrace faulted on unknown error "); |
| 1021 | print_ip_sym(ip); |
| 1022 | } |
| 1023 | } |
| 1024 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1025 | |
Masami Hiramatsu | 2cfa197 | 2010-02-02 16:49:11 -0500 | [diff] [blame] | 1026 | /* Return 1 if the address range is reserved for ftrace */ |
| 1027 | int ftrace_text_reserved(void *start, void *end) |
| 1028 | { |
| 1029 | struct dyn_ftrace *rec; |
| 1030 | struct ftrace_page *pg; |
| 1031 | |
| 1032 | do_for_each_ftrace_rec(pg, rec) { |
| 1033 | if (rec->ip <= (unsigned long)end && |
| 1034 | rec->ip + MCOUNT_INSN_SIZE > (unsigned long)start) |
| 1035 | return 1; |
| 1036 | } while_for_each_ftrace_rec(); |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 1041 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1042 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1043 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1044 | unsigned long ftrace_addr; |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1045 | unsigned long flag = 0UL; |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1046 | |
Shaohua Li | f000120 | 2009-01-09 11:29:42 +0800 | [diff] [blame] | 1047 | ftrace_addr = (unsigned long)FTRACE_ADDR; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1048 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1049 | /* |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1050 | * If this record is not to be traced or we want to disable it, |
| 1051 | * then disable it. |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1052 | * |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1053 | * If we want to enable it and filtering is off, then enable it. |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1054 | * |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1055 | * If we want to enable it and filtering is on, enable it only if |
| 1056 | * it's filtered |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1057 | */ |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1058 | if (enable && !(rec->flags & FTRACE_FL_NOTRACE)) { |
| 1059 | if (!ftrace_filtered || (rec->flags & FTRACE_FL_FILTER)) |
| 1060 | flag = FTRACE_FL_ENABLED; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1063 | /* If the state of this record hasn't changed, then do nothing */ |
| 1064 | if ((rec->flags & FTRACE_FL_ENABLED) == flag) |
| 1065 | return 0; |
| 1066 | |
| 1067 | if (flag) { |
| 1068 | rec->flags |= FTRACE_FL_ENABLED; |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1069 | return ftrace_make_call(rec, ftrace_addr); |
Xiao Guangrong | 64fbcd1 | 2009-07-15 12:32:15 +0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 1073 | return ftrace_make_nop(NULL, rec, ftrace_addr); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static void ftrace_replace_code(int enable) |
| 1077 | { |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1078 | struct dyn_ftrace *rec; |
| 1079 | struct ftrace_page *pg; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1080 | int failed; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1081 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1082 | do_for_each_ftrace_rec(pg, rec) { |
| 1083 | /* |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 1084 | * Skip over free records, records that have |
| 1085 | * failed and not converted. |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1086 | */ |
| 1087 | if (rec->flags & FTRACE_FL_FREE || |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 1088 | rec->flags & FTRACE_FL_FAILED || |
Frederic Weisbecker | 0330354 | 2009-03-16 22:41:00 +0100 | [diff] [blame] | 1089 | !(rec->flags & FTRACE_FL_CONVERTED)) |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1090 | continue; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1091 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1092 | failed = __ftrace_replace_code(rec, enable); |
Zhaolei | fa9d13c | 2009-03-13 17:16:34 +0800 | [diff] [blame] | 1093 | if (failed) { |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1094 | rec->flags |= FTRACE_FL_FAILED; |
Steven Rostedt | 3279ba3 | 2009-10-07 16:57:56 -0400 | [diff] [blame] | 1095 | ftrace_bug(failed, rec->ip); |
| 1096 | /* Stop processing */ |
| 1097 | return; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1098 | } |
| 1099 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1100 | } |
| 1101 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1102 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1103 | ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1104 | { |
| 1105 | unsigned long ip; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 1106 | int ret; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1107 | |
| 1108 | ip = rec->ip; |
| 1109 | |
Shaohua Li | 25aac9d | 2009-01-09 11:29:40 +0800 | [diff] [blame] | 1110 | ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR); |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 1111 | if (ret) { |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1112 | ftrace_bug(ret, ip); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1113 | rec->flags |= FTRACE_FL_FAILED; |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 1114 | return 0; |
Steven Rostedt | 37ad508 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1115 | } |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 1116 | return 1; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1117 | } |
| 1118 | |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 1119 | /* |
| 1120 | * archs can override this function if they must do something |
| 1121 | * before the modifying code is performed. |
| 1122 | */ |
| 1123 | int __weak ftrace_arch_code_modify_prepare(void) |
| 1124 | { |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | /* |
| 1129 | * archs can override this function if they must do something |
| 1130 | * after the modifying code is performed. |
| 1131 | */ |
| 1132 | int __weak ftrace_arch_code_modify_post_process(void) |
| 1133 | { |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1137 | static int __ftrace_modify_code(void *data) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1138 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1139 | int *command = data; |
| 1140 | |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 1141 | if (*command & FTRACE_ENABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1142 | ftrace_replace_code(1); |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 1143 | else if (*command & FTRACE_DISABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1144 | ftrace_replace_code(0); |
| 1145 | |
| 1146 | if (*command & FTRACE_UPDATE_TRACE_FUNC) |
| 1147 | ftrace_update_ftrace_func(ftrace_trace_function); |
| 1148 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1149 | if (*command & FTRACE_START_FUNC_RET) |
| 1150 | ftrace_enable_ftrace_graph_caller(); |
| 1151 | else if (*command & FTRACE_STOP_FUNC_RET) |
| 1152 | ftrace_disable_ftrace_graph_caller(); |
| 1153 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1154 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1157 | static void ftrace_run_update_code(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1158 | { |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 1159 | int ret; |
| 1160 | |
| 1161 | ret = ftrace_arch_code_modify_prepare(); |
| 1162 | FTRACE_WARN_ON(ret); |
| 1163 | if (ret) |
| 1164 | return; |
| 1165 | |
Rusty Russell | 784e2d7 | 2008-07-28 12:16:31 -0500 | [diff] [blame] | 1166 | stop_machine(__ftrace_modify_code, &command, NULL); |
Steven Rostedt | 000ab69 | 2009-02-17 13:35:06 -0500 | [diff] [blame] | 1167 | |
| 1168 | ret = ftrace_arch_code_modify_post_process(); |
| 1169 | FTRACE_WARN_ON(ret); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1170 | } |
| 1171 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1172 | static ftrace_func_t saved_ftrace_func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1173 | static int ftrace_start_up; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1174 | |
| 1175 | static void ftrace_startup_enable(int command) |
| 1176 | { |
| 1177 | if (saved_ftrace_func != ftrace_trace_function) { |
| 1178 | saved_ftrace_func = ftrace_trace_function; |
| 1179 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 1180 | } |
| 1181 | |
| 1182 | if (!command || !ftrace_enabled) |
| 1183 | return; |
| 1184 | |
| 1185 | ftrace_run_update_code(command); |
| 1186 | } |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1187 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1188 | static void ftrace_startup(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1189 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1190 | if (unlikely(ftrace_disabled)) |
| 1191 | return; |
| 1192 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1193 | ftrace_start_up++; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1194 | command |= FTRACE_ENABLE_CALLS; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1195 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1196 | ftrace_startup_enable(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1197 | } |
| 1198 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1199 | static void ftrace_shutdown(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1200 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1201 | if (unlikely(ftrace_disabled)) |
| 1202 | return; |
| 1203 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1204 | ftrace_start_up--; |
Frederic Weisbecker | 9ea1a15 | 2009-06-20 06:52:21 +0200 | [diff] [blame] | 1205 | /* |
| 1206 | * Just warn in case of unbalance, no need to kill ftrace, it's not |
| 1207 | * critical but the ftrace_call callers may be never nopped again after |
| 1208 | * further ftrace uses. |
| 1209 | */ |
| 1210 | WARN_ON_ONCE(ftrace_start_up < 0); |
| 1211 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1212 | if (!ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1213 | command |= FTRACE_DISABLE_CALLS; |
| 1214 | |
| 1215 | if (saved_ftrace_func != ftrace_trace_function) { |
| 1216 | saved_ftrace_func = ftrace_trace_function; |
| 1217 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 1218 | } |
| 1219 | |
| 1220 | if (!command || !ftrace_enabled) |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 1221 | return; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1222 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1223 | ftrace_run_update_code(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1224 | } |
| 1225 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1226 | static void ftrace_startup_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1227 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1228 | if (unlikely(ftrace_disabled)) |
| 1229 | return; |
| 1230 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1231 | /* Force update next time */ |
| 1232 | saved_ftrace_func = NULL; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1233 | /* ftrace_start_up is true if we want ftrace running */ |
| 1234 | if (ftrace_start_up) |
Steven Rostedt | 79e406d | 2010-09-14 22:19:46 -0400 | [diff] [blame] | 1235 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1236 | } |
| 1237 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1238 | static void ftrace_shutdown_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1239 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1240 | if (unlikely(ftrace_disabled)) |
| 1241 | return; |
| 1242 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 1243 | /* ftrace_start_up is true if ftrace is running */ |
| 1244 | if (ftrace_start_up) |
Steven Rostedt | 79e406d | 2010-09-14 22:19:46 -0400 | [diff] [blame] | 1245 | ftrace_run_update_code(FTRACE_DISABLE_CALLS); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1248 | static cycle_t ftrace_update_time; |
| 1249 | static unsigned long ftrace_update_cnt; |
| 1250 | unsigned long ftrace_update_tot_cnt; |
| 1251 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1252 | static int ftrace_update_code(struct module *mod) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1253 | { |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 1254 | struct dyn_ftrace *p; |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 1255 | cycle_t start, stop; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1256 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1257 | start = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1258 | ftrace_update_cnt = 0; |
| 1259 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 1260 | while (ftrace_new_addrs) { |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 1261 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1262 | /* If something went wrong, bail without enabling anything */ |
| 1263 | if (unlikely(ftrace_disabled)) |
| 1264 | return -1; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1265 | |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 1266 | p = ftrace_new_addrs; |
Lai Jiangshan | ee000b7 | 2009-03-24 13:38:06 +0800 | [diff] [blame] | 1267 | ftrace_new_addrs = p->newlist; |
Lai Jiangshan | e94142a | 2009-03-13 17:51:27 +0800 | [diff] [blame] | 1268 | p->flags = 0L; |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 1269 | |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 1270 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1271 | * Do the initial record conversion from mcount jump |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 1272 | * to the NOP instructions. |
| 1273 | */ |
| 1274 | if (!ftrace_code_disable(mod, p)) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1275 | ftrace_free_rec(p); |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 1276 | continue; |
| 1277 | } |
| 1278 | |
| 1279 | p->flags |= FTRACE_FL_CONVERTED; |
| 1280 | ftrace_update_cnt++; |
| 1281 | |
| 1282 | /* |
| 1283 | * If the tracing is enabled, go ahead and enable the record. |
| 1284 | * |
| 1285 | * The reason not to enable the record immediatelly is the |
| 1286 | * inherent check of ftrace_make_nop/ftrace_make_call for |
| 1287 | * correct previous instructions. Making first the NOP |
| 1288 | * conversion puts the module to the correct state, thus |
| 1289 | * passing the ftrace_make_call check. |
| 1290 | */ |
| 1291 | if (ftrace_start_up) { |
| 1292 | int failed = __ftrace_replace_code(p, 1); |
| 1293 | if (failed) { |
| 1294 | ftrace_bug(failed, p->ip); |
| 1295 | ftrace_free_rec(p); |
| 1296 | } |
| 1297 | } |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1298 | } |
| 1299 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1300 | stop = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1301 | ftrace_update_time = stop - start; |
| 1302 | ftrace_update_tot_cnt += ftrace_update_cnt; |
| 1303 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1304 | return 0; |
| 1305 | } |
| 1306 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1307 | static int __init ftrace_dyn_table_alloc(unsigned long num_to_init) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1308 | { |
| 1309 | struct ftrace_page *pg; |
| 1310 | int cnt; |
| 1311 | int i; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1312 | |
| 1313 | /* allocate a few pages */ |
| 1314 | ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL); |
| 1315 | if (!ftrace_pages_start) |
| 1316 | return -1; |
| 1317 | |
| 1318 | /* |
| 1319 | * Allocate a few more pages. |
| 1320 | * |
| 1321 | * TODO: have some parser search vmlinux before |
| 1322 | * final linking to find all calls to ftrace. |
| 1323 | * Then we can: |
| 1324 | * a) know how many pages to allocate. |
| 1325 | * and/or |
| 1326 | * b) set up the table then. |
| 1327 | * |
| 1328 | * The dynamic code is still necessary for |
| 1329 | * modules. |
| 1330 | */ |
| 1331 | |
| 1332 | pg = ftrace_pages = ftrace_pages_start; |
| 1333 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1334 | cnt = num_to_init / ENTRIES_PER_PAGE; |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1335 | pr_info("ftrace: allocating %ld entries in %d pages\n", |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 1336 | num_to_init, cnt + 1); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1337 | |
| 1338 | for (i = 0; i < cnt; i++) { |
| 1339 | pg->next = (void *)get_zeroed_page(GFP_KERNEL); |
| 1340 | |
| 1341 | /* If we fail, we'll try later anyway */ |
| 1342 | if (!pg->next) |
| 1343 | break; |
| 1344 | |
| 1345 | pg = pg->next; |
| 1346 | } |
| 1347 | |
| 1348 | return 0; |
| 1349 | } |
| 1350 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1351 | enum { |
| 1352 | FTRACE_ITER_FILTER = (1 << 0), |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 1353 | FTRACE_ITER_NOTRACE = (1 << 1), |
| 1354 | FTRACE_ITER_FAILURES = (1 << 2), |
| 1355 | FTRACE_ITER_PRINTALL = (1 << 3), |
| 1356 | FTRACE_ITER_HASH = (1 << 4), |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1357 | }; |
| 1358 | |
| 1359 | #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */ |
| 1360 | |
| 1361 | struct ftrace_iterator { |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1362 | loff_t pos; |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1363 | loff_t func_pos; |
| 1364 | struct ftrace_page *pg; |
| 1365 | struct dyn_ftrace *func; |
| 1366 | struct ftrace_func_probe *probe; |
| 1367 | struct trace_parser parser; |
| 1368 | int hidx; |
| 1369 | int idx; |
| 1370 | unsigned flags; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1371 | }; |
| 1372 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1373 | static void * |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1374 | t_hash_next(struct seq_file *m, loff_t *pos) |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1375 | { |
| 1376 | struct ftrace_iterator *iter = m->private; |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1377 | struct hlist_node *hnd = NULL; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1378 | struct hlist_head *hhd; |
| 1379 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1380 | (*pos)++; |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1381 | iter->pos = *pos; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1382 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1383 | if (iter->probe) |
| 1384 | hnd = &iter->probe->node; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1385 | retry: |
| 1386 | if (iter->hidx >= FTRACE_FUNC_HASHSIZE) |
| 1387 | return NULL; |
| 1388 | |
| 1389 | hhd = &ftrace_func_hash[iter->hidx]; |
| 1390 | |
| 1391 | if (hlist_empty(hhd)) { |
| 1392 | iter->hidx++; |
| 1393 | hnd = NULL; |
| 1394 | goto retry; |
| 1395 | } |
| 1396 | |
| 1397 | if (!hnd) |
| 1398 | hnd = hhd->first; |
| 1399 | else { |
| 1400 | hnd = hnd->next; |
| 1401 | if (!hnd) { |
| 1402 | iter->hidx++; |
| 1403 | goto retry; |
| 1404 | } |
| 1405 | } |
| 1406 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1407 | if (WARN_ON_ONCE(!hnd)) |
| 1408 | return NULL; |
| 1409 | |
| 1410 | iter->probe = hlist_entry(hnd, struct ftrace_func_probe, node); |
| 1411 | |
| 1412 | return iter; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | static void *t_hash_start(struct seq_file *m, loff_t *pos) |
| 1416 | { |
| 1417 | struct ftrace_iterator *iter = m->private; |
| 1418 | void *p = NULL; |
Li Zefan | d82d624 | 2009-06-24 09:54:54 +0800 | [diff] [blame] | 1419 | loff_t l; |
| 1420 | |
Steven Rostedt | 2bccfff | 2010-09-09 08:43:22 -0400 | [diff] [blame] | 1421 | if (iter->func_pos > *pos) |
| 1422 | return NULL; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1423 | |
Li Zefan | d82d624 | 2009-06-24 09:54:54 +0800 | [diff] [blame] | 1424 | iter->hidx = 0; |
Steven Rostedt | 2bccfff | 2010-09-09 08:43:22 -0400 | [diff] [blame] | 1425 | for (l = 0; l <= (*pos - iter->func_pos); ) { |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1426 | p = t_hash_next(m, &l); |
Li Zefan | d82d624 | 2009-06-24 09:54:54 +0800 | [diff] [blame] | 1427 | if (!p) |
| 1428 | break; |
| 1429 | } |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1430 | if (!p) |
| 1431 | return NULL; |
| 1432 | |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1433 | /* Only set this if we have an item */ |
| 1434 | iter->flags |= FTRACE_ITER_HASH; |
| 1435 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1436 | return iter; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1437 | } |
| 1438 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1439 | static int |
| 1440 | t_hash_show(struct seq_file *m, struct ftrace_iterator *iter) |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1441 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1442 | struct ftrace_func_probe *rec; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1443 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1444 | rec = iter->probe; |
| 1445 | if (WARN_ON_ONCE(!rec)) |
| 1446 | return -EIO; |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1447 | |
Steven Rostedt | 809dcf2 | 2009-02-16 23:06:01 -0500 | [diff] [blame] | 1448 | if (rec->ops->print) |
| 1449 | return rec->ops->print(m, rec->ip, rec->ops, rec->data); |
| 1450 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 1451 | seq_printf(m, "%ps:%ps", (void *)rec->ip, (void *)rec->ops->func); |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1452 | |
| 1453 | if (rec->data) |
| 1454 | seq_printf(m, ":%p", rec->data); |
| 1455 | seq_putc(m, '\n'); |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | static void * |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1461 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 1462 | { |
| 1463 | struct ftrace_iterator *iter = m->private; |
| 1464 | struct dyn_ftrace *rec = NULL; |
| 1465 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1466 | if (iter->flags & FTRACE_ITER_HASH) |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1467 | return t_hash_next(m, pos); |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1468 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1469 | (*pos)++; |
Jiri Olsa | 1106b69 | 2011-02-16 17:35:34 +0100 | [diff] [blame] | 1470 | iter->pos = iter->func_pos = *pos; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1471 | |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1472 | if (iter->flags & FTRACE_ITER_PRINTALL) |
Steven Rostedt | 57c072c | 2010-09-14 11:21:11 -0400 | [diff] [blame] | 1473 | return t_hash_start(m, pos); |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1474 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1475 | retry: |
| 1476 | if (iter->idx >= iter->pg->index) { |
| 1477 | if (iter->pg->next) { |
| 1478 | iter->pg = iter->pg->next; |
| 1479 | iter->idx = 0; |
| 1480 | goto retry; |
| 1481 | } |
| 1482 | } else { |
| 1483 | rec = &iter->pg->records[iter->idx++]; |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 1484 | if ((rec->flags & FTRACE_FL_FREE) || |
| 1485 | |
| 1486 | (!(iter->flags & FTRACE_ITER_FAILURES) && |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1487 | (rec->flags & FTRACE_FL_FAILED)) || |
| 1488 | |
| 1489 | ((iter->flags & FTRACE_ITER_FAILURES) && |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 1490 | !(rec->flags & FTRACE_FL_FAILED)) || |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1491 | |
Steven Rostedt | 0183fb1 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 1492 | ((iter->flags & FTRACE_ITER_FILTER) && |
| 1493 | !(rec->flags & FTRACE_FL_FILTER)) || |
| 1494 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1495 | ((iter->flags & FTRACE_ITER_NOTRACE) && |
| 1496 | !(rec->flags & FTRACE_FL_NOTRACE))) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1497 | rec = NULL; |
| 1498 | goto retry; |
| 1499 | } |
| 1500 | } |
| 1501 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1502 | if (!rec) |
Steven Rostedt | 57c072c | 2010-09-14 11:21:11 -0400 | [diff] [blame] | 1503 | return t_hash_start(m, pos); |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1504 | |
| 1505 | iter->func = rec; |
| 1506 | |
| 1507 | return iter; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1508 | } |
| 1509 | |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1510 | static void reset_iter_read(struct ftrace_iterator *iter) |
| 1511 | { |
| 1512 | iter->pos = 0; |
| 1513 | iter->func_pos = 0; |
| 1514 | iter->flags &= ~(FTRACE_ITER_PRINTALL & FTRACE_ITER_HASH); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 1518 | { |
| 1519 | struct ftrace_iterator *iter = m->private; |
| 1520 | void *p = NULL; |
Li Zefan | 694ce0a | 2009-06-24 09:54:19 +0800 | [diff] [blame] | 1521 | loff_t l; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1522 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1523 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1524 | /* |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1525 | * If an lseek was done, then reset and start from beginning. |
| 1526 | */ |
| 1527 | if (*pos < iter->pos) |
| 1528 | reset_iter_read(iter); |
| 1529 | |
| 1530 | /* |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1531 | * For set_ftrace_filter reading, if we have the filter |
| 1532 | * off, we can short cut and just print out that all |
| 1533 | * functions are enabled. |
| 1534 | */ |
| 1535 | if (iter->flags & FTRACE_ITER_FILTER && !ftrace_filtered) { |
| 1536 | if (*pos > 0) |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1537 | return t_hash_start(m, pos); |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1538 | iter->flags |= FTRACE_ITER_PRINTALL; |
Chris Wright | df09162 | 2010-09-09 16:34:59 -0700 | [diff] [blame] | 1539 | /* reset in case of seek/pread */ |
| 1540 | iter->flags &= ~FTRACE_ITER_HASH; |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1541 | return iter; |
| 1542 | } |
| 1543 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1544 | if (iter->flags & FTRACE_ITER_HASH) |
| 1545 | return t_hash_start(m, pos); |
| 1546 | |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 1547 | /* |
| 1548 | * Unfortunately, we need to restart at ftrace_pages_start |
| 1549 | * every time we let go of the ftrace_mutex. This is because |
| 1550 | * those pointers can change without the lock. |
| 1551 | */ |
Li Zefan | 694ce0a | 2009-06-24 09:54:19 +0800 | [diff] [blame] | 1552 | iter->pg = ftrace_pages_start; |
| 1553 | iter->idx = 0; |
| 1554 | for (l = 0; l <= *pos; ) { |
| 1555 | p = t_next(m, p, &l); |
| 1556 | if (!p) |
| 1557 | break; |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 1558 | } |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 1559 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1560 | if (!p) { |
| 1561 | if (iter->flags & FTRACE_ITER_FILTER) |
| 1562 | return t_hash_start(m, pos); |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1563 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1564 | return NULL; |
| 1565 | } |
| 1566 | |
| 1567 | return iter; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | static void t_stop(struct seq_file *m, void *p) |
| 1571 | { |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1572 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | static int t_show(struct seq_file *m, void *v) |
| 1576 | { |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1577 | struct ftrace_iterator *iter = m->private; |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1578 | struct dyn_ftrace *rec; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1579 | |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1580 | if (iter->flags & FTRACE_ITER_HASH) |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1581 | return t_hash_show(m, iter); |
Steven Rostedt | 8fc0c70 | 2009-02-16 15:28:00 -0500 | [diff] [blame] | 1582 | |
Steven Rostedt | 0c75a3e | 2009-02-16 11:21:52 -0500 | [diff] [blame] | 1583 | if (iter->flags & FTRACE_ITER_PRINTALL) { |
| 1584 | seq_printf(m, "#### all functions enabled ####\n"); |
| 1585 | return 0; |
| 1586 | } |
| 1587 | |
Steven Rostedt | 4aeb696 | 2010-09-09 10:00:28 -0400 | [diff] [blame] | 1588 | rec = iter->func; |
| 1589 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1590 | if (!rec) |
| 1591 | return 0; |
| 1592 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 1593 | seq_printf(m, "%ps\n", (void *)rec->ip); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1594 | |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 1598 | static const struct seq_operations show_ftrace_seq_ops = { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1599 | .start = t_start, |
| 1600 | .next = t_next, |
| 1601 | .stop = t_stop, |
| 1602 | .show = t_show, |
| 1603 | }; |
| 1604 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1605 | static int |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1606 | ftrace_avail_open(struct inode *inode, struct file *file) |
| 1607 | { |
| 1608 | struct ftrace_iterator *iter; |
| 1609 | int ret; |
| 1610 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1611 | if (unlikely(ftrace_disabled)) |
| 1612 | return -ENODEV; |
| 1613 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1614 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 1615 | if (!iter) |
| 1616 | return -ENOMEM; |
| 1617 | |
| 1618 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1619 | |
| 1620 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 1621 | if (!ret) { |
| 1622 | struct seq_file *m = file->private_data; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1623 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1624 | m->private = iter; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1625 | } else { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1626 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 1627 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1628 | |
| 1629 | return ret; |
| 1630 | } |
| 1631 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1632 | static int |
| 1633 | ftrace_failures_open(struct inode *inode, struct file *file) |
| 1634 | { |
| 1635 | int ret; |
| 1636 | struct seq_file *m; |
| 1637 | struct ftrace_iterator *iter; |
| 1638 | |
| 1639 | ret = ftrace_avail_open(inode, file); |
| 1640 | if (!ret) { |
matt mooney | 907f278 | 2010-09-27 19:04:53 -0700 | [diff] [blame] | 1641 | m = file->private_data; |
| 1642 | iter = m->private; |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1643 | iter->flags = FTRACE_ITER_FAILURES; |
| 1644 | } |
| 1645 | |
| 1646 | return ret; |
| 1647 | } |
| 1648 | |
| 1649 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1650 | static void ftrace_filter_reset(int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1651 | { |
| 1652 | struct ftrace_page *pg; |
| 1653 | struct dyn_ftrace *rec; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1654 | unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1655 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1656 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1657 | if (enable) |
| 1658 | ftrace_filtered = 0; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1659 | do_for_each_ftrace_rec(pg, rec) { |
| 1660 | if (rec->flags & FTRACE_FL_FAILED) |
| 1661 | continue; |
| 1662 | rec->flags &= ~type; |
| 1663 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1664 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1665 | } |
| 1666 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1667 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1668 | ftrace_regex_open(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1669 | { |
| 1670 | struct ftrace_iterator *iter; |
| 1671 | int ret = 0; |
| 1672 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1673 | if (unlikely(ftrace_disabled)) |
| 1674 | return -ENODEV; |
| 1675 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1676 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 1677 | if (!iter) |
| 1678 | return -ENOMEM; |
| 1679 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 1680 | if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) { |
| 1681 | kfree(iter); |
| 1682 | return -ENOMEM; |
| 1683 | } |
| 1684 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1685 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1686 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 1687 | (file->f_flags & O_TRUNC)) |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1688 | ftrace_filter_reset(enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1689 | |
| 1690 | if (file->f_mode & FMODE_READ) { |
| 1691 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1692 | iter->flags = enable ? FTRACE_ITER_FILTER : |
| 1693 | FTRACE_ITER_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1694 | |
| 1695 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 1696 | if (!ret) { |
| 1697 | struct seq_file *m = file->private_data; |
| 1698 | m->private = iter; |
Li Zefan | 79fe249 | 2009-09-22 13:54:28 +0800 | [diff] [blame] | 1699 | } else { |
| 1700 | trace_parser_put(&iter->parser); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1701 | kfree(iter); |
Li Zefan | 79fe249 | 2009-09-22 13:54:28 +0800 | [diff] [blame] | 1702 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1703 | } else |
| 1704 | file->private_data = iter; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1705 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1706 | |
| 1707 | return ret; |
| 1708 | } |
| 1709 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1710 | static int |
| 1711 | ftrace_filter_open(struct inode *inode, struct file *file) |
| 1712 | { |
| 1713 | return ftrace_regex_open(inode, file, 1); |
| 1714 | } |
| 1715 | |
| 1716 | static int |
| 1717 | ftrace_notrace_open(struct inode *inode, struct file *file) |
| 1718 | { |
| 1719 | return ftrace_regex_open(inode, file, 0); |
| 1720 | } |
| 1721 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1722 | static loff_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1723 | ftrace_regex_lseek(struct file *file, loff_t offset, int origin) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1724 | { |
| 1725 | loff_t ret; |
| 1726 | |
| 1727 | if (file->f_mode & FMODE_READ) |
| 1728 | ret = seq_lseek(file, offset, origin); |
| 1729 | else |
| 1730 | file->f_pos = ret = 1; |
| 1731 | |
| 1732 | return ret; |
| 1733 | } |
| 1734 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1735 | static int ftrace_match(char *str, char *regex, int len, int type) |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1736 | { |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1737 | int matched = 0; |
Li Zefan | 751e998 | 2010-01-14 10:53:02 +0800 | [diff] [blame] | 1738 | int slen; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1739 | |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1740 | switch (type) { |
| 1741 | case MATCH_FULL: |
| 1742 | if (strcmp(str, regex) == 0) |
| 1743 | matched = 1; |
| 1744 | break; |
| 1745 | case MATCH_FRONT_ONLY: |
| 1746 | if (strncmp(str, regex, len) == 0) |
| 1747 | matched = 1; |
| 1748 | break; |
| 1749 | case MATCH_MIDDLE_ONLY: |
| 1750 | if (strstr(str, regex)) |
| 1751 | matched = 1; |
| 1752 | break; |
| 1753 | case MATCH_END_ONLY: |
Li Zefan | 751e998 | 2010-01-14 10:53:02 +0800 | [diff] [blame] | 1754 | slen = strlen(str); |
| 1755 | if (slen >= len && memcmp(str + slen - len, regex, len) == 0) |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1756 | matched = 1; |
| 1757 | break; |
| 1758 | } |
| 1759 | |
| 1760 | return matched; |
| 1761 | } |
| 1762 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1763 | static int |
| 1764 | ftrace_match_record(struct dyn_ftrace *rec, char *regex, int len, int type) |
| 1765 | { |
| 1766 | char str[KSYM_SYMBOL_LEN]; |
| 1767 | |
| 1768 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 1769 | return ftrace_match(str, regex, len, type); |
| 1770 | } |
| 1771 | |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1772 | static int ftrace_match_records(char *buff, int len, int enable) |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1773 | { |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1774 | unsigned int search_len; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1775 | struct ftrace_page *pg; |
| 1776 | struct dyn_ftrace *rec; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1777 | unsigned long flag; |
| 1778 | char *search; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1779 | int type; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1780 | int not; |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1781 | int found = 0; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1782 | |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1783 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Frederic Weisbecker | 3f6fe06 | 2009-09-24 21:31:51 +0200 | [diff] [blame] | 1784 | type = filter_parse_regex(buff, len, &search, ¬); |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1785 | |
| 1786 | search_len = strlen(search); |
| 1787 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1788 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1789 | do_for_each_ftrace_rec(pg, rec) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1790 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1791 | if (rec->flags & FTRACE_FL_FAILED) |
| 1792 | continue; |
Steven Rostedt | 9f4801e | 2009-02-13 15:56:43 -0500 | [diff] [blame] | 1793 | |
| 1794 | if (ftrace_match_record(rec, search, search_len, type)) { |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1795 | if (not) |
| 1796 | rec->flags &= ~flag; |
| 1797 | else |
| 1798 | rec->flags |= flag; |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1799 | found = 1; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1800 | } |
Steven Rostedt | e68746a | 2009-02-13 20:53:42 -0500 | [diff] [blame] | 1801 | /* |
| 1802 | * Only enable filtering if we have a function that |
| 1803 | * is filtered on. |
| 1804 | */ |
| 1805 | if (enable && (rec->flags & FTRACE_FL_FILTER)) |
| 1806 | ftrace_filtered = 1; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 1807 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1808 | mutex_unlock(&ftrace_lock); |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1809 | |
| 1810 | return found; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1813 | static int |
| 1814 | ftrace_match_module_record(struct dyn_ftrace *rec, char *mod, |
| 1815 | char *regex, int len, int type) |
| 1816 | { |
| 1817 | char str[KSYM_SYMBOL_LEN]; |
| 1818 | char *modname; |
| 1819 | |
| 1820 | kallsyms_lookup(rec->ip, NULL, NULL, &modname, str); |
| 1821 | |
| 1822 | if (!modname || strcmp(modname, mod)) |
| 1823 | return 0; |
| 1824 | |
| 1825 | /* blank search means to match all funcs in the mod */ |
| 1826 | if (len) |
| 1827 | return ftrace_match(str, regex, len, type); |
| 1828 | else |
| 1829 | return 1; |
| 1830 | } |
| 1831 | |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1832 | static int ftrace_match_module_records(char *buff, char *mod, int enable) |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1833 | { |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1834 | unsigned search_len = 0; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1835 | struct ftrace_page *pg; |
| 1836 | struct dyn_ftrace *rec; |
| 1837 | int type = MATCH_FULL; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1838 | char *search = buff; |
| 1839 | unsigned long flag; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1840 | int not = 0; |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1841 | int found = 0; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1842 | |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 1843 | flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
| 1844 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1845 | /* blank or '*' mean the same */ |
| 1846 | if (strcmp(buff, "*") == 0) |
| 1847 | buff[0] = 0; |
| 1848 | |
| 1849 | /* handle the case of 'dont filter this module' */ |
| 1850 | if (strcmp(buff, "!") == 0 || strcmp(buff, "!*") == 0) { |
| 1851 | buff[0] = 0; |
| 1852 | not = 1; |
| 1853 | } |
| 1854 | |
| 1855 | if (strlen(buff)) { |
Frederic Weisbecker | 3f6fe06 | 2009-09-24 21:31:51 +0200 | [diff] [blame] | 1856 | type = filter_parse_regex(buff, strlen(buff), &search, ¬); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1857 | search_len = strlen(search); |
| 1858 | } |
| 1859 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1860 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1861 | do_for_each_ftrace_rec(pg, rec) { |
| 1862 | |
| 1863 | if (rec->flags & FTRACE_FL_FAILED) |
| 1864 | continue; |
| 1865 | |
| 1866 | if (ftrace_match_module_record(rec, mod, |
| 1867 | search, search_len, type)) { |
| 1868 | if (not) |
| 1869 | rec->flags &= ~flag; |
| 1870 | else |
| 1871 | rec->flags |= flag; |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1872 | found = 1; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1873 | } |
Steven Rostedt | e68746a | 2009-02-13 20:53:42 -0500 | [diff] [blame] | 1874 | if (enable && (rec->flags & FTRACE_FL_FILTER)) |
| 1875 | ftrace_filtered = 1; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1876 | |
| 1877 | } while_for_each_ftrace_rec(); |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 1878 | mutex_unlock(&ftrace_lock); |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1879 | |
| 1880 | return found; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 1881 | } |
| 1882 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1883 | /* |
| 1884 | * We register the module command as a template to show others how |
| 1885 | * to register the a command as well. |
| 1886 | */ |
| 1887 | |
| 1888 | static int |
| 1889 | ftrace_mod_callback(char *func, char *cmd, char *param, int enable) |
| 1890 | { |
| 1891 | char *mod; |
| 1892 | |
| 1893 | /* |
| 1894 | * cmd == 'mod' because we only registered this func |
| 1895 | * for the 'mod' ftrace_func_command. |
| 1896 | * But if you register one func with multiple commands, |
| 1897 | * you can tell which command was used by the cmd |
| 1898 | * parameter. |
| 1899 | */ |
| 1900 | |
| 1901 | /* we must have a module name */ |
| 1902 | if (!param) |
| 1903 | return -EINVAL; |
| 1904 | |
| 1905 | mod = strsep(¶m, ":"); |
| 1906 | if (!strlen(mod)) |
| 1907 | return -EINVAL; |
| 1908 | |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 1909 | if (ftrace_match_module_records(func, mod, enable)) |
| 1910 | return 0; |
| 1911 | return -EINVAL; |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | static struct ftrace_func_command ftrace_mod_cmd = { |
| 1915 | .name = "mod", |
| 1916 | .func = ftrace_mod_callback, |
| 1917 | }; |
| 1918 | |
| 1919 | static int __init ftrace_mod_cmd_init(void) |
| 1920 | { |
| 1921 | return register_ftrace_command(&ftrace_mod_cmd); |
| 1922 | } |
| 1923 | device_initcall(ftrace_mod_cmd_init); |
| 1924 | |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1925 | static void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1926 | function_trace_probe_call(unsigned long ip, unsigned long parent_ip) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1927 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1928 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1929 | struct hlist_head *hhd; |
| 1930 | struct hlist_node *n; |
| 1931 | unsigned long key; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1932 | |
| 1933 | key = hash_long(ip, FTRACE_HASH_BITS); |
| 1934 | |
| 1935 | hhd = &ftrace_func_hash[key]; |
| 1936 | |
| 1937 | if (hlist_empty(hhd)) |
| 1938 | return; |
| 1939 | |
| 1940 | /* |
| 1941 | * Disable preemption for these calls to prevent a RCU grace |
| 1942 | * period. This syncs the hash iteration and freeing of items |
| 1943 | * on the hash. rcu_read_lock is too dangerous here. |
| 1944 | */ |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1945 | preempt_disable_notrace(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1946 | hlist_for_each_entry_rcu(entry, n, hhd, node) { |
| 1947 | if (entry->ip == ip) |
| 1948 | entry->ops->func(ip, parent_ip, &entry->data); |
| 1949 | } |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1950 | preempt_enable_notrace(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1951 | } |
| 1952 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1953 | static struct ftrace_ops trace_probe_ops __read_mostly = |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1954 | { |
Steven Rostedt | fb9fb01 | 2009-03-25 13:26:41 -0400 | [diff] [blame] | 1955 | .func = function_trace_probe_call, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1956 | }; |
| 1957 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1958 | static int ftrace_probe_registered; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1959 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1960 | static void __enable_ftrace_function_probe(void) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1961 | { |
| 1962 | int i; |
| 1963 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1964 | if (ftrace_probe_registered) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1965 | return; |
| 1966 | |
| 1967 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 1968 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 1969 | if (hhd->first) |
| 1970 | break; |
| 1971 | } |
| 1972 | /* Nothing registered? */ |
| 1973 | if (i == FTRACE_FUNC_HASHSIZE) |
| 1974 | return; |
| 1975 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1976 | __register_ftrace_function(&trace_probe_ops); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1977 | ftrace_startup(0); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1978 | ftrace_probe_registered = 1; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1979 | } |
| 1980 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1981 | static void __disable_ftrace_function_probe(void) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1982 | { |
| 1983 | int i; |
| 1984 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1985 | if (!ftrace_probe_registered) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1986 | return; |
| 1987 | |
| 1988 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 1989 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 1990 | if (hhd->first) |
| 1991 | return; |
| 1992 | } |
| 1993 | |
| 1994 | /* no more funcs left */ |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1995 | __unregister_ftrace_function(&trace_probe_ops); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1996 | ftrace_shutdown(0); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 1997 | ftrace_probe_registered = 0; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | |
| 2001 | static void ftrace_free_entry_rcu(struct rcu_head *rhp) |
| 2002 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2003 | struct ftrace_func_probe *entry = |
| 2004 | container_of(rhp, struct ftrace_func_probe, rcu); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2005 | |
| 2006 | if (entry->ops->free) |
| 2007 | entry->ops->free(&entry->data); |
| 2008 | kfree(entry); |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | int |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2013 | register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2014 | void *data) |
| 2015 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2016 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2017 | struct ftrace_page *pg; |
| 2018 | struct dyn_ftrace *rec; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2019 | int type, len, not; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 2020 | unsigned long key; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2021 | int count = 0; |
| 2022 | char *search; |
| 2023 | |
Frederic Weisbecker | 3f6fe06 | 2009-09-24 21:31:51 +0200 | [diff] [blame] | 2024 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2025 | len = strlen(search); |
| 2026 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2027 | /* we do not support '!' for function probes */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2028 | if (WARN_ON(not)) |
| 2029 | return -EINVAL; |
| 2030 | |
| 2031 | mutex_lock(&ftrace_lock); |
| 2032 | do_for_each_ftrace_rec(pg, rec) { |
| 2033 | |
| 2034 | if (rec->flags & FTRACE_FL_FAILED) |
| 2035 | continue; |
| 2036 | |
| 2037 | if (!ftrace_match_record(rec, search, len, type)) |
| 2038 | continue; |
| 2039 | |
| 2040 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 2041 | if (!entry) { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2042 | /* If we did not process any, then return error */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2043 | if (!count) |
| 2044 | count = -ENOMEM; |
| 2045 | goto out_unlock; |
| 2046 | } |
| 2047 | |
| 2048 | count++; |
| 2049 | |
| 2050 | entry->data = data; |
| 2051 | |
| 2052 | /* |
| 2053 | * The caller might want to do something special |
| 2054 | * for each function we find. We call the callback |
| 2055 | * to give the caller an opportunity to do so. |
| 2056 | */ |
| 2057 | if (ops->callback) { |
| 2058 | if (ops->callback(rec->ip, &entry->data) < 0) { |
| 2059 | /* caller does not like this func */ |
| 2060 | kfree(entry); |
| 2061 | continue; |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | entry->ops = ops; |
| 2066 | entry->ip = rec->ip; |
| 2067 | |
| 2068 | key = hash_long(entry->ip, FTRACE_HASH_BITS); |
| 2069 | hlist_add_head_rcu(&entry->node, &ftrace_func_hash[key]); |
| 2070 | |
| 2071 | } while_for_each_ftrace_rec(); |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2072 | __enable_ftrace_function_probe(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2073 | |
| 2074 | out_unlock: |
| 2075 | mutex_unlock(&ftrace_lock); |
| 2076 | |
| 2077 | return count; |
| 2078 | } |
| 2079 | |
| 2080 | enum { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2081 | PROBE_TEST_FUNC = 1, |
| 2082 | PROBE_TEST_DATA = 2 |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2083 | }; |
| 2084 | |
| 2085 | static void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2086 | __unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2087 | void *data, int flags) |
| 2088 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2089 | struct ftrace_func_probe *entry; |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2090 | struct hlist_node *n, *tmp; |
| 2091 | char str[KSYM_SYMBOL_LEN]; |
| 2092 | int type = MATCH_FULL; |
| 2093 | int i, len = 0; |
| 2094 | char *search; |
| 2095 | |
Atsushi Tsuji | b36461d | 2009-09-15 19:06:30 +0900 | [diff] [blame] | 2096 | if (glob && (strcmp(glob, "*") == 0 || !strlen(glob))) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2097 | glob = NULL; |
Atsushi Tsuji | b36461d | 2009-09-15 19:06:30 +0900 | [diff] [blame] | 2098 | else if (glob) { |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2099 | int not; |
| 2100 | |
Frederic Weisbecker | 3f6fe06 | 2009-09-24 21:31:51 +0200 | [diff] [blame] | 2101 | type = filter_parse_regex(glob, strlen(glob), &search, ¬); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2102 | len = strlen(search); |
| 2103 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2104 | /* we do not support '!' for function probes */ |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2105 | if (WARN_ON(not)) |
| 2106 | return; |
| 2107 | } |
| 2108 | |
| 2109 | mutex_lock(&ftrace_lock); |
| 2110 | for (i = 0; i < FTRACE_FUNC_HASHSIZE; i++) { |
| 2111 | struct hlist_head *hhd = &ftrace_func_hash[i]; |
| 2112 | |
| 2113 | hlist_for_each_entry_safe(entry, n, tmp, hhd, node) { |
| 2114 | |
| 2115 | /* break up if statements for readability */ |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2116 | if ((flags & PROBE_TEST_FUNC) && entry->ops != ops) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2117 | continue; |
| 2118 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2119 | if ((flags & PROBE_TEST_DATA) && entry->data != data) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2120 | continue; |
| 2121 | |
| 2122 | /* do this last, since it is the most expensive */ |
| 2123 | if (glob) { |
| 2124 | kallsyms_lookup(entry->ip, NULL, NULL, |
| 2125 | NULL, str); |
| 2126 | if (!ftrace_match(str, glob, len, type)) |
| 2127 | continue; |
| 2128 | } |
| 2129 | |
| 2130 | hlist_del(&entry->node); |
| 2131 | call_rcu(&entry->rcu, ftrace_free_entry_rcu); |
| 2132 | } |
| 2133 | } |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2134 | __disable_ftrace_function_probe(); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2135 | mutex_unlock(&ftrace_lock); |
| 2136 | } |
| 2137 | |
| 2138 | void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2139 | unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops, |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2140 | void *data) |
| 2141 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2142 | __unregister_ftrace_function_probe(glob, ops, data, |
| 2143 | PROBE_TEST_FUNC | PROBE_TEST_DATA); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | void |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2147 | unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2148 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2149 | __unregister_ftrace_function_probe(glob, ops, NULL, PROBE_TEST_FUNC); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2150 | } |
| 2151 | |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2152 | void unregister_ftrace_function_probe_all(char *glob) |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2153 | { |
Steven Rostedt | b6887d7 | 2009-02-17 12:32:04 -0500 | [diff] [blame] | 2154 | __unregister_ftrace_function_probe(glob, NULL, NULL, 0); |
Steven Rostedt | 59df055f | 2009-02-14 15:29:06 -0500 | [diff] [blame] | 2155 | } |
| 2156 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2157 | static LIST_HEAD(ftrace_commands); |
| 2158 | static DEFINE_MUTEX(ftrace_cmd_mutex); |
| 2159 | |
| 2160 | int register_ftrace_command(struct ftrace_func_command *cmd) |
| 2161 | { |
| 2162 | struct ftrace_func_command *p; |
| 2163 | int ret = 0; |
| 2164 | |
| 2165 | mutex_lock(&ftrace_cmd_mutex); |
| 2166 | list_for_each_entry(p, &ftrace_commands, list) { |
| 2167 | if (strcmp(cmd->name, p->name) == 0) { |
| 2168 | ret = -EBUSY; |
| 2169 | goto out_unlock; |
| 2170 | } |
| 2171 | } |
| 2172 | list_add(&cmd->list, &ftrace_commands); |
| 2173 | out_unlock: |
| 2174 | mutex_unlock(&ftrace_cmd_mutex); |
| 2175 | |
| 2176 | return ret; |
| 2177 | } |
| 2178 | |
| 2179 | int unregister_ftrace_command(struct ftrace_func_command *cmd) |
| 2180 | { |
| 2181 | struct ftrace_func_command *p, *n; |
| 2182 | int ret = -ENODEV; |
| 2183 | |
| 2184 | mutex_lock(&ftrace_cmd_mutex); |
| 2185 | list_for_each_entry_safe(p, n, &ftrace_commands, list) { |
| 2186 | if (strcmp(cmd->name, p->name) == 0) { |
| 2187 | ret = 0; |
| 2188 | list_del_init(&p->list); |
| 2189 | goto out_unlock; |
| 2190 | } |
| 2191 | } |
| 2192 | out_unlock: |
| 2193 | mutex_unlock(&ftrace_cmd_mutex); |
| 2194 | |
| 2195 | return ret; |
| 2196 | } |
| 2197 | |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2198 | static int ftrace_process_regex(char *buff, int len, int enable) |
| 2199 | { |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2200 | char *func, *command, *next = buff; |
Steven Rostedt | 6a24a24 | 2009-02-17 11:20:26 -0500 | [diff] [blame] | 2201 | struct ftrace_func_command *p; |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2202 | int ret = -EINVAL; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2203 | |
| 2204 | func = strsep(&next, ":"); |
| 2205 | |
| 2206 | if (!next) { |
Li Zefan | 311d16d | 2009-12-08 11:15:11 +0800 | [diff] [blame] | 2207 | if (ftrace_match_records(func, len, enable)) |
| 2208 | return 0; |
| 2209 | return ret; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2210 | } |
| 2211 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2212 | /* command found */ |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2213 | |
| 2214 | command = strsep(&next, ":"); |
| 2215 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2216 | mutex_lock(&ftrace_cmd_mutex); |
| 2217 | list_for_each_entry(p, &ftrace_commands, list) { |
| 2218 | if (strcmp(p->name, command) == 0) { |
| 2219 | ret = p->func(func, command, next, enable); |
| 2220 | goto out_unlock; |
| 2221 | } |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2222 | } |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2223 | out_unlock: |
| 2224 | mutex_unlock(&ftrace_cmd_mutex); |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2225 | |
Steven Rostedt | f618077 | 2009-02-14 00:40:25 -0500 | [diff] [blame] | 2226 | return ret; |
Steven Rostedt | 64e7c44 | 2009-02-13 17:08:48 -0500 | [diff] [blame] | 2227 | } |
| 2228 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2229 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2230 | ftrace_regex_write(struct file *file, const char __user *ubuf, |
| 2231 | size_t cnt, loff_t *ppos, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2232 | { |
| 2233 | struct ftrace_iterator *iter; |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2234 | struct trace_parser *parser; |
| 2235 | ssize_t ret, read; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2236 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 2237 | if (!cnt) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2238 | return 0; |
| 2239 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2240 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2241 | |
| 2242 | if (file->f_mode & FMODE_READ) { |
| 2243 | struct seq_file *m = file->private_data; |
| 2244 | iter = m->private; |
| 2245 | } else |
| 2246 | iter = file->private_data; |
| 2247 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2248 | parser = &iter->parser; |
| 2249 | read = trace_get_user(parser, ubuf, cnt, ppos); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2250 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 2251 | if (read >= 0 && trace_parser_loaded(parser) && |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2252 | !trace_parser_cont(parser)) { |
| 2253 | ret = ftrace_process_regex(parser->buffer, |
| 2254 | parser->idx, enable); |
Li Zefan | 313254a | 2009-12-08 11:15:30 +0800 | [diff] [blame] | 2255 | trace_parser_clear(parser); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2256 | if (ret) |
Li Zefan | ed146b25 | 2009-11-03 08:55:38 +0800 | [diff] [blame] | 2257 | goto out_unlock; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2258 | } |
| 2259 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2260 | ret = read; |
Li Zefan | ed146b25 | 2009-11-03 08:55:38 +0800 | [diff] [blame] | 2261 | out_unlock: |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2262 | mutex_unlock(&ftrace_regex_lock); |
Li Zefan | ed146b25 | 2009-11-03 08:55:38 +0800 | [diff] [blame] | 2263 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2264 | return ret; |
| 2265 | } |
| 2266 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2267 | static ssize_t |
| 2268 | ftrace_filter_write(struct file *file, const char __user *ubuf, |
| 2269 | size_t cnt, loff_t *ppos) |
| 2270 | { |
| 2271 | return ftrace_regex_write(file, ubuf, cnt, ppos, 1); |
| 2272 | } |
| 2273 | |
| 2274 | static ssize_t |
| 2275 | ftrace_notrace_write(struct file *file, const char __user *ubuf, |
| 2276 | size_t cnt, loff_t *ppos) |
| 2277 | { |
| 2278 | return ftrace_regex_write(file, ubuf, cnt, ppos, 0); |
| 2279 | } |
| 2280 | |
| 2281 | static void |
| 2282 | ftrace_set_regex(unsigned char *buf, int len, int reset, int enable) |
| 2283 | { |
| 2284 | if (unlikely(ftrace_disabled)) |
| 2285 | return; |
| 2286 | |
| 2287 | mutex_lock(&ftrace_regex_lock); |
| 2288 | if (reset) |
| 2289 | ftrace_filter_reset(enable); |
| 2290 | if (buf) |
Steven Rostedt | 7f24b31 | 2009-02-13 14:37:33 -0500 | [diff] [blame] | 2291 | ftrace_match_records(buf, len, enable); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2292 | mutex_unlock(&ftrace_regex_lock); |
| 2293 | } |
| 2294 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2295 | /** |
| 2296 | * ftrace_set_filter - set a function to filter on in ftrace |
| 2297 | * @buf - the string that holds the function filter text. |
| 2298 | * @len - the length of the string. |
| 2299 | * @reset - non zero to reset all filters before applying this filter. |
| 2300 | * |
| 2301 | * Filters denote which functions should be enabled when tracing is enabled. |
| 2302 | * If @buf is NULL and reset is set, all functions will be enabled for tracing. |
| 2303 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2304 | void ftrace_set_filter(unsigned char *buf, int len, int reset) |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2305 | { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2306 | ftrace_set_regex(buf, len, reset, 1); |
| 2307 | } |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 2308 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2309 | /** |
| 2310 | * ftrace_set_notrace - set a function to not trace in ftrace |
| 2311 | * @buf - the string that holds the function notrace text. |
| 2312 | * @len - the length of the string. |
| 2313 | * @reset - non zero to reset all filters before applying this filter. |
| 2314 | * |
| 2315 | * Notrace Filters denote which functions should not be enabled when tracing |
| 2316 | * is enabled. If @buf is NULL and reset is set, all functions will be enabled |
| 2317 | * for tracing. |
| 2318 | */ |
| 2319 | void ftrace_set_notrace(unsigned char *buf, int len, int reset) |
| 2320 | { |
| 2321 | ftrace_set_regex(buf, len, reset, 0); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
Steven Rostedt | 2af15d6 | 2009-05-28 13:37:24 -0400 | [diff] [blame] | 2324 | /* |
| 2325 | * command line interface to allow users to set filters on boot up. |
| 2326 | */ |
| 2327 | #define FTRACE_FILTER_SIZE COMMAND_LINE_SIZE |
| 2328 | static char ftrace_notrace_buf[FTRACE_FILTER_SIZE] __initdata; |
| 2329 | static char ftrace_filter_buf[FTRACE_FILTER_SIZE] __initdata; |
| 2330 | |
| 2331 | static int __init set_ftrace_notrace(char *str) |
| 2332 | { |
| 2333 | strncpy(ftrace_notrace_buf, str, FTRACE_FILTER_SIZE); |
| 2334 | return 1; |
| 2335 | } |
| 2336 | __setup("ftrace_notrace=", set_ftrace_notrace); |
| 2337 | |
| 2338 | static int __init set_ftrace_filter(char *str) |
| 2339 | { |
| 2340 | strncpy(ftrace_filter_buf, str, FTRACE_FILTER_SIZE); |
| 2341 | return 1; |
| 2342 | } |
| 2343 | __setup("ftrace_filter=", set_ftrace_filter); |
| 2344 | |
Stefan Assmann | 369bc18 | 2009-10-12 22:17:21 +0200 | [diff] [blame] | 2345 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Lai Jiangshan | f6060f4 | 2009-11-05 11:16:17 +0800 | [diff] [blame] | 2346 | static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata; |
Steven Rostedt | 801c29f | 2010-03-05 20:02:19 -0500 | [diff] [blame] | 2347 | static int ftrace_set_func(unsigned long *array, int *idx, char *buffer); |
| 2348 | |
Stefan Assmann | 369bc18 | 2009-10-12 22:17:21 +0200 | [diff] [blame] | 2349 | static int __init set_graph_function(char *str) |
| 2350 | { |
Frederic Weisbecker | 06f43d6 | 2009-10-14 20:43:39 +0200 | [diff] [blame] | 2351 | strlcpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE); |
Stefan Assmann | 369bc18 | 2009-10-12 22:17:21 +0200 | [diff] [blame] | 2352 | return 1; |
| 2353 | } |
| 2354 | __setup("ftrace_graph_filter=", set_graph_function); |
| 2355 | |
| 2356 | static void __init set_ftrace_early_graph(char *buf) |
| 2357 | { |
| 2358 | int ret; |
| 2359 | char *func; |
| 2360 | |
| 2361 | while (buf) { |
| 2362 | func = strsep(&buf, ","); |
| 2363 | /* we allow only one expression at a time */ |
| 2364 | ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count, |
| 2365 | func); |
| 2366 | if (ret) |
| 2367 | printk(KERN_DEBUG "ftrace: function %s not " |
| 2368 | "traceable\n", func); |
| 2369 | } |
| 2370 | } |
| 2371 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 2372 | |
Steven Rostedt | 2af15d6 | 2009-05-28 13:37:24 -0400 | [diff] [blame] | 2373 | static void __init set_ftrace_early_filter(char *buf, int enable) |
| 2374 | { |
| 2375 | char *func; |
| 2376 | |
| 2377 | while (buf) { |
| 2378 | func = strsep(&buf, ","); |
| 2379 | ftrace_set_regex(func, strlen(func), 0, enable); |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | static void __init set_ftrace_early_filters(void) |
| 2384 | { |
| 2385 | if (ftrace_filter_buf[0]) |
| 2386 | set_ftrace_early_filter(ftrace_filter_buf, 1); |
| 2387 | if (ftrace_notrace_buf[0]) |
| 2388 | set_ftrace_early_filter(ftrace_notrace_buf, 0); |
Stefan Assmann | 369bc18 | 2009-10-12 22:17:21 +0200 | [diff] [blame] | 2389 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 2390 | if (ftrace_graph_buf[0]) |
| 2391 | set_ftrace_early_graph(ftrace_graph_buf); |
| 2392 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
Steven Rostedt | 2af15d6 | 2009-05-28 13:37:24 -0400 | [diff] [blame] | 2393 | } |
| 2394 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 2395 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2396 | ftrace_regex_release(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2397 | { |
| 2398 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 2399 | struct ftrace_iterator *iter; |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2400 | struct trace_parser *parser; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2401 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2402 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2403 | if (file->f_mode & FMODE_READ) { |
| 2404 | iter = m->private; |
| 2405 | |
| 2406 | seq_release(inode, file); |
| 2407 | } else |
| 2408 | iter = file->private_data; |
| 2409 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2410 | parser = &iter->parser; |
| 2411 | if (trace_parser_loaded(parser)) { |
| 2412 | parser->buffer[parser->idx] = 0; |
| 2413 | ftrace_match_records(parser->buffer, parser->idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2414 | } |
| 2415 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2416 | mutex_lock(&ftrace_lock); |
Steven Rostedt | ee02a2e | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 2417 | if (ftrace_start_up && ftrace_enabled) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2418 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2419 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2420 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2421 | trace_parser_put(parser); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2422 | kfree(iter); |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2423 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2424 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2425 | return 0; |
| 2426 | } |
| 2427 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2428 | static int |
| 2429 | ftrace_filter_release(struct inode *inode, struct file *file) |
| 2430 | { |
| 2431 | return ftrace_regex_release(inode, file, 1); |
| 2432 | } |
| 2433 | |
| 2434 | static int |
| 2435 | ftrace_notrace_release(struct inode *inode, struct file *file) |
| 2436 | { |
| 2437 | return ftrace_regex_release(inode, file, 0); |
| 2438 | } |
| 2439 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2440 | static const struct file_operations ftrace_avail_fops = { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2441 | .open = ftrace_avail_open, |
| 2442 | .read = seq_read, |
| 2443 | .llseek = seq_lseek, |
Li Zefan | 3be04b4 | 2009-08-17 16:54:03 +0800 | [diff] [blame] | 2444 | .release = seq_release_private, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2445 | }; |
| 2446 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2447 | static const struct file_operations ftrace_failures_fops = { |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 2448 | .open = ftrace_failures_open, |
| 2449 | .read = seq_read, |
| 2450 | .llseek = seq_lseek, |
Li Zefan | 3be04b4 | 2009-08-17 16:54:03 +0800 | [diff] [blame] | 2451 | .release = seq_release_private, |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 2452 | }; |
| 2453 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2454 | static const struct file_operations ftrace_filter_fops = { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2455 | .open = ftrace_filter_open, |
Lai Jiangshan | 850a80c | 2009-03-13 17:47:23 +0800 | [diff] [blame] | 2456 | .read = seq_read, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2457 | .write = ftrace_filter_write, |
Steven Rostedt | 98c4fd0 | 2010-09-10 11:47:43 -0400 | [diff] [blame] | 2458 | .llseek = ftrace_regex_lseek, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2459 | .release = ftrace_filter_release, |
| 2460 | }; |
| 2461 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 2462 | static const struct file_operations ftrace_notrace_fops = { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2463 | .open = ftrace_notrace_open, |
Lai Jiangshan | 850a80c | 2009-03-13 17:47:23 +0800 | [diff] [blame] | 2464 | .read = seq_read, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2465 | .write = ftrace_notrace_write, |
| 2466 | .llseek = ftrace_regex_lseek, |
| 2467 | .release = ftrace_notrace_release, |
| 2468 | }; |
| 2469 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2470 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 2471 | |
| 2472 | static DEFINE_MUTEX(graph_lock); |
| 2473 | |
| 2474 | int ftrace_graph_count; |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2475 | int ftrace_graph_filter_enabled; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2476 | unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; |
| 2477 | |
| 2478 | static void * |
Li Zefan | 8595184 | 2009-06-24 09:54:00 +0800 | [diff] [blame] | 2479 | __g_next(struct seq_file *m, loff_t *pos) |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2480 | { |
Li Zefan | 8595184 | 2009-06-24 09:54:00 +0800 | [diff] [blame] | 2481 | if (*pos >= ftrace_graph_count) |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2482 | return NULL; |
Li Zefan | a4ec5e0 | 2009-09-18 14:06:28 +0800 | [diff] [blame] | 2483 | return &ftrace_graph_funcs[*pos]; |
Li Zefan | 8595184 | 2009-06-24 09:54:00 +0800 | [diff] [blame] | 2484 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2485 | |
Li Zefan | 8595184 | 2009-06-24 09:54:00 +0800 | [diff] [blame] | 2486 | static void * |
| 2487 | g_next(struct seq_file *m, void *v, loff_t *pos) |
| 2488 | { |
| 2489 | (*pos)++; |
| 2490 | return __g_next(m, pos); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | static void *g_start(struct seq_file *m, loff_t *pos) |
| 2494 | { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2495 | mutex_lock(&graph_lock); |
| 2496 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2497 | /* Nothing, tell g_show to print all functions are enabled */ |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2498 | if (!ftrace_graph_filter_enabled && !*pos) |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2499 | return (void *)1; |
| 2500 | |
Li Zefan | 8595184 | 2009-06-24 09:54:00 +0800 | [diff] [blame] | 2501 | return __g_next(m, pos); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | static void g_stop(struct seq_file *m, void *p) |
| 2505 | { |
| 2506 | mutex_unlock(&graph_lock); |
| 2507 | } |
| 2508 | |
| 2509 | static int g_show(struct seq_file *m, void *v) |
| 2510 | { |
| 2511 | unsigned long *ptr = v; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2512 | |
| 2513 | if (!ptr) |
| 2514 | return 0; |
| 2515 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2516 | if (ptr == (unsigned long *)1) { |
| 2517 | seq_printf(m, "#### all functions enabled ####\n"); |
| 2518 | return 0; |
| 2519 | } |
| 2520 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 2521 | seq_printf(m, "%ps\n", (void *)*ptr); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2522 | |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 2526 | static const struct seq_operations ftrace_graph_seq_ops = { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2527 | .start = g_start, |
| 2528 | .next = g_next, |
| 2529 | .stop = g_stop, |
| 2530 | .show = g_show, |
| 2531 | }; |
| 2532 | |
| 2533 | static int |
| 2534 | ftrace_graph_open(struct inode *inode, struct file *file) |
| 2535 | { |
| 2536 | int ret = 0; |
| 2537 | |
| 2538 | if (unlikely(ftrace_disabled)) |
| 2539 | return -ENODEV; |
| 2540 | |
| 2541 | mutex_lock(&graph_lock); |
| 2542 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 2543 | (file->f_flags & O_TRUNC)) { |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2544 | ftrace_graph_filter_enabled = 0; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2545 | ftrace_graph_count = 0; |
| 2546 | memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); |
| 2547 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2548 | mutex_unlock(&graph_lock); |
| 2549 | |
Li Zefan | a4ec5e0 | 2009-09-18 14:06:28 +0800 | [diff] [blame] | 2550 | if (file->f_mode & FMODE_READ) |
| 2551 | ret = seq_open(file, &ftrace_graph_seq_ops); |
| 2552 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2553 | return ret; |
| 2554 | } |
| 2555 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2556 | static int |
Li Zefan | 8782711 | 2009-07-23 11:29:11 +0800 | [diff] [blame] | 2557 | ftrace_graph_release(struct inode *inode, struct file *file) |
| 2558 | { |
| 2559 | if (file->f_mode & FMODE_READ) |
| 2560 | seq_release(inode, file); |
| 2561 | return 0; |
| 2562 | } |
| 2563 | |
| 2564 | static int |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2565 | ftrace_set_func(unsigned long *array, int *idx, char *buffer) |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2566 | { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2567 | struct dyn_ftrace *rec; |
| 2568 | struct ftrace_page *pg; |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2569 | int search_len; |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2570 | int fail = 1; |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2571 | int type, not; |
| 2572 | char *search; |
| 2573 | bool exists; |
| 2574 | int i; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2575 | |
| 2576 | if (ftrace_disabled) |
| 2577 | return -ENODEV; |
| 2578 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2579 | /* decode regex */ |
Frederic Weisbecker | 3f6fe06 | 2009-09-24 21:31:51 +0200 | [diff] [blame] | 2580 | type = filter_parse_regex(buffer, strlen(buffer), &search, ¬); |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2581 | if (!not && *idx >= FTRACE_GRAPH_MAX_FUNCS) |
| 2582 | return -EBUSY; |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2583 | |
| 2584 | search_len = strlen(search); |
| 2585 | |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 2586 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2587 | do_for_each_ftrace_rec(pg, rec) { |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2588 | |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2589 | if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) |
| 2590 | continue; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2591 | |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2592 | if (ftrace_match_record(rec, search, search_len, type)) { |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2593 | /* if it is in the array */ |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2594 | exists = false; |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2595 | for (i = 0; i < *idx; i++) { |
Frederic Weisbecker | f9349a8 | 2009-02-19 21:13:12 +0100 | [diff] [blame] | 2596 | if (array[i] == rec->ip) { |
| 2597 | exists = true; |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2598 | break; |
| 2599 | } |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | if (!not) { |
| 2603 | fail = 0; |
| 2604 | if (!exists) { |
| 2605 | array[(*idx)++] = rec->ip; |
| 2606 | if (*idx >= FTRACE_GRAPH_MAX_FUNCS) |
| 2607 | goto out; |
| 2608 | } |
| 2609 | } else { |
| 2610 | if (exists) { |
| 2611 | array[i] = array[--(*idx)]; |
| 2612 | array[*idx] = 0; |
| 2613 | fail = 0; |
| 2614 | } |
| 2615 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2616 | } |
Steven Rostedt | 265c831 | 2009-02-13 12:43:56 -0500 | [diff] [blame] | 2617 | } while_for_each_ftrace_rec(); |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2618 | out: |
Steven Rostedt | 52baf11 | 2009-02-14 01:15:39 -0500 | [diff] [blame] | 2619 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2620 | |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2621 | if (fail) |
| 2622 | return -EINVAL; |
| 2623 | |
| 2624 | ftrace_graph_filter_enabled = 1; |
| 2625 | return 0; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | static ssize_t |
| 2629 | ftrace_graph_write(struct file *file, const char __user *ubuf, |
| 2630 | size_t cnt, loff_t *ppos) |
| 2631 | { |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2632 | struct trace_parser parser; |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 2633 | ssize_t read, ret; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2634 | |
Li Zefan | c7c6b1f | 2010-02-10 15:43:04 +0800 | [diff] [blame] | 2635 | if (!cnt) |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2636 | return 0; |
| 2637 | |
| 2638 | mutex_lock(&graph_lock); |
| 2639 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2640 | if (trace_parser_get_init(&parser, FTRACE_BUFF_MAX)) { |
| 2641 | ret = -ENOMEM; |
Li Zefan | 1eb90f1 | 2009-09-22 13:52:57 +0800 | [diff] [blame] | 2642 | goto out_unlock; |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2643 | } |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2644 | |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2645 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
| 2646 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 2647 | if (read >= 0 && trace_parser_loaded((&parser))) { |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2648 | parser.buffer[parser.idx] = 0; |
| 2649 | |
| 2650 | /* we allow only one expression at a time */ |
Li Zefan | a4ec5e0 | 2009-09-18 14:06:28 +0800 | [diff] [blame] | 2651 | ret = ftrace_set_func(ftrace_graph_funcs, &ftrace_graph_count, |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2652 | parser.buffer); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2653 | if (ret) |
Li Zefan | 1eb90f1 | 2009-09-22 13:52:57 +0800 | [diff] [blame] | 2654 | goto out_free; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2655 | } |
| 2656 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2657 | ret = read; |
Li Zefan | 1eb90f1 | 2009-09-22 13:52:57 +0800 | [diff] [blame] | 2658 | |
| 2659 | out_free: |
jolsa@redhat.com | 689fd8b | 2009-09-11 17:29:29 +0200 | [diff] [blame] | 2660 | trace_parser_put(&parser); |
Li Zefan | 1eb90f1 | 2009-09-22 13:52:57 +0800 | [diff] [blame] | 2661 | out_unlock: |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2662 | mutex_unlock(&graph_lock); |
| 2663 | |
| 2664 | return ret; |
| 2665 | } |
| 2666 | |
| 2667 | static const struct file_operations ftrace_graph_fops = { |
Li Zefan | 8782711 | 2009-07-23 11:29:11 +0800 | [diff] [blame] | 2668 | .open = ftrace_graph_open, |
| 2669 | .read = seq_read, |
| 2670 | .write = ftrace_graph_write, |
| 2671 | .release = ftrace_graph_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 2672 | .llseek = seq_lseek, |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2673 | }; |
| 2674 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 2675 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2676 | static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2677 | { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2678 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 2679 | trace_create_file("available_filter_functions", 0444, |
| 2680 | d_tracer, NULL, &ftrace_avail_fops); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2681 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 2682 | trace_create_file("failures", 0444, |
| 2683 | d_tracer, NULL, &ftrace_failures_fops); |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 2684 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 2685 | trace_create_file("set_ftrace_filter", 0644, d_tracer, |
| 2686 | NULL, &ftrace_filter_fops); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2687 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 2688 | trace_create_file("set_ftrace_notrace", 0644, d_tracer, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 2689 | NULL, &ftrace_notrace_fops); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 2690 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2691 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 2692 | trace_create_file("set_graph_function", 0444, d_tracer, |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2693 | NULL, |
| 2694 | &ftrace_graph_fops); |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 2695 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 2696 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 2697 | return 0; |
| 2698 | } |
| 2699 | |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 2700 | static int ftrace_process_locs(struct module *mod, |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2701 | unsigned long *start, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2702 | unsigned long *end) |
| 2703 | { |
| 2704 | unsigned long *p; |
| 2705 | unsigned long addr; |
| 2706 | unsigned long flags; |
| 2707 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2708 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2709 | p = start; |
| 2710 | while (p < end) { |
| 2711 | addr = ftrace_call_adjust(*p++); |
Steven Rostedt | 20e5227 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2712 | /* |
| 2713 | * Some architecture linkers will pad between |
| 2714 | * the different mcount_loc sections of different |
| 2715 | * object files to satisfy alignments. |
| 2716 | * Skip any NULL pointers. |
| 2717 | */ |
| 2718 | if (!addr) |
| 2719 | continue; |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2720 | ftrace_record_ip(addr); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2721 | } |
| 2722 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 2723 | /* disable interrupts to prevent kstop machine */ |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2724 | local_irq_save(flags); |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2725 | ftrace_update_code(mod); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2726 | local_irq_restore(flags); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 2727 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2728 | |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2732 | #ifdef CONFIG_MODULES |
jolsa@redhat.com | e7247a1 | 2009-10-07 19:00:35 +0200 | [diff] [blame] | 2733 | void ftrace_release_mod(struct module *mod) |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2734 | { |
| 2735 | struct dyn_ftrace *rec; |
| 2736 | struct ftrace_page *pg; |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2737 | |
jolsa@redhat.com | e7247a1 | 2009-10-07 19:00:35 +0200 | [diff] [blame] | 2738 | if (ftrace_disabled) |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2739 | return; |
| 2740 | |
| 2741 | mutex_lock(&ftrace_lock); |
| 2742 | do_for_each_ftrace_rec(pg, rec) { |
jolsa@redhat.com | e7247a1 | 2009-10-07 19:00:35 +0200 | [diff] [blame] | 2743 | if (within_module_core(rec->ip, mod)) { |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2744 | /* |
| 2745 | * rec->ip is changed in ftrace_free_rec() |
| 2746 | * It should not between s and e if record was freed. |
| 2747 | */ |
| 2748 | FTRACE_WARN_ON(rec->flags & FTRACE_FL_FREE); |
| 2749 | ftrace_free_rec(rec); |
| 2750 | } |
| 2751 | } while_for_each_ftrace_rec(); |
| 2752 | mutex_unlock(&ftrace_lock); |
| 2753 | } |
| 2754 | |
| 2755 | static void ftrace_init_module(struct module *mod, |
| 2756 | unsigned long *start, unsigned long *end) |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 2757 | { |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 2758 | if (ftrace_disabled || start == end) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 2759 | return; |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 2760 | ftrace_process_locs(mod, start, end); |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 2761 | } |
| 2762 | |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2763 | static int ftrace_module_notify(struct notifier_block *self, |
| 2764 | unsigned long val, void *data) |
| 2765 | { |
| 2766 | struct module *mod = data; |
| 2767 | |
| 2768 | switch (val) { |
| 2769 | case MODULE_STATE_COMING: |
| 2770 | ftrace_init_module(mod, mod->ftrace_callsites, |
| 2771 | mod->ftrace_callsites + |
| 2772 | mod->num_ftrace_callsites); |
| 2773 | break; |
| 2774 | case MODULE_STATE_GOING: |
jolsa@redhat.com | e7247a1 | 2009-10-07 19:00:35 +0200 | [diff] [blame] | 2775 | ftrace_release_mod(mod); |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2776 | break; |
| 2777 | } |
| 2778 | |
| 2779 | return 0; |
| 2780 | } |
| 2781 | #else |
| 2782 | static int ftrace_module_notify(struct notifier_block *self, |
| 2783 | unsigned long val, void *data) |
| 2784 | { |
| 2785 | return 0; |
| 2786 | } |
| 2787 | #endif /* CONFIG_MODULES */ |
| 2788 | |
| 2789 | struct notifier_block ftrace_module_nb = { |
| 2790 | .notifier_call = ftrace_module_notify, |
| 2791 | .priority = 0, |
| 2792 | }; |
| 2793 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2794 | extern unsigned long __start_mcount_loc[]; |
| 2795 | extern unsigned long __stop_mcount_loc[]; |
| 2796 | |
| 2797 | void __init ftrace_init(void) |
| 2798 | { |
| 2799 | unsigned long count, addr, flags; |
| 2800 | int ret; |
| 2801 | |
| 2802 | /* Keep the ftrace pointer to the stub */ |
| 2803 | addr = (unsigned long)ftrace_stub; |
| 2804 | |
| 2805 | local_irq_save(flags); |
| 2806 | ftrace_dyn_arch_init(&addr); |
| 2807 | local_irq_restore(flags); |
| 2808 | |
| 2809 | /* ftrace_dyn_arch_init places the return code in addr */ |
| 2810 | if (addr) |
| 2811 | goto failed; |
| 2812 | |
| 2813 | count = __stop_mcount_loc - __start_mcount_loc; |
| 2814 | |
| 2815 | ret = ftrace_dyn_table_alloc(count); |
| 2816 | if (ret) |
| 2817 | goto failed; |
| 2818 | |
| 2819 | last_ftrace_enabled = ftrace_enabled = 1; |
| 2820 | |
Jiri Olsa | 5cb084b | 2009-10-13 16:33:53 -0400 | [diff] [blame] | 2821 | ret = ftrace_process_locs(NULL, |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 2822 | __start_mcount_loc, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2823 | __stop_mcount_loc); |
| 2824 | |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2825 | ret = register_module_notifier(&ftrace_module_nb); |
Ming Lei | 24ed0c4 | 2009-05-17 15:31:38 +0800 | [diff] [blame] | 2826 | if (ret) |
Steven Rostedt | 93eb677 | 2009-04-15 13:24:06 -0400 | [diff] [blame] | 2827 | pr_warning("Failed to register trace ftrace module notifier\n"); |
| 2828 | |
Steven Rostedt | 2af15d6 | 2009-05-28 13:37:24 -0400 | [diff] [blame] | 2829 | set_ftrace_early_filters(); |
| 2830 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2831 | return; |
| 2832 | failed: |
| 2833 | ftrace_disabled = 1; |
| 2834 | } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 2835 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2836 | #else |
Frederic Weisbecker | 0b6e4d5 | 2008-10-28 20:17:38 +0100 | [diff] [blame] | 2837 | |
| 2838 | static int __init ftrace_nodyn_init(void) |
| 2839 | { |
| 2840 | ftrace_enabled = 1; |
| 2841 | return 0; |
| 2842 | } |
| 2843 | device_initcall(ftrace_nodyn_init); |
| 2844 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 2845 | static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; } |
| 2846 | static inline void ftrace_startup_enable(int command) { } |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2847 | /* Keep as macros so we do not need to define the commands */ |
| 2848 | # define ftrace_startup(command) do { } while (0) |
| 2849 | # define ftrace_shutdown(command) do { } while (0) |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 2850 | # define ftrace_startup_sysctl() do { } while (0) |
| 2851 | # define ftrace_shutdown_sysctl() do { } while (0) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 2852 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 2853 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2854 | static void clear_ftrace_swapper(void) |
| 2855 | { |
| 2856 | struct task_struct *p; |
| 2857 | int cpu; |
| 2858 | |
| 2859 | get_online_cpus(); |
| 2860 | for_each_online_cpu(cpu) { |
| 2861 | p = idle_task(cpu); |
| 2862 | clear_tsk_trace_trace(p); |
| 2863 | } |
| 2864 | put_online_cpus(); |
| 2865 | } |
| 2866 | |
| 2867 | static void set_ftrace_swapper(void) |
| 2868 | { |
| 2869 | struct task_struct *p; |
| 2870 | int cpu; |
| 2871 | |
| 2872 | get_online_cpus(); |
| 2873 | for_each_online_cpu(cpu) { |
| 2874 | p = idle_task(cpu); |
| 2875 | set_tsk_trace_trace(p); |
| 2876 | } |
| 2877 | put_online_cpus(); |
| 2878 | } |
| 2879 | |
| 2880 | static void clear_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2881 | { |
| 2882 | struct task_struct *p; |
| 2883 | |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2884 | rcu_read_lock(); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2885 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2886 | clear_tsk_trace_trace(p); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2887 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2888 | rcu_read_unlock(); |
| 2889 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2890 | put_pid(pid); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2891 | } |
| 2892 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2893 | static void set_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2894 | { |
| 2895 | struct task_struct *p; |
| 2896 | |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2897 | rcu_read_lock(); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2898 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
| 2899 | set_tsk_trace_trace(p); |
| 2900 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
Oleg Nesterov | 229c4ef | 2009-02-03 20:39:04 +0100 | [diff] [blame] | 2901 | rcu_read_unlock(); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 2902 | } |
| 2903 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 2904 | static void clear_ftrace_pid_task(struct pid *pid) |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2905 | { |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 2906 | if (pid == ftrace_swapper_pid) |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2907 | clear_ftrace_swapper(); |
| 2908 | else |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 2909 | clear_ftrace_pid(pid); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | static void set_ftrace_pid_task(struct pid *pid) |
| 2913 | { |
| 2914 | if (pid == ftrace_swapper_pid) |
| 2915 | set_ftrace_swapper(); |
| 2916 | else |
| 2917 | set_ftrace_pid(pid); |
| 2918 | } |
| 2919 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 2920 | static int ftrace_pid_add(int p) |
| 2921 | { |
| 2922 | struct pid *pid; |
| 2923 | struct ftrace_pid *fpid; |
| 2924 | int ret = -EINVAL; |
| 2925 | |
| 2926 | mutex_lock(&ftrace_lock); |
| 2927 | |
| 2928 | if (!p) |
| 2929 | pid = ftrace_swapper_pid; |
| 2930 | else |
| 2931 | pid = find_get_pid(p); |
| 2932 | |
| 2933 | if (!pid) |
| 2934 | goto out; |
| 2935 | |
| 2936 | ret = 0; |
| 2937 | |
| 2938 | list_for_each_entry(fpid, &ftrace_pids, list) |
| 2939 | if (fpid->pid == pid) |
| 2940 | goto out_put; |
| 2941 | |
| 2942 | ret = -ENOMEM; |
| 2943 | |
| 2944 | fpid = kmalloc(sizeof(*fpid), GFP_KERNEL); |
| 2945 | if (!fpid) |
| 2946 | goto out_put; |
| 2947 | |
| 2948 | list_add(&fpid->list, &ftrace_pids); |
| 2949 | fpid->pid = pid; |
| 2950 | |
| 2951 | set_ftrace_pid_task(pid); |
| 2952 | |
| 2953 | ftrace_update_pid_func(); |
| 2954 | ftrace_startup_enable(0); |
| 2955 | |
| 2956 | mutex_unlock(&ftrace_lock); |
| 2957 | return 0; |
| 2958 | |
| 2959 | out_put: |
| 2960 | if (pid != ftrace_swapper_pid) |
| 2961 | put_pid(pid); |
| 2962 | |
| 2963 | out: |
| 2964 | mutex_unlock(&ftrace_lock); |
| 2965 | return ret; |
| 2966 | } |
| 2967 | |
| 2968 | static void ftrace_pid_reset(void) |
| 2969 | { |
| 2970 | struct ftrace_pid *fpid, *safe; |
| 2971 | |
| 2972 | mutex_lock(&ftrace_lock); |
| 2973 | list_for_each_entry_safe(fpid, safe, &ftrace_pids, list) { |
| 2974 | struct pid *pid = fpid->pid; |
| 2975 | |
| 2976 | clear_ftrace_pid_task(pid); |
| 2977 | |
| 2978 | list_del(&fpid->list); |
| 2979 | kfree(fpid); |
| 2980 | } |
| 2981 | |
| 2982 | ftrace_update_pid_func(); |
| 2983 | ftrace_startup_enable(0); |
| 2984 | |
| 2985 | mutex_unlock(&ftrace_lock); |
| 2986 | } |
| 2987 | |
| 2988 | static void *fpid_start(struct seq_file *m, loff_t *pos) |
| 2989 | { |
| 2990 | mutex_lock(&ftrace_lock); |
| 2991 | |
| 2992 | if (list_empty(&ftrace_pids) && (!*pos)) |
| 2993 | return (void *) 1; |
| 2994 | |
| 2995 | return seq_list_start(&ftrace_pids, *pos); |
| 2996 | } |
| 2997 | |
| 2998 | static void *fpid_next(struct seq_file *m, void *v, loff_t *pos) |
| 2999 | { |
| 3000 | if (v == (void *)1) |
| 3001 | return NULL; |
| 3002 | |
| 3003 | return seq_list_next(v, &ftrace_pids, pos); |
| 3004 | } |
| 3005 | |
| 3006 | static void fpid_stop(struct seq_file *m, void *p) |
| 3007 | { |
| 3008 | mutex_unlock(&ftrace_lock); |
| 3009 | } |
| 3010 | |
| 3011 | static int fpid_show(struct seq_file *m, void *v) |
| 3012 | { |
| 3013 | const struct ftrace_pid *fpid = list_entry(v, struct ftrace_pid, list); |
| 3014 | |
| 3015 | if (v == (void *)1) { |
| 3016 | seq_printf(m, "no pid\n"); |
| 3017 | return 0; |
| 3018 | } |
| 3019 | |
| 3020 | if (fpid->pid == ftrace_swapper_pid) |
| 3021 | seq_printf(m, "swapper tasks\n"); |
| 3022 | else |
| 3023 | seq_printf(m, "%u\n", pid_vnr(fpid->pid)); |
| 3024 | |
| 3025 | return 0; |
| 3026 | } |
| 3027 | |
| 3028 | static const struct seq_operations ftrace_pid_sops = { |
| 3029 | .start = fpid_start, |
| 3030 | .next = fpid_next, |
| 3031 | .stop = fpid_stop, |
| 3032 | .show = fpid_show, |
| 3033 | }; |
| 3034 | |
| 3035 | static int |
| 3036 | ftrace_pid_open(struct inode *inode, struct file *file) |
| 3037 | { |
| 3038 | int ret = 0; |
| 3039 | |
| 3040 | if ((file->f_mode & FMODE_WRITE) && |
| 3041 | (file->f_flags & O_TRUNC)) |
| 3042 | ftrace_pid_reset(); |
| 3043 | |
| 3044 | if (file->f_mode & FMODE_READ) |
| 3045 | ret = seq_open(file, &ftrace_pid_sops); |
| 3046 | |
| 3047 | return ret; |
| 3048 | } |
| 3049 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3050 | static ssize_t |
| 3051 | ftrace_pid_write(struct file *filp, const char __user *ubuf, |
| 3052 | size_t cnt, loff_t *ppos) |
| 3053 | { |
Ingo Molnar | 457dc92 | 2009-11-23 11:03:28 +0100 | [diff] [blame] | 3054 | char buf[64], *tmp; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3055 | long val; |
| 3056 | int ret; |
| 3057 | |
| 3058 | if (cnt >= sizeof(buf)) |
| 3059 | return -EINVAL; |
| 3060 | |
| 3061 | if (copy_from_user(&buf, ubuf, cnt)) |
| 3062 | return -EFAULT; |
| 3063 | |
| 3064 | buf[cnt] = 0; |
| 3065 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3066 | /* |
| 3067 | * Allow "echo > set_ftrace_pid" or "echo -n '' > set_ftrace_pid" |
| 3068 | * to clean the filter quietly. |
| 3069 | */ |
Ingo Molnar | 457dc92 | 2009-11-23 11:03:28 +0100 | [diff] [blame] | 3070 | tmp = strstrip(buf); |
| 3071 | if (strlen(tmp) == 0) |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3072 | return 1; |
| 3073 | |
Ingo Molnar | 457dc92 | 2009-11-23 11:03:28 +0100 | [diff] [blame] | 3074 | ret = strict_strtol(tmp, 10, &val); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3075 | if (ret < 0) |
| 3076 | return ret; |
| 3077 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3078 | ret = ftrace_pid_add(val); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 3079 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3080 | return ret ? ret : cnt; |
| 3081 | } |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3082 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3083 | static int |
| 3084 | ftrace_pid_release(struct inode *inode, struct file *file) |
| 3085 | { |
| 3086 | if (file->f_mode & FMODE_READ) |
| 3087 | seq_release(inode, file); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3088 | |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3089 | return 0; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3090 | } |
| 3091 | |
Steven Rostedt | 5e2336a | 2009-03-05 21:44:55 -0500 | [diff] [blame] | 3092 | static const struct file_operations ftrace_pid_fops = { |
jolsa@redhat.com | 756d17e | 2009-10-13 16:33:52 -0400 | [diff] [blame] | 3093 | .open = ftrace_pid_open, |
| 3094 | .write = ftrace_pid_write, |
| 3095 | .read = seq_read, |
| 3096 | .llseek = seq_lseek, |
| 3097 | .release = ftrace_pid_release, |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3098 | }; |
| 3099 | |
| 3100 | static __init int ftrace_init_debugfs(void) |
| 3101 | { |
| 3102 | struct dentry *d_tracer; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3103 | |
| 3104 | d_tracer = tracing_init_dentry(); |
| 3105 | if (!d_tracer) |
| 3106 | return 0; |
| 3107 | |
| 3108 | ftrace_init_dyn_debugfs(d_tracer); |
| 3109 | |
Frederic Weisbecker | 5452af6 | 2009-03-27 00:25:38 +0100 | [diff] [blame] | 3110 | trace_create_file("set_ftrace_pid", 0644, d_tracer, |
| 3111 | NULL, &ftrace_pid_fops); |
Steven Rostedt | 493762f | 2009-03-23 17:12:36 -0400 | [diff] [blame] | 3112 | |
| 3113 | ftrace_profile_debugfs(d_tracer); |
| 3114 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3115 | return 0; |
| 3116 | } |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 3117 | fs_initcall(ftrace_init_debugfs); |
| 3118 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3119 | /** |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 3120 | * ftrace_kill - kill ftrace |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 3121 | * |
| 3122 | * This function should be used by panic code. It stops ftrace |
| 3123 | * but in a not so nice way. If you need to simply kill ftrace |
| 3124 | * from a non-atomic section, use ftrace_kill. |
| 3125 | */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 3126 | void ftrace_kill(void) |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 3127 | { |
| 3128 | ftrace_disabled = 1; |
| 3129 | ftrace_enabled = 0; |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 3130 | clear_ftrace_function(); |
| 3131 | } |
| 3132 | |
| 3133 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3134 | * register_ftrace_function - register a function for profiling |
| 3135 | * @ops - ops structure that holds the function for profiling. |
| 3136 | * |
| 3137 | * Register a function to be called by all functions in the |
| 3138 | * kernel. |
| 3139 | * |
| 3140 | * Note: @ops->func and all the functions it calls must be labeled |
| 3141 | * with "notrace", otherwise it will go into a |
| 3142 | * recursive loop. |
| 3143 | */ |
| 3144 | int register_ftrace_function(struct ftrace_ops *ops) |
| 3145 | { |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3146 | int ret; |
| 3147 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3148 | if (unlikely(ftrace_disabled)) |
| 3149 | return -1; |
| 3150 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3151 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3152 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3153 | ret = __register_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 3154 | ftrace_startup(0); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3155 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3156 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3157 | return ret; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /** |
Uwe Kleine-Koenig | 3263292 | 2009-01-12 23:35:50 +0100 | [diff] [blame] | 3161 | * unregister_ftrace_function - unregister a function for profiling. |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3162 | * @ops - ops structure that holds the function to unregister |
| 3163 | * |
| 3164 | * Unregister a function that was added to be called by ftrace profiling. |
| 3165 | */ |
| 3166 | int unregister_ftrace_function(struct ftrace_ops *ops) |
| 3167 | { |
| 3168 | int ret; |
| 3169 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3170 | mutex_lock(&ftrace_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3171 | ret = __unregister_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 3172 | ftrace_shutdown(0); |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3173 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3174 | |
| 3175 | return ret; |
| 3176 | } |
| 3177 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 3178 | int |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3179 | ftrace_enable_sysctl(struct ctl_table *table, int write, |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 3180 | void __user *buffer, size_t *lenp, |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3181 | loff_t *ppos) |
| 3182 | { |
| 3183 | int ret; |
| 3184 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 3185 | if (unlikely(ftrace_disabled)) |
| 3186 | return -ENODEV; |
| 3187 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3188 | mutex_lock(&ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3189 | |
Alexey Dobriyan | 8d65af7 | 2009-09-23 15:57:19 -0700 | [diff] [blame] | 3190 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3191 | |
Li Zefan | a32c776 | 2009-06-26 16:55:51 +0800 | [diff] [blame] | 3192 | if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled)) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3193 | goto out; |
| 3194 | |
Li Zefan | a32c776 | 2009-06-26 16:55:51 +0800 | [diff] [blame] | 3195 | last_ftrace_enabled = !!ftrace_enabled; |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 3196 | |
| 3197 | if (ftrace_enabled) { |
| 3198 | |
| 3199 | ftrace_startup_sysctl(); |
| 3200 | |
| 3201 | /* we are starting ftrace again */ |
| 3202 | if (ftrace_list != &ftrace_list_end) { |
| 3203 | if (ftrace_list->next == &ftrace_list_end) |
| 3204 | ftrace_trace_function = ftrace_list->func; |
| 3205 | else |
| 3206 | ftrace_trace_function = ftrace_list_func; |
| 3207 | } |
| 3208 | |
| 3209 | } else { |
| 3210 | /* stopping ftrace calls (just send to ftrace_stub) */ |
| 3211 | ftrace_trace_function = ftrace_stub; |
| 3212 | |
| 3213 | ftrace_shutdown_sysctl(); |
| 3214 | } |
| 3215 | |
| 3216 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3217 | mutex_unlock(&ftrace_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3218 | return ret; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 3219 | } |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 3220 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3221 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3222 | |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3223 | static int ftrace_graph_active; |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 3224 | static struct notifier_block ftrace_suspend_notifier; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3225 | |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 3226 | int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) |
| 3227 | { |
| 3228 | return 0; |
| 3229 | } |
| 3230 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 3231 | /* The callbacks that hook a function */ |
| 3232 | trace_func_graph_ret_t ftrace_graph_return = |
| 3233 | (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 3234 | trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3235 | |
| 3236 | /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */ |
| 3237 | static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) |
| 3238 | { |
| 3239 | int i; |
| 3240 | int ret = 0; |
| 3241 | unsigned long flags; |
| 3242 | int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE; |
| 3243 | struct task_struct *g, *t; |
| 3244 | |
| 3245 | for (i = 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) { |
| 3246 | ret_stack_list[i] = kmalloc(FTRACE_RETFUNC_DEPTH |
| 3247 | * sizeof(struct ftrace_ret_stack), |
| 3248 | GFP_KERNEL); |
| 3249 | if (!ret_stack_list[i]) { |
| 3250 | start = 0; |
| 3251 | end = i; |
| 3252 | ret = -ENOMEM; |
| 3253 | goto free; |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | read_lock_irqsave(&tasklist_lock, flags); |
| 3258 | do_each_thread(g, t) { |
| 3259 | if (start == end) { |
| 3260 | ret = -EAGAIN; |
| 3261 | goto unlock; |
| 3262 | } |
| 3263 | |
| 3264 | if (t->ret_stack == NULL) { |
Frederic Weisbecker | 380c4b1 | 2008-12-06 03:43:41 +0100 | [diff] [blame] | 3265 | atomic_set(&t->tracing_graph_pause, 0); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3266 | atomic_set(&t->trace_overrun, 0); |
Steven Rostedt | 26c0162 | 2009-06-02 14:01:19 -0400 | [diff] [blame] | 3267 | t->curr_ret_stack = -1; |
| 3268 | /* Make sure the tasks see the -1 first: */ |
| 3269 | smp_wmb(); |
| 3270 | t->ret_stack = ret_stack_list[start++]; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3271 | } |
| 3272 | } while_each_thread(g, t); |
| 3273 | |
| 3274 | unlock: |
| 3275 | read_unlock_irqrestore(&tasklist_lock, flags); |
| 3276 | free: |
| 3277 | for (i = start; i < end; i++) |
| 3278 | kfree(ret_stack_list[i]); |
| 3279 | return ret; |
| 3280 | } |
| 3281 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 3282 | static void |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 3283 | ftrace_graph_probe_sched_switch(void *ignore, |
| 3284 | struct task_struct *prev, struct task_struct *next) |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 3285 | { |
| 3286 | unsigned long long timestamp; |
| 3287 | int index; |
| 3288 | |
Steven Rostedt | be6f164 | 2009-03-24 11:06:24 -0400 | [diff] [blame] | 3289 | /* |
| 3290 | * Does the user want to count the time a function was asleep. |
| 3291 | * If so, do not update the time stamps. |
| 3292 | */ |
| 3293 | if (trace_flags & TRACE_ITER_SLEEP_TIME) |
| 3294 | return; |
| 3295 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 3296 | timestamp = trace_clock_local(); |
| 3297 | |
| 3298 | prev->ftrace_timestamp = timestamp; |
| 3299 | |
| 3300 | /* only process tasks that we timestamped */ |
| 3301 | if (!next->ftrace_timestamp) |
| 3302 | return; |
| 3303 | |
| 3304 | /* |
| 3305 | * Update all the counters in next to make up for the |
| 3306 | * time next was sleeping. |
| 3307 | */ |
| 3308 | timestamp -= next->ftrace_timestamp; |
| 3309 | |
| 3310 | for (index = next->curr_ret_stack; index >= 0; index--) |
| 3311 | next->ret_stack[index].calltime += timestamp; |
| 3312 | } |
| 3313 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3314 | /* Allocate a return stack for each task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3315 | static int start_graph_tracing(void) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3316 | { |
| 3317 | struct ftrace_ret_stack **ret_stack_list; |
Frederic Weisbecker | 5b058bc | 2009-02-17 18:35:34 +0100 | [diff] [blame] | 3318 | int ret, cpu; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3319 | |
| 3320 | ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE * |
| 3321 | sizeof(struct ftrace_ret_stack *), |
| 3322 | GFP_KERNEL); |
| 3323 | |
| 3324 | if (!ret_stack_list) |
| 3325 | return -ENOMEM; |
| 3326 | |
Frederic Weisbecker | 5b058bc | 2009-02-17 18:35:34 +0100 | [diff] [blame] | 3327 | /* The cpu_boot init_task->ret_stack will never be freed */ |
Steven Rostedt | 179c498 | 2009-06-02 12:03:19 -0400 | [diff] [blame] | 3328 | for_each_online_cpu(cpu) { |
| 3329 | if (!idle_task(cpu)->ret_stack) |
Steven Rostedt | 868baf0 | 2011-02-10 21:26:13 -0500 | [diff] [blame] | 3330 | ftrace_graph_init_idle_task(idle_task(cpu), cpu); |
Steven Rostedt | 179c498 | 2009-06-02 12:03:19 -0400 | [diff] [blame] | 3331 | } |
Frederic Weisbecker | 5b058bc | 2009-02-17 18:35:34 +0100 | [diff] [blame] | 3332 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3333 | do { |
| 3334 | ret = alloc_retstack_tasklist(ret_stack_list); |
| 3335 | } while (ret == -EAGAIN); |
| 3336 | |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 3337 | if (!ret) { |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 3338 | ret = register_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
Steven Rostedt | 8aef2d2 | 2009-03-24 01:10:15 -0400 | [diff] [blame] | 3339 | if (ret) |
| 3340 | pr_info("ftrace_graph: Couldn't activate tracepoint" |
| 3341 | " probe to kernel_sched_switch\n"); |
| 3342 | } |
| 3343 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3344 | kfree(ret_stack_list); |
| 3345 | return ret; |
| 3346 | } |
| 3347 | |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 3348 | /* |
| 3349 | * Hibernation protection. |
| 3350 | * The state of the current task is too much unstable during |
| 3351 | * suspend/restore to disk. We want to protect against that. |
| 3352 | */ |
| 3353 | static int |
| 3354 | ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state, |
| 3355 | void *unused) |
| 3356 | { |
| 3357 | switch (state) { |
| 3358 | case PM_HIBERNATION_PREPARE: |
| 3359 | pause_graph_tracing(); |
| 3360 | break; |
| 3361 | |
| 3362 | case PM_POST_HIBERNATION: |
| 3363 | unpause_graph_tracing(); |
| 3364 | break; |
| 3365 | } |
| 3366 | return NOTIFY_DONE; |
| 3367 | } |
| 3368 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 3369 | int register_ftrace_graph(trace_func_graph_ret_t retfunc, |
| 3370 | trace_func_graph_ent_t entryfunc) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 3371 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3372 | int ret = 0; |
| 3373 | |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3374 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3375 | |
Steven Rostedt | 05ce581 | 2009-03-24 00:18:31 -0400 | [diff] [blame] | 3376 | /* we currently allow only one tracer registered at a time */ |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3377 | if (ftrace_graph_active) { |
Steven Rostedt | 05ce581 | 2009-03-24 00:18:31 -0400 | [diff] [blame] | 3378 | ret = -EBUSY; |
| 3379 | goto out; |
| 3380 | } |
| 3381 | |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 3382 | ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call; |
| 3383 | register_pm_notifier(&ftrace_suspend_notifier); |
| 3384 | |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3385 | ftrace_graph_active++; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3386 | ret = start_graph_tracing(); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3387 | if (ret) { |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3388 | ftrace_graph_active--; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3389 | goto out; |
| 3390 | } |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 3391 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 3392 | ftrace_graph_return = retfunc; |
| 3393 | ftrace_graph_entry = entryfunc; |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 3394 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 3395 | ftrace_startup(FTRACE_START_FUNC_RET); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3396 | |
| 3397 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3398 | mutex_unlock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3399 | return ret; |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 3400 | } |
| 3401 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3402 | void unregister_ftrace_graph(void) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 3403 | { |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3404 | mutex_lock(&ftrace_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3405 | |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3406 | if (unlikely(!ftrace_graph_active)) |
Steven Rostedt | 2aad1b7 | 2009-03-30 11:11:28 -0400 | [diff] [blame] | 3407 | goto out; |
| 3408 | |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3409 | ftrace_graph_active--; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 3410 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 3411 | ftrace_graph_entry = ftrace_graph_entry_stub; |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 3412 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
Frederic Weisbecker | 4a2b8dd | 2009-01-14 13:33:27 -0800 | [diff] [blame] | 3413 | unregister_pm_notifier(&ftrace_suspend_notifier); |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 3414 | unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 3415 | |
Steven Rostedt | 2aad1b7 | 2009-03-30 11:11:28 -0400 | [diff] [blame] | 3416 | out: |
Steven Rostedt | e6ea44e | 2009-02-14 01:42:44 -0500 | [diff] [blame] | 3417 | mutex_unlock(&ftrace_lock); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 3418 | } |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3419 | |
Steven Rostedt | 868baf0 | 2011-02-10 21:26:13 -0500 | [diff] [blame] | 3420 | static DEFINE_PER_CPU(struct ftrace_ret_stack *, idle_ret_stack); |
| 3421 | |
| 3422 | static void |
| 3423 | graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack) |
| 3424 | { |
| 3425 | atomic_set(&t->tracing_graph_pause, 0); |
| 3426 | atomic_set(&t->trace_overrun, 0); |
| 3427 | t->ftrace_timestamp = 0; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 3428 | /* make curr_ret_stack visible before we add the ret_stack */ |
Steven Rostedt | 868baf0 | 2011-02-10 21:26:13 -0500 | [diff] [blame] | 3429 | smp_wmb(); |
| 3430 | t->ret_stack = ret_stack; |
| 3431 | } |
| 3432 | |
| 3433 | /* |
| 3434 | * Allocate a return stack for the idle task. May be the first |
| 3435 | * time through, or it may be done by CPU hotplug online. |
| 3436 | */ |
| 3437 | void ftrace_graph_init_idle_task(struct task_struct *t, int cpu) |
| 3438 | { |
| 3439 | t->curr_ret_stack = -1; |
| 3440 | /* |
| 3441 | * The idle task has no parent, it either has its own |
| 3442 | * stack or no stack at all. |
| 3443 | */ |
| 3444 | if (t->ret_stack) |
| 3445 | WARN_ON(t->ret_stack != per_cpu(idle_ret_stack, cpu)); |
| 3446 | |
| 3447 | if (ftrace_graph_active) { |
| 3448 | struct ftrace_ret_stack *ret_stack; |
| 3449 | |
| 3450 | ret_stack = per_cpu(idle_ret_stack, cpu); |
| 3451 | if (!ret_stack) { |
| 3452 | ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH |
| 3453 | * sizeof(struct ftrace_ret_stack), |
| 3454 | GFP_KERNEL); |
| 3455 | if (!ret_stack) |
| 3456 | return; |
| 3457 | per_cpu(idle_ret_stack, cpu) = ret_stack; |
| 3458 | } |
| 3459 | graph_init_task(t, ret_stack); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3463 | /* Allocate a return stack for newly created task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3464 | void ftrace_graph_init_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3465 | { |
Steven Rostedt | 84047e3 | 2009-06-02 16:51:55 -0400 | [diff] [blame] | 3466 | /* Make sure we do not use the parent ret_stack */ |
| 3467 | t->ret_stack = NULL; |
Steven Rostedt | ea14eb7 | 2010-03-12 19:41:23 -0500 | [diff] [blame] | 3468 | t->curr_ret_stack = -1; |
Steven Rostedt | 84047e3 | 2009-06-02 16:51:55 -0400 | [diff] [blame] | 3469 | |
Steven Rostedt | 597af81 | 2009-04-03 15:24:12 -0400 | [diff] [blame] | 3470 | if (ftrace_graph_active) { |
Steven Rostedt | 82310a3 | 2009-06-02 12:26:07 -0400 | [diff] [blame] | 3471 | struct ftrace_ret_stack *ret_stack; |
| 3472 | |
| 3473 | ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3474 | * sizeof(struct ftrace_ret_stack), |
| 3475 | GFP_KERNEL); |
Steven Rostedt | 82310a3 | 2009-06-02 12:26:07 -0400 | [diff] [blame] | 3476 | if (!ret_stack) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3477 | return; |
Steven Rostedt | 868baf0 | 2011-02-10 21:26:13 -0500 | [diff] [blame] | 3478 | graph_init_task(t, ret_stack); |
Steven Rostedt | 84047e3 | 2009-06-02 16:51:55 -0400 | [diff] [blame] | 3479 | } |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3480 | } |
| 3481 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 3482 | void ftrace_graph_exit_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3483 | { |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 3484 | struct ftrace_ret_stack *ret_stack = t->ret_stack; |
| 3485 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3486 | t->ret_stack = NULL; |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 3487 | /* NULL must become visible to IRQs before we free it: */ |
| 3488 | barrier(); |
| 3489 | |
| 3490 | kfree(ret_stack); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 3491 | } |
Steven Rostedt | 14a866c | 2008-12-02 23:50:02 -0500 | [diff] [blame] | 3492 | |
| 3493 | void ftrace_graph_stop(void) |
| 3494 | { |
| 3495 | ftrace_stop(); |
| 3496 | } |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 3497 | #endif |