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