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