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