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> |
| 20 | #include <linux/debugfs.h> |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 21 | #include <linux/hardirq.h> |
Ingo Molnar | 2d8b820 | 2008-02-23 16:55:50 +0100 | [diff] [blame] | 22 | #include <linux/kthread.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 24 | #include <linux/kprobes.h> |
Ingo Molnar | 2d8b820 | 2008-02-23 16:55:50 +0100 | [diff] [blame] | 25 | #include <linux/ftrace.h> |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 26 | #include <linux/sysctl.h> |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 27 | #include <linux/ctype.h> |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 28 | #include <linux/list.h> |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 29 | |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 30 | #include <asm/ftrace.h> |
| 31 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 32 | #include "trace.h" |
| 33 | |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 34 | #define FTRACE_WARN_ON(cond) \ |
| 35 | do { \ |
| 36 | if (WARN_ON(cond)) \ |
| 37 | ftrace_kill(); \ |
| 38 | } while (0) |
| 39 | |
| 40 | #define FTRACE_WARN_ON_ONCE(cond) \ |
| 41 | do { \ |
| 42 | if (WARN_ON_ONCE(cond)) \ |
| 43 | ftrace_kill(); \ |
| 44 | } while (0) |
| 45 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 46 | /* ftrace_enabled is a method to turn ftrace on or off */ |
| 47 | int ftrace_enabled __read_mostly; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 48 | static int last_ftrace_enabled; |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 49 | |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 50 | /* set when tracing only a pid */ |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 51 | struct pid *ftrace_pid_trace; |
Steven Rostedt | 21bbecd | 2008-12-04 23:30:56 -0500 | [diff] [blame] | 52 | static struct pid * const ftrace_swapper_pid = &init_struct_pid; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 53 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 54 | /* Quick disabling of function tracer. */ |
| 55 | int function_trace_stop; |
| 56 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 57 | /* |
| 58 | * ftrace_disabled is set when an anomaly is discovered. |
| 59 | * ftrace_disabled is much stronger than ftrace_enabled. |
| 60 | */ |
| 61 | static int ftrace_disabled __read_mostly; |
| 62 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 63 | static DEFINE_SPINLOCK(ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 64 | static DEFINE_MUTEX(ftrace_sysctl_lock); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 65 | static DEFINE_MUTEX(ftrace_start_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 66 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 67 | static struct ftrace_ops ftrace_list_end __read_mostly = |
| 68 | { |
| 69 | .func = ftrace_stub, |
| 70 | }; |
| 71 | |
| 72 | static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end; |
| 73 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 74 | ftrace_func_t __ftrace_trace_function __read_mostly = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 75 | ftrace_func_t ftrace_pid_function __read_mostly = ftrace_stub; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 76 | |
Ingo Molnar | f225293 | 2008-05-22 10:37:48 +0200 | [diff] [blame] | 77 | static void ftrace_list_func(unsigned long ip, unsigned long parent_ip) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 78 | { |
| 79 | struct ftrace_ops *op = ftrace_list; |
| 80 | |
| 81 | /* in case someone actually ports this to alpha! */ |
| 82 | read_barrier_depends(); |
| 83 | |
| 84 | while (op != &ftrace_list_end) { |
| 85 | /* silly alpha */ |
| 86 | read_barrier_depends(); |
| 87 | op->func(ip, parent_ip); |
| 88 | op = op->next; |
| 89 | }; |
| 90 | } |
| 91 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 92 | static void ftrace_pid_func(unsigned long ip, unsigned long parent_ip) |
| 93 | { |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 94 | if (!test_tsk_trace_trace(current)) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 95 | return; |
| 96 | |
| 97 | ftrace_pid_function(ip, parent_ip); |
| 98 | } |
| 99 | |
| 100 | static void set_ftrace_pid_function(ftrace_func_t func) |
| 101 | { |
| 102 | /* do not set ftrace_pid_function to itself! */ |
| 103 | if (func != ftrace_pid_func) |
| 104 | ftrace_pid_function = func; |
| 105 | } |
| 106 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 107 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 108 | * clear_ftrace_function - reset the ftrace function |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 109 | * |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 110 | * This NULLs the ftrace function and in essence stops |
| 111 | * tracing. There may be lag |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 112 | */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 113 | void clear_ftrace_function(void) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 114 | { |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 115 | ftrace_trace_function = ftrace_stub; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 116 | __ftrace_trace_function = ftrace_stub; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 117 | ftrace_pid_function = ftrace_stub; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 118 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 119 | |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 120 | #ifndef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 121 | /* |
| 122 | * For those archs that do not test ftrace_trace_stop in their |
| 123 | * mcount call site, we need to do it from C. |
| 124 | */ |
| 125 | static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip) |
| 126 | { |
| 127 | if (function_trace_stop) |
| 128 | return; |
| 129 | |
| 130 | __ftrace_trace_function(ip, parent_ip); |
| 131 | } |
| 132 | #endif |
| 133 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 134 | static int __register_ftrace_function(struct ftrace_ops *ops) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 135 | { |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 136 | /* should not be called from interrupt context */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 137 | spin_lock(&ftrace_lock); |
| 138 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 139 | ops->next = ftrace_list; |
| 140 | /* |
| 141 | * We are entering ops into the ftrace_list but another |
| 142 | * CPU might be walking that list. We need to make sure |
| 143 | * the ops->next pointer is valid before another CPU sees |
| 144 | * the ops pointer included into the ftrace_list. |
| 145 | */ |
| 146 | smp_wmb(); |
| 147 | ftrace_list = ops; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 148 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 149 | if (ftrace_enabled) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 150 | ftrace_func_t func; |
| 151 | |
| 152 | if (ops->next == &ftrace_list_end) |
| 153 | func = ops->func; |
| 154 | else |
| 155 | func = ftrace_list_func; |
| 156 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 157 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 158 | set_ftrace_pid_function(func); |
| 159 | func = ftrace_pid_func; |
| 160 | } |
| 161 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 162 | /* |
| 163 | * For one func, simply call it directly. |
| 164 | * For more than one func, call the chain. |
| 165 | */ |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 166 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 167 | ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 168 | #else |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 169 | __ftrace_trace_function = func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 170 | ftrace_trace_function = ftrace_test_stop_func; |
| 171 | #endif |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 172 | } |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 173 | |
| 174 | spin_unlock(&ftrace_lock); |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 179 | static int __unregister_ftrace_function(struct ftrace_ops *ops) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 180 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 181 | struct ftrace_ops **p; |
| 182 | int ret = 0; |
| 183 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 184 | /* should not be called from interrupt context */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 185 | spin_lock(&ftrace_lock); |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 186 | |
| 187 | /* |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 188 | * If we are removing the last function, then simply point |
| 189 | * to the ftrace_stub. |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 190 | */ |
| 191 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { |
| 192 | ftrace_trace_function = ftrace_stub; |
| 193 | ftrace_list = &ftrace_list_end; |
| 194 | goto out; |
| 195 | } |
| 196 | |
| 197 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) |
| 198 | if (*p == ops) |
| 199 | break; |
| 200 | |
| 201 | if (*p != ops) { |
| 202 | ret = -1; |
| 203 | goto out; |
| 204 | } |
| 205 | |
| 206 | *p = (*p)->next; |
| 207 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 208 | if (ftrace_enabled) { |
| 209 | /* If we only have one func left, then call that directly */ |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 210 | if (ftrace_list->next == &ftrace_list_end) { |
| 211 | ftrace_func_t func = ftrace_list->func; |
| 212 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 213 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 214 | set_ftrace_pid_function(func); |
| 215 | func = ftrace_pid_func; |
| 216 | } |
| 217 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 218 | ftrace_trace_function = func; |
| 219 | #else |
| 220 | __ftrace_trace_function = func; |
| 221 | #endif |
| 222 | } |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 223 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 224 | |
| 225 | out: |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 226 | spin_unlock(&ftrace_lock); |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 231 | static void ftrace_update_pid_func(void) |
| 232 | { |
| 233 | ftrace_func_t func; |
| 234 | |
| 235 | /* should not be called from interrupt context */ |
| 236 | spin_lock(&ftrace_lock); |
| 237 | |
| 238 | if (ftrace_trace_function == ftrace_stub) |
| 239 | goto out; |
| 240 | |
| 241 | func = ftrace_trace_function; |
| 242 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 243 | if (ftrace_pid_trace) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 244 | set_ftrace_pid_function(func); |
| 245 | func = ftrace_pid_func; |
| 246 | } else { |
Liming Wang | 66eafeb | 2008-12-02 10:33:08 +0800 | [diff] [blame] | 247 | if (func == ftrace_pid_func) |
| 248 | func = ftrace_pid_function; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST |
| 252 | ftrace_trace_function = func; |
| 253 | #else |
| 254 | __ftrace_trace_function = func; |
| 255 | #endif |
| 256 | |
| 257 | out: |
| 258 | spin_unlock(&ftrace_lock); |
| 259 | } |
| 260 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 261 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 262 | #ifndef CONFIG_FTRACE_MCOUNT_RECORD |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 263 | # error Dynamic ftrace depends on MCOUNT_RECORD |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 264 | #endif |
| 265 | |
Steven Noonan | 71c67d5 | 2008-09-20 01:00:37 -0700 | [diff] [blame] | 266 | /* |
| 267 | * Since MCOUNT_ADDR may point to mcount itself, we do not want |
| 268 | * to get it confused by reading a reference in the code as we |
| 269 | * are parsing on objcopy output of text. Use a variable for |
| 270 | * it instead. |
| 271 | */ |
| 272 | static unsigned long mcount_addr = MCOUNT_ADDR; |
| 273 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 274 | enum { |
| 275 | FTRACE_ENABLE_CALLS = (1 << 0), |
| 276 | FTRACE_DISABLE_CALLS = (1 << 1), |
| 277 | FTRACE_UPDATE_TRACE_FUNC = (1 << 2), |
| 278 | FTRACE_ENABLE_MCOUNT = (1 << 3), |
| 279 | FTRACE_DISABLE_MCOUNT = (1 << 4), |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 280 | FTRACE_START_FUNC_RET = (1 << 5), |
| 281 | FTRACE_STOP_FUNC_RET = (1 << 6), |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 282 | }; |
| 283 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 284 | static int ftrace_filtered; |
| 285 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 286 | static LIST_HEAD(ftrace_new_addrs); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 287 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 288 | static DEFINE_MUTEX(ftrace_regex_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 289 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 290 | struct ftrace_page { |
| 291 | struct ftrace_page *next; |
Steven Rostedt | 431aa3f | 2009-01-06 12:43:01 -0500 | [diff] [blame^] | 292 | int index; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 293 | struct dyn_ftrace records[]; |
David Miller | aa5e5ce | 2008-05-13 22:06:56 -0700 | [diff] [blame] | 294 | }; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 295 | |
| 296 | #define ENTRIES_PER_PAGE \ |
| 297 | ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace)) |
| 298 | |
| 299 | /* estimate from running different kernels */ |
| 300 | #define NR_TO_INIT 10000 |
| 301 | |
| 302 | static struct ftrace_page *ftrace_pages_start; |
| 303 | static struct ftrace_page *ftrace_pages; |
| 304 | |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 305 | static struct dyn_ftrace *ftrace_free_records; |
| 306 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 307 | |
| 308 | #ifdef CONFIG_KPROBES |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 309 | |
| 310 | static int frozen_record_count; |
| 311 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 312 | static inline void freeze_record(struct dyn_ftrace *rec) |
| 313 | { |
| 314 | if (!(rec->flags & FTRACE_FL_FROZEN)) { |
| 315 | rec->flags |= FTRACE_FL_FROZEN; |
| 316 | frozen_record_count++; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | static inline void unfreeze_record(struct dyn_ftrace *rec) |
| 321 | { |
| 322 | if (rec->flags & FTRACE_FL_FROZEN) { |
| 323 | rec->flags &= ~FTRACE_FL_FROZEN; |
| 324 | frozen_record_count--; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | static inline int record_frozen(struct dyn_ftrace *rec) |
| 329 | { |
| 330 | return rec->flags & FTRACE_FL_FROZEN; |
| 331 | } |
| 332 | #else |
| 333 | # define freeze_record(rec) ({ 0; }) |
| 334 | # define unfreeze_record(rec) ({ 0; }) |
| 335 | # define record_frozen(rec) ({ 0; }) |
| 336 | #endif /* CONFIG_KPROBES */ |
| 337 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 338 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 339 | { |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 340 | rec->ip = (unsigned long)ftrace_free_records; |
| 341 | ftrace_free_records = rec; |
| 342 | rec->flags |= FTRACE_FL_FREE; |
| 343 | } |
| 344 | |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 345 | void ftrace_release(void *start, unsigned long size) |
| 346 | { |
| 347 | struct dyn_ftrace *rec; |
| 348 | struct ftrace_page *pg; |
| 349 | unsigned long s = (unsigned long)start; |
| 350 | unsigned long e = s + size; |
| 351 | int i; |
| 352 | |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 353 | if (ftrace_disabled || !start) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 354 | return; |
| 355 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 356 | /* should not be called from interrupt context */ |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 357 | spin_lock(&ftrace_lock); |
| 358 | |
| 359 | for (pg = ftrace_pages_start; pg; pg = pg->next) { |
| 360 | for (i = 0; i < pg->index; i++) { |
| 361 | rec = &pg->records[i]; |
| 362 | |
| 363 | if ((rec->ip >= s) && (rec->ip < e)) |
| 364 | ftrace_free_rec(rec); |
| 365 | } |
| 366 | } |
| 367 | spin_unlock(&ftrace_lock); |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 368 | } |
| 369 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 370 | static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 371 | { |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 372 | struct dyn_ftrace *rec; |
| 373 | |
| 374 | /* First check for freed records */ |
| 375 | if (ftrace_free_records) { |
| 376 | rec = ftrace_free_records; |
| 377 | |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 378 | if (unlikely(!(rec->flags & FTRACE_FL_FREE))) { |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 379 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 380 | ftrace_free_records = NULL; |
| 381 | return NULL; |
| 382 | } |
| 383 | |
| 384 | ftrace_free_records = (void *)rec->ip; |
| 385 | memset(rec, 0, sizeof(*rec)); |
| 386 | return rec; |
| 387 | } |
| 388 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 389 | if (ftrace_pages->index == ENTRIES_PER_PAGE) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 390 | if (!ftrace_pages->next) { |
| 391 | /* allocate another page */ |
| 392 | ftrace_pages->next = |
| 393 | (void *)get_zeroed_page(GFP_KERNEL); |
| 394 | if (!ftrace_pages->next) |
| 395 | return NULL; |
| 396 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 397 | ftrace_pages = ftrace_pages->next; |
| 398 | } |
| 399 | |
| 400 | return &ftrace_pages->records[ftrace_pages->index++]; |
| 401 | } |
| 402 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 403 | static struct dyn_ftrace * |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 404 | ftrace_record_ip(unsigned long ip) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 405 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 406 | struct dyn_ftrace *rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 407 | |
Steven Rostedt | f3c7ac4 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 408 | if (ftrace_disabled) |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 409 | return NULL; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 410 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 411 | rec = ftrace_alloc_dyn_node(ip); |
| 412 | if (!rec) |
| 413 | return NULL; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 414 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 415 | rec->ip = ip; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 416 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 417 | list_add(&rec->list, &ftrace_new_addrs); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 418 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 419 | return rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 422 | static void print_ip_ins(const char *fmt, unsigned char *p) |
| 423 | { |
| 424 | int i; |
| 425 | |
| 426 | printk(KERN_CONT "%s", fmt); |
| 427 | |
| 428 | for (i = 0; i < MCOUNT_INSN_SIZE; i++) |
| 429 | printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); |
| 430 | } |
| 431 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 432 | static void ftrace_bug(int failed, unsigned long ip) |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 433 | { |
| 434 | switch (failed) { |
| 435 | case -EFAULT: |
| 436 | FTRACE_WARN_ON_ONCE(1); |
| 437 | pr_info("ftrace faulted on modifying "); |
| 438 | print_ip_sym(ip); |
| 439 | break; |
| 440 | case -EINVAL: |
| 441 | FTRACE_WARN_ON_ONCE(1); |
| 442 | pr_info("ftrace failed to modify "); |
| 443 | print_ip_sym(ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 444 | print_ip_ins(" actual: ", (unsigned char *)ip); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 445 | printk(KERN_CONT "\n"); |
| 446 | break; |
| 447 | case -EPERM: |
| 448 | FTRACE_WARN_ON_ONCE(1); |
| 449 | pr_info("ftrace faulted on writing "); |
| 450 | print_ip_sym(ip); |
| 451 | break; |
| 452 | default: |
| 453 | FTRACE_WARN_ON_ONCE(1); |
| 454 | pr_info("ftrace faulted on unknown error "); |
| 455 | print_ip_sym(ip); |
| 456 | } |
| 457 | } |
| 458 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 459 | |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 460 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 461 | __ftrace_replace_code(struct dyn_ftrace *rec, int enable) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 462 | { |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 463 | unsigned long ip, fl; |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 464 | unsigned long ftrace_addr; |
| 465 | |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 466 | ftrace_addr = (unsigned long)ftrace_caller; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 467 | |
| 468 | ip = rec->ip; |
| 469 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 470 | /* |
| 471 | * If this record is not to be traced and |
| 472 | * it is not enabled then do nothing. |
| 473 | * |
| 474 | * If this record is not to be traced and |
| 475 | * it is enabled then disabled it. |
| 476 | * |
| 477 | */ |
| 478 | if (rec->flags & FTRACE_FL_NOTRACE) { |
| 479 | if (rec->flags & FTRACE_FL_ENABLED) |
| 480 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 481 | else |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 482 | return 0; |
| 483 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 484 | } else if (ftrace_filtered && enable) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 485 | /* |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 486 | * Filtering is on: |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 487 | */ |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 488 | |
| 489 | fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_ENABLED); |
| 490 | |
| 491 | /* Record is filtered and enabled, do nothing */ |
| 492 | if (fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) |
| 493 | return 0; |
| 494 | |
| 495 | /* Record is not filtered and is not enabled do nothing */ |
| 496 | if (!fl) |
| 497 | return 0; |
| 498 | |
| 499 | /* Record is not filtered but enabled, disable it */ |
| 500 | if (fl == FTRACE_FL_ENABLED) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 501 | rec->flags &= ~FTRACE_FL_ENABLED; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 502 | else |
| 503 | /* Otherwise record is filtered but not enabled, enable it */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 504 | rec->flags |= FTRACE_FL_ENABLED; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 505 | } else { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 506 | /* Disable or not filtered */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 507 | |
| 508 | if (enable) { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 509 | /* if record is enabled, do nothing */ |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 510 | if (rec->flags & FTRACE_FL_ENABLED) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 511 | return 0; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 512 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 513 | rec->flags |= FTRACE_FL_ENABLED; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 514 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 515 | } else { |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 516 | |
| 517 | /* if record is not enabled do nothing */ |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 518 | if (!(rec->flags & FTRACE_FL_ENABLED)) |
| 519 | return 0; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 520 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 521 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 522 | } |
| 523 | } |
| 524 | |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 525 | if (rec->flags & FTRACE_FL_ENABLED) |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 526 | return ftrace_make_call(rec, ftrace_addr); |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 527 | else |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 528 | return ftrace_make_nop(NULL, rec, ftrace_addr); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | static void ftrace_replace_code(int enable) |
| 532 | { |
| 533 | int i, failed; |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 534 | struct dyn_ftrace *rec; |
| 535 | struct ftrace_page *pg; |
| 536 | |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 537 | for (pg = ftrace_pages_start; pg; pg = pg->next) { |
| 538 | for (i = 0; i < pg->index; i++) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 539 | rec = &pg->records[i]; |
| 540 | |
Steven Rostedt | 918c115 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 541 | /* |
| 542 | * Skip over free records and records that have |
| 543 | * failed. |
| 544 | */ |
| 545 | if (rec->flags & FTRACE_FL_FREE || |
| 546 | rec->flags & FTRACE_FL_FAILED) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 547 | continue; |
| 548 | |
| 549 | /* ignore updates to this record's mcount site */ |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 550 | if (get_kprobe((void *)rec->ip)) { |
| 551 | freeze_record(rec); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 552 | continue; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 553 | } else { |
| 554 | unfreeze_record(rec); |
| 555 | } |
| 556 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 557 | failed = __ftrace_replace_code(rec, enable); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 558 | if (failed && (rec->flags & FTRACE_FL_CONVERTED)) { |
| 559 | rec->flags |= FTRACE_FL_FAILED; |
| 560 | if ((system_state == SYSTEM_BOOTING) || |
| 561 | !core_kernel_text(rec->ip)) { |
| 562 | ftrace_free_rec(rec); |
Steven Rostedt | b17e8a3 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 563 | } else |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 564 | ftrace_bug(failed, rec->ip); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 565 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 566 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 570 | static int |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 571 | ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 572 | { |
| 573 | unsigned long ip; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 574 | int ret; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 575 | |
| 576 | ip = rec->ip; |
| 577 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 578 | ret = ftrace_make_nop(mod, rec, mcount_addr); |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 579 | if (ret) { |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 580 | ftrace_bug(ret, ip); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 581 | rec->flags |= FTRACE_FL_FAILED; |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 582 | return 0; |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 583 | } |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 584 | return 1; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 587 | static int __ftrace_modify_code(void *data) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 588 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 589 | int *command = data; |
| 590 | |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 591 | if (*command & FTRACE_ENABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 592 | ftrace_replace_code(1); |
Steven Rostedt | a358324 | 2008-11-11 15:01:42 -0500 | [diff] [blame] | 593 | else if (*command & FTRACE_DISABLE_CALLS) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 594 | ftrace_replace_code(0); |
| 595 | |
| 596 | if (*command & FTRACE_UPDATE_TRACE_FUNC) |
| 597 | ftrace_update_ftrace_func(ftrace_trace_function); |
| 598 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 599 | if (*command & FTRACE_START_FUNC_RET) |
| 600 | ftrace_enable_ftrace_graph_caller(); |
| 601 | else if (*command & FTRACE_STOP_FUNC_RET) |
| 602 | ftrace_disable_ftrace_graph_caller(); |
| 603 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 604 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 605 | } |
| 606 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 607 | static void ftrace_run_update_code(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 608 | { |
Rusty Russell | 784e2d7 | 2008-07-28 12:16:31 -0500 | [diff] [blame] | 609 | stop_machine(__ftrace_modify_code, &command, NULL); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 610 | } |
| 611 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 612 | static ftrace_func_t saved_ftrace_func; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 613 | static int ftrace_start_up; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 614 | |
| 615 | static void ftrace_startup_enable(int command) |
| 616 | { |
| 617 | if (saved_ftrace_func != ftrace_trace_function) { |
| 618 | saved_ftrace_func = ftrace_trace_function; |
| 619 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 620 | } |
| 621 | |
| 622 | if (!command || !ftrace_enabled) |
| 623 | return; |
| 624 | |
| 625 | ftrace_run_update_code(command); |
| 626 | } |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 627 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 628 | static void ftrace_startup(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 629 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 630 | if (unlikely(ftrace_disabled)) |
| 631 | return; |
| 632 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 633 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 634 | ftrace_start_up++; |
Steven Rostedt | 982c350 | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 635 | command |= FTRACE_ENABLE_CALLS; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 636 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 637 | ftrace_startup_enable(command); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 638 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 639 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 640 | } |
| 641 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 642 | static void ftrace_shutdown(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 643 | { |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 644 | if (unlikely(ftrace_disabled)) |
| 645 | return; |
| 646 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 647 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 648 | ftrace_start_up--; |
| 649 | if (!ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 650 | command |= FTRACE_DISABLE_CALLS; |
| 651 | |
| 652 | if (saved_ftrace_func != ftrace_trace_function) { |
| 653 | saved_ftrace_func = ftrace_trace_function; |
| 654 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 655 | } |
| 656 | |
| 657 | if (!command || !ftrace_enabled) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 658 | goto out; |
| 659 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 660 | ftrace_run_update_code(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 661 | out: |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 662 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 665 | static void ftrace_startup_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 666 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 667 | int command = FTRACE_ENABLE_MCOUNT; |
| 668 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 669 | if (unlikely(ftrace_disabled)) |
| 670 | return; |
| 671 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 672 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 673 | /* Force update next time */ |
| 674 | saved_ftrace_func = NULL; |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 675 | /* ftrace_start_up is true if we want ftrace running */ |
| 676 | if (ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 677 | command |= FTRACE_ENABLE_CALLS; |
| 678 | |
| 679 | ftrace_run_update_code(command); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 680 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 681 | } |
| 682 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 683 | static void ftrace_shutdown_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 684 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 685 | int command = FTRACE_DISABLE_MCOUNT; |
| 686 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 687 | if (unlikely(ftrace_disabled)) |
| 688 | return; |
| 689 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 690 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 60a7ecf | 2008-11-05 16:05:44 -0500 | [diff] [blame] | 691 | /* ftrace_start_up is true if ftrace is running */ |
| 692 | if (ftrace_start_up) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 693 | command |= FTRACE_DISABLE_CALLS; |
| 694 | |
| 695 | ftrace_run_update_code(command); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 696 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 697 | } |
| 698 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 699 | static cycle_t ftrace_update_time; |
| 700 | static unsigned long ftrace_update_cnt; |
| 701 | unsigned long ftrace_update_tot_cnt; |
| 702 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 703 | static int ftrace_update_code(struct module *mod) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 704 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 705 | struct dyn_ftrace *p, *t; |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 706 | cycle_t start, stop; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 707 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 708 | start = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 709 | ftrace_update_cnt = 0; |
| 710 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 711 | list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) { |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 712 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 713 | /* If something went wrong, bail without enabling anything */ |
| 714 | if (unlikely(ftrace_disabled)) |
| 715 | return -1; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 716 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 717 | list_del_init(&p->list); |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 718 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 719 | /* convert record (i.e, patch mcount-call with NOP) */ |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 720 | if (ftrace_code_disable(mod, p)) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 721 | p->flags |= FTRACE_FL_CONVERTED; |
| 722 | ftrace_update_cnt++; |
| 723 | } else |
| 724 | ftrace_free_rec(p); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 725 | } |
| 726 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 727 | stop = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 728 | ftrace_update_time = stop - start; |
| 729 | ftrace_update_tot_cnt += ftrace_update_cnt; |
| 730 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 731 | return 0; |
| 732 | } |
| 733 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 734 | static int __init ftrace_dyn_table_alloc(unsigned long num_to_init) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 735 | { |
| 736 | struct ftrace_page *pg; |
| 737 | int cnt; |
| 738 | int i; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 739 | |
| 740 | /* allocate a few pages */ |
| 741 | ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL); |
| 742 | if (!ftrace_pages_start) |
| 743 | return -1; |
| 744 | |
| 745 | /* |
| 746 | * Allocate a few more pages. |
| 747 | * |
| 748 | * TODO: have some parser search vmlinux before |
| 749 | * final linking to find all calls to ftrace. |
| 750 | * Then we can: |
| 751 | * a) know how many pages to allocate. |
| 752 | * and/or |
| 753 | * b) set up the table then. |
| 754 | * |
| 755 | * The dynamic code is still necessary for |
| 756 | * modules. |
| 757 | */ |
| 758 | |
| 759 | pg = ftrace_pages = ftrace_pages_start; |
| 760 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 761 | cnt = num_to_init / ENTRIES_PER_PAGE; |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 762 | pr_info("ftrace: allocating %ld entries in %d pages\n", |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 763 | num_to_init, cnt + 1); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 764 | |
| 765 | for (i = 0; i < cnt; i++) { |
| 766 | pg->next = (void *)get_zeroed_page(GFP_KERNEL); |
| 767 | |
| 768 | /* If we fail, we'll try later anyway */ |
| 769 | if (!pg->next) |
| 770 | break; |
| 771 | |
| 772 | pg = pg->next; |
| 773 | } |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 778 | enum { |
| 779 | FTRACE_ITER_FILTER = (1 << 0), |
| 780 | FTRACE_ITER_CONT = (1 << 1), |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 781 | FTRACE_ITER_NOTRACE = (1 << 2), |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 782 | FTRACE_ITER_FAILURES = (1 << 3), |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 783 | }; |
| 784 | |
| 785 | #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */ |
| 786 | |
| 787 | struct ftrace_iterator { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 788 | struct ftrace_page *pg; |
Steven Rostedt | 431aa3f | 2009-01-06 12:43:01 -0500 | [diff] [blame^] | 789 | int idx; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 790 | unsigned flags; |
| 791 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 792 | unsigned buffer_idx; |
| 793 | unsigned filtered; |
| 794 | }; |
| 795 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 796 | static void * |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 797 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 798 | { |
| 799 | struct ftrace_iterator *iter = m->private; |
| 800 | struct dyn_ftrace *rec = NULL; |
| 801 | |
| 802 | (*pos)++; |
| 803 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 804 | /* should not be called from interrupt context */ |
| 805 | spin_lock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 806 | retry: |
| 807 | if (iter->idx >= iter->pg->index) { |
| 808 | if (iter->pg->next) { |
| 809 | iter->pg = iter->pg->next; |
| 810 | iter->idx = 0; |
| 811 | goto retry; |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 812 | } else { |
| 813 | iter->idx = -1; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 814 | } |
| 815 | } else { |
| 816 | rec = &iter->pg->records[iter->idx++]; |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 817 | if ((rec->flags & FTRACE_FL_FREE) || |
| 818 | |
| 819 | (!(iter->flags & FTRACE_ITER_FAILURES) && |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 820 | (rec->flags & FTRACE_FL_FAILED)) || |
| 821 | |
| 822 | ((iter->flags & FTRACE_ITER_FAILURES) && |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 823 | !(rec->flags & FTRACE_FL_FAILED)) || |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 824 | |
Steven Rostedt | 0183fb1c | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 825 | ((iter->flags & FTRACE_ITER_FILTER) && |
| 826 | !(rec->flags & FTRACE_FL_FILTER)) || |
| 827 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 828 | ((iter->flags & FTRACE_ITER_NOTRACE) && |
| 829 | !(rec->flags & FTRACE_FL_NOTRACE))) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 830 | rec = NULL; |
| 831 | goto retry; |
| 832 | } |
| 833 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 834 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 835 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 836 | return rec; |
| 837 | } |
| 838 | |
| 839 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 840 | { |
| 841 | struct ftrace_iterator *iter = m->private; |
| 842 | void *p = NULL; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 843 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 844 | if (*pos > 0) { |
| 845 | if (iter->idx < 0) |
| 846 | return p; |
| 847 | (*pos)--; |
| 848 | iter->idx--; |
| 849 | } |
walimis | 5821e1b | 2008-11-15 15:19:06 +0800 | [diff] [blame] | 850 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 851 | p = t_next(m, p, pos); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 852 | |
| 853 | return p; |
| 854 | } |
| 855 | |
| 856 | static void t_stop(struct seq_file *m, void *p) |
| 857 | { |
| 858 | } |
| 859 | |
| 860 | static int t_show(struct seq_file *m, void *v) |
| 861 | { |
| 862 | struct dyn_ftrace *rec = v; |
| 863 | char str[KSYM_SYMBOL_LEN]; |
| 864 | |
| 865 | if (!rec) |
| 866 | return 0; |
| 867 | |
| 868 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 869 | |
Liming Wang | 50cdaf0 | 2008-11-28 12:13:21 +0800 | [diff] [blame] | 870 | seq_printf(m, "%s\n", str); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | static struct seq_operations show_ftrace_seq_ops = { |
| 876 | .start = t_start, |
| 877 | .next = t_next, |
| 878 | .stop = t_stop, |
| 879 | .show = t_show, |
| 880 | }; |
| 881 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 882 | static int |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 883 | ftrace_avail_open(struct inode *inode, struct file *file) |
| 884 | { |
| 885 | struct ftrace_iterator *iter; |
| 886 | int ret; |
| 887 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 888 | if (unlikely(ftrace_disabled)) |
| 889 | return -ENODEV; |
| 890 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 891 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 892 | if (!iter) |
| 893 | return -ENOMEM; |
| 894 | |
| 895 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 896 | |
| 897 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 898 | if (!ret) { |
| 899 | struct seq_file *m = file->private_data; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 900 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 901 | m->private = iter; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 902 | } else { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 903 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 904 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 905 | |
| 906 | return ret; |
| 907 | } |
| 908 | |
| 909 | int ftrace_avail_release(struct inode *inode, struct file *file) |
| 910 | { |
| 911 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 912 | struct ftrace_iterator *iter = m->private; |
| 913 | |
| 914 | seq_release(inode, file); |
| 915 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 916 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 917 | return 0; |
| 918 | } |
| 919 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 920 | static int |
| 921 | ftrace_failures_open(struct inode *inode, struct file *file) |
| 922 | { |
| 923 | int ret; |
| 924 | struct seq_file *m; |
| 925 | struct ftrace_iterator *iter; |
| 926 | |
| 927 | ret = ftrace_avail_open(inode, file); |
| 928 | if (!ret) { |
| 929 | m = (struct seq_file *)file->private_data; |
| 930 | iter = (struct ftrace_iterator *)m->private; |
| 931 | iter->flags = FTRACE_ITER_FAILURES; |
| 932 | } |
| 933 | |
| 934 | return ret; |
| 935 | } |
| 936 | |
| 937 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 938 | static void ftrace_filter_reset(int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 939 | { |
| 940 | struct ftrace_page *pg; |
| 941 | struct dyn_ftrace *rec; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 942 | unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 943 | unsigned i; |
| 944 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 945 | /* should not be called from interrupt context */ |
| 946 | spin_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 947 | if (enable) |
| 948 | ftrace_filtered = 0; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 949 | pg = ftrace_pages_start; |
| 950 | while (pg) { |
| 951 | for (i = 0; i < pg->index; i++) { |
| 952 | rec = &pg->records[i]; |
| 953 | if (rec->flags & FTRACE_FL_FAILED) |
| 954 | continue; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 955 | rec->flags &= ~type; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 956 | } |
| 957 | pg = pg->next; |
| 958 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 959 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 960 | } |
| 961 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 962 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 963 | ftrace_regex_open(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 964 | { |
| 965 | struct ftrace_iterator *iter; |
| 966 | int ret = 0; |
| 967 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 968 | if (unlikely(ftrace_disabled)) |
| 969 | return -ENODEV; |
| 970 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 971 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 972 | if (!iter) |
| 973 | return -ENOMEM; |
| 974 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 975 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 976 | if ((file->f_mode & FMODE_WRITE) && |
| 977 | !(file->f_flags & O_APPEND)) |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 978 | ftrace_filter_reset(enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 979 | |
| 980 | if (file->f_mode & FMODE_READ) { |
| 981 | iter->pg = ftrace_pages_start; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 982 | iter->flags = enable ? FTRACE_ITER_FILTER : |
| 983 | FTRACE_ITER_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 984 | |
| 985 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 986 | if (!ret) { |
| 987 | struct seq_file *m = file->private_data; |
| 988 | m->private = iter; |
| 989 | } else |
| 990 | kfree(iter); |
| 991 | } else |
| 992 | file->private_data = iter; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 993 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 994 | |
| 995 | return ret; |
| 996 | } |
| 997 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 998 | static int |
| 999 | ftrace_filter_open(struct inode *inode, struct file *file) |
| 1000 | { |
| 1001 | return ftrace_regex_open(inode, file, 1); |
| 1002 | } |
| 1003 | |
| 1004 | static int |
| 1005 | ftrace_notrace_open(struct inode *inode, struct file *file) |
| 1006 | { |
| 1007 | return ftrace_regex_open(inode, file, 0); |
| 1008 | } |
| 1009 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1010 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1011 | ftrace_regex_read(struct file *file, char __user *ubuf, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1012 | size_t cnt, loff_t *ppos) |
| 1013 | { |
| 1014 | if (file->f_mode & FMODE_READ) |
| 1015 | return seq_read(file, ubuf, cnt, ppos); |
| 1016 | else |
| 1017 | return -EPERM; |
| 1018 | } |
| 1019 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1020 | static loff_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1021 | ftrace_regex_lseek(struct file *file, loff_t offset, int origin) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1022 | { |
| 1023 | loff_t ret; |
| 1024 | |
| 1025 | if (file->f_mode & FMODE_READ) |
| 1026 | ret = seq_lseek(file, offset, origin); |
| 1027 | else |
| 1028 | file->f_pos = ret = 1; |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | enum { |
| 1034 | MATCH_FULL, |
| 1035 | MATCH_FRONT_ONLY, |
| 1036 | MATCH_MIDDLE_ONLY, |
| 1037 | MATCH_END_ONLY, |
| 1038 | }; |
| 1039 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1040 | static void |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1041 | ftrace_match(unsigned char *buff, int len, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1042 | { |
| 1043 | char str[KSYM_SYMBOL_LEN]; |
| 1044 | char *search = NULL; |
| 1045 | struct ftrace_page *pg; |
| 1046 | struct dyn_ftrace *rec; |
| 1047 | int type = MATCH_FULL; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1048 | unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1049 | unsigned i, match = 0, search_len = 0; |
Steven Rostedt | ea3a6d6 | 2008-12-17 15:05:36 -0500 | [diff] [blame] | 1050 | int not = 0; |
| 1051 | |
| 1052 | if (buff[0] == '!') { |
| 1053 | not = 1; |
| 1054 | buff++; |
| 1055 | len--; |
| 1056 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1057 | |
| 1058 | for (i = 0; i < len; i++) { |
| 1059 | if (buff[i] == '*') { |
| 1060 | if (!i) { |
| 1061 | search = buff + i + 1; |
| 1062 | type = MATCH_END_ONLY; |
| 1063 | search_len = len - (i + 1); |
| 1064 | } else { |
| 1065 | if (type == MATCH_END_ONLY) { |
| 1066 | type = MATCH_MIDDLE_ONLY; |
| 1067 | } else { |
| 1068 | match = i; |
| 1069 | type = MATCH_FRONT_ONLY; |
| 1070 | } |
| 1071 | buff[i] = 0; |
| 1072 | break; |
| 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 1077 | /* should not be called from interrupt context */ |
| 1078 | spin_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1079 | if (enable) |
| 1080 | ftrace_filtered = 1; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1081 | pg = ftrace_pages_start; |
| 1082 | while (pg) { |
| 1083 | for (i = 0; i < pg->index; i++) { |
| 1084 | int matched = 0; |
| 1085 | char *ptr; |
| 1086 | |
| 1087 | rec = &pg->records[i]; |
| 1088 | if (rec->flags & FTRACE_FL_FAILED) |
| 1089 | continue; |
| 1090 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 1091 | switch (type) { |
| 1092 | case MATCH_FULL: |
| 1093 | if (strcmp(str, buff) == 0) |
| 1094 | matched = 1; |
| 1095 | break; |
| 1096 | case MATCH_FRONT_ONLY: |
| 1097 | if (memcmp(str, buff, match) == 0) |
| 1098 | matched = 1; |
| 1099 | break; |
| 1100 | case MATCH_MIDDLE_ONLY: |
| 1101 | if (strstr(str, search)) |
| 1102 | matched = 1; |
| 1103 | break; |
| 1104 | case MATCH_END_ONLY: |
| 1105 | ptr = strstr(str, search); |
| 1106 | if (ptr && (ptr[search_len] == 0)) |
| 1107 | matched = 1; |
| 1108 | break; |
| 1109 | } |
Steven Rostedt | ea3a6d6 | 2008-12-17 15:05:36 -0500 | [diff] [blame] | 1110 | if (matched) { |
| 1111 | if (not) |
| 1112 | rec->flags &= ~flag; |
| 1113 | else |
| 1114 | rec->flags |= flag; |
| 1115 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1116 | } |
| 1117 | pg = pg->next; |
| 1118 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 1119 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1122 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1123 | ftrace_regex_write(struct file *file, const char __user *ubuf, |
| 1124 | size_t cnt, loff_t *ppos, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1125 | { |
| 1126 | struct ftrace_iterator *iter; |
| 1127 | char ch; |
| 1128 | size_t read = 0; |
| 1129 | ssize_t ret; |
| 1130 | |
| 1131 | if (!cnt || cnt < 0) |
| 1132 | return 0; |
| 1133 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1134 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1135 | |
| 1136 | if (file->f_mode & FMODE_READ) { |
| 1137 | struct seq_file *m = file->private_data; |
| 1138 | iter = m->private; |
| 1139 | } else |
| 1140 | iter = file->private_data; |
| 1141 | |
| 1142 | if (!*ppos) { |
| 1143 | iter->flags &= ~FTRACE_ITER_CONT; |
| 1144 | iter->buffer_idx = 0; |
| 1145 | } |
| 1146 | |
| 1147 | ret = get_user(ch, ubuf++); |
| 1148 | if (ret) |
| 1149 | goto out; |
| 1150 | read++; |
| 1151 | cnt--; |
| 1152 | |
| 1153 | if (!(iter->flags & ~FTRACE_ITER_CONT)) { |
| 1154 | /* skip white space */ |
| 1155 | while (cnt && isspace(ch)) { |
| 1156 | ret = get_user(ch, ubuf++); |
| 1157 | if (ret) |
| 1158 | goto out; |
| 1159 | read++; |
| 1160 | cnt--; |
| 1161 | } |
| 1162 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1163 | if (isspace(ch)) { |
| 1164 | file->f_pos += read; |
| 1165 | ret = read; |
| 1166 | goto out; |
| 1167 | } |
| 1168 | |
| 1169 | iter->buffer_idx = 0; |
| 1170 | } |
| 1171 | |
| 1172 | while (cnt && !isspace(ch)) { |
| 1173 | if (iter->buffer_idx < FTRACE_BUFF_MAX) |
| 1174 | iter->buffer[iter->buffer_idx++] = ch; |
| 1175 | else { |
| 1176 | ret = -EINVAL; |
| 1177 | goto out; |
| 1178 | } |
| 1179 | ret = get_user(ch, ubuf++); |
| 1180 | if (ret) |
| 1181 | goto out; |
| 1182 | read++; |
| 1183 | cnt--; |
| 1184 | } |
| 1185 | |
| 1186 | if (isspace(ch)) { |
| 1187 | iter->filtered++; |
| 1188 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1189 | ftrace_match(iter->buffer, iter->buffer_idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1190 | iter->buffer_idx = 0; |
| 1191 | } else |
| 1192 | iter->flags |= FTRACE_ITER_CONT; |
| 1193 | |
| 1194 | |
| 1195 | file->f_pos += read; |
| 1196 | |
| 1197 | ret = read; |
| 1198 | out: |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1199 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1200 | |
| 1201 | return ret; |
| 1202 | } |
| 1203 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1204 | static ssize_t |
| 1205 | ftrace_filter_write(struct file *file, const char __user *ubuf, |
| 1206 | size_t cnt, loff_t *ppos) |
| 1207 | { |
| 1208 | return ftrace_regex_write(file, ubuf, cnt, ppos, 1); |
| 1209 | } |
| 1210 | |
| 1211 | static ssize_t |
| 1212 | ftrace_notrace_write(struct file *file, const char __user *ubuf, |
| 1213 | size_t cnt, loff_t *ppos) |
| 1214 | { |
| 1215 | return ftrace_regex_write(file, ubuf, cnt, ppos, 0); |
| 1216 | } |
| 1217 | |
| 1218 | static void |
| 1219 | ftrace_set_regex(unsigned char *buf, int len, int reset, int enable) |
| 1220 | { |
| 1221 | if (unlikely(ftrace_disabled)) |
| 1222 | return; |
| 1223 | |
| 1224 | mutex_lock(&ftrace_regex_lock); |
| 1225 | if (reset) |
| 1226 | ftrace_filter_reset(enable); |
| 1227 | if (buf) |
| 1228 | ftrace_match(buf, len, enable); |
| 1229 | mutex_unlock(&ftrace_regex_lock); |
| 1230 | } |
| 1231 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1232 | /** |
| 1233 | * ftrace_set_filter - set a function to filter on in ftrace |
| 1234 | * @buf - the string that holds the function filter text. |
| 1235 | * @len - the length of the string. |
| 1236 | * @reset - non zero to reset all filters before applying this filter. |
| 1237 | * |
| 1238 | * Filters denote which functions should be enabled when tracing is enabled. |
| 1239 | * If @buf is NULL and reset is set, all functions will be enabled for tracing. |
| 1240 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1241 | void ftrace_set_filter(unsigned char *buf, int len, int reset) |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1242 | { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1243 | ftrace_set_regex(buf, len, reset, 1); |
| 1244 | } |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1245 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1246 | /** |
| 1247 | * ftrace_set_notrace - set a function to not trace in ftrace |
| 1248 | * @buf - the string that holds the function notrace text. |
| 1249 | * @len - the length of the string. |
| 1250 | * @reset - non zero to reset all filters before applying this filter. |
| 1251 | * |
| 1252 | * Notrace Filters denote which functions should not be enabled when tracing |
| 1253 | * is enabled. If @buf is NULL and reset is set, all functions will be enabled |
| 1254 | * for tracing. |
| 1255 | */ |
| 1256 | void ftrace_set_notrace(unsigned char *buf, int len, int reset) |
| 1257 | { |
| 1258 | ftrace_set_regex(buf, len, reset, 0); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1259 | } |
| 1260 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1261 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1262 | ftrace_regex_release(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1263 | { |
| 1264 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1265 | struct ftrace_iterator *iter; |
| 1266 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1267 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1268 | if (file->f_mode & FMODE_READ) { |
| 1269 | iter = m->private; |
| 1270 | |
| 1271 | seq_release(inode, file); |
| 1272 | } else |
| 1273 | iter = file->private_data; |
| 1274 | |
| 1275 | if (iter->buffer_idx) { |
| 1276 | iter->filtered++; |
| 1277 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1278 | ftrace_match(iter->buffer, iter->buffer_idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | mutex_lock(&ftrace_sysctl_lock); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 1282 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | ee02a2e | 2008-11-15 16:31:41 -0500 | [diff] [blame] | 1283 | if (ftrace_start_up && ftrace_enabled) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1284 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 1285 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1286 | mutex_unlock(&ftrace_sysctl_lock); |
| 1287 | |
| 1288 | kfree(iter); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1289 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1290 | return 0; |
| 1291 | } |
| 1292 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1293 | static int |
| 1294 | ftrace_filter_release(struct inode *inode, struct file *file) |
| 1295 | { |
| 1296 | return ftrace_regex_release(inode, file, 1); |
| 1297 | } |
| 1298 | |
| 1299 | static int |
| 1300 | ftrace_notrace_release(struct inode *inode, struct file *file) |
| 1301 | { |
| 1302 | return ftrace_regex_release(inode, file, 0); |
| 1303 | } |
| 1304 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1305 | static struct file_operations ftrace_avail_fops = { |
| 1306 | .open = ftrace_avail_open, |
| 1307 | .read = seq_read, |
| 1308 | .llseek = seq_lseek, |
| 1309 | .release = ftrace_avail_release, |
| 1310 | }; |
| 1311 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1312 | static struct file_operations ftrace_failures_fops = { |
| 1313 | .open = ftrace_failures_open, |
| 1314 | .read = seq_read, |
| 1315 | .llseek = seq_lseek, |
| 1316 | .release = ftrace_avail_release, |
| 1317 | }; |
| 1318 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1319 | static struct file_operations ftrace_filter_fops = { |
| 1320 | .open = ftrace_filter_open, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1321 | .read = ftrace_regex_read, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1322 | .write = ftrace_filter_write, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1323 | .llseek = ftrace_regex_lseek, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1324 | .release = ftrace_filter_release, |
| 1325 | }; |
| 1326 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1327 | static struct file_operations ftrace_notrace_fops = { |
| 1328 | .open = ftrace_notrace_open, |
| 1329 | .read = ftrace_regex_read, |
| 1330 | .write = ftrace_notrace_write, |
| 1331 | .llseek = ftrace_regex_lseek, |
| 1332 | .release = ftrace_notrace_release, |
| 1333 | }; |
| 1334 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1335 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1336 | |
| 1337 | static DEFINE_MUTEX(graph_lock); |
| 1338 | |
| 1339 | int ftrace_graph_count; |
| 1340 | unsigned long ftrace_graph_funcs[FTRACE_GRAPH_MAX_FUNCS] __read_mostly; |
| 1341 | |
| 1342 | static void * |
| 1343 | g_next(struct seq_file *m, void *v, loff_t *pos) |
| 1344 | { |
| 1345 | unsigned long *array = m->private; |
| 1346 | int index = *pos; |
| 1347 | |
| 1348 | (*pos)++; |
| 1349 | |
| 1350 | if (index >= ftrace_graph_count) |
| 1351 | return NULL; |
| 1352 | |
| 1353 | return &array[index]; |
| 1354 | } |
| 1355 | |
| 1356 | static void *g_start(struct seq_file *m, loff_t *pos) |
| 1357 | { |
| 1358 | void *p = NULL; |
| 1359 | |
| 1360 | mutex_lock(&graph_lock); |
| 1361 | |
| 1362 | p = g_next(m, p, pos); |
| 1363 | |
| 1364 | return p; |
| 1365 | } |
| 1366 | |
| 1367 | static void g_stop(struct seq_file *m, void *p) |
| 1368 | { |
| 1369 | mutex_unlock(&graph_lock); |
| 1370 | } |
| 1371 | |
| 1372 | static int g_show(struct seq_file *m, void *v) |
| 1373 | { |
| 1374 | unsigned long *ptr = v; |
| 1375 | char str[KSYM_SYMBOL_LEN]; |
| 1376 | |
| 1377 | if (!ptr) |
| 1378 | return 0; |
| 1379 | |
| 1380 | kallsyms_lookup(*ptr, NULL, NULL, NULL, str); |
| 1381 | |
| 1382 | seq_printf(m, "%s\n", str); |
| 1383 | |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | static struct seq_operations ftrace_graph_seq_ops = { |
| 1388 | .start = g_start, |
| 1389 | .next = g_next, |
| 1390 | .stop = g_stop, |
| 1391 | .show = g_show, |
| 1392 | }; |
| 1393 | |
| 1394 | static int |
| 1395 | ftrace_graph_open(struct inode *inode, struct file *file) |
| 1396 | { |
| 1397 | int ret = 0; |
| 1398 | |
| 1399 | if (unlikely(ftrace_disabled)) |
| 1400 | return -ENODEV; |
| 1401 | |
| 1402 | mutex_lock(&graph_lock); |
| 1403 | if ((file->f_mode & FMODE_WRITE) && |
| 1404 | !(file->f_flags & O_APPEND)) { |
| 1405 | ftrace_graph_count = 0; |
| 1406 | memset(ftrace_graph_funcs, 0, sizeof(ftrace_graph_funcs)); |
| 1407 | } |
| 1408 | |
| 1409 | if (file->f_mode & FMODE_READ) { |
| 1410 | ret = seq_open(file, &ftrace_graph_seq_ops); |
| 1411 | if (!ret) { |
| 1412 | struct seq_file *m = file->private_data; |
| 1413 | m->private = ftrace_graph_funcs; |
| 1414 | } |
| 1415 | } else |
| 1416 | file->private_data = ftrace_graph_funcs; |
| 1417 | mutex_unlock(&graph_lock); |
| 1418 | |
| 1419 | return ret; |
| 1420 | } |
| 1421 | |
| 1422 | static ssize_t |
| 1423 | ftrace_graph_read(struct file *file, char __user *ubuf, |
| 1424 | size_t cnt, loff_t *ppos) |
| 1425 | { |
| 1426 | if (file->f_mode & FMODE_READ) |
| 1427 | return seq_read(file, ubuf, cnt, ppos); |
| 1428 | else |
| 1429 | return -EPERM; |
| 1430 | } |
| 1431 | |
| 1432 | static int |
| 1433 | ftrace_set_func(unsigned long *array, int idx, char *buffer) |
| 1434 | { |
| 1435 | char str[KSYM_SYMBOL_LEN]; |
| 1436 | struct dyn_ftrace *rec; |
| 1437 | struct ftrace_page *pg; |
| 1438 | int found = 0; |
Liming Wang | faec2ec | 2008-12-04 14:24:49 +0800 | [diff] [blame] | 1439 | int i, j; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1440 | |
| 1441 | if (ftrace_disabled) |
| 1442 | return -ENODEV; |
| 1443 | |
| 1444 | /* should not be called from interrupt context */ |
| 1445 | spin_lock(&ftrace_lock); |
| 1446 | |
| 1447 | for (pg = ftrace_pages_start; pg; pg = pg->next) { |
| 1448 | for (i = 0; i < pg->index; i++) { |
| 1449 | rec = &pg->records[i]; |
| 1450 | |
| 1451 | if (rec->flags & (FTRACE_FL_FAILED | FTRACE_FL_FREE)) |
| 1452 | continue; |
| 1453 | |
| 1454 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 1455 | if (strcmp(str, buffer) == 0) { |
| 1456 | found = 1; |
Liming Wang | faec2ec | 2008-12-04 14:24:49 +0800 | [diff] [blame] | 1457 | for (j = 0; j < idx; j++) |
| 1458 | if (array[j] == rec->ip) { |
| 1459 | found = 0; |
| 1460 | break; |
| 1461 | } |
| 1462 | if (found) |
| 1463 | array[idx] = rec->ip; |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1464 | break; |
| 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | spin_unlock(&ftrace_lock); |
| 1469 | |
| 1470 | return found ? 0 : -EINVAL; |
| 1471 | } |
| 1472 | |
| 1473 | static ssize_t |
| 1474 | ftrace_graph_write(struct file *file, const char __user *ubuf, |
| 1475 | size_t cnt, loff_t *ppos) |
| 1476 | { |
| 1477 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 1478 | unsigned long *array; |
| 1479 | size_t read = 0; |
| 1480 | ssize_t ret; |
| 1481 | int index = 0; |
| 1482 | char ch; |
| 1483 | |
| 1484 | if (!cnt || cnt < 0) |
| 1485 | return 0; |
| 1486 | |
| 1487 | mutex_lock(&graph_lock); |
| 1488 | |
| 1489 | if (ftrace_graph_count >= FTRACE_GRAPH_MAX_FUNCS) { |
| 1490 | ret = -EBUSY; |
| 1491 | goto out; |
| 1492 | } |
| 1493 | |
| 1494 | if (file->f_mode & FMODE_READ) { |
| 1495 | struct seq_file *m = file->private_data; |
| 1496 | array = m->private; |
| 1497 | } else |
| 1498 | array = file->private_data; |
| 1499 | |
| 1500 | ret = get_user(ch, ubuf++); |
| 1501 | if (ret) |
| 1502 | goto out; |
| 1503 | read++; |
| 1504 | cnt--; |
| 1505 | |
| 1506 | /* skip white space */ |
| 1507 | while (cnt && isspace(ch)) { |
| 1508 | ret = get_user(ch, ubuf++); |
| 1509 | if (ret) |
| 1510 | goto out; |
| 1511 | read++; |
| 1512 | cnt--; |
| 1513 | } |
| 1514 | |
| 1515 | if (isspace(ch)) { |
| 1516 | *ppos += read; |
| 1517 | ret = read; |
| 1518 | goto out; |
| 1519 | } |
| 1520 | |
| 1521 | while (cnt && !isspace(ch)) { |
| 1522 | if (index < FTRACE_BUFF_MAX) |
| 1523 | buffer[index++] = ch; |
| 1524 | else { |
| 1525 | ret = -EINVAL; |
| 1526 | goto out; |
| 1527 | } |
| 1528 | ret = get_user(ch, ubuf++); |
| 1529 | if (ret) |
| 1530 | goto out; |
| 1531 | read++; |
| 1532 | cnt--; |
| 1533 | } |
| 1534 | buffer[index] = 0; |
| 1535 | |
| 1536 | /* we allow only one at a time */ |
| 1537 | ret = ftrace_set_func(array, ftrace_graph_count, buffer); |
| 1538 | if (ret) |
| 1539 | goto out; |
| 1540 | |
| 1541 | ftrace_graph_count++; |
| 1542 | |
| 1543 | file->f_pos += read; |
| 1544 | |
| 1545 | ret = read; |
| 1546 | out: |
| 1547 | mutex_unlock(&graph_lock); |
| 1548 | |
| 1549 | return ret; |
| 1550 | } |
| 1551 | |
| 1552 | static const struct file_operations ftrace_graph_fops = { |
| 1553 | .open = ftrace_graph_open, |
| 1554 | .read = ftrace_graph_read, |
| 1555 | .write = ftrace_graph_write, |
| 1556 | }; |
| 1557 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 1558 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1559 | static __init int ftrace_init_dyn_debugfs(struct dentry *d_tracer) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1560 | { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1561 | struct dentry *entry; |
| 1562 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1563 | entry = debugfs_create_file("available_filter_functions", 0444, |
| 1564 | d_tracer, NULL, &ftrace_avail_fops); |
| 1565 | if (!entry) |
| 1566 | pr_warning("Could not create debugfs " |
| 1567 | "'available_filter_functions' entry\n"); |
| 1568 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1569 | entry = debugfs_create_file("failures", 0444, |
| 1570 | d_tracer, NULL, &ftrace_failures_fops); |
| 1571 | if (!entry) |
| 1572 | pr_warning("Could not create debugfs 'failures' entry\n"); |
| 1573 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1574 | entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer, |
| 1575 | NULL, &ftrace_filter_fops); |
| 1576 | if (!entry) |
| 1577 | pr_warning("Could not create debugfs " |
| 1578 | "'set_ftrace_filter' entry\n"); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1579 | |
| 1580 | entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer, |
| 1581 | NULL, &ftrace_notrace_fops); |
| 1582 | if (!entry) |
| 1583 | pr_warning("Could not create debugfs " |
| 1584 | "'set_ftrace_notrace' entry\n"); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 1585 | |
Steven Rostedt | ea4e2bc | 2008-12-03 15:36:57 -0500 | [diff] [blame] | 1586 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1587 | entry = debugfs_create_file("set_graph_function", 0444, d_tracer, |
| 1588 | NULL, |
| 1589 | &ftrace_graph_fops); |
| 1590 | if (!entry) |
| 1591 | pr_warning("Could not create debugfs " |
| 1592 | "'set_graph_function' entry\n"); |
| 1593 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 1594 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1595 | return 0; |
| 1596 | } |
| 1597 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1598 | static int ftrace_convert_nops(struct module *mod, |
| 1599 | unsigned long *start, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1600 | unsigned long *end) |
| 1601 | { |
| 1602 | unsigned long *p; |
| 1603 | unsigned long addr; |
| 1604 | unsigned long flags; |
| 1605 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1606 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1607 | p = start; |
| 1608 | while (p < end) { |
| 1609 | addr = ftrace_call_adjust(*p++); |
Steven Rostedt | 20e5227 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1610 | /* |
| 1611 | * Some architecture linkers will pad between |
| 1612 | * the different mcount_loc sections of different |
| 1613 | * object files to satisfy alignments. |
| 1614 | * Skip any NULL pointers. |
| 1615 | */ |
| 1616 | if (!addr) |
| 1617 | continue; |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1618 | ftrace_record_ip(addr); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1619 | } |
| 1620 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1621 | /* disable interrupts to prevent kstop machine */ |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1622 | local_irq_save(flags); |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1623 | ftrace_update_code(mod); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1624 | local_irq_restore(flags); |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1625 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1626 | |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1630 | void ftrace_init_module(struct module *mod, |
| 1631 | unsigned long *start, unsigned long *end) |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 1632 | { |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 1633 | if (ftrace_disabled || start == end) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 1634 | return; |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1635 | ftrace_convert_nops(mod, start, end); |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 1636 | } |
| 1637 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1638 | extern unsigned long __start_mcount_loc[]; |
| 1639 | extern unsigned long __stop_mcount_loc[]; |
| 1640 | |
| 1641 | void __init ftrace_init(void) |
| 1642 | { |
| 1643 | unsigned long count, addr, flags; |
| 1644 | int ret; |
| 1645 | |
| 1646 | /* Keep the ftrace pointer to the stub */ |
| 1647 | addr = (unsigned long)ftrace_stub; |
| 1648 | |
| 1649 | local_irq_save(flags); |
| 1650 | ftrace_dyn_arch_init(&addr); |
| 1651 | local_irq_restore(flags); |
| 1652 | |
| 1653 | /* ftrace_dyn_arch_init places the return code in addr */ |
| 1654 | if (addr) |
| 1655 | goto failed; |
| 1656 | |
| 1657 | count = __stop_mcount_loc - __start_mcount_loc; |
| 1658 | |
| 1659 | ret = ftrace_dyn_table_alloc(count); |
| 1660 | if (ret) |
| 1661 | goto failed; |
| 1662 | |
| 1663 | last_ftrace_enabled = ftrace_enabled = 1; |
| 1664 | |
Steven Rostedt | 31e8890 | 2008-11-14 16:21:19 -0800 | [diff] [blame] | 1665 | ret = ftrace_convert_nops(NULL, |
| 1666 | __start_mcount_loc, |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1667 | __stop_mcount_loc); |
| 1668 | |
| 1669 | return; |
| 1670 | failed: |
| 1671 | ftrace_disabled = 1; |
| 1672 | } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1673 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1674 | #else |
Frederic Weisbecker | 0b6e4d5 | 2008-10-28 20:17:38 +0100 | [diff] [blame] | 1675 | |
| 1676 | static int __init ftrace_nodyn_init(void) |
| 1677 | { |
| 1678 | ftrace_enabled = 1; |
| 1679 | return 0; |
| 1680 | } |
| 1681 | device_initcall(ftrace_nodyn_init); |
| 1682 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1683 | static inline int ftrace_init_dyn_debugfs(struct dentry *d_tracer) { return 0; } |
| 1684 | static inline void ftrace_startup_enable(int command) { } |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1685 | /* Keep as macros so we do not need to define the commands */ |
| 1686 | # define ftrace_startup(command) do { } while (0) |
| 1687 | # define ftrace_shutdown(command) do { } while (0) |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1688 | # define ftrace_startup_sysctl() do { } while (0) |
| 1689 | # define ftrace_shutdown_sysctl() do { } while (0) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1690 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 1691 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1692 | static ssize_t |
| 1693 | ftrace_pid_read(struct file *file, char __user *ubuf, |
| 1694 | size_t cnt, loff_t *ppos) |
| 1695 | { |
| 1696 | char buf[64]; |
| 1697 | int r; |
| 1698 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1699 | if (ftrace_pid_trace == ftrace_swapper_pid) |
| 1700 | r = sprintf(buf, "swapper tasks\n"); |
| 1701 | else if (ftrace_pid_trace) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1702 | r = sprintf(buf, "%u\n", pid_nr(ftrace_pid_trace)); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1703 | else |
| 1704 | r = sprintf(buf, "no pid\n"); |
| 1705 | |
| 1706 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
| 1707 | } |
| 1708 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1709 | static void clear_ftrace_swapper(void) |
| 1710 | { |
| 1711 | struct task_struct *p; |
| 1712 | int cpu; |
| 1713 | |
| 1714 | get_online_cpus(); |
| 1715 | for_each_online_cpu(cpu) { |
| 1716 | p = idle_task(cpu); |
| 1717 | clear_tsk_trace_trace(p); |
| 1718 | } |
| 1719 | put_online_cpus(); |
| 1720 | } |
| 1721 | |
| 1722 | static void set_ftrace_swapper(void) |
| 1723 | { |
| 1724 | struct task_struct *p; |
| 1725 | int cpu; |
| 1726 | |
| 1727 | get_online_cpus(); |
| 1728 | for_each_online_cpu(cpu) { |
| 1729 | p = idle_task(cpu); |
| 1730 | set_tsk_trace_trace(p); |
| 1731 | } |
| 1732 | put_online_cpus(); |
| 1733 | } |
| 1734 | |
| 1735 | static void clear_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1736 | { |
| 1737 | struct task_struct *p; |
| 1738 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1739 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1740 | clear_tsk_trace_trace(p); |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1741 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
| 1742 | put_pid(pid); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1743 | } |
| 1744 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1745 | static void set_ftrace_pid(struct pid *pid) |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1746 | { |
| 1747 | struct task_struct *p; |
| 1748 | |
| 1749 | do_each_pid_task(pid, PIDTYPE_PID, p) { |
| 1750 | set_tsk_trace_trace(p); |
| 1751 | } while_each_pid_task(pid, PIDTYPE_PID, p); |
| 1752 | } |
| 1753 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1754 | static void clear_ftrace_pid_task(struct pid **pid) |
| 1755 | { |
| 1756 | if (*pid == ftrace_swapper_pid) |
| 1757 | clear_ftrace_swapper(); |
| 1758 | else |
| 1759 | clear_ftrace_pid(*pid); |
| 1760 | |
| 1761 | *pid = NULL; |
| 1762 | } |
| 1763 | |
| 1764 | static void set_ftrace_pid_task(struct pid *pid) |
| 1765 | { |
| 1766 | if (pid == ftrace_swapper_pid) |
| 1767 | set_ftrace_swapper(); |
| 1768 | else |
| 1769 | set_ftrace_pid(pid); |
| 1770 | } |
| 1771 | |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1772 | static ssize_t |
| 1773 | ftrace_pid_write(struct file *filp, const char __user *ubuf, |
| 1774 | size_t cnt, loff_t *ppos) |
| 1775 | { |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1776 | struct pid *pid; |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1777 | char buf[64]; |
| 1778 | long val; |
| 1779 | int ret; |
| 1780 | |
| 1781 | if (cnt >= sizeof(buf)) |
| 1782 | return -EINVAL; |
| 1783 | |
| 1784 | if (copy_from_user(&buf, ubuf, cnt)) |
| 1785 | return -EFAULT; |
| 1786 | |
| 1787 | buf[cnt] = 0; |
| 1788 | |
| 1789 | ret = strict_strtol(buf, 10, &val); |
| 1790 | if (ret < 0) |
| 1791 | return ret; |
| 1792 | |
| 1793 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1794 | if (val < 0) { |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1795 | /* disable pid tracing */ |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1796 | if (!ftrace_pid_trace) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1797 | goto out; |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1798 | |
| 1799 | clear_ftrace_pid_task(&ftrace_pid_trace); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1800 | |
| 1801 | } else { |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1802 | /* swapper task is special */ |
| 1803 | if (!val) { |
| 1804 | pid = ftrace_swapper_pid; |
| 1805 | if (pid == ftrace_pid_trace) |
| 1806 | goto out; |
| 1807 | } else { |
| 1808 | pid = find_get_pid(val); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1809 | |
Steven Rostedt | e32d895 | 2008-12-04 00:26:41 -0500 | [diff] [blame] | 1810 | if (pid == ftrace_pid_trace) { |
| 1811 | put_pid(pid); |
| 1812 | goto out; |
| 1813 | } |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1814 | } |
| 1815 | |
| 1816 | if (ftrace_pid_trace) |
| 1817 | clear_ftrace_pid_task(&ftrace_pid_trace); |
| 1818 | |
| 1819 | if (!pid) |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1820 | goto out; |
| 1821 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1822 | ftrace_pid_trace = pid; |
Steven Rostedt | 0ef8cde | 2008-12-03 15:36:58 -0500 | [diff] [blame] | 1823 | |
Steven Rostedt | 978f3a4 | 2008-12-04 00:26:40 -0500 | [diff] [blame] | 1824 | set_ftrace_pid_task(ftrace_pid_trace); |
Steven Rostedt | df4fc31 | 2008-11-26 00:16:23 -0500 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | /* update the function call */ |
| 1828 | ftrace_update_pid_func(); |
| 1829 | ftrace_startup_enable(0); |
| 1830 | |
| 1831 | out: |
| 1832 | mutex_unlock(&ftrace_start_lock); |
| 1833 | |
| 1834 | return cnt; |
| 1835 | } |
| 1836 | |
| 1837 | static struct file_operations ftrace_pid_fops = { |
| 1838 | .read = ftrace_pid_read, |
| 1839 | .write = ftrace_pid_write, |
| 1840 | }; |
| 1841 | |
| 1842 | static __init int ftrace_init_debugfs(void) |
| 1843 | { |
| 1844 | struct dentry *d_tracer; |
| 1845 | struct dentry *entry; |
| 1846 | |
| 1847 | d_tracer = tracing_init_dentry(); |
| 1848 | if (!d_tracer) |
| 1849 | return 0; |
| 1850 | |
| 1851 | ftrace_init_dyn_debugfs(d_tracer); |
| 1852 | |
| 1853 | entry = debugfs_create_file("set_ftrace_pid", 0644, d_tracer, |
| 1854 | NULL, &ftrace_pid_fops); |
| 1855 | if (!entry) |
| 1856 | pr_warning("Could not create debugfs " |
| 1857 | "'set_ftrace_pid' entry\n"); |
| 1858 | return 0; |
| 1859 | } |
| 1860 | |
| 1861 | fs_initcall(ftrace_init_debugfs); |
| 1862 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1863 | /** |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 1864 | * ftrace_kill - kill ftrace |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1865 | * |
| 1866 | * This function should be used by panic code. It stops ftrace |
| 1867 | * but in a not so nice way. If you need to simply kill ftrace |
| 1868 | * from a non-atomic section, use ftrace_kill. |
| 1869 | */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 1870 | void ftrace_kill(void) |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1871 | { |
| 1872 | ftrace_disabled = 1; |
| 1873 | ftrace_enabled = 0; |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1874 | clear_ftrace_function(); |
| 1875 | } |
| 1876 | |
| 1877 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1878 | * register_ftrace_function - register a function for profiling |
| 1879 | * @ops - ops structure that holds the function for profiling. |
| 1880 | * |
| 1881 | * Register a function to be called by all functions in the |
| 1882 | * kernel. |
| 1883 | * |
| 1884 | * Note: @ops->func and all the functions it calls must be labeled |
| 1885 | * with "notrace", otherwise it will go into a |
| 1886 | * recursive loop. |
| 1887 | */ |
| 1888 | int register_ftrace_function(struct ftrace_ops *ops) |
| 1889 | { |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1890 | int ret; |
| 1891 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1892 | if (unlikely(ftrace_disabled)) |
| 1893 | return -1; |
| 1894 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1895 | mutex_lock(&ftrace_sysctl_lock); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1896 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1897 | ret = __register_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1898 | ftrace_startup(0); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1899 | |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1900 | mutex_unlock(&ftrace_sysctl_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1901 | return ret; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /** |
| 1905 | * unregister_ftrace_function - unresgister a function for profiling. |
| 1906 | * @ops - ops structure that holds the function to unregister |
| 1907 | * |
| 1908 | * Unregister a function that was added to be called by ftrace profiling. |
| 1909 | */ |
| 1910 | int unregister_ftrace_function(struct ftrace_ops *ops) |
| 1911 | { |
| 1912 | int ret; |
| 1913 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1914 | mutex_lock(&ftrace_sysctl_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1915 | ret = __unregister_ftrace_function(ops); |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 1916 | ftrace_shutdown(0); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1917 | mutex_unlock(&ftrace_sysctl_lock); |
| 1918 | |
| 1919 | return ret; |
| 1920 | } |
| 1921 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1922 | int |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1923 | ftrace_enable_sysctl(struct ctl_table *table, int write, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1924 | struct file *file, void __user *buffer, size_t *lenp, |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1925 | loff_t *ppos) |
| 1926 | { |
| 1927 | int ret; |
| 1928 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1929 | if (unlikely(ftrace_disabled)) |
| 1930 | return -ENODEV; |
| 1931 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1932 | mutex_lock(&ftrace_sysctl_lock); |
| 1933 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1934 | ret = proc_dointvec(table, write, file, buffer, lenp, ppos); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1935 | |
| 1936 | if (ret || !write || (last_ftrace_enabled == ftrace_enabled)) |
| 1937 | goto out; |
| 1938 | |
| 1939 | last_ftrace_enabled = ftrace_enabled; |
| 1940 | |
| 1941 | if (ftrace_enabled) { |
| 1942 | |
| 1943 | ftrace_startup_sysctl(); |
| 1944 | |
| 1945 | /* we are starting ftrace again */ |
| 1946 | if (ftrace_list != &ftrace_list_end) { |
| 1947 | if (ftrace_list->next == &ftrace_list_end) |
| 1948 | ftrace_trace_function = ftrace_list->func; |
| 1949 | else |
| 1950 | ftrace_trace_function = ftrace_list_func; |
| 1951 | } |
| 1952 | |
| 1953 | } else { |
| 1954 | /* stopping ftrace calls (just send to ftrace_stub) */ |
| 1955 | ftrace_trace_function = ftrace_stub; |
| 1956 | |
| 1957 | ftrace_shutdown_sysctl(); |
| 1958 | } |
| 1959 | |
| 1960 | out: |
| 1961 | mutex_unlock(&ftrace_sysctl_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1962 | return ret; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1963 | } |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 1964 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1965 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 1966 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1967 | static atomic_t ftrace_graph_active; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 1968 | |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 1969 | int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace) |
| 1970 | { |
| 1971 | return 0; |
| 1972 | } |
| 1973 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1974 | /* The callbacks that hook a function */ |
| 1975 | trace_func_graph_ret_t ftrace_graph_return = |
| 1976 | (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 1977 | trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub; |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 1978 | |
| 1979 | /* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */ |
| 1980 | static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list) |
| 1981 | { |
| 1982 | int i; |
| 1983 | int ret = 0; |
| 1984 | unsigned long flags; |
| 1985 | int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE; |
| 1986 | struct task_struct *g, *t; |
| 1987 | |
| 1988 | for (i = 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) { |
| 1989 | ret_stack_list[i] = kmalloc(FTRACE_RETFUNC_DEPTH |
| 1990 | * sizeof(struct ftrace_ret_stack), |
| 1991 | GFP_KERNEL); |
| 1992 | if (!ret_stack_list[i]) { |
| 1993 | start = 0; |
| 1994 | end = i; |
| 1995 | ret = -ENOMEM; |
| 1996 | goto free; |
| 1997 | } |
| 1998 | } |
| 1999 | |
| 2000 | read_lock_irqsave(&tasklist_lock, flags); |
| 2001 | do_each_thread(g, t) { |
| 2002 | if (start == end) { |
| 2003 | ret = -EAGAIN; |
| 2004 | goto unlock; |
| 2005 | } |
| 2006 | |
| 2007 | if (t->ret_stack == NULL) { |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2008 | t->curr_ret_stack = -1; |
Frederic Weisbecker | 48d68b2 | 2008-12-02 00:20:39 +0100 | [diff] [blame] | 2009 | /* Make sure IRQs see the -1 first: */ |
| 2010 | barrier(); |
| 2011 | t->ret_stack = ret_stack_list[start++]; |
Frederic Weisbecker | 380c4b1 | 2008-12-06 03:43:41 +0100 | [diff] [blame] | 2012 | atomic_set(&t->tracing_graph_pause, 0); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2013 | atomic_set(&t->trace_overrun, 0); |
| 2014 | } |
| 2015 | } while_each_thread(g, t); |
| 2016 | |
| 2017 | unlock: |
| 2018 | read_unlock_irqrestore(&tasklist_lock, flags); |
| 2019 | free: |
| 2020 | for (i = start; i < end; i++) |
| 2021 | kfree(ret_stack_list[i]); |
| 2022 | return ret; |
| 2023 | } |
| 2024 | |
| 2025 | /* Allocate a return stack for each task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2026 | static int start_graph_tracing(void) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2027 | { |
| 2028 | struct ftrace_ret_stack **ret_stack_list; |
| 2029 | int ret; |
| 2030 | |
| 2031 | ret_stack_list = kmalloc(FTRACE_RETSTACK_ALLOC_SIZE * |
| 2032 | sizeof(struct ftrace_ret_stack *), |
| 2033 | GFP_KERNEL); |
| 2034 | |
| 2035 | if (!ret_stack_list) |
| 2036 | return -ENOMEM; |
| 2037 | |
| 2038 | do { |
| 2039 | ret = alloc_retstack_tasklist(ret_stack_list); |
| 2040 | } while (ret == -EAGAIN); |
| 2041 | |
| 2042 | kfree(ret_stack_list); |
| 2043 | return ret; |
| 2044 | } |
| 2045 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2046 | int register_ftrace_graph(trace_func_graph_ret_t retfunc, |
| 2047 | trace_func_graph_ent_t entryfunc) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2048 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2049 | int ret = 0; |
| 2050 | |
| 2051 | mutex_lock(&ftrace_sysctl_lock); |
| 2052 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2053 | atomic_inc(&ftrace_graph_active); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2054 | ret = start_graph_tracing(); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2055 | if (ret) { |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2056 | atomic_dec(&ftrace_graph_active); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2057 | goto out; |
| 2058 | } |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 2059 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2060 | ftrace_graph_return = retfunc; |
| 2061 | ftrace_graph_entry = entryfunc; |
Steven Rostedt | e53a631 | 2008-11-26 00:16:25 -0500 | [diff] [blame] | 2062 | |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2063 | ftrace_startup(FTRACE_START_FUNC_RET); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2064 | |
| 2065 | out: |
| 2066 | mutex_unlock(&ftrace_sysctl_lock); |
| 2067 | return ret; |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2068 | } |
| 2069 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2070 | void unregister_ftrace_graph(void) |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2071 | { |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2072 | mutex_lock(&ftrace_sysctl_lock); |
| 2073 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2074 | atomic_dec(&ftrace_graph_active); |
| 2075 | ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub; |
Steven Rostedt | e49dc19 | 2008-12-02 23:50:05 -0500 | [diff] [blame] | 2076 | ftrace_graph_entry = ftrace_graph_entry_stub; |
Steven Rostedt | 5a45cfe | 2008-11-26 00:16:24 -0500 | [diff] [blame] | 2077 | ftrace_shutdown(FTRACE_STOP_FUNC_RET); |
Frederic Weisbecker | e7d3737 | 2008-11-16 06:02:06 +0100 | [diff] [blame] | 2078 | |
| 2079 | mutex_unlock(&ftrace_sysctl_lock); |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2080 | } |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2081 | |
| 2082 | /* Allocate a return stack for newly created task */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2083 | void ftrace_graph_init_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2084 | { |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 2085 | if (atomic_read(&ftrace_graph_active)) { |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2086 | t->ret_stack = kmalloc(FTRACE_RETFUNC_DEPTH |
| 2087 | * sizeof(struct ftrace_ret_stack), |
| 2088 | GFP_KERNEL); |
| 2089 | if (!t->ret_stack) |
| 2090 | return; |
| 2091 | t->curr_ret_stack = -1; |
Frederic Weisbecker | 380c4b1 | 2008-12-06 03:43:41 +0100 | [diff] [blame] | 2092 | atomic_set(&t->tracing_graph_pause, 0); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2093 | atomic_set(&t->trace_overrun, 0); |
| 2094 | } else |
| 2095 | t->ret_stack = NULL; |
| 2096 | } |
| 2097 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 2098 | void ftrace_graph_exit_task(struct task_struct *t) |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2099 | { |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 2100 | struct ftrace_ret_stack *ret_stack = t->ret_stack; |
| 2101 | |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2102 | t->ret_stack = NULL; |
Frederic Weisbecker | eae849c | 2008-11-23 17:33:12 +0100 | [diff] [blame] | 2103 | /* NULL must become visible to IRQs before we free it: */ |
| 2104 | barrier(); |
| 2105 | |
| 2106 | kfree(ret_stack); |
Frederic Weisbecker | f201ae2 | 2008-11-23 06:22:56 +0100 | [diff] [blame] | 2107 | } |
Steven Rostedt | 14a866c | 2008-12-02 23:50:02 -0500 | [diff] [blame] | 2108 | |
| 2109 | void ftrace_graph_stop(void) |
| 2110 | { |
| 2111 | ftrace_stop(); |
| 2112 | } |
Frederic Weisbecker | 15e6cb3 | 2008-11-11 07:14:25 +0100 | [diff] [blame] | 2113 | #endif |
| 2114 | |