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