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