diff options
author | Steven Rostedt <srostedt@redhat.com> | 2011-04-27 21:43:36 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2011-04-29 22:53:11 -0400 |
commit | 491d0dcfb9707e1f83eff93ca503eb7573162ef2 (patch) | |
tree | ab156f8c4bc8ebfcc7429533a34726226a11bbba /kernel/trace/ftrace.c | |
parent | 996e87be7f537fb34638875dd37083166c733425 (diff) |
ftrace: Consolidate updating of ftrace_trace_function
There are three locations that perform almost identical functions in order
to update the ftrace_trace_function (the ftrace function variable that gets
called by mcount).
Consolidate these into a single function called update_ftrace_function().
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/ftrace.c')
-rw-r--r-- | kernel/trace/ftrace.c | 95 |
1 files changed, 34 insertions, 61 deletions
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 5b758ea344ce..33bcc71ca09a 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c | |||
@@ -151,6 +151,34 @@ static void ftrace_test_stop_func(unsigned long ip, unsigned long parent_ip) | |||
151 | } | 151 | } |
152 | #endif | 152 | #endif |
153 | 153 | ||
154 | static void update_ftrace_function(void) | ||
155 | { | ||
156 | ftrace_func_t func; | ||
157 | |||
158 | /* | ||
159 | * If there's only one function registered, then call that | ||
160 | * function directly. Otherwise, we need to iterate over the | ||
161 | * registered callers. | ||
162 | */ | ||
163 | if (ftrace_list == &ftrace_list_end || | ||
164 | ftrace_list->next == &ftrace_list_end) | ||
165 | func = ftrace_list->func; | ||
166 | else | ||
167 | func = ftrace_list_func; | ||
168 | |||
169 | /* If we filter on pids, update to use the pid function */ | ||
170 | if (!list_empty(&ftrace_pids)) { | ||
171 | set_ftrace_pid_function(func); | ||
172 | func = ftrace_pid_func; | ||
173 | } | ||
174 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
175 | ftrace_trace_function = func; | ||
176 | #else | ||
177 | __ftrace_trace_function = func; | ||
178 | ftrace_trace_function = ftrace_test_stop_func; | ||
179 | #endif | ||
180 | } | ||
181 | |||
154 | static int __register_ftrace_function(struct ftrace_ops *ops) | 182 | static int __register_ftrace_function(struct ftrace_ops *ops) |
155 | { | 183 | { |
156 | ops->next = ftrace_list; | 184 | ops->next = ftrace_list; |
@@ -162,30 +190,8 @@ static int __register_ftrace_function(struct ftrace_ops *ops) | |||
162 | */ | 190 | */ |
163 | rcu_assign_pointer(ftrace_list, ops); | 191 | rcu_assign_pointer(ftrace_list, ops); |
164 | 192 | ||
165 | if (ftrace_enabled) { | 193 | if (ftrace_enabled) |
166 | ftrace_func_t func; | 194 | update_ftrace_function(); |
167 | |||
168 | if (ops->next == &ftrace_list_end) | ||
169 | func = ops->func; | ||
170 | else | ||
171 | func = ftrace_list_func; | ||
172 | |||
173 | if (!list_empty(&ftrace_pids)) { | ||
174 | set_ftrace_pid_function(func); | ||
175 | func = ftrace_pid_func; | ||
176 | } | ||
177 | |||
178 | /* | ||
179 | * For one func, simply call it directly. | ||
180 | * For more than one func, call the chain. | ||
181 | */ | ||
182 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
183 | ftrace_trace_function = func; | ||
184 | #else | ||
185 | __ftrace_trace_function = func; | ||
186 | ftrace_trace_function = ftrace_test_stop_func; | ||
187 | #endif | ||
188 | } | ||
189 | 195 | ||
190 | return 0; | 196 | return 0; |
191 | } | 197 | } |
@@ -213,52 +219,19 @@ static int __unregister_ftrace_function(struct ftrace_ops *ops) | |||
213 | 219 | ||
214 | *p = (*p)->next; | 220 | *p = (*p)->next; |
215 | 221 | ||
216 | if (ftrace_enabled) { | 222 | if (ftrace_enabled) |
217 | /* If we only have one func left, then call that directly */ | 223 | update_ftrace_function(); |
218 | if (ftrace_list->next == &ftrace_list_end) { | ||
219 | ftrace_func_t func = ftrace_list->func; | ||
220 | |||
221 | if (!list_empty(&ftrace_pids)) { | ||
222 | set_ftrace_pid_function(func); | ||
223 | func = ftrace_pid_func; | ||
224 | } | ||
225 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
226 | ftrace_trace_function = func; | ||
227 | #else | ||
228 | __ftrace_trace_function = func; | ||
229 | #endif | ||
230 | } | ||
231 | } | ||
232 | 224 | ||
233 | return 0; | 225 | return 0; |
234 | } | 226 | } |
235 | 227 | ||
236 | static void ftrace_update_pid_func(void) | 228 | static void ftrace_update_pid_func(void) |
237 | { | 229 | { |
238 | ftrace_func_t func; | 230 | /* Only do something if we are tracing something */ |
239 | |||
240 | if (ftrace_trace_function == ftrace_stub) | 231 | if (ftrace_trace_function == ftrace_stub) |
241 | return; | 232 | return; |
242 | 233 | ||
243 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | 234 | update_ftrace_function(); |
244 | func = ftrace_trace_function; | ||
245 | #else | ||
246 | func = __ftrace_trace_function; | ||
247 | #endif | ||
248 | |||
249 | if (!list_empty(&ftrace_pids)) { | ||
250 | set_ftrace_pid_function(func); | ||
251 | func = ftrace_pid_func; | ||
252 | } else { | ||
253 | if (func == ftrace_pid_func) | ||
254 | func = ftrace_pid_function; | ||
255 | } | ||
256 | |||
257 | #ifdef CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST | ||
258 | ftrace_trace_function = func; | ||
259 | #else | ||
260 | __ftrace_trace_function = func; | ||
261 | #endif | ||
262 | } | 235 | } |
263 | 236 | ||
264 | #ifdef CONFIG_FUNCTION_PROFILER | 237 | #ifdef CONFIG_FUNCTION_PROFILER |