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 | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 50 | /* |
| 51 | * ftrace_disabled is set when an anomaly is discovered. |
| 52 | * ftrace_disabled is much stronger than ftrace_enabled. |
| 53 | */ |
| 54 | static int ftrace_disabled __read_mostly; |
| 55 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 56 | static DEFINE_SPINLOCK(ftrace_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 57 | static DEFINE_MUTEX(ftrace_sysctl_lock); |
| 58 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 59 | static struct ftrace_ops ftrace_list_end __read_mostly = |
| 60 | { |
| 61 | .func = ftrace_stub, |
| 62 | }; |
| 63 | |
| 64 | static struct ftrace_ops *ftrace_list __read_mostly = &ftrace_list_end; |
| 65 | ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub; |
| 66 | |
Ingo Molnar | f225293 | 2008-05-22 10:37:48 +0200 | [diff] [blame] | 67 | 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] | 68 | { |
| 69 | struct ftrace_ops *op = ftrace_list; |
| 70 | |
| 71 | /* in case someone actually ports this to alpha! */ |
| 72 | read_barrier_depends(); |
| 73 | |
| 74 | while (op != &ftrace_list_end) { |
| 75 | /* silly alpha */ |
| 76 | read_barrier_depends(); |
| 77 | op->func(ip, parent_ip); |
| 78 | op = op->next; |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 83 | * clear_ftrace_function - reset the ftrace function |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 84 | * |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 85 | * This NULLs the ftrace function and in essence stops |
| 86 | * tracing. There may be lag |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 87 | */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 88 | void clear_ftrace_function(void) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 89 | { |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 90 | ftrace_trace_function = ftrace_stub; |
| 91 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 92 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 93 | static int __register_ftrace_function(struct ftrace_ops *ops) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 94 | { |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 95 | /* should not be called from interrupt context */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 96 | spin_lock(&ftrace_lock); |
| 97 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 98 | ops->next = ftrace_list; |
| 99 | /* |
| 100 | * We are entering ops into the ftrace_list but another |
| 101 | * CPU might be walking that list. We need to make sure |
| 102 | * the ops->next pointer is valid before another CPU sees |
| 103 | * the ops pointer included into the ftrace_list. |
| 104 | */ |
| 105 | smp_wmb(); |
| 106 | ftrace_list = ops; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 107 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 108 | if (ftrace_enabled) { |
| 109 | /* |
| 110 | * For one func, simply call it directly. |
| 111 | * For more than one func, call the chain. |
| 112 | */ |
| 113 | if (ops->next == &ftrace_list_end) |
| 114 | ftrace_trace_function = ops->func; |
| 115 | else |
| 116 | ftrace_trace_function = ftrace_list_func; |
| 117 | } |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 118 | |
| 119 | spin_unlock(&ftrace_lock); |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 124 | static int __unregister_ftrace_function(struct ftrace_ops *ops) |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 125 | { |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 126 | struct ftrace_ops **p; |
| 127 | int ret = 0; |
| 128 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 129 | /* should not be called from interrupt context */ |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 130 | spin_lock(&ftrace_lock); |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 131 | |
| 132 | /* |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 133 | * If we are removing the last function, then simply point |
| 134 | * to the ftrace_stub. |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 135 | */ |
| 136 | if (ftrace_list == ops && ops->next == &ftrace_list_end) { |
| 137 | ftrace_trace_function = ftrace_stub; |
| 138 | ftrace_list = &ftrace_list_end; |
| 139 | goto out; |
| 140 | } |
| 141 | |
| 142 | for (p = &ftrace_list; *p != &ftrace_list_end; p = &(*p)->next) |
| 143 | if (*p == ops) |
| 144 | break; |
| 145 | |
| 146 | if (*p != ops) { |
| 147 | ret = -1; |
| 148 | goto out; |
| 149 | } |
| 150 | |
| 151 | *p = (*p)->next; |
| 152 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 153 | if (ftrace_enabled) { |
| 154 | /* If we only have one func left, then call that directly */ |
| 155 | if (ftrace_list == &ftrace_list_end || |
| 156 | ftrace_list->next == &ftrace_list_end) |
| 157 | ftrace_trace_function = ftrace_list->func; |
| 158 | } |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 159 | |
| 160 | out: |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 161 | spin_unlock(&ftrace_lock); |
| 162 | |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | #ifdef CONFIG_DYNAMIC_FTRACE |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 167 | #ifndef CONFIG_FTRACE_MCOUNT_RECORD |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 168 | # error Dynamic ftrace depends on MCOUNT_RECORD |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 169 | #endif |
| 170 | |
Steven Noonan | 71c67d5 | 2008-09-20 01:00:37 -0700 | [diff] [blame] | 171 | /* |
| 172 | * Since MCOUNT_ADDR may point to mcount itself, we do not want |
| 173 | * to get it confused by reading a reference in the code as we |
| 174 | * are parsing on objcopy output of text. Use a variable for |
| 175 | * it instead. |
| 176 | */ |
| 177 | static unsigned long mcount_addr = MCOUNT_ADDR; |
| 178 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 179 | enum { |
| 180 | FTRACE_ENABLE_CALLS = (1 << 0), |
| 181 | FTRACE_DISABLE_CALLS = (1 << 1), |
| 182 | FTRACE_UPDATE_TRACE_FUNC = (1 << 2), |
| 183 | FTRACE_ENABLE_MCOUNT = (1 << 3), |
| 184 | FTRACE_DISABLE_MCOUNT = (1 << 4), |
| 185 | }; |
| 186 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 187 | static int ftrace_filtered; |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 188 | static int tracing_on; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 189 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 190 | static LIST_HEAD(ftrace_new_addrs); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 191 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 192 | static DEFINE_MUTEX(ftrace_regex_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 193 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 194 | struct ftrace_page { |
| 195 | struct ftrace_page *next; |
David Miller | aa5e5ce | 2008-05-13 22:06:56 -0700 | [diff] [blame] | 196 | unsigned long index; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 197 | struct dyn_ftrace records[]; |
David Miller | aa5e5ce | 2008-05-13 22:06:56 -0700 | [diff] [blame] | 198 | }; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 199 | |
| 200 | #define ENTRIES_PER_PAGE \ |
| 201 | ((PAGE_SIZE - sizeof(struct ftrace_page)) / sizeof(struct dyn_ftrace)) |
| 202 | |
| 203 | /* estimate from running different kernels */ |
| 204 | #define NR_TO_INIT 10000 |
| 205 | |
| 206 | static struct ftrace_page *ftrace_pages_start; |
| 207 | static struct ftrace_page *ftrace_pages; |
| 208 | |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 209 | static struct dyn_ftrace *ftrace_free_records; |
| 210 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 211 | |
| 212 | #ifdef CONFIG_KPROBES |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 213 | |
| 214 | static int frozen_record_count; |
| 215 | |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 216 | static inline void freeze_record(struct dyn_ftrace *rec) |
| 217 | { |
| 218 | if (!(rec->flags & FTRACE_FL_FROZEN)) { |
| 219 | rec->flags |= FTRACE_FL_FROZEN; |
| 220 | frozen_record_count++; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | static inline void unfreeze_record(struct dyn_ftrace *rec) |
| 225 | { |
| 226 | if (rec->flags & FTRACE_FL_FROZEN) { |
| 227 | rec->flags &= ~FTRACE_FL_FROZEN; |
| 228 | frozen_record_count--; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | static inline int record_frozen(struct dyn_ftrace *rec) |
| 233 | { |
| 234 | return rec->flags & FTRACE_FL_FROZEN; |
| 235 | } |
| 236 | #else |
| 237 | # define freeze_record(rec) ({ 0; }) |
| 238 | # define unfreeze_record(rec) ({ 0; }) |
| 239 | # define record_frozen(rec) ({ 0; }) |
| 240 | #endif /* CONFIG_KPROBES */ |
| 241 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 242 | static void ftrace_free_rec(struct dyn_ftrace *rec) |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 243 | { |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 244 | rec->ip = (unsigned long)ftrace_free_records; |
| 245 | ftrace_free_records = rec; |
| 246 | rec->flags |= FTRACE_FL_FREE; |
| 247 | } |
| 248 | |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 249 | void ftrace_release(void *start, unsigned long size) |
| 250 | { |
| 251 | struct dyn_ftrace *rec; |
| 252 | struct ftrace_page *pg; |
| 253 | unsigned long s = (unsigned long)start; |
| 254 | unsigned long e = s + size; |
| 255 | int i; |
| 256 | |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 257 | if (ftrace_disabled || !start) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 258 | return; |
| 259 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 260 | /* should not be called from interrupt context */ |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 261 | spin_lock(&ftrace_lock); |
| 262 | |
| 263 | for (pg = ftrace_pages_start; pg; pg = pg->next) { |
| 264 | for (i = 0; i < pg->index; i++) { |
| 265 | rec = &pg->records[i]; |
| 266 | |
| 267 | if ((rec->ip >= s) && (rec->ip < e)) |
| 268 | ftrace_free_rec(rec); |
| 269 | } |
| 270 | } |
| 271 | spin_unlock(&ftrace_lock); |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 274 | static struct dyn_ftrace *ftrace_alloc_dyn_node(unsigned long ip) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 275 | { |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 276 | struct dyn_ftrace *rec; |
| 277 | |
| 278 | /* First check for freed records */ |
| 279 | if (ftrace_free_records) { |
| 280 | rec = ftrace_free_records; |
| 281 | |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 282 | if (unlikely(!(rec->flags & FTRACE_FL_FREE))) { |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 283 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 284 | ftrace_free_records = NULL; |
| 285 | return NULL; |
| 286 | } |
| 287 | |
| 288 | ftrace_free_records = (void *)rec->ip; |
| 289 | memset(rec, 0, sizeof(*rec)); |
| 290 | return rec; |
| 291 | } |
| 292 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 293 | if (ftrace_pages->index == ENTRIES_PER_PAGE) { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 294 | if (!ftrace_pages->next) { |
| 295 | /* allocate another page */ |
| 296 | ftrace_pages->next = |
| 297 | (void *)get_zeroed_page(GFP_KERNEL); |
| 298 | if (!ftrace_pages->next) |
| 299 | return NULL; |
| 300 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 301 | ftrace_pages = ftrace_pages->next; |
| 302 | } |
| 303 | |
| 304 | return &ftrace_pages->records[ftrace_pages->index++]; |
| 305 | } |
| 306 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 307 | static struct dyn_ftrace * |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 308 | ftrace_record_ip(unsigned long ip) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 309 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 310 | struct dyn_ftrace *rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 311 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 312 | if (!ftrace_enabled || ftrace_disabled) |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 313 | return NULL; |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 314 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 315 | rec = ftrace_alloc_dyn_node(ip); |
| 316 | if (!rec) |
| 317 | return NULL; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 318 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 319 | rec->ip = ip; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 320 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 321 | list_add(&rec->list, &ftrace_new_addrs); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 322 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 323 | return rec; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Steven Rostedt | caf8cde | 2008-05-12 21:20:50 +0200 | [diff] [blame] | 326 | #define FTRACE_ADDR ((long)(ftrace_caller)) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 327 | |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 328 | static int |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 329 | __ftrace_replace_code(struct dyn_ftrace *rec, |
| 330 | unsigned char *old, unsigned char *new, int enable) |
| 331 | { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 332 | unsigned long ip, fl; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 333 | |
| 334 | ip = rec->ip; |
| 335 | |
| 336 | if (ftrace_filtered && enable) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 337 | /* |
| 338 | * If filtering is on: |
| 339 | * |
| 340 | * If this record is set to be filtered and |
| 341 | * is enabled then do nothing. |
| 342 | * |
| 343 | * If this record is set to be filtered and |
| 344 | * it is not enabled, enable it. |
| 345 | * |
| 346 | * If this record is not set to be filtered |
| 347 | * and it is not enabled do nothing. |
| 348 | * |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 349 | * If this record is set not to trace then |
| 350 | * do nothing. |
| 351 | * |
Abhishek Sagar | a4500b8 | 2008-06-14 11:59:39 +0530 | [diff] [blame] | 352 | * If this record is set not to trace and |
| 353 | * it is enabled then disable it. |
| 354 | * |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 355 | * If this record is not set to be filtered and |
| 356 | * it is enabled, disable it. |
| 357 | */ |
Abhishek Sagar | a4500b8 | 2008-06-14 11:59:39 +0530 | [diff] [blame] | 358 | |
| 359 | fl = rec->flags & (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE | |
| 360 | FTRACE_FL_ENABLED); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 361 | |
| 362 | if ((fl == (FTRACE_FL_FILTER | FTRACE_FL_ENABLED)) || |
Abhishek Sagar | a4500b8 | 2008-06-14 11:59:39 +0530 | [diff] [blame] | 363 | (fl == (FTRACE_FL_FILTER | FTRACE_FL_NOTRACE)) || |
| 364 | !fl || (fl == FTRACE_FL_NOTRACE)) |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 365 | return 0; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 366 | |
| 367 | /* |
| 368 | * If it is enabled disable it, |
| 369 | * otherwise enable it! |
| 370 | */ |
Abhishek Sagar | a4500b8 | 2008-06-14 11:59:39 +0530 | [diff] [blame] | 371 | if (fl & FTRACE_FL_ENABLED) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 372 | /* swap new and old */ |
| 373 | new = old; |
| 374 | old = ftrace_call_replace(ip, FTRACE_ADDR); |
| 375 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 376 | } else { |
| 377 | new = ftrace_call_replace(ip, FTRACE_ADDR); |
| 378 | rec->flags |= FTRACE_FL_ENABLED; |
| 379 | } |
| 380 | } else { |
| 381 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 382 | if (enable) { |
| 383 | /* |
| 384 | * If this record is set not to trace and is |
| 385 | * not enabled, do nothing. |
| 386 | */ |
| 387 | fl = rec->flags & (FTRACE_FL_NOTRACE | FTRACE_FL_ENABLED); |
| 388 | if (fl == FTRACE_FL_NOTRACE) |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 389 | return 0; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 390 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 391 | new = ftrace_call_replace(ip, FTRACE_ADDR); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 392 | } else |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 393 | old = ftrace_call_replace(ip, FTRACE_ADDR); |
| 394 | |
| 395 | if (enable) { |
| 396 | if (rec->flags & FTRACE_FL_ENABLED) |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 397 | return 0; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 398 | rec->flags |= FTRACE_FL_ENABLED; |
| 399 | } else { |
| 400 | if (!(rec->flags & FTRACE_FL_ENABLED)) |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 401 | return 0; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 402 | rec->flags &= ~FTRACE_FL_ENABLED; |
| 403 | } |
| 404 | } |
| 405 | |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 406 | return ftrace_modify_code(ip, old, new); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 409 | static void ftrace_replace_code(int enable) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 410 | { |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 411 | int i, failed; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 412 | unsigned char *new = NULL, *old = NULL; |
| 413 | struct dyn_ftrace *rec; |
| 414 | struct ftrace_page *pg; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 415 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 416 | if (enable) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 417 | old = ftrace_nop_replace(); |
| 418 | else |
| 419 | new = ftrace_nop_replace(); |
| 420 | |
| 421 | for (pg = ftrace_pages_start; pg; pg = pg->next) { |
| 422 | for (i = 0; i < pg->index; i++) { |
| 423 | rec = &pg->records[i]; |
| 424 | |
| 425 | /* don't modify code that has already faulted */ |
| 426 | if (rec->flags & FTRACE_FL_FAILED) |
| 427 | continue; |
| 428 | |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 429 | /* ignore updates to this record's mcount site */ |
Abhishek Sagar | 98a05ed | 2008-06-26 22:51:51 +0530 | [diff] [blame] | 430 | if (get_kprobe((void *)rec->ip)) { |
| 431 | freeze_record(rec); |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 432 | continue; |
Abhishek Sagar | 98a05ed | 2008-06-26 22:51:51 +0530 | [diff] [blame] | 433 | } else { |
| 434 | unfreeze_record(rec); |
| 435 | } |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 436 | |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 437 | failed = __ftrace_replace_code(rec, old, new, enable); |
| 438 | if (failed && (rec->flags & FTRACE_FL_CONVERTED)) { |
| 439 | rec->flags |= FTRACE_FL_FAILED; |
| 440 | if ((system_state == SYSTEM_BOOTING) || |
Abhishek Sagar | 34078a5 | 2008-06-03 08:33:41 +0530 | [diff] [blame] | 441 | !core_kernel_text(rec->ip)) { |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 442 | ftrace_free_rec(rec); |
| 443 | } |
| 444 | } |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 449 | static void print_ip_ins(const char *fmt, unsigned char *p) |
| 450 | { |
| 451 | int i; |
| 452 | |
| 453 | printk(KERN_CONT "%s", fmt); |
| 454 | |
| 455 | for (i = 0; i < MCOUNT_INSN_SIZE; i++) |
| 456 | printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); |
| 457 | } |
| 458 | |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 459 | static int |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 460 | ftrace_code_disable(struct dyn_ftrace *rec) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 461 | { |
| 462 | unsigned long ip; |
| 463 | unsigned char *nop, *call; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 464 | int ret; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 465 | |
| 466 | ip = rec->ip; |
| 467 | |
| 468 | nop = ftrace_nop_replace(); |
Steven Rostedt | 3b47bfc | 2008-08-27 23:24:15 -0400 | [diff] [blame] | 469 | call = ftrace_call_replace(ip, mcount_addr); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 470 | |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 471 | ret = ftrace_modify_code(ip, call, nop); |
| 472 | if (ret) { |
| 473 | switch (ret) { |
| 474 | case -EFAULT: |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 475 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 476 | pr_info("ftrace faulted on modifying "); |
| 477 | print_ip_sym(ip); |
| 478 | break; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 479 | case -EINVAL: |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 480 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 481 | pr_info("ftrace failed to modify "); |
| 482 | print_ip_sym(ip); |
| 483 | print_ip_ins(" expected: ", call); |
| 484 | print_ip_ins(" actual: ", (unsigned char *)ip); |
| 485 | print_ip_ins(" replace: ", nop); |
| 486 | printk(KERN_CONT "\n"); |
| 487 | break; |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 488 | case -EPERM: |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 489 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 490 | pr_info("ftrace faulted on writing "); |
| 491 | print_ip_sym(ip); |
| 492 | break; |
| 493 | default: |
Steven Rostedt | 6912896e | 2008-10-23 09:33:03 -0400 | [diff] [blame] | 494 | FTRACE_WARN_ON_ONCE(1); |
Steven Rostedt | 593eb8a | 2008-10-23 09:32:59 -0400 | [diff] [blame] | 495 | pr_info("ftrace faulted on unknown error "); |
| 496 | print_ip_sym(ip); |
Steven Rostedt | 05736a4 | 2008-09-22 14:55:47 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 499 | rec->flags |= FTRACE_FL_FAILED; |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 500 | return 0; |
Steven Rostedt | 37ad5084 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 501 | } |
Abhishek Sagar | 492a7ea5 | 2008-05-25 00:10:04 +0530 | [diff] [blame] | 502 | return 1; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 505 | static int __ftrace_modify_code(void *data) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 506 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 507 | int *command = data; |
| 508 | |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 509 | if (*command & FTRACE_ENABLE_CALLS) { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 510 | ftrace_replace_code(1); |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 511 | tracing_on = 1; |
| 512 | } else if (*command & FTRACE_DISABLE_CALLS) { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 513 | ftrace_replace_code(0); |
Abhishek Sagar | ecea656 | 2008-06-21 23:47:53 +0530 | [diff] [blame] | 514 | tracing_on = 0; |
| 515 | } |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 516 | |
| 517 | if (*command & FTRACE_UPDATE_TRACE_FUNC) |
| 518 | ftrace_update_ftrace_func(ftrace_trace_function); |
| 519 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 520 | return 0; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 521 | } |
| 522 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 523 | static void ftrace_run_update_code(int command) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 524 | { |
Rusty Russell | 784e2d7 | 2008-07-28 12:16:31 -0500 | [diff] [blame] | 525 | stop_machine(__ftrace_modify_code, &command, NULL); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 528 | static ftrace_func_t saved_ftrace_func; |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 529 | static int ftrace_start; |
| 530 | static DEFINE_MUTEX(ftrace_start_lock); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 531 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 532 | static void ftrace_startup(void) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 533 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 534 | int command = 0; |
| 535 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 536 | if (unlikely(ftrace_disabled)) |
| 537 | return; |
| 538 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 539 | mutex_lock(&ftrace_start_lock); |
| 540 | ftrace_start++; |
| 541 | if (ftrace_start == 1) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 542 | command |= FTRACE_ENABLE_CALLS; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 543 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 544 | if (saved_ftrace_func != ftrace_trace_function) { |
| 545 | saved_ftrace_func = ftrace_trace_function; |
| 546 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 547 | } |
| 548 | |
| 549 | if (!command || !ftrace_enabled) |
| 550 | goto out; |
| 551 | |
| 552 | ftrace_run_update_code(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 553 | out: |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 554 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 557 | static void ftrace_shutdown(void) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 558 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 559 | int command = 0; |
| 560 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 561 | if (unlikely(ftrace_disabled)) |
| 562 | return; |
| 563 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 564 | mutex_lock(&ftrace_start_lock); |
| 565 | ftrace_start--; |
| 566 | if (!ftrace_start) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 567 | command |= FTRACE_DISABLE_CALLS; |
| 568 | |
| 569 | if (saved_ftrace_func != ftrace_trace_function) { |
| 570 | saved_ftrace_func = ftrace_trace_function; |
| 571 | command |= FTRACE_UPDATE_TRACE_FUNC; |
| 572 | } |
| 573 | |
| 574 | if (!command || !ftrace_enabled) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 575 | goto out; |
| 576 | |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 577 | ftrace_run_update_code(command); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 578 | out: |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 579 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 582 | static void ftrace_startup_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 583 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 584 | int command = FTRACE_ENABLE_MCOUNT; |
| 585 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 586 | if (unlikely(ftrace_disabled)) |
| 587 | return; |
| 588 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 589 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 590 | /* Force update next time */ |
| 591 | saved_ftrace_func = NULL; |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 592 | /* ftrace_start is true if we want ftrace running */ |
| 593 | if (ftrace_start) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 594 | command |= FTRACE_ENABLE_CALLS; |
| 595 | |
| 596 | ftrace_run_update_code(command); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 597 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 600 | static void ftrace_shutdown_sysctl(void) |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 601 | { |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 602 | int command = FTRACE_DISABLE_MCOUNT; |
| 603 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 604 | if (unlikely(ftrace_disabled)) |
| 605 | return; |
| 606 | |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 607 | mutex_lock(&ftrace_start_lock); |
| 608 | /* ftrace_start is true if ftrace is running */ |
| 609 | if (ftrace_start) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 610 | command |= FTRACE_DISABLE_CALLS; |
| 611 | |
| 612 | ftrace_run_update_code(command); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 613 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 616 | static cycle_t ftrace_update_time; |
| 617 | static unsigned long ftrace_update_cnt; |
| 618 | unsigned long ftrace_update_tot_cnt; |
| 619 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 620 | static int ftrace_update_code(void) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 621 | { |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 622 | struct dyn_ftrace *p, *t; |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 623 | cycle_t start, stop; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 624 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 625 | start = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 626 | ftrace_update_cnt = 0; |
| 627 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 628 | list_for_each_entry_safe(p, t, &ftrace_new_addrs, list) { |
Abhishek Sagar | f22f9a8 | 2008-06-21 23:50:29 +0530 | [diff] [blame] | 629 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 630 | /* If something went wrong, bail without enabling anything */ |
| 631 | if (unlikely(ftrace_disabled)) |
| 632 | return -1; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 633 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 634 | list_del_init(&p->list); |
Abhishek Sagar | 0eb9670 | 2008-06-01 21:47:30 +0530 | [diff] [blame] | 635 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 636 | /* convert record (i.e, patch mcount-call with NOP) */ |
| 637 | if (ftrace_code_disable(p)) { |
| 638 | p->flags |= FTRACE_FL_CONVERTED; |
| 639 | ftrace_update_cnt++; |
| 640 | } else |
| 641 | ftrace_free_rec(p); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 642 | } |
| 643 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 644 | stop = ftrace_now(raw_smp_processor_id()); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 645 | ftrace_update_time = stop - start; |
| 646 | ftrace_update_tot_cnt += ftrace_update_cnt; |
| 647 | |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 651 | static int __init ftrace_dyn_table_alloc(unsigned long num_to_init) |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 652 | { |
| 653 | struct ftrace_page *pg; |
| 654 | int cnt; |
| 655 | int i; |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 656 | |
| 657 | /* allocate a few pages */ |
| 658 | ftrace_pages_start = (void *)get_zeroed_page(GFP_KERNEL); |
| 659 | if (!ftrace_pages_start) |
| 660 | return -1; |
| 661 | |
| 662 | /* |
| 663 | * Allocate a few more pages. |
| 664 | * |
| 665 | * TODO: have some parser search vmlinux before |
| 666 | * final linking to find all calls to ftrace. |
| 667 | * Then we can: |
| 668 | * a) know how many pages to allocate. |
| 669 | * and/or |
| 670 | * b) set up the table then. |
| 671 | * |
| 672 | * The dynamic code is still necessary for |
| 673 | * modules. |
| 674 | */ |
| 675 | |
| 676 | pg = ftrace_pages = ftrace_pages_start; |
| 677 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 678 | cnt = num_to_init / ENTRIES_PER_PAGE; |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 679 | pr_info("ftrace: allocating %ld entries in %d pages\n", |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 680 | num_to_init, cnt); |
Steven Rostedt | 3c1720f | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 681 | |
| 682 | for (i = 0; i < cnt; i++) { |
| 683 | pg->next = (void *)get_zeroed_page(GFP_KERNEL); |
| 684 | |
| 685 | /* If we fail, we'll try later anyway */ |
| 686 | if (!pg->next) |
| 687 | break; |
| 688 | |
| 689 | pg = pg->next; |
| 690 | } |
| 691 | |
| 692 | return 0; |
| 693 | } |
| 694 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 695 | enum { |
| 696 | FTRACE_ITER_FILTER = (1 << 0), |
| 697 | FTRACE_ITER_CONT = (1 << 1), |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 698 | FTRACE_ITER_NOTRACE = (1 << 2), |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 699 | FTRACE_ITER_FAILURES = (1 << 3), |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 700 | }; |
| 701 | |
| 702 | #define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4) /* room for wildcards */ |
| 703 | |
| 704 | struct ftrace_iterator { |
| 705 | loff_t pos; |
| 706 | struct ftrace_page *pg; |
| 707 | unsigned idx; |
| 708 | unsigned flags; |
| 709 | unsigned char buffer[FTRACE_BUFF_MAX+1]; |
| 710 | unsigned buffer_idx; |
| 711 | unsigned filtered; |
| 712 | }; |
| 713 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 714 | static void * |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 715 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 716 | { |
| 717 | struct ftrace_iterator *iter = m->private; |
| 718 | struct dyn_ftrace *rec = NULL; |
| 719 | |
| 720 | (*pos)++; |
| 721 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 722 | /* should not be called from interrupt context */ |
| 723 | spin_lock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 724 | retry: |
| 725 | if (iter->idx >= iter->pg->index) { |
| 726 | if (iter->pg->next) { |
| 727 | iter->pg = iter->pg->next; |
| 728 | iter->idx = 0; |
| 729 | goto retry; |
| 730 | } |
| 731 | } else { |
| 732 | rec = &iter->pg->records[iter->idx++]; |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 733 | if ((rec->flags & FTRACE_FL_FREE) || |
| 734 | |
| 735 | (!(iter->flags & FTRACE_ITER_FAILURES) && |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 736 | (rec->flags & FTRACE_FL_FAILED)) || |
| 737 | |
| 738 | ((iter->flags & FTRACE_ITER_FAILURES) && |
Steven Rostedt | a9fdda3 | 2008-08-14 22:47:17 -0400 | [diff] [blame] | 739 | !(rec->flags & FTRACE_FL_FAILED)) || |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 740 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 741 | ((iter->flags & FTRACE_ITER_NOTRACE) && |
| 742 | !(rec->flags & FTRACE_FL_NOTRACE))) { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 743 | rec = NULL; |
| 744 | goto retry; |
| 745 | } |
| 746 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 747 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 748 | |
| 749 | iter->pos = *pos; |
| 750 | |
| 751 | return rec; |
| 752 | } |
| 753 | |
| 754 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 755 | { |
| 756 | struct ftrace_iterator *iter = m->private; |
| 757 | void *p = NULL; |
| 758 | loff_t l = -1; |
| 759 | |
| 760 | if (*pos != iter->pos) { |
| 761 | for (p = t_next(m, p, &l); p && l < *pos; p = t_next(m, p, &l)) |
| 762 | ; |
| 763 | } else { |
| 764 | l = *pos; |
| 765 | p = t_next(m, p, &l); |
| 766 | } |
| 767 | |
| 768 | return p; |
| 769 | } |
| 770 | |
| 771 | static void t_stop(struct seq_file *m, void *p) |
| 772 | { |
| 773 | } |
| 774 | |
| 775 | static int t_show(struct seq_file *m, void *v) |
| 776 | { |
| 777 | struct dyn_ftrace *rec = v; |
| 778 | char str[KSYM_SYMBOL_LEN]; |
| 779 | |
| 780 | if (!rec) |
| 781 | return 0; |
| 782 | |
| 783 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 784 | |
| 785 | seq_printf(m, "%s\n", str); |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | static struct seq_operations show_ftrace_seq_ops = { |
| 791 | .start = t_start, |
| 792 | .next = t_next, |
| 793 | .stop = t_stop, |
| 794 | .show = t_show, |
| 795 | }; |
| 796 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 797 | static int |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 798 | ftrace_avail_open(struct inode *inode, struct file *file) |
| 799 | { |
| 800 | struct ftrace_iterator *iter; |
| 801 | int ret; |
| 802 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 803 | if (unlikely(ftrace_disabled)) |
| 804 | return -ENODEV; |
| 805 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 806 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 807 | if (!iter) |
| 808 | return -ENOMEM; |
| 809 | |
| 810 | iter->pg = ftrace_pages_start; |
| 811 | iter->pos = -1; |
| 812 | |
| 813 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 814 | if (!ret) { |
| 815 | struct seq_file *m = file->private_data; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 816 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 817 | m->private = iter; |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 818 | } else { |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 819 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 820 | } |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 821 | |
| 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | int ftrace_avail_release(struct inode *inode, struct file *file) |
| 826 | { |
| 827 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 828 | struct ftrace_iterator *iter = m->private; |
| 829 | |
| 830 | seq_release(inode, file); |
| 831 | kfree(iter); |
Ingo Molnar | 4bf39a9 | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 832 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 836 | static int |
| 837 | ftrace_failures_open(struct inode *inode, struct file *file) |
| 838 | { |
| 839 | int ret; |
| 840 | struct seq_file *m; |
| 841 | struct ftrace_iterator *iter; |
| 842 | |
| 843 | ret = ftrace_avail_open(inode, file); |
| 844 | if (!ret) { |
| 845 | m = (struct seq_file *)file->private_data; |
| 846 | iter = (struct ftrace_iterator *)m->private; |
| 847 | iter->flags = FTRACE_ITER_FAILURES; |
| 848 | } |
| 849 | |
| 850 | return ret; |
| 851 | } |
| 852 | |
| 853 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 854 | static void ftrace_filter_reset(int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 855 | { |
| 856 | struct ftrace_page *pg; |
| 857 | struct dyn_ftrace *rec; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 858 | unsigned long type = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 859 | unsigned i; |
| 860 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 861 | /* should not be called from interrupt context */ |
| 862 | spin_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 863 | if (enable) |
| 864 | ftrace_filtered = 0; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 865 | pg = ftrace_pages_start; |
| 866 | while (pg) { |
| 867 | for (i = 0; i < pg->index; i++) { |
| 868 | rec = &pg->records[i]; |
| 869 | if (rec->flags & FTRACE_FL_FAILED) |
| 870 | continue; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 871 | rec->flags &= ~type; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 872 | } |
| 873 | pg = pg->next; |
| 874 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 875 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 878 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 879 | ftrace_regex_open(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 880 | { |
| 881 | struct ftrace_iterator *iter; |
| 882 | int ret = 0; |
| 883 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 884 | if (unlikely(ftrace_disabled)) |
| 885 | return -ENODEV; |
| 886 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 887 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 888 | if (!iter) |
| 889 | return -ENOMEM; |
| 890 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 891 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 892 | if ((file->f_mode & FMODE_WRITE) && |
| 893 | !(file->f_flags & O_APPEND)) |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 894 | ftrace_filter_reset(enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 895 | |
| 896 | if (file->f_mode & FMODE_READ) { |
| 897 | iter->pg = ftrace_pages_start; |
| 898 | iter->pos = -1; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 899 | iter->flags = enable ? FTRACE_ITER_FILTER : |
| 900 | FTRACE_ITER_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 901 | |
| 902 | ret = seq_open(file, &show_ftrace_seq_ops); |
| 903 | if (!ret) { |
| 904 | struct seq_file *m = file->private_data; |
| 905 | m->private = iter; |
| 906 | } else |
| 907 | kfree(iter); |
| 908 | } else |
| 909 | file->private_data = iter; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 910 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 911 | |
| 912 | return ret; |
| 913 | } |
| 914 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 915 | static int |
| 916 | ftrace_filter_open(struct inode *inode, struct file *file) |
| 917 | { |
| 918 | return ftrace_regex_open(inode, file, 1); |
| 919 | } |
| 920 | |
| 921 | static int |
| 922 | ftrace_notrace_open(struct inode *inode, struct file *file) |
| 923 | { |
| 924 | return ftrace_regex_open(inode, file, 0); |
| 925 | } |
| 926 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 927 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 928 | ftrace_regex_read(struct file *file, char __user *ubuf, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 929 | size_t cnt, loff_t *ppos) |
| 930 | { |
| 931 | if (file->f_mode & FMODE_READ) |
| 932 | return seq_read(file, ubuf, cnt, ppos); |
| 933 | else |
| 934 | return -EPERM; |
| 935 | } |
| 936 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 937 | static loff_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 938 | ftrace_regex_lseek(struct file *file, loff_t offset, int origin) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 939 | { |
| 940 | loff_t ret; |
| 941 | |
| 942 | if (file->f_mode & FMODE_READ) |
| 943 | ret = seq_lseek(file, offset, origin); |
| 944 | else |
| 945 | file->f_pos = ret = 1; |
| 946 | |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | enum { |
| 951 | MATCH_FULL, |
| 952 | MATCH_FRONT_ONLY, |
| 953 | MATCH_MIDDLE_ONLY, |
| 954 | MATCH_END_ONLY, |
| 955 | }; |
| 956 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 957 | static void |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 958 | ftrace_match(unsigned char *buff, int len, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 959 | { |
| 960 | char str[KSYM_SYMBOL_LEN]; |
| 961 | char *search = NULL; |
| 962 | struct ftrace_page *pg; |
| 963 | struct dyn_ftrace *rec; |
| 964 | int type = MATCH_FULL; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 965 | unsigned long flag = enable ? FTRACE_FL_FILTER : FTRACE_FL_NOTRACE; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 966 | unsigned i, match = 0, search_len = 0; |
| 967 | |
| 968 | for (i = 0; i < len; i++) { |
| 969 | if (buff[i] == '*') { |
| 970 | if (!i) { |
| 971 | search = buff + i + 1; |
| 972 | type = MATCH_END_ONLY; |
| 973 | search_len = len - (i + 1); |
| 974 | } else { |
| 975 | if (type == MATCH_END_ONLY) { |
| 976 | type = MATCH_MIDDLE_ONLY; |
| 977 | } else { |
| 978 | match = i; |
| 979 | type = MATCH_FRONT_ONLY; |
| 980 | } |
| 981 | buff[i] = 0; |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 987 | /* should not be called from interrupt context */ |
| 988 | spin_lock(&ftrace_lock); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 989 | if (enable) |
| 990 | ftrace_filtered = 1; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 991 | pg = ftrace_pages_start; |
| 992 | while (pg) { |
| 993 | for (i = 0; i < pg->index; i++) { |
| 994 | int matched = 0; |
| 995 | char *ptr; |
| 996 | |
| 997 | rec = &pg->records[i]; |
| 998 | if (rec->flags & FTRACE_FL_FAILED) |
| 999 | continue; |
| 1000 | kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); |
| 1001 | switch (type) { |
| 1002 | case MATCH_FULL: |
| 1003 | if (strcmp(str, buff) == 0) |
| 1004 | matched = 1; |
| 1005 | break; |
| 1006 | case MATCH_FRONT_ONLY: |
| 1007 | if (memcmp(str, buff, match) == 0) |
| 1008 | matched = 1; |
| 1009 | break; |
| 1010 | case MATCH_MIDDLE_ONLY: |
| 1011 | if (strstr(str, search)) |
| 1012 | matched = 1; |
| 1013 | break; |
| 1014 | case MATCH_END_ONLY: |
| 1015 | ptr = strstr(str, search); |
| 1016 | if (ptr && (ptr[search_len] == 0)) |
| 1017 | matched = 1; |
| 1018 | break; |
| 1019 | } |
| 1020 | if (matched) |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1021 | rec->flags |= flag; |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1022 | } |
| 1023 | pg = pg->next; |
| 1024 | } |
Steven Rostedt | 99ecdc4 | 2008-08-15 21:40:05 -0400 | [diff] [blame] | 1025 | spin_unlock(&ftrace_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1028 | static ssize_t |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1029 | ftrace_regex_write(struct file *file, const char __user *ubuf, |
| 1030 | size_t cnt, loff_t *ppos, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1031 | { |
| 1032 | struct ftrace_iterator *iter; |
| 1033 | char ch; |
| 1034 | size_t read = 0; |
| 1035 | ssize_t ret; |
| 1036 | |
| 1037 | if (!cnt || cnt < 0) |
| 1038 | return 0; |
| 1039 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1040 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1041 | |
| 1042 | if (file->f_mode & FMODE_READ) { |
| 1043 | struct seq_file *m = file->private_data; |
| 1044 | iter = m->private; |
| 1045 | } else |
| 1046 | iter = file->private_data; |
| 1047 | |
| 1048 | if (!*ppos) { |
| 1049 | iter->flags &= ~FTRACE_ITER_CONT; |
| 1050 | iter->buffer_idx = 0; |
| 1051 | } |
| 1052 | |
| 1053 | ret = get_user(ch, ubuf++); |
| 1054 | if (ret) |
| 1055 | goto out; |
| 1056 | read++; |
| 1057 | cnt--; |
| 1058 | |
| 1059 | if (!(iter->flags & ~FTRACE_ITER_CONT)) { |
| 1060 | /* skip white space */ |
| 1061 | while (cnt && isspace(ch)) { |
| 1062 | ret = get_user(ch, ubuf++); |
| 1063 | if (ret) |
| 1064 | goto out; |
| 1065 | read++; |
| 1066 | cnt--; |
| 1067 | } |
| 1068 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1069 | if (isspace(ch)) { |
| 1070 | file->f_pos += read; |
| 1071 | ret = read; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
| 1075 | iter->buffer_idx = 0; |
| 1076 | } |
| 1077 | |
| 1078 | while (cnt && !isspace(ch)) { |
| 1079 | if (iter->buffer_idx < FTRACE_BUFF_MAX) |
| 1080 | iter->buffer[iter->buffer_idx++] = ch; |
| 1081 | else { |
| 1082 | ret = -EINVAL; |
| 1083 | goto out; |
| 1084 | } |
| 1085 | ret = get_user(ch, ubuf++); |
| 1086 | if (ret) |
| 1087 | goto out; |
| 1088 | read++; |
| 1089 | cnt--; |
| 1090 | } |
| 1091 | |
| 1092 | if (isspace(ch)) { |
| 1093 | iter->filtered++; |
| 1094 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1095 | ftrace_match(iter->buffer, iter->buffer_idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1096 | iter->buffer_idx = 0; |
| 1097 | } else |
| 1098 | iter->flags |= FTRACE_ITER_CONT; |
| 1099 | |
| 1100 | |
| 1101 | file->f_pos += read; |
| 1102 | |
| 1103 | ret = read; |
| 1104 | out: |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1105 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1106 | |
| 1107 | return ret; |
| 1108 | } |
| 1109 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1110 | static ssize_t |
| 1111 | ftrace_filter_write(struct file *file, const char __user *ubuf, |
| 1112 | size_t cnt, loff_t *ppos) |
| 1113 | { |
| 1114 | return ftrace_regex_write(file, ubuf, cnt, ppos, 1); |
| 1115 | } |
| 1116 | |
| 1117 | static ssize_t |
| 1118 | ftrace_notrace_write(struct file *file, const char __user *ubuf, |
| 1119 | size_t cnt, loff_t *ppos) |
| 1120 | { |
| 1121 | return ftrace_regex_write(file, ubuf, cnt, ppos, 0); |
| 1122 | } |
| 1123 | |
| 1124 | static void |
| 1125 | ftrace_set_regex(unsigned char *buf, int len, int reset, int enable) |
| 1126 | { |
| 1127 | if (unlikely(ftrace_disabled)) |
| 1128 | return; |
| 1129 | |
| 1130 | mutex_lock(&ftrace_regex_lock); |
| 1131 | if (reset) |
| 1132 | ftrace_filter_reset(enable); |
| 1133 | if (buf) |
| 1134 | ftrace_match(buf, len, enable); |
| 1135 | mutex_unlock(&ftrace_regex_lock); |
| 1136 | } |
| 1137 | |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1138 | /** |
| 1139 | * ftrace_set_filter - set a function to filter on in ftrace |
| 1140 | * @buf - the string that holds the function filter text. |
| 1141 | * @len - the length of the string. |
| 1142 | * @reset - non zero to reset all filters before applying this filter. |
| 1143 | * |
| 1144 | * Filters denote which functions should be enabled when tracing is enabled. |
| 1145 | * If @buf is NULL and reset is set, all functions will be enabled for tracing. |
| 1146 | */ |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1147 | void ftrace_set_filter(unsigned char *buf, int len, int reset) |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1148 | { |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1149 | ftrace_set_regex(buf, len, reset, 1); |
| 1150 | } |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1151 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1152 | /** |
| 1153 | * ftrace_set_notrace - set a function to not trace in ftrace |
| 1154 | * @buf - the string that holds the function notrace text. |
| 1155 | * @len - the length of the string. |
| 1156 | * @reset - non zero to reset all filters before applying this filter. |
| 1157 | * |
| 1158 | * Notrace Filters denote which functions should not be enabled when tracing |
| 1159 | * is enabled. If @buf is NULL and reset is set, all functions will be enabled |
| 1160 | * for tracing. |
| 1161 | */ |
| 1162 | void ftrace_set_notrace(unsigned char *buf, int len, int reset) |
| 1163 | { |
| 1164 | ftrace_set_regex(buf, len, reset, 0); |
Steven Rostedt | 77a2b37 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1165 | } |
| 1166 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1167 | static int |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1168 | ftrace_regex_release(struct inode *inode, struct file *file, int enable) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1169 | { |
| 1170 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 1171 | struct ftrace_iterator *iter; |
| 1172 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1173 | mutex_lock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1174 | if (file->f_mode & FMODE_READ) { |
| 1175 | iter = m->private; |
| 1176 | |
| 1177 | seq_release(inode, file); |
| 1178 | } else |
| 1179 | iter = file->private_data; |
| 1180 | |
| 1181 | if (iter->buffer_idx) { |
| 1182 | iter->filtered++; |
| 1183 | iter->buffer[iter->buffer_idx] = 0; |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1184 | ftrace_match(iter->buffer, iter->buffer_idx, enable); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | mutex_lock(&ftrace_sysctl_lock); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 1188 | mutex_lock(&ftrace_start_lock); |
| 1189 | if (iter->filtered && ftrace_start && ftrace_enabled) |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1190 | ftrace_run_update_code(FTRACE_ENABLE_CALLS); |
Steven Rostedt | cb7be3b | 2008-10-23 09:33:05 -0400 | [diff] [blame] | 1191 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1192 | mutex_unlock(&ftrace_sysctl_lock); |
| 1193 | |
| 1194 | kfree(iter); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1195 | mutex_unlock(&ftrace_regex_lock); |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1196 | return 0; |
| 1197 | } |
| 1198 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1199 | static int |
| 1200 | ftrace_filter_release(struct inode *inode, struct file *file) |
| 1201 | { |
| 1202 | return ftrace_regex_release(inode, file, 1); |
| 1203 | } |
| 1204 | |
| 1205 | static int |
| 1206 | ftrace_notrace_release(struct inode *inode, struct file *file) |
| 1207 | { |
| 1208 | return ftrace_regex_release(inode, file, 0); |
| 1209 | } |
| 1210 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1211 | static struct file_operations ftrace_avail_fops = { |
| 1212 | .open = ftrace_avail_open, |
| 1213 | .read = seq_read, |
| 1214 | .llseek = seq_lseek, |
| 1215 | .release = ftrace_avail_release, |
| 1216 | }; |
| 1217 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1218 | static struct file_operations ftrace_failures_fops = { |
| 1219 | .open = ftrace_failures_open, |
| 1220 | .read = seq_read, |
| 1221 | .llseek = seq_lseek, |
| 1222 | .release = ftrace_avail_release, |
| 1223 | }; |
| 1224 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1225 | static struct file_operations ftrace_filter_fops = { |
| 1226 | .open = ftrace_filter_open, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1227 | .read = ftrace_regex_read, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1228 | .write = ftrace_filter_write, |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1229 | .llseek = ftrace_regex_lseek, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1230 | .release = ftrace_filter_release, |
| 1231 | }; |
| 1232 | |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1233 | static struct file_operations ftrace_notrace_fops = { |
| 1234 | .open = ftrace_notrace_open, |
| 1235 | .read = ftrace_regex_read, |
| 1236 | .write = ftrace_notrace_write, |
| 1237 | .llseek = ftrace_regex_lseek, |
| 1238 | .release = ftrace_notrace_release, |
| 1239 | }; |
| 1240 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1241 | static __init int ftrace_init_debugfs(void) |
| 1242 | { |
| 1243 | struct dentry *d_tracer; |
| 1244 | struct dentry *entry; |
| 1245 | |
| 1246 | d_tracer = tracing_init_dentry(); |
| 1247 | |
| 1248 | entry = debugfs_create_file("available_filter_functions", 0444, |
| 1249 | d_tracer, NULL, &ftrace_avail_fops); |
| 1250 | if (!entry) |
| 1251 | pr_warning("Could not create debugfs " |
| 1252 | "'available_filter_functions' entry\n"); |
| 1253 | |
Abhishek Sagar | eb9a7bf | 2008-06-01 21:47:54 +0530 | [diff] [blame] | 1254 | entry = debugfs_create_file("failures", 0444, |
| 1255 | d_tracer, NULL, &ftrace_failures_fops); |
| 1256 | if (!entry) |
| 1257 | pr_warning("Could not create debugfs 'failures' entry\n"); |
| 1258 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1259 | entry = debugfs_create_file("set_ftrace_filter", 0644, d_tracer, |
| 1260 | NULL, &ftrace_filter_fops); |
| 1261 | if (!entry) |
| 1262 | pr_warning("Could not create debugfs " |
| 1263 | "'set_ftrace_filter' entry\n"); |
Steven Rostedt | 41c52c0 | 2008-05-22 11:46:33 -0400 | [diff] [blame] | 1264 | |
| 1265 | entry = debugfs_create_file("set_ftrace_notrace", 0644, d_tracer, |
| 1266 | NULL, &ftrace_notrace_fops); |
| 1267 | if (!entry) |
| 1268 | pr_warning("Could not create debugfs " |
| 1269 | "'set_ftrace_notrace' entry\n"); |
Steven Rostedt | ad90c0e | 2008-05-27 20:48:37 -0400 | [diff] [blame] | 1270 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1271 | return 0; |
| 1272 | } |
| 1273 | |
| 1274 | fs_initcall(ftrace_init_debugfs); |
| 1275 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1276 | static int ftrace_convert_nops(unsigned long *start, |
| 1277 | unsigned long *end) |
| 1278 | { |
| 1279 | unsigned long *p; |
| 1280 | unsigned long addr; |
| 1281 | unsigned long flags; |
| 1282 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1283 | mutex_lock(&ftrace_start_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1284 | p = start; |
| 1285 | while (p < end) { |
| 1286 | addr = ftrace_call_adjust(*p++); |
| 1287 | ftrace_record_ip(addr); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1290 | /* disable interrupts to prevent kstop machine */ |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1291 | local_irq_save(flags); |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1292 | ftrace_update_code(); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1293 | local_irq_restore(flags); |
Steven Rostedt | 08f5ac90 | 2008-10-23 09:33:07 -0400 | [diff] [blame] | 1294 | mutex_unlock(&ftrace_start_lock); |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 1299 | void ftrace_init_module(unsigned long *start, unsigned long *end) |
| 1300 | { |
Steven Rostedt | 00fd61a | 2008-08-15 21:40:04 -0400 | [diff] [blame] | 1301 | if (ftrace_disabled || start == end) |
Steven Rostedt | fed1939 | 2008-08-14 22:47:19 -0400 | [diff] [blame] | 1302 | return; |
Steven Rostedt | 90d595f | 2008-08-14 15:45:09 -0400 | [diff] [blame] | 1303 | ftrace_convert_nops(start, end); |
| 1304 | } |
| 1305 | |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1306 | extern unsigned long __start_mcount_loc[]; |
| 1307 | extern unsigned long __stop_mcount_loc[]; |
| 1308 | |
| 1309 | void __init ftrace_init(void) |
| 1310 | { |
| 1311 | unsigned long count, addr, flags; |
| 1312 | int ret; |
| 1313 | |
| 1314 | /* Keep the ftrace pointer to the stub */ |
| 1315 | addr = (unsigned long)ftrace_stub; |
| 1316 | |
| 1317 | local_irq_save(flags); |
| 1318 | ftrace_dyn_arch_init(&addr); |
| 1319 | local_irq_restore(flags); |
| 1320 | |
| 1321 | /* ftrace_dyn_arch_init places the return code in addr */ |
| 1322 | if (addr) |
| 1323 | goto failed; |
| 1324 | |
| 1325 | count = __stop_mcount_loc - __start_mcount_loc; |
| 1326 | |
| 1327 | ret = ftrace_dyn_table_alloc(count); |
| 1328 | if (ret) |
| 1329 | goto failed; |
| 1330 | |
| 1331 | last_ftrace_enabled = ftrace_enabled = 1; |
| 1332 | |
| 1333 | ret = ftrace_convert_nops(__start_mcount_loc, |
| 1334 | __stop_mcount_loc); |
| 1335 | |
| 1336 | return; |
| 1337 | failed: |
| 1338 | ftrace_disabled = 1; |
| 1339 | } |
Steven Rostedt | 68bf21a | 2008-08-14 15:45:08 -0400 | [diff] [blame] | 1340 | |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1341 | #else |
Ingo Molnar | c7aafc5 | 2008-05-12 21:20:45 +0200 | [diff] [blame] | 1342 | # define ftrace_startup() do { } while (0) |
| 1343 | # define ftrace_shutdown() do { } while (0) |
| 1344 | # define ftrace_startup_sysctl() do { } while (0) |
| 1345 | # define ftrace_shutdown_sysctl() do { } while (0) |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1346 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 1347 | |
| 1348 | /** |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 1349 | * ftrace_kill - kill ftrace |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1350 | * |
| 1351 | * This function should be used by panic code. It stops ftrace |
| 1352 | * but in a not so nice way. If you need to simply kill ftrace |
| 1353 | * from a non-atomic section, use ftrace_kill. |
| 1354 | */ |
Steven Rostedt | 81adbdc | 2008-10-23 09:33:02 -0400 | [diff] [blame] | 1355 | void ftrace_kill(void) |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1356 | { |
| 1357 | ftrace_disabled = 1; |
| 1358 | ftrace_enabled = 0; |
Steven Rostedt | a2bb6a3 | 2008-07-10 20:58:15 -0400 | [diff] [blame] | 1359 | clear_ftrace_function(); |
| 1360 | } |
| 1361 | |
| 1362 | /** |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1363 | * register_ftrace_function - register a function for profiling |
| 1364 | * @ops - ops structure that holds the function for profiling. |
| 1365 | * |
| 1366 | * Register a function to be called by all functions in the |
| 1367 | * kernel. |
| 1368 | * |
| 1369 | * Note: @ops->func and all the functions it calls must be labeled |
| 1370 | * with "notrace", otherwise it will go into a |
| 1371 | * recursive loop. |
| 1372 | */ |
| 1373 | int register_ftrace_function(struct ftrace_ops *ops) |
| 1374 | { |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1375 | int ret; |
| 1376 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1377 | if (unlikely(ftrace_disabled)) |
| 1378 | return -1; |
| 1379 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1380 | mutex_lock(&ftrace_sysctl_lock); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1381 | ret = __register_ftrace_function(ops); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1382 | ftrace_startup(); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1383 | mutex_unlock(&ftrace_sysctl_lock); |
| 1384 | |
| 1385 | return ret; |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /** |
| 1389 | * unregister_ftrace_function - unresgister a function for profiling. |
| 1390 | * @ops - ops structure that holds the function to unregister |
| 1391 | * |
| 1392 | * Unregister a function that was added to be called by ftrace profiling. |
| 1393 | */ |
| 1394 | int unregister_ftrace_function(struct ftrace_ops *ops) |
| 1395 | { |
| 1396 | int ret; |
| 1397 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1398 | mutex_lock(&ftrace_sysctl_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1399 | ret = __unregister_ftrace_function(ops); |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1400 | ftrace_shutdown(); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1401 | mutex_unlock(&ftrace_sysctl_lock); |
| 1402 | |
| 1403 | return ret; |
| 1404 | } |
| 1405 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 1406 | int |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1407 | ftrace_enable_sysctl(struct ctl_table *table, int write, |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1408 | struct file *file, void __user *buffer, size_t *lenp, |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1409 | loff_t *ppos) |
| 1410 | { |
| 1411 | int ret; |
| 1412 | |
Steven Rostedt | 4eebcc8 | 2008-05-12 21:20:48 +0200 | [diff] [blame] | 1413 | if (unlikely(ftrace_disabled)) |
| 1414 | return -ENODEV; |
| 1415 | |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1416 | mutex_lock(&ftrace_sysctl_lock); |
| 1417 | |
Steven Rostedt | 5072c59 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1418 | ret = proc_dointvec(table, write, file, buffer, lenp, ppos); |
Steven Rostedt | b0fc494 | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 1419 | |
| 1420 | if (ret || !write || (last_ftrace_enabled == ftrace_enabled)) |
| 1421 | goto out; |
| 1422 | |
| 1423 | last_ftrace_enabled = ftrace_enabled; |
| 1424 | |
| 1425 | if (ftrace_enabled) { |
| 1426 | |
| 1427 | ftrace_startup_sysctl(); |
| 1428 | |
| 1429 | /* we are starting ftrace again */ |
| 1430 | if (ftrace_list != &ftrace_list_end) { |
| 1431 | if (ftrace_list->next == &ftrace_list_end) |
| 1432 | ftrace_trace_function = ftrace_list->func; |
| 1433 | else |
| 1434 | ftrace_trace_function = ftrace_list_func; |
| 1435 | } |
| 1436 | |
| 1437 | } else { |
| 1438 | /* stopping ftrace calls (just send to ftrace_stub) */ |
| 1439 | ftrace_trace_function = ftrace_stub; |
| 1440 | |
| 1441 | ftrace_shutdown_sysctl(); |
| 1442 | } |
| 1443 | |
| 1444 | out: |
| 1445 | mutex_unlock(&ftrace_sysctl_lock); |
Steven Rostedt | 3d08339 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1446 | return ret; |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 1447 | } |
Ingo Molnar | f17845e | 2008-10-24 12:47:10 +0200 | [diff] [blame] | 1448 | |