Commit | Line | Data |
---|---|---|
b77e38aa SR |
1 | /* |
2 | * event tracer | |
3 | * | |
4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | |
5 | * | |
981d081e SR |
6 | * - Added format output of fields of the trace point. |
7 | * This was based off of work by Tom Zanussi <tzanussi@gmail.com>. | |
8 | * | |
b77e38aa SR |
9 | */ |
10 | ||
e6187007 SR |
11 | #include <linux/workqueue.h> |
12 | #include <linux/spinlock.h> | |
13 | #include <linux/kthread.h> | |
b77e38aa SR |
14 | #include <linux/debugfs.h> |
15 | #include <linux/uaccess.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/ctype.h> | |
5a0e3ad6 | 18 | #include <linux/slab.h> |
e6187007 | 19 | #include <linux/delay.h> |
b77e38aa | 20 | |
020e5f85 LZ |
21 | #include <asm/setup.h> |
22 | ||
91729ef9 | 23 | #include "trace_output.h" |
b77e38aa | 24 | |
4e5292ea | 25 | #undef TRACE_SYSTEM |
b628b3e6 SR |
26 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
27 | ||
20c8928a | 28 | DEFINE_MUTEX(event_mutex); |
11a241a3 | 29 | |
04295780 SR |
30 | DEFINE_MUTEX(event_storage_mutex); |
31 | EXPORT_SYMBOL_GPL(event_storage_mutex); | |
32 | ||
33 | char event_storage[EVENT_STORAGE_SIZE]; | |
34 | EXPORT_SYMBOL_GPL(event_storage); | |
35 | ||
a59fd602 | 36 | LIST_HEAD(ftrace_events); |
b3a8c6fd | 37 | static LIST_HEAD(ftrace_common_fields); |
a59fd602 | 38 | |
d1a29143 SR |
39 | #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO) |
40 | ||
41 | static struct kmem_cache *field_cachep; | |
42 | static struct kmem_cache *file_cachep; | |
43 | ||
e6929efa SR |
44 | #define SYSTEM_FL_FREE_NAME (1 << 31) |
45 | ||
46 | static inline int system_refcount(struct event_subsystem *system) | |
47 | { | |
48 | return system->ref_count & ~SYSTEM_FL_FREE_NAME; | |
49 | } | |
50 | ||
51 | static int system_refcount_inc(struct event_subsystem *system) | |
52 | { | |
53 | return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME; | |
54 | } | |
55 | ||
56 | static int system_refcount_dec(struct event_subsystem *system) | |
57 | { | |
58 | return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME; | |
59 | } | |
60 | ||
ae63b31e SR |
61 | /* Double loops, do not use break, only goto's work */ |
62 | #define do_for_each_event_file(tr, file) \ | |
63 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ | |
64 | list_for_each_entry(file, &tr->events, list) | |
65 | ||
66 | #define do_for_each_event_file_safe(tr, file) \ | |
67 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ | |
68 | struct ftrace_event_file *___n; \ | |
69 | list_for_each_entry_safe(file, ___n, &tr->events, list) | |
70 | ||
71 | #define while_for_each_event_file() \ | |
72 | } | |
73 | ||
b3a8c6fd | 74 | static struct list_head * |
2e33af02 SR |
75 | trace_get_fields(struct ftrace_event_call *event_call) |
76 | { | |
77 | if (!event_call->class->get_fields) | |
78 | return &event_call->class->fields; | |
79 | return event_call->class->get_fields(event_call); | |
80 | } | |
81 | ||
b3a8c6fd J |
82 | static struct ftrace_event_field * |
83 | __find_event_field(struct list_head *head, char *name) | |
84 | { | |
85 | struct ftrace_event_field *field; | |
86 | ||
87 | list_for_each_entry(field, head, link) { | |
88 | if (!strcmp(field->name, name)) | |
89 | return field; | |
90 | } | |
91 | ||
92 | return NULL; | |
93 | } | |
94 | ||
95 | struct ftrace_event_field * | |
96 | trace_find_event_field(struct ftrace_event_call *call, char *name) | |
97 | { | |
98 | struct ftrace_event_field *field; | |
99 | struct list_head *head; | |
100 | ||
101 | field = __find_event_field(&ftrace_common_fields, name); | |
102 | if (field) | |
103 | return field; | |
104 | ||
105 | head = trace_get_fields(call); | |
106 | return __find_event_field(head, name); | |
107 | } | |
108 | ||
8728fe50 LZ |
109 | static int __trace_define_field(struct list_head *head, const char *type, |
110 | const char *name, int offset, int size, | |
111 | int is_signed, int filter_type) | |
cf027f64 TZ |
112 | { |
113 | struct ftrace_event_field *field; | |
114 | ||
d1a29143 | 115 | field = kmem_cache_alloc(field_cachep, GFP_TRACE); |
cf027f64 | 116 | if (!field) |
b0cfaffa | 117 | return -ENOMEM; |
fe9f57f2 | 118 | |
92edca07 SR |
119 | field->name = name; |
120 | field->type = type; | |
fe9f57f2 | 121 | |
43b51ead LZ |
122 | if (filter_type == FILTER_OTHER) |
123 | field->filter_type = filter_assign_type(type); | |
124 | else | |
125 | field->filter_type = filter_type; | |
126 | ||
cf027f64 TZ |
127 | field->offset = offset; |
128 | field->size = size; | |
a118e4d1 | 129 | field->is_signed = is_signed; |
aa38e9fc | 130 | |
2e33af02 | 131 | list_add(&field->link, head); |
cf027f64 TZ |
132 | |
133 | return 0; | |
cf027f64 | 134 | } |
8728fe50 LZ |
135 | |
136 | int trace_define_field(struct ftrace_event_call *call, const char *type, | |
137 | const char *name, int offset, int size, int is_signed, | |
138 | int filter_type) | |
139 | { | |
140 | struct list_head *head; | |
141 | ||
142 | if (WARN_ON(!call->class)) | |
143 | return 0; | |
144 | ||
145 | head = trace_get_fields(call); | |
146 | return __trace_define_field(head, type, name, offset, size, | |
147 | is_signed, filter_type); | |
148 | } | |
17c873ec | 149 | EXPORT_SYMBOL_GPL(trace_define_field); |
cf027f64 | 150 | |
e647d6b3 | 151 | #define __common_field(type, item) \ |
8728fe50 LZ |
152 | ret = __trace_define_field(&ftrace_common_fields, #type, \ |
153 | "common_" #item, \ | |
154 | offsetof(typeof(ent), item), \ | |
155 | sizeof(ent.item), \ | |
156 | is_signed_type(type), FILTER_OTHER); \ | |
e647d6b3 LZ |
157 | if (ret) \ |
158 | return ret; | |
159 | ||
8728fe50 | 160 | static int trace_define_common_fields(void) |
e647d6b3 LZ |
161 | { |
162 | int ret; | |
163 | struct trace_entry ent; | |
164 | ||
165 | __common_field(unsigned short, type); | |
166 | __common_field(unsigned char, flags); | |
167 | __common_field(unsigned char, preempt_count); | |
168 | __common_field(int, pid); | |
e647d6b3 LZ |
169 | |
170 | return ret; | |
171 | } | |
172 | ||
ad7067ce | 173 | static void trace_destroy_fields(struct ftrace_event_call *call) |
2df75e41 LZ |
174 | { |
175 | struct ftrace_event_field *field, *next; | |
2e33af02 | 176 | struct list_head *head; |
2df75e41 | 177 | |
2e33af02 SR |
178 | head = trace_get_fields(call); |
179 | list_for_each_entry_safe(field, next, head, link) { | |
2df75e41 | 180 | list_del(&field->link); |
d1a29143 | 181 | kmem_cache_free(field_cachep, field); |
2df75e41 LZ |
182 | } |
183 | } | |
184 | ||
87d9b4e1 LZ |
185 | int trace_event_raw_init(struct ftrace_event_call *call) |
186 | { | |
187 | int id; | |
188 | ||
80decc70 | 189 | id = register_ftrace_event(&call->event); |
87d9b4e1 LZ |
190 | if (!id) |
191 | return -ENODEV; | |
87d9b4e1 LZ |
192 | |
193 | return 0; | |
194 | } | |
195 | EXPORT_SYMBOL_GPL(trace_event_raw_init); | |
196 | ||
ceec0b6f JO |
197 | int ftrace_event_reg(struct ftrace_event_call *call, |
198 | enum trace_reg type, void *data) | |
a1d0ce82 | 199 | { |
ae63b31e SR |
200 | struct ftrace_event_file *file = data; |
201 | ||
a1d0ce82 SR |
202 | switch (type) { |
203 | case TRACE_REG_REGISTER: | |
204 | return tracepoint_probe_register(call->name, | |
205 | call->class->probe, | |
ae63b31e | 206 | file); |
a1d0ce82 SR |
207 | case TRACE_REG_UNREGISTER: |
208 | tracepoint_probe_unregister(call->name, | |
209 | call->class->probe, | |
ae63b31e | 210 | file); |
a1d0ce82 SR |
211 | return 0; |
212 | ||
213 | #ifdef CONFIG_PERF_EVENTS | |
214 | case TRACE_REG_PERF_REGISTER: | |
215 | return tracepoint_probe_register(call->name, | |
216 | call->class->perf_probe, | |
217 | call); | |
218 | case TRACE_REG_PERF_UNREGISTER: | |
219 | tracepoint_probe_unregister(call->name, | |
220 | call->class->perf_probe, | |
221 | call); | |
222 | return 0; | |
ceec0b6f JO |
223 | case TRACE_REG_PERF_OPEN: |
224 | case TRACE_REG_PERF_CLOSE: | |
489c75c3 JO |
225 | case TRACE_REG_PERF_ADD: |
226 | case TRACE_REG_PERF_DEL: | |
ceec0b6f | 227 | return 0; |
a1d0ce82 SR |
228 | #endif |
229 | } | |
230 | return 0; | |
231 | } | |
232 | EXPORT_SYMBOL_GPL(ftrace_event_reg); | |
233 | ||
e870e9a1 LZ |
234 | void trace_event_enable_cmd_record(bool enable) |
235 | { | |
ae63b31e SR |
236 | struct ftrace_event_file *file; |
237 | struct trace_array *tr; | |
e870e9a1 LZ |
238 | |
239 | mutex_lock(&event_mutex); | |
ae63b31e SR |
240 | do_for_each_event_file(tr, file) { |
241 | ||
242 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) | |
e870e9a1 LZ |
243 | continue; |
244 | ||
245 | if (enable) { | |
246 | tracing_start_cmdline_record(); | |
417944c4 | 247 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 LZ |
248 | } else { |
249 | tracing_stop_cmdline_record(); | |
417944c4 | 250 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 251 | } |
ae63b31e | 252 | } while_for_each_event_file(); |
e870e9a1 LZ |
253 | mutex_unlock(&event_mutex); |
254 | } | |
255 | ||
417944c4 SRRH |
256 | static int __ftrace_event_enable_disable(struct ftrace_event_file *file, |
257 | int enable, int soft_disable) | |
fd994989 | 258 | { |
ae63b31e | 259 | struct ftrace_event_call *call = file->event_call; |
3b8e4273 | 260 | int ret = 0; |
417944c4 | 261 | int disable; |
3b8e4273 | 262 | |
fd994989 SR |
263 | switch (enable) { |
264 | case 0: | |
417944c4 | 265 | /* |
1cf4c073 MH |
266 | * When soft_disable is set and enable is cleared, the sm_ref |
267 | * reference counter is decremented. If it reaches 0, we want | |
417944c4 SRRH |
268 | * to clear the SOFT_DISABLED flag but leave the event in the |
269 | * state that it was. That is, if the event was enabled and | |
270 | * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED | |
271 | * is set we do not want the event to be enabled before we | |
272 | * clear the bit. | |
273 | * | |
274 | * When soft_disable is not set but the SOFT_MODE flag is, | |
275 | * we do nothing. Do not disable the tracepoint, otherwise | |
276 | * "soft enable"s (clearing the SOFT_DISABLED bit) wont work. | |
277 | */ | |
278 | if (soft_disable) { | |
1cf4c073 MH |
279 | if (atomic_dec_return(&file->sm_ref) > 0) |
280 | break; | |
417944c4 SRRH |
281 | disable = file->flags & FTRACE_EVENT_FL_SOFT_DISABLED; |
282 | clear_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); | |
283 | } else | |
284 | disable = !(file->flags & FTRACE_EVENT_FL_SOFT_MODE); | |
285 | ||
286 | if (disable && (file->flags & FTRACE_EVENT_FL_ENABLED)) { | |
287 | clear_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); | |
ae63b31e | 288 | if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) { |
e870e9a1 | 289 | tracing_stop_cmdline_record(); |
417944c4 | 290 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 291 | } |
ae63b31e | 292 | call->class->reg(call, TRACE_REG_UNREGISTER, file); |
fd994989 | 293 | } |
417944c4 SRRH |
294 | /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT */ |
295 | if (file->flags & FTRACE_EVENT_FL_SOFT_MODE) | |
296 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
fd994989 SR |
297 | break; |
298 | case 1: | |
417944c4 SRRH |
299 | /* |
300 | * When soft_disable is set and enable is set, we want to | |
301 | * register the tracepoint for the event, but leave the event | |
302 | * as is. That means, if the event was already enabled, we do | |
303 | * nothing (but set SOFT_MODE). If the event is disabled, we | |
304 | * set SOFT_DISABLED before enabling the event tracepoint, so | |
305 | * it still seems to be disabled. | |
306 | */ | |
307 | if (!soft_disable) | |
308 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
1cf4c073 MH |
309 | else { |
310 | if (atomic_inc_return(&file->sm_ref) > 1) | |
311 | break; | |
417944c4 | 312 | set_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); |
1cf4c073 | 313 | } |
417944c4 | 314 | |
ae63b31e | 315 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) { |
417944c4 SRRH |
316 | |
317 | /* Keep the event disabled, when going to SOFT_MODE. */ | |
318 | if (soft_disable) | |
319 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
320 | ||
e870e9a1 LZ |
321 | if (trace_flags & TRACE_ITER_RECORD_CMD) { |
322 | tracing_start_cmdline_record(); | |
417944c4 | 323 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 324 | } |
ae63b31e | 325 | ret = call->class->reg(call, TRACE_REG_REGISTER, file); |
3b8e4273 LZ |
326 | if (ret) { |
327 | tracing_stop_cmdline_record(); | |
328 | pr_info("event trace: Could not enable event " | |
329 | "%s\n", call->name); | |
330 | break; | |
331 | } | |
417944c4 | 332 | set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); |
575380da SRRH |
333 | |
334 | /* WAS_ENABLED gets set but never cleared. */ | |
335 | call->flags |= TRACE_EVENT_FL_WAS_ENABLED; | |
fd994989 | 336 | } |
fd994989 SR |
337 | break; |
338 | } | |
3b8e4273 LZ |
339 | |
340 | return ret; | |
fd994989 SR |
341 | } |
342 | ||
417944c4 SRRH |
343 | static int ftrace_event_enable_disable(struct ftrace_event_file *file, |
344 | int enable) | |
345 | { | |
346 | return __ftrace_event_enable_disable(file, enable, 0); | |
347 | } | |
348 | ||
ae63b31e | 349 | static void ftrace_clear_events(struct trace_array *tr) |
0e907c99 | 350 | { |
ae63b31e | 351 | struct ftrace_event_file *file; |
0e907c99 Z |
352 | |
353 | mutex_lock(&event_mutex); | |
ae63b31e SR |
354 | list_for_each_entry(file, &tr->events, list) { |
355 | ftrace_event_enable_disable(file, 0); | |
0e907c99 Z |
356 | } |
357 | mutex_unlock(&event_mutex); | |
358 | } | |
359 | ||
e9dbfae5 SR |
360 | static void __put_system(struct event_subsystem *system) |
361 | { | |
362 | struct event_filter *filter = system->filter; | |
363 | ||
e6929efa SR |
364 | WARN_ON_ONCE(system_refcount(system) == 0); |
365 | if (system_refcount_dec(system)) | |
e9dbfae5 SR |
366 | return; |
367 | ||
ae63b31e SR |
368 | list_del(&system->list); |
369 | ||
e9dbfae5 SR |
370 | if (filter) { |
371 | kfree(filter->filter_string); | |
372 | kfree(filter); | |
373 | } | |
e6929efa SR |
374 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
375 | kfree(system->name); | |
e9dbfae5 SR |
376 | kfree(system); |
377 | } | |
378 | ||
379 | static void __get_system(struct event_subsystem *system) | |
380 | { | |
e6929efa SR |
381 | WARN_ON_ONCE(system_refcount(system) == 0); |
382 | system_refcount_inc(system); | |
e9dbfae5 SR |
383 | } |
384 | ||
ae63b31e SR |
385 | static void __get_system_dir(struct ftrace_subsystem_dir *dir) |
386 | { | |
387 | WARN_ON_ONCE(dir->ref_count == 0); | |
388 | dir->ref_count++; | |
389 | __get_system(dir->subsystem); | |
390 | } | |
391 | ||
392 | static void __put_system_dir(struct ftrace_subsystem_dir *dir) | |
393 | { | |
394 | WARN_ON_ONCE(dir->ref_count == 0); | |
395 | /* If the subsystem is about to be freed, the dir must be too */ | |
e6929efa | 396 | WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1); |
ae63b31e SR |
397 | |
398 | __put_system(dir->subsystem); | |
399 | if (!--dir->ref_count) | |
400 | kfree(dir); | |
401 | } | |
402 | ||
403 | static void put_system(struct ftrace_subsystem_dir *dir) | |
e9dbfae5 SR |
404 | { |
405 | mutex_lock(&event_mutex); | |
ae63b31e | 406 | __put_system_dir(dir); |
e9dbfae5 SR |
407 | mutex_unlock(&event_mutex); |
408 | } | |
409 | ||
c6febdf2 ON |
410 | static void remove_subsystem(struct ftrace_subsystem_dir *dir) |
411 | { | |
412 | if (!dir) | |
413 | return; | |
414 | ||
415 | if (!--dir->nr_events) { | |
416 | debugfs_remove_recursive(dir->entry); | |
417 | list_del(&dir->list); | |
418 | __put_system_dir(dir); | |
419 | } | |
420 | } | |
421 | ||
fdb65fe2 ON |
422 | static void *event_file_data(struct file *filp) |
423 | { | |
424 | return ACCESS_ONCE(file_inode(filp)->i_private); | |
425 | } | |
426 | ||
c6febdf2 ON |
427 | static void remove_event_file_dir(struct ftrace_event_file *file) |
428 | { | |
012dc156 ON |
429 | struct dentry *dir = file->dir; |
430 | struct dentry *child; | |
431 | ||
432 | if (dir) { | |
433 | spin_lock(&dir->d_lock); /* probably unneeded */ | |
434 | list_for_each_entry(child, &dir->d_subdirs, d_u.d_child) { | |
435 | if (child->d_inode) /* probably unneeded */ | |
436 | child->d_inode->i_private = NULL; | |
437 | } | |
438 | spin_unlock(&dir->d_lock); | |
439 | ||
440 | debugfs_remove_recursive(dir); | |
441 | } | |
442 | ||
c6febdf2 | 443 | list_del(&file->list); |
c6febdf2 ON |
444 | remove_subsystem(file->system); |
445 | kmem_cache_free(file_cachep, file); | |
446 | } | |
447 | ||
8f31bfe5 LZ |
448 | /* |
449 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. | |
450 | */ | |
68cebd26 SRRH |
451 | static int |
452 | __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, | |
453 | const char *sub, const char *event, int set) | |
b77e38aa | 454 | { |
ae63b31e | 455 | struct ftrace_event_file *file; |
a59fd602 | 456 | struct ftrace_event_call *call; |
29f93943 | 457 | int ret = -EINVAL; |
8f31bfe5 | 458 | |
ae63b31e SR |
459 | list_for_each_entry(file, &tr->events, list) { |
460 | ||
461 | call = file->event_call; | |
8f31bfe5 | 462 | |
a1d0ce82 | 463 | if (!call->name || !call->class || !call->class->reg) |
8f31bfe5 LZ |
464 | continue; |
465 | ||
9b63776f SR |
466 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
467 | continue; | |
468 | ||
8f31bfe5 LZ |
469 | if (match && |
470 | strcmp(match, call->name) != 0 && | |
8f082018 | 471 | strcmp(match, call->class->system) != 0) |
8f31bfe5 LZ |
472 | continue; |
473 | ||
8f082018 | 474 | if (sub && strcmp(sub, call->class->system) != 0) |
8f31bfe5 LZ |
475 | continue; |
476 | ||
477 | if (event && strcmp(event, call->name) != 0) | |
478 | continue; | |
479 | ||
ae63b31e | 480 | ftrace_event_enable_disable(file, set); |
8f31bfe5 LZ |
481 | |
482 | ret = 0; | |
483 | } | |
68cebd26 SRRH |
484 | |
485 | return ret; | |
486 | } | |
487 | ||
488 | static int __ftrace_set_clr_event(struct trace_array *tr, const char *match, | |
489 | const char *sub, const char *event, int set) | |
490 | { | |
491 | int ret; | |
492 | ||
493 | mutex_lock(&event_mutex); | |
494 | ret = __ftrace_set_clr_event_nolock(tr, match, sub, event, set); | |
8f31bfe5 LZ |
495 | mutex_unlock(&event_mutex); |
496 | ||
497 | return ret; | |
498 | } | |
499 | ||
ae63b31e | 500 | static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set) |
8f31bfe5 | 501 | { |
b628b3e6 | 502 | char *event = NULL, *sub = NULL, *match; |
b628b3e6 SR |
503 | |
504 | /* | |
505 | * The buf format can be <subsystem>:<event-name> | |
506 | * *:<event-name> means any event by that name. | |
507 | * :<event-name> is the same. | |
508 | * | |
509 | * <subsystem>:* means all events in that subsystem | |
510 | * <subsystem>: means the same. | |
511 | * | |
512 | * <name> (no ':') means all events in a subsystem with | |
513 | * the name <name> or any event that matches <name> | |
514 | */ | |
515 | ||
516 | match = strsep(&buf, ":"); | |
517 | if (buf) { | |
518 | sub = match; | |
519 | event = buf; | |
520 | match = NULL; | |
521 | ||
522 | if (!strlen(sub) || strcmp(sub, "*") == 0) | |
523 | sub = NULL; | |
524 | if (!strlen(event) || strcmp(event, "*") == 0) | |
525 | event = NULL; | |
526 | } | |
b77e38aa | 527 | |
ae63b31e | 528 | return __ftrace_set_clr_event(tr, match, sub, event, set); |
b77e38aa SR |
529 | } |
530 | ||
4671c794 SR |
531 | /** |
532 | * trace_set_clr_event - enable or disable an event | |
533 | * @system: system name to match (NULL for any system) | |
534 | * @event: event name to match (NULL for all events, within system) | |
535 | * @set: 1 to enable, 0 to disable | |
536 | * | |
537 | * This is a way for other parts of the kernel to enable or disable | |
538 | * event recording. | |
539 | * | |
540 | * Returns 0 on success, -EINVAL if the parameters do not match any | |
541 | * registered events. | |
542 | */ | |
543 | int trace_set_clr_event(const char *system, const char *event, int set) | |
544 | { | |
ae63b31e SR |
545 | struct trace_array *tr = top_trace_array(); |
546 | ||
547 | return __ftrace_set_clr_event(tr, NULL, system, event, set); | |
4671c794 | 548 | } |
56355b83 | 549 | EXPORT_SYMBOL_GPL(trace_set_clr_event); |
4671c794 | 550 | |
b77e38aa SR |
551 | /* 128 should be much more than enough */ |
552 | #define EVENT_BUF_SIZE 127 | |
553 | ||
554 | static ssize_t | |
555 | ftrace_event_write(struct file *file, const char __user *ubuf, | |
556 | size_t cnt, loff_t *ppos) | |
557 | { | |
48966364 | 558 | struct trace_parser parser; |
ae63b31e SR |
559 | struct seq_file *m = file->private_data; |
560 | struct trace_array *tr = m->private; | |
4ba7978e | 561 | ssize_t read, ret; |
b77e38aa | 562 | |
4ba7978e | 563 | if (!cnt) |
b77e38aa SR |
564 | return 0; |
565 | ||
1852fcce SR |
566 | ret = tracing_update_buffers(); |
567 | if (ret < 0) | |
568 | return ret; | |
569 | ||
48966364 | 570 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
b77e38aa SR |
571 | return -ENOMEM; |
572 | ||
48966364 | 573 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
574 | ||
4ba7978e | 575 | if (read >= 0 && trace_parser_loaded((&parser))) { |
48966364 | 576 | int set = 1; |
b77e38aa | 577 | |
48966364 | 578 | if (*parser.buffer == '!') |
b77e38aa | 579 | set = 0; |
b77e38aa | 580 | |
48966364 | 581 | parser.buffer[parser.idx] = 0; |
582 | ||
ae63b31e | 583 | ret = ftrace_set_clr_event(tr, parser.buffer + !set, set); |
b77e38aa | 584 | if (ret) |
48966364 | 585 | goto out_put; |
b77e38aa | 586 | } |
b77e38aa SR |
587 | |
588 | ret = read; | |
589 | ||
48966364 | 590 | out_put: |
591 | trace_parser_put(&parser); | |
b77e38aa SR |
592 | |
593 | return ret; | |
594 | } | |
595 | ||
596 | static void * | |
597 | t_next(struct seq_file *m, void *v, loff_t *pos) | |
598 | { | |
ae63b31e SR |
599 | struct ftrace_event_file *file = v; |
600 | struct ftrace_event_call *call; | |
601 | struct trace_array *tr = m->private; | |
b77e38aa SR |
602 | |
603 | (*pos)++; | |
604 | ||
ae63b31e SR |
605 | list_for_each_entry_continue(file, &tr->events, list) { |
606 | call = file->event_call; | |
40e26815 SR |
607 | /* |
608 | * The ftrace subsystem is for showing formats only. | |
609 | * They can not be enabled or disabled via the event files. | |
610 | */ | |
a1d0ce82 | 611 | if (call->class && call->class->reg) |
ae63b31e | 612 | return file; |
40e26815 | 613 | } |
b77e38aa | 614 | |
30bd39cd | 615 | return NULL; |
b77e38aa SR |
616 | } |
617 | ||
618 | static void *t_start(struct seq_file *m, loff_t *pos) | |
619 | { | |
ae63b31e SR |
620 | struct ftrace_event_file *file; |
621 | struct trace_array *tr = m->private; | |
e1c7e2a6 LZ |
622 | loff_t l; |
623 | ||
20c8928a | 624 | mutex_lock(&event_mutex); |
e1c7e2a6 | 625 | |
ae63b31e | 626 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
e1c7e2a6 | 627 | for (l = 0; l <= *pos; ) { |
ae63b31e SR |
628 | file = t_next(m, file, &l); |
629 | if (!file) | |
e1c7e2a6 LZ |
630 | break; |
631 | } | |
ae63b31e | 632 | return file; |
b77e38aa SR |
633 | } |
634 | ||
635 | static void * | |
636 | s_next(struct seq_file *m, void *v, loff_t *pos) | |
637 | { | |
ae63b31e SR |
638 | struct ftrace_event_file *file = v; |
639 | struct trace_array *tr = m->private; | |
b77e38aa SR |
640 | |
641 | (*pos)++; | |
642 | ||
ae63b31e SR |
643 | list_for_each_entry_continue(file, &tr->events, list) { |
644 | if (file->flags & FTRACE_EVENT_FL_ENABLED) | |
645 | return file; | |
b77e38aa SR |
646 | } |
647 | ||
30bd39cd | 648 | return NULL; |
b77e38aa SR |
649 | } |
650 | ||
651 | static void *s_start(struct seq_file *m, loff_t *pos) | |
652 | { | |
ae63b31e SR |
653 | struct ftrace_event_file *file; |
654 | struct trace_array *tr = m->private; | |
e1c7e2a6 LZ |
655 | loff_t l; |
656 | ||
20c8928a | 657 | mutex_lock(&event_mutex); |
e1c7e2a6 | 658 | |
ae63b31e | 659 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
e1c7e2a6 | 660 | for (l = 0; l <= *pos; ) { |
ae63b31e SR |
661 | file = s_next(m, file, &l); |
662 | if (!file) | |
e1c7e2a6 LZ |
663 | break; |
664 | } | |
ae63b31e | 665 | return file; |
b77e38aa SR |
666 | } |
667 | ||
668 | static int t_show(struct seq_file *m, void *v) | |
669 | { | |
ae63b31e SR |
670 | struct ftrace_event_file *file = v; |
671 | struct ftrace_event_call *call = file->event_call; | |
b77e38aa | 672 | |
8f082018 SR |
673 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
674 | seq_printf(m, "%s:", call->class->system); | |
b77e38aa SR |
675 | seq_printf(m, "%s\n", call->name); |
676 | ||
677 | return 0; | |
678 | } | |
679 | ||
680 | static void t_stop(struct seq_file *m, void *p) | |
681 | { | |
20c8928a | 682 | mutex_unlock(&event_mutex); |
b77e38aa SR |
683 | } |
684 | ||
1473e441 SR |
685 | static ssize_t |
686 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |
687 | loff_t *ppos) | |
688 | { | |
df89bf77 ON |
689 | struct ftrace_event_file *file; |
690 | unsigned long flags; | |
1473e441 SR |
691 | char *buf; |
692 | ||
df89bf77 ON |
693 | mutex_lock(&event_mutex); |
694 | file = event_file_data(filp); | |
695 | if (likely(file)) | |
696 | flags = file->flags; | |
697 | mutex_unlock(&event_mutex); | |
698 | ||
699 | if (!file) | |
700 | return -ENODEV; | |
701 | ||
702 | if (flags & FTRACE_EVENT_FL_ENABLED) { | |
703 | if (flags & FTRACE_EVENT_FL_SOFT_DISABLED) | |
417944c4 | 704 | buf = "0*\n"; |
df89bf77 | 705 | else if (flags & FTRACE_EVENT_FL_SOFT_MODE) |
30052170 | 706 | buf = "1*\n"; |
417944c4 SRRH |
707 | else |
708 | buf = "1\n"; | |
709 | } else | |
1473e441 SR |
710 | buf = "0\n"; |
711 | ||
417944c4 | 712 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf)); |
1473e441 SR |
713 | } |
714 | ||
715 | static ssize_t | |
716 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
717 | loff_t *ppos) | |
718 | { | |
df89bf77 | 719 | struct ftrace_event_file *file; |
1473e441 SR |
720 | unsigned long val; |
721 | int ret; | |
722 | ||
22fe9b54 PH |
723 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
724 | if (ret) | |
1473e441 SR |
725 | return ret; |
726 | ||
1852fcce SR |
727 | ret = tracing_update_buffers(); |
728 | if (ret < 0) | |
729 | return ret; | |
730 | ||
1473e441 SR |
731 | switch (val) { |
732 | case 0: | |
1473e441 | 733 | case 1: |
df89bf77 | 734 | ret = -ENODEV; |
11a241a3 | 735 | mutex_lock(&event_mutex); |
df89bf77 ON |
736 | file = event_file_data(filp); |
737 | if (likely(file)) | |
738 | ret = ftrace_event_enable_disable(file, val); | |
11a241a3 | 739 | mutex_unlock(&event_mutex); |
1473e441 SR |
740 | break; |
741 | ||
742 | default: | |
743 | return -EINVAL; | |
744 | } | |
745 | ||
746 | *ppos += cnt; | |
747 | ||
3b8e4273 | 748 | return ret ? ret : cnt; |
1473e441 SR |
749 | } |
750 | ||
8ae79a13 SR |
751 | static ssize_t |
752 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |
753 | loff_t *ppos) | |
754 | { | |
c142b15d | 755 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
ae63b31e SR |
756 | struct ftrace_subsystem_dir *dir = filp->private_data; |
757 | struct event_subsystem *system = dir->subsystem; | |
8ae79a13 | 758 | struct ftrace_event_call *call; |
ae63b31e SR |
759 | struct ftrace_event_file *file; |
760 | struct trace_array *tr = dir->tr; | |
8ae79a13 | 761 | char buf[2]; |
c142b15d | 762 | int set = 0; |
8ae79a13 SR |
763 | int ret; |
764 | ||
8ae79a13 | 765 | mutex_lock(&event_mutex); |
ae63b31e SR |
766 | list_for_each_entry(file, &tr->events, list) { |
767 | call = file->event_call; | |
a1d0ce82 | 768 | if (!call->name || !call->class || !call->class->reg) |
8ae79a13 SR |
769 | continue; |
770 | ||
40ee4dff | 771 | if (system && strcmp(call->class->system, system->name) != 0) |
8ae79a13 SR |
772 | continue; |
773 | ||
774 | /* | |
775 | * We need to find out if all the events are set | |
776 | * or if all events or cleared, or if we have | |
777 | * a mixture. | |
778 | */ | |
ae63b31e | 779 | set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED)); |
c142b15d | 780 | |
8ae79a13 SR |
781 | /* |
782 | * If we have a mixture, no need to look further. | |
783 | */ | |
c142b15d | 784 | if (set == 3) |
8ae79a13 SR |
785 | break; |
786 | } | |
787 | mutex_unlock(&event_mutex); | |
788 | ||
c142b15d | 789 | buf[0] = set_to_char[set]; |
8ae79a13 | 790 | buf[1] = '\n'; |
8ae79a13 SR |
791 | |
792 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
793 | ||
794 | return ret; | |
795 | } | |
796 | ||
797 | static ssize_t | |
798 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
799 | loff_t *ppos) | |
800 | { | |
ae63b31e SR |
801 | struct ftrace_subsystem_dir *dir = filp->private_data; |
802 | struct event_subsystem *system = dir->subsystem; | |
40ee4dff | 803 | const char *name = NULL; |
8ae79a13 | 804 | unsigned long val; |
8ae79a13 SR |
805 | ssize_t ret; |
806 | ||
22fe9b54 PH |
807 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
808 | if (ret) | |
8ae79a13 SR |
809 | return ret; |
810 | ||
811 | ret = tracing_update_buffers(); | |
812 | if (ret < 0) | |
813 | return ret; | |
814 | ||
8f31bfe5 | 815 | if (val != 0 && val != 1) |
8ae79a13 | 816 | return -EINVAL; |
8ae79a13 | 817 | |
40ee4dff SR |
818 | /* |
819 | * Opening of "enable" adds a ref count to system, | |
820 | * so the name is safe to use. | |
821 | */ | |
822 | if (system) | |
823 | name = system->name; | |
824 | ||
ae63b31e | 825 | ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val); |
8ae79a13 | 826 | if (ret) |
8f31bfe5 | 827 | goto out; |
8ae79a13 SR |
828 | |
829 | ret = cnt; | |
830 | ||
8f31bfe5 | 831 | out: |
8ae79a13 SR |
832 | *ppos += cnt; |
833 | ||
834 | return ret; | |
835 | } | |
836 | ||
2a37a3df SR |
837 | enum { |
838 | FORMAT_HEADER = 1, | |
86397dc3 LZ |
839 | FORMAT_FIELD_SEPERATOR = 2, |
840 | FORMAT_PRINTFMT = 3, | |
2a37a3df SR |
841 | }; |
842 | ||
843 | static void *f_next(struct seq_file *m, void *v, loff_t *pos) | |
981d081e | 844 | { |
b86d0ba6 | 845 | struct ftrace_event_call *call = event_file_data(m->private); |
5a65e956 | 846 | struct ftrace_event_field *field; |
86397dc3 LZ |
847 | struct list_head *common_head = &ftrace_common_fields; |
848 | struct list_head *head = trace_get_fields(call); | |
981d081e | 849 | |
2a37a3df | 850 | (*pos)++; |
5a65e956 | 851 | |
2a37a3df SR |
852 | switch ((unsigned long)v) { |
853 | case FORMAT_HEADER: | |
86397dc3 LZ |
854 | if (unlikely(list_empty(common_head))) |
855 | return NULL; | |
856 | ||
857 | field = list_entry(common_head->prev, | |
858 | struct ftrace_event_field, link); | |
859 | return field; | |
5a65e956 | 860 | |
86397dc3 | 861 | case FORMAT_FIELD_SEPERATOR: |
2a37a3df SR |
862 | if (unlikely(list_empty(head))) |
863 | return NULL; | |
5a65e956 | 864 | |
2a37a3df SR |
865 | field = list_entry(head->prev, struct ftrace_event_field, link); |
866 | return field; | |
5a65e956 | 867 | |
2a37a3df SR |
868 | case FORMAT_PRINTFMT: |
869 | /* all done */ | |
870 | return NULL; | |
5a65e956 LJ |
871 | } |
872 | ||
2a37a3df | 873 | field = v; |
86397dc3 LZ |
874 | if (field->link.prev == common_head) |
875 | return (void *)FORMAT_FIELD_SEPERATOR; | |
876 | else if (field->link.prev == head) | |
2a37a3df SR |
877 | return (void *)FORMAT_PRINTFMT; |
878 | ||
879 | field = list_entry(field->link.prev, struct ftrace_event_field, link); | |
880 | ||
2a37a3df | 881 | return field; |
8728fe50 | 882 | } |
5a65e956 | 883 | |
2a37a3df | 884 | static void *f_start(struct seq_file *m, loff_t *pos) |
8728fe50 | 885 | { |
2a37a3df SR |
886 | loff_t l = 0; |
887 | void *p; | |
5a65e956 | 888 | |
b86d0ba6 ON |
889 | /* ->stop() is called even if ->start() fails */ |
890 | mutex_lock(&event_mutex); | |
891 | if (!event_file_data(m->private)) | |
892 | return ERR_PTR(-ENODEV); | |
893 | ||
2a37a3df SR |
894 | /* Start by showing the header */ |
895 | if (!*pos) | |
896 | return (void *)FORMAT_HEADER; | |
897 | ||
898 | p = (void *)FORMAT_HEADER; | |
899 | do { | |
900 | p = f_next(m, p, &l); | |
901 | } while (p && l < *pos); | |
902 | ||
903 | return p; | |
904 | } | |
905 | ||
906 | static int f_show(struct seq_file *m, void *v) | |
907 | { | |
b86d0ba6 | 908 | struct ftrace_event_call *call = event_file_data(m->private); |
2a37a3df SR |
909 | struct ftrace_event_field *field; |
910 | const char *array_descriptor; | |
911 | ||
912 | switch ((unsigned long)v) { | |
913 | case FORMAT_HEADER: | |
914 | seq_printf(m, "name: %s\n", call->name); | |
915 | seq_printf(m, "ID: %d\n", call->event.type); | |
916 | seq_printf(m, "format:\n"); | |
8728fe50 | 917 | return 0; |
5a65e956 | 918 | |
86397dc3 LZ |
919 | case FORMAT_FIELD_SEPERATOR: |
920 | seq_putc(m, '\n'); | |
921 | return 0; | |
922 | ||
2a37a3df SR |
923 | case FORMAT_PRINTFMT: |
924 | seq_printf(m, "\nprint fmt: %s\n", | |
925 | call->print_fmt); | |
926 | return 0; | |
981d081e | 927 | } |
8728fe50 | 928 | |
2a37a3df | 929 | field = v; |
8728fe50 | 930 | |
2a37a3df SR |
931 | /* |
932 | * Smartly shows the array type(except dynamic array). | |
933 | * Normal: | |
934 | * field:TYPE VAR | |
935 | * If TYPE := TYPE[LEN], it is shown: | |
936 | * field:TYPE VAR[LEN] | |
937 | */ | |
938 | array_descriptor = strchr(field->type, '['); | |
8728fe50 | 939 | |
2a37a3df SR |
940 | if (!strncmp(field->type, "__data_loc", 10)) |
941 | array_descriptor = NULL; | |
8728fe50 | 942 | |
2a37a3df SR |
943 | if (!array_descriptor) |
944 | seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", | |
945 | field->type, field->name, field->offset, | |
946 | field->size, !!field->is_signed); | |
947 | else | |
948 | seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", | |
949 | (int)(array_descriptor - field->type), | |
950 | field->type, field->name, | |
951 | array_descriptor, field->offset, | |
952 | field->size, !!field->is_signed); | |
8728fe50 | 953 | |
2a37a3df SR |
954 | return 0; |
955 | } | |
5a65e956 | 956 | |
2a37a3df SR |
957 | static void f_stop(struct seq_file *m, void *p) |
958 | { | |
b86d0ba6 | 959 | mutex_unlock(&event_mutex); |
2a37a3df | 960 | } |
981d081e | 961 | |
2a37a3df SR |
962 | static const struct seq_operations trace_format_seq_ops = { |
963 | .start = f_start, | |
964 | .next = f_next, | |
965 | .stop = f_stop, | |
966 | .show = f_show, | |
967 | }; | |
968 | ||
969 | static int trace_format_open(struct inode *inode, struct file *file) | |
970 | { | |
2a37a3df SR |
971 | struct seq_file *m; |
972 | int ret; | |
973 | ||
974 | ret = seq_open(file, &trace_format_seq_ops); | |
975 | if (ret < 0) | |
976 | return ret; | |
977 | ||
978 | m = file->private_data; | |
b86d0ba6 | 979 | m->private = file; |
2a37a3df SR |
980 | |
981 | return 0; | |
981d081e SR |
982 | } |
983 | ||
23725aee PZ |
984 | static ssize_t |
985 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |
986 | { | |
fdb65fe2 | 987 | int id = (long)event_file_data(filp); |
23725aee PZ |
988 | struct trace_seq *s; |
989 | int r; | |
990 | ||
991 | if (*ppos) | |
992 | return 0; | |
993 | ||
fdb65fe2 ON |
994 | if (unlikely(!id)) |
995 | return -ENODEV; | |
996 | ||
23725aee PZ |
997 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
998 | if (!s) | |
999 | return -ENOMEM; | |
1000 | ||
1001 | trace_seq_init(s); | |
fdb65fe2 | 1002 | trace_seq_printf(s, "%d\n", id); |
23725aee PZ |
1003 | |
1004 | r = simple_read_from_buffer(ubuf, cnt, ppos, | |
1005 | s->buffer, s->len); | |
1006 | kfree(s); | |
1007 | return r; | |
1008 | } | |
1009 | ||
7ce7e424 TZ |
1010 | static ssize_t |
1011 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
1012 | loff_t *ppos) | |
1013 | { | |
70c91fb9 | 1014 | struct ftrace_event_call *call; |
7ce7e424 | 1015 | struct trace_seq *s; |
70c91fb9 | 1016 | int r = -ENODEV; |
7ce7e424 TZ |
1017 | |
1018 | if (*ppos) | |
1019 | return 0; | |
1020 | ||
1021 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
70c91fb9 | 1022 | |
7ce7e424 TZ |
1023 | if (!s) |
1024 | return -ENOMEM; | |
1025 | ||
1026 | trace_seq_init(s); | |
1027 | ||
70c91fb9 ON |
1028 | mutex_lock(&event_mutex); |
1029 | call = event_file_data(filp); | |
1030 | if (call) | |
1031 | print_event_filter(call, s); | |
1032 | mutex_unlock(&event_mutex); | |
1033 | ||
1034 | if (call) | |
1035 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | |
7ce7e424 TZ |
1036 | |
1037 | kfree(s); | |
1038 | ||
1039 | return r; | |
1040 | } | |
1041 | ||
1042 | static ssize_t | |
1043 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
1044 | loff_t *ppos) | |
1045 | { | |
70c91fb9 | 1046 | struct ftrace_event_call *call; |
8b372562 | 1047 | char *buf; |
70c91fb9 | 1048 | int err = -ENODEV; |
7ce7e424 | 1049 | |
8b372562 | 1050 | if (cnt >= PAGE_SIZE) |
7ce7e424 TZ |
1051 | return -EINVAL; |
1052 | ||
8b372562 TZ |
1053 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
1054 | if (!buf) | |
7ce7e424 TZ |
1055 | return -ENOMEM; |
1056 | ||
8b372562 TZ |
1057 | if (copy_from_user(buf, ubuf, cnt)) { |
1058 | free_page((unsigned long) buf); | |
1059 | return -EFAULT; | |
7ce7e424 | 1060 | } |
8b372562 | 1061 | buf[cnt] = '\0'; |
7ce7e424 | 1062 | |
70c91fb9 ON |
1063 | mutex_lock(&event_mutex); |
1064 | call = event_file_data(filp); | |
1065 | if (call) | |
1066 | err = apply_event_filter(call, buf); | |
1067 | mutex_unlock(&event_mutex); | |
1068 | ||
8b372562 TZ |
1069 | free_page((unsigned long) buf); |
1070 | if (err < 0) | |
44e9c8b7 | 1071 | return err; |
0a19e53c | 1072 | |
7ce7e424 TZ |
1073 | *ppos += cnt; |
1074 | ||
1075 | return cnt; | |
1076 | } | |
1077 | ||
e9dbfae5 SR |
1078 | static LIST_HEAD(event_subsystems); |
1079 | ||
1080 | static int subsystem_open(struct inode *inode, struct file *filp) | |
1081 | { | |
1082 | struct event_subsystem *system = NULL; | |
ae63b31e SR |
1083 | struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */ |
1084 | struct trace_array *tr; | |
e9dbfae5 SR |
1085 | int ret; |
1086 | ||
1087 | /* Make sure the system still exists */ | |
9713f785 | 1088 | mutex_lock(&trace_types_lock); |
e9dbfae5 | 1089 | mutex_lock(&event_mutex); |
ae63b31e SR |
1090 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
1091 | list_for_each_entry(dir, &tr->systems, list) { | |
1092 | if (dir == inode->i_private) { | |
1093 | /* Don't open systems with no events */ | |
1094 | if (dir->nr_events) { | |
1095 | __get_system_dir(dir); | |
1096 | system = dir->subsystem; | |
1097 | } | |
1098 | goto exit_loop; | |
e9dbfae5 | 1099 | } |
e9dbfae5 SR |
1100 | } |
1101 | } | |
ae63b31e | 1102 | exit_loop: |
e9dbfae5 | 1103 | mutex_unlock(&event_mutex); |
9713f785 | 1104 | mutex_unlock(&trace_types_lock); |
e9dbfae5 | 1105 | |
ae63b31e | 1106 | if (!system) |
e9dbfae5 SR |
1107 | return -ENODEV; |
1108 | ||
ae63b31e SR |
1109 | /* Some versions of gcc think dir can be uninitialized here */ |
1110 | WARN_ON(!dir); | |
1111 | ||
fc82a11a SRRH |
1112 | /* Still need to increment the ref count of the system */ |
1113 | if (trace_array_get(tr) < 0) { | |
1114 | put_system(dir); | |
1115 | return -ENODEV; | |
1116 | } | |
1117 | ||
e9dbfae5 | 1118 | ret = tracing_open_generic(inode, filp); |
fc82a11a SRRH |
1119 | if (ret < 0) { |
1120 | trace_array_put(tr); | |
ae63b31e | 1121 | put_system(dir); |
fc82a11a | 1122 | } |
ae63b31e SR |
1123 | |
1124 | return ret; | |
1125 | } | |
1126 | ||
1127 | static int system_tr_open(struct inode *inode, struct file *filp) | |
1128 | { | |
1129 | struct ftrace_subsystem_dir *dir; | |
1130 | struct trace_array *tr = inode->i_private; | |
1131 | int ret; | |
1132 | ||
fc82a11a SRRH |
1133 | if (trace_array_get(tr) < 0) |
1134 | return -ENODEV; | |
1135 | ||
ae63b31e SR |
1136 | /* Make a temporary dir that has no system but points to tr */ |
1137 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); | |
fc82a11a SRRH |
1138 | if (!dir) { |
1139 | trace_array_put(tr); | |
ae63b31e | 1140 | return -ENOMEM; |
fc82a11a | 1141 | } |
ae63b31e SR |
1142 | |
1143 | dir->tr = tr; | |
1144 | ||
1145 | ret = tracing_open_generic(inode, filp); | |
fc82a11a SRRH |
1146 | if (ret < 0) { |
1147 | trace_array_put(tr); | |
ae63b31e | 1148 | kfree(dir); |
fc82a11a | 1149 | } |
ae63b31e SR |
1150 | |
1151 | filp->private_data = dir; | |
e9dbfae5 SR |
1152 | |
1153 | return ret; | |
1154 | } | |
1155 | ||
1156 | static int subsystem_release(struct inode *inode, struct file *file) | |
1157 | { | |
ae63b31e | 1158 | struct ftrace_subsystem_dir *dir = file->private_data; |
e9dbfae5 | 1159 | |
fc82a11a SRRH |
1160 | trace_array_put(dir->tr); |
1161 | ||
ae63b31e SR |
1162 | /* |
1163 | * If dir->subsystem is NULL, then this is a temporary | |
1164 | * descriptor that was made for a trace_array to enable | |
1165 | * all subsystems. | |
1166 | */ | |
1167 | if (dir->subsystem) | |
1168 | put_system(dir); | |
1169 | else | |
1170 | kfree(dir); | |
e9dbfae5 SR |
1171 | |
1172 | return 0; | |
1173 | } | |
1174 | ||
cfb180f3 TZ |
1175 | static ssize_t |
1176 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
1177 | loff_t *ppos) | |
1178 | { | |
ae63b31e SR |
1179 | struct ftrace_subsystem_dir *dir = filp->private_data; |
1180 | struct event_subsystem *system = dir->subsystem; | |
cfb180f3 TZ |
1181 | struct trace_seq *s; |
1182 | int r; | |
1183 | ||
1184 | if (*ppos) | |
1185 | return 0; | |
1186 | ||
1187 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
1188 | if (!s) | |
1189 | return -ENOMEM; | |
1190 | ||
1191 | trace_seq_init(s); | |
1192 | ||
8b372562 | 1193 | print_subsystem_event_filter(system, s); |
4bda2d51 | 1194 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
cfb180f3 TZ |
1195 | |
1196 | kfree(s); | |
1197 | ||
1198 | return r; | |
1199 | } | |
1200 | ||
1201 | static ssize_t | |
1202 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
1203 | loff_t *ppos) | |
1204 | { | |
ae63b31e | 1205 | struct ftrace_subsystem_dir *dir = filp->private_data; |
8b372562 | 1206 | char *buf; |
cfb180f3 TZ |
1207 | int err; |
1208 | ||
8b372562 | 1209 | if (cnt >= PAGE_SIZE) |
cfb180f3 TZ |
1210 | return -EINVAL; |
1211 | ||
8b372562 TZ |
1212 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
1213 | if (!buf) | |
cfb180f3 TZ |
1214 | return -ENOMEM; |
1215 | ||
8b372562 TZ |
1216 | if (copy_from_user(buf, ubuf, cnt)) { |
1217 | free_page((unsigned long) buf); | |
1218 | return -EFAULT; | |
cfb180f3 | 1219 | } |
8b372562 | 1220 | buf[cnt] = '\0'; |
cfb180f3 | 1221 | |
ae63b31e | 1222 | err = apply_subsystem_event_filter(dir, buf); |
8b372562 TZ |
1223 | free_page((unsigned long) buf); |
1224 | if (err < 0) | |
44e9c8b7 | 1225 | return err; |
cfb180f3 TZ |
1226 | |
1227 | *ppos += cnt; | |
1228 | ||
1229 | return cnt; | |
1230 | } | |
1231 | ||
d1b182a8 SR |
1232 | static ssize_t |
1233 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |
1234 | { | |
1235 | int (*func)(struct trace_seq *s) = filp->private_data; | |
1236 | struct trace_seq *s; | |
1237 | int r; | |
1238 | ||
1239 | if (*ppos) | |
1240 | return 0; | |
1241 | ||
1242 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
1243 | if (!s) | |
1244 | return -ENOMEM; | |
1245 | ||
1246 | trace_seq_init(s); | |
1247 | ||
1248 | func(s); | |
1249 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | |
1250 | ||
1251 | kfree(s); | |
1252 | ||
1253 | return r; | |
1254 | } | |
1255 | ||
15075cac SR |
1256 | static int ftrace_event_avail_open(struct inode *inode, struct file *file); |
1257 | static int ftrace_event_set_open(struct inode *inode, struct file *file); | |
e45ccd09 | 1258 | static int ftrace_event_release(struct inode *inode, struct file *file); |
15075cac | 1259 | |
b77e38aa SR |
1260 | static const struct seq_operations show_event_seq_ops = { |
1261 | .start = t_start, | |
1262 | .next = t_next, | |
1263 | .show = t_show, | |
1264 | .stop = t_stop, | |
1265 | }; | |
1266 | ||
1267 | static const struct seq_operations show_set_event_seq_ops = { | |
1268 | .start = s_start, | |
1269 | .next = s_next, | |
1270 | .show = t_show, | |
1271 | .stop = t_stop, | |
1272 | }; | |
1273 | ||
2314c4ae | 1274 | static const struct file_operations ftrace_avail_fops = { |
15075cac | 1275 | .open = ftrace_event_avail_open, |
2314c4ae SR |
1276 | .read = seq_read, |
1277 | .llseek = seq_lseek, | |
1278 | .release = seq_release, | |
1279 | }; | |
1280 | ||
b77e38aa | 1281 | static const struct file_operations ftrace_set_event_fops = { |
15075cac | 1282 | .open = ftrace_event_set_open, |
b77e38aa SR |
1283 | .read = seq_read, |
1284 | .write = ftrace_event_write, | |
1285 | .llseek = seq_lseek, | |
e45ccd09 | 1286 | .release = ftrace_event_release, |
b77e38aa SR |
1287 | }; |
1288 | ||
1473e441 | 1289 | static const struct file_operations ftrace_enable_fops = { |
012dc156 | 1290 | .open = tracing_open_generic, |
1473e441 SR |
1291 | .read = event_enable_read, |
1292 | .write = event_enable_write, | |
6038f373 | 1293 | .llseek = default_llseek, |
1473e441 SR |
1294 | }; |
1295 | ||
981d081e | 1296 | static const struct file_operations ftrace_event_format_fops = { |
2a37a3df SR |
1297 | .open = trace_format_open, |
1298 | .read = seq_read, | |
1299 | .llseek = seq_lseek, | |
1300 | .release = seq_release, | |
981d081e SR |
1301 | }; |
1302 | ||
23725aee | 1303 | static const struct file_operations ftrace_event_id_fops = { |
23725aee | 1304 | .read = event_id_read, |
6038f373 | 1305 | .llseek = default_llseek, |
23725aee PZ |
1306 | }; |
1307 | ||
7ce7e424 TZ |
1308 | static const struct file_operations ftrace_event_filter_fops = { |
1309 | .open = tracing_open_generic, | |
1310 | .read = event_filter_read, | |
1311 | .write = event_filter_write, | |
6038f373 | 1312 | .llseek = default_llseek, |
7ce7e424 TZ |
1313 | }; |
1314 | ||
cfb180f3 | 1315 | static const struct file_operations ftrace_subsystem_filter_fops = { |
e9dbfae5 | 1316 | .open = subsystem_open, |
cfb180f3 TZ |
1317 | .read = subsystem_filter_read, |
1318 | .write = subsystem_filter_write, | |
6038f373 | 1319 | .llseek = default_llseek, |
e9dbfae5 | 1320 | .release = subsystem_release, |
cfb180f3 TZ |
1321 | }; |
1322 | ||
8ae79a13 | 1323 | static const struct file_operations ftrace_system_enable_fops = { |
40ee4dff | 1324 | .open = subsystem_open, |
8ae79a13 SR |
1325 | .read = system_enable_read, |
1326 | .write = system_enable_write, | |
6038f373 | 1327 | .llseek = default_llseek, |
40ee4dff | 1328 | .release = subsystem_release, |
8ae79a13 SR |
1329 | }; |
1330 | ||
ae63b31e SR |
1331 | static const struct file_operations ftrace_tr_enable_fops = { |
1332 | .open = system_tr_open, | |
1333 | .read = system_enable_read, | |
1334 | .write = system_enable_write, | |
1335 | .llseek = default_llseek, | |
1336 | .release = subsystem_release, | |
1337 | }; | |
1338 | ||
d1b182a8 SR |
1339 | static const struct file_operations ftrace_show_header_fops = { |
1340 | .open = tracing_open_generic, | |
1341 | .read = show_header, | |
6038f373 | 1342 | .llseek = default_llseek, |
d1b182a8 SR |
1343 | }; |
1344 | ||
ae63b31e SR |
1345 | static int |
1346 | ftrace_event_open(struct inode *inode, struct file *file, | |
1347 | const struct seq_operations *seq_ops) | |
1473e441 | 1348 | { |
ae63b31e SR |
1349 | struct seq_file *m; |
1350 | int ret; | |
1473e441 | 1351 | |
ae63b31e SR |
1352 | ret = seq_open(file, seq_ops); |
1353 | if (ret < 0) | |
1354 | return ret; | |
1355 | m = file->private_data; | |
1356 | /* copy tr over to seq ops */ | |
1357 | m->private = inode->i_private; | |
1473e441 | 1358 | |
ae63b31e | 1359 | return ret; |
1473e441 SR |
1360 | } |
1361 | ||
e45ccd09 AL |
1362 | static int ftrace_event_release(struct inode *inode, struct file *file) |
1363 | { | |
1364 | struct trace_array *tr = inode->i_private; | |
1365 | ||
1366 | trace_array_put(tr); | |
1367 | ||
1368 | return seq_release(inode, file); | |
1369 | } | |
1370 | ||
15075cac SR |
1371 | static int |
1372 | ftrace_event_avail_open(struct inode *inode, struct file *file) | |
1373 | { | |
1374 | const struct seq_operations *seq_ops = &show_event_seq_ops; | |
1375 | ||
ae63b31e | 1376 | return ftrace_event_open(inode, file, seq_ops); |
15075cac SR |
1377 | } |
1378 | ||
1379 | static int | |
1380 | ftrace_event_set_open(struct inode *inode, struct file *file) | |
1381 | { | |
1382 | const struct seq_operations *seq_ops = &show_set_event_seq_ops; | |
ae63b31e | 1383 | struct trace_array *tr = inode->i_private; |
e45ccd09 AL |
1384 | int ret; |
1385 | ||
1386 | if (trace_array_get(tr) < 0) | |
1387 | return -ENODEV; | |
15075cac SR |
1388 | |
1389 | if ((file->f_mode & FMODE_WRITE) && | |
1390 | (file->f_flags & O_TRUNC)) | |
ae63b31e | 1391 | ftrace_clear_events(tr); |
15075cac | 1392 | |
e45ccd09 AL |
1393 | ret = ftrace_event_open(inode, file, seq_ops); |
1394 | if (ret < 0) | |
1395 | trace_array_put(tr); | |
1396 | return ret; | |
ae63b31e SR |
1397 | } |
1398 | ||
1399 | static struct event_subsystem * | |
1400 | create_new_subsystem(const char *name) | |
1401 | { | |
1402 | struct event_subsystem *system; | |
1403 | ||
1404 | /* need to create new entry */ | |
1405 | system = kmalloc(sizeof(*system), GFP_KERNEL); | |
1406 | if (!system) | |
1407 | return NULL; | |
1408 | ||
1409 | system->ref_count = 1; | |
e6929efa SR |
1410 | |
1411 | /* Only allocate if dynamic (kprobes and modules) */ | |
1412 | if (!core_kernel_data((unsigned long)name)) { | |
1413 | system->ref_count |= SYSTEM_FL_FREE_NAME; | |
1414 | system->name = kstrdup(name, GFP_KERNEL); | |
1415 | if (!system->name) | |
1416 | goto out_free; | |
1417 | } else | |
1418 | system->name = name; | |
ae63b31e SR |
1419 | |
1420 | system->filter = NULL; | |
1421 | ||
1422 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); | |
1423 | if (!system->filter) | |
1424 | goto out_free; | |
1425 | ||
1426 | list_add(&system->list, &event_subsystems); | |
1427 | ||
1428 | return system; | |
1429 | ||
1430 | out_free: | |
e6929efa SR |
1431 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
1432 | kfree(system->name); | |
ae63b31e SR |
1433 | kfree(system); |
1434 | return NULL; | |
15075cac SR |
1435 | } |
1436 | ||
6ecc2d1c | 1437 | static struct dentry * |
ae63b31e SR |
1438 | event_subsystem_dir(struct trace_array *tr, const char *name, |
1439 | struct ftrace_event_file *file, struct dentry *parent) | |
6ecc2d1c | 1440 | { |
ae63b31e | 1441 | struct ftrace_subsystem_dir *dir; |
6ecc2d1c | 1442 | struct event_subsystem *system; |
e1112b4d | 1443 | struct dentry *entry; |
6ecc2d1c SR |
1444 | |
1445 | /* First see if we did not already create this dir */ | |
ae63b31e SR |
1446 | list_for_each_entry(dir, &tr->systems, list) { |
1447 | system = dir->subsystem; | |
dc82ec98 | 1448 | if (strcmp(system->name, name) == 0) { |
ae63b31e SR |
1449 | dir->nr_events++; |
1450 | file->system = dir; | |
1451 | return dir->entry; | |
dc82ec98 | 1452 | } |
6ecc2d1c SR |
1453 | } |
1454 | ||
ae63b31e SR |
1455 | /* Now see if the system itself exists. */ |
1456 | list_for_each_entry(system, &event_subsystems, list) { | |
1457 | if (strcmp(system->name, name) == 0) | |
1458 | break; | |
6ecc2d1c | 1459 | } |
ae63b31e SR |
1460 | /* Reset system variable when not found */ |
1461 | if (&system->list == &event_subsystems) | |
1462 | system = NULL; | |
6ecc2d1c | 1463 | |
ae63b31e SR |
1464 | dir = kmalloc(sizeof(*dir), GFP_KERNEL); |
1465 | if (!dir) | |
1466 | goto out_fail; | |
6ecc2d1c | 1467 | |
ae63b31e SR |
1468 | if (!system) { |
1469 | system = create_new_subsystem(name); | |
1470 | if (!system) | |
1471 | goto out_free; | |
1472 | } else | |
1473 | __get_system(system); | |
1474 | ||
1475 | dir->entry = debugfs_create_dir(name, parent); | |
1476 | if (!dir->entry) { | |
1477 | pr_warning("Failed to create system directory %s\n", name); | |
1478 | __put_system(system); | |
1479 | goto out_free; | |
6d723736 SR |
1480 | } |
1481 | ||
ae63b31e SR |
1482 | dir->tr = tr; |
1483 | dir->ref_count = 1; | |
1484 | dir->nr_events = 1; | |
1485 | dir->subsystem = system; | |
1486 | file->system = dir; | |
8b372562 | 1487 | |
ae63b31e | 1488 | entry = debugfs_create_file("filter", 0644, dir->entry, dir, |
e1112b4d | 1489 | &ftrace_subsystem_filter_fops); |
8b372562 TZ |
1490 | if (!entry) { |
1491 | kfree(system->filter); | |
1492 | system->filter = NULL; | |
ae63b31e | 1493 | pr_warning("Could not create debugfs '%s/filter' entry\n", name); |
8b372562 | 1494 | } |
e1112b4d | 1495 | |
ae63b31e | 1496 | trace_create_file("enable", 0644, dir->entry, dir, |
f3f3f009 | 1497 | &ftrace_system_enable_fops); |
8ae79a13 | 1498 | |
ae63b31e SR |
1499 | list_add(&dir->list, &tr->systems); |
1500 | ||
1501 | return dir->entry; | |
1502 | ||
1503 | out_free: | |
1504 | kfree(dir); | |
1505 | out_fail: | |
1506 | /* Only print this message if failed on memory allocation */ | |
1507 | if (!dir || !system) | |
1508 | pr_warning("No memory to create event subsystem %s\n", | |
1509 | name); | |
1510 | return NULL; | |
6ecc2d1c SR |
1511 | } |
1512 | ||
1473e441 | 1513 | static int |
ae63b31e SR |
1514 | event_create_dir(struct dentry *parent, |
1515 | struct ftrace_event_file *file, | |
701970b3 SR |
1516 | const struct file_operations *id, |
1517 | const struct file_operations *enable, | |
1518 | const struct file_operations *filter, | |
1519 | const struct file_operations *format) | |
1473e441 | 1520 | { |
ae63b31e SR |
1521 | struct ftrace_event_call *call = file->event_call; |
1522 | struct trace_array *tr = file->tr; | |
2e33af02 | 1523 | struct list_head *head; |
ae63b31e | 1524 | struct dentry *d_events; |
fd994989 | 1525 | int ret; |
1473e441 | 1526 | |
6ecc2d1c SR |
1527 | /* |
1528 | * If the trace point header did not define TRACE_SYSTEM | |
1529 | * then the system would be called "TRACE_SYSTEM". | |
1530 | */ | |
ae63b31e SR |
1531 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) { |
1532 | d_events = event_subsystem_dir(tr, call->class->system, file, parent); | |
1533 | if (!d_events) | |
1534 | return -ENOMEM; | |
1535 | } else | |
1536 | d_events = parent; | |
1537 | ||
1538 | file->dir = debugfs_create_dir(call->name, d_events); | |
1539 | if (!file->dir) { | |
1540 | pr_warning("Could not create debugfs '%s' directory\n", | |
1541 | call->name); | |
1473e441 SR |
1542 | return -1; |
1543 | } | |
1544 | ||
9b63776f | 1545 | if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) |
ae63b31e | 1546 | trace_create_file("enable", 0644, file->dir, file, |
f3f3f009 | 1547 | enable); |
1473e441 | 1548 | |
2239291a | 1549 | #ifdef CONFIG_PERF_EVENTS |
a1d0ce82 | 1550 | if (call->event.type && call->class->reg) |
fdb65fe2 ON |
1551 | trace_create_file("id", 0444, file->dir, |
1552 | (void *)(long)call->event.type, id); | |
2239291a | 1553 | #endif |
23725aee | 1554 | |
c9d932cf LZ |
1555 | /* |
1556 | * Other events may have the same class. Only update | |
1557 | * the fields if they are not already defined. | |
1558 | */ | |
1559 | head = trace_get_fields(call); | |
1560 | if (list_empty(head)) { | |
1561 | ret = call->class->define_fields(call); | |
1562 | if (ret < 0) { | |
1563 | pr_warning("Could not initialize trace point" | |
1564 | " events/%s\n", call->name); | |
ae63b31e | 1565 | return -1; |
cf027f64 TZ |
1566 | } |
1567 | } | |
ae63b31e | 1568 | trace_create_file("filter", 0644, file->dir, call, |
c9d932cf | 1569 | filter); |
cf027f64 | 1570 | |
ae63b31e | 1571 | trace_create_file("format", 0444, file->dir, call, |
f3f3f009 | 1572 | format); |
6d723736 SR |
1573 | |
1574 | return 0; | |
1575 | } | |
1576 | ||
ae63b31e SR |
1577 | static void remove_event_from_tracers(struct ftrace_event_call *call) |
1578 | { | |
1579 | struct ftrace_event_file *file; | |
1580 | struct trace_array *tr; | |
1581 | ||
1582 | do_for_each_event_file_safe(tr, file) { | |
ae63b31e SR |
1583 | if (file->event_call != call) |
1584 | continue; | |
1585 | ||
c6febdf2 | 1586 | remove_event_file_dir(file); |
ae63b31e SR |
1587 | /* |
1588 | * The do_for_each_event_file_safe() is | |
1589 | * a double loop. After finding the call for this | |
1590 | * trace_array, we use break to jump to the next | |
1591 | * trace_array. | |
1592 | */ | |
1593 | break; | |
1594 | } while_for_each_event_file(); | |
1595 | } | |
1596 | ||
8781915a EG |
1597 | static void event_remove(struct ftrace_event_call *call) |
1598 | { | |
ae63b31e SR |
1599 | struct trace_array *tr; |
1600 | struct ftrace_event_file *file; | |
1601 | ||
1602 | do_for_each_event_file(tr, file) { | |
1603 | if (file->event_call != call) | |
1604 | continue; | |
1605 | ftrace_event_enable_disable(file, 0); | |
1606 | /* | |
1607 | * The do_for_each_event_file() is | |
1608 | * a double loop. After finding the call for this | |
1609 | * trace_array, we use break to jump to the next | |
1610 | * trace_array. | |
1611 | */ | |
1612 | break; | |
1613 | } while_for_each_event_file(); | |
1614 | ||
8781915a EG |
1615 | if (call->event.funcs) |
1616 | __unregister_ftrace_event(&call->event); | |
ae63b31e | 1617 | remove_event_from_tracers(call); |
8781915a EG |
1618 | list_del(&call->list); |
1619 | } | |
1620 | ||
1621 | static int event_init(struct ftrace_event_call *call) | |
1622 | { | |
1623 | int ret = 0; | |
1624 | ||
1625 | if (WARN_ON(!call->name)) | |
1626 | return -EINVAL; | |
1627 | ||
1628 | if (call->class->raw_init) { | |
1629 | ret = call->class->raw_init(call); | |
1630 | if (ret < 0 && ret != -ENOSYS) | |
1631 | pr_warn("Could not initialize trace events/%s\n", | |
1632 | call->name); | |
1633 | } | |
1634 | ||
1635 | return ret; | |
1636 | } | |
1637 | ||
67ead0a6 | 1638 | static int |
ae63b31e | 1639 | __register_event(struct ftrace_event_call *call, struct module *mod) |
bd1a5c84 | 1640 | { |
bd1a5c84 | 1641 | int ret; |
6d723736 | 1642 | |
8781915a EG |
1643 | ret = event_init(call); |
1644 | if (ret < 0) | |
1645 | return ret; | |
701970b3 | 1646 | |
ae63b31e | 1647 | list_add(&call->list, &ftrace_events); |
67ead0a6 | 1648 | call->mod = mod; |
88f70d75 | 1649 | |
ae63b31e | 1650 | return 0; |
bd1a5c84 MH |
1651 | } |
1652 | ||
da511bf3 SRRH |
1653 | static struct ftrace_event_file * |
1654 | trace_create_new_event(struct ftrace_event_call *call, | |
1655 | struct trace_array *tr) | |
1656 | { | |
1657 | struct ftrace_event_file *file; | |
1658 | ||
1659 | file = kmem_cache_alloc(file_cachep, GFP_TRACE); | |
1660 | if (!file) | |
1661 | return NULL; | |
1662 | ||
1663 | file->event_call = call; | |
1664 | file->tr = tr; | |
1665 | atomic_set(&file->sm_ref, 0); | |
1666 | list_add(&file->list, &tr->events); | |
1667 | ||
1668 | return file; | |
1669 | } | |
1670 | ||
ae63b31e SR |
1671 | /* Add an event to a trace directory */ |
1672 | static int | |
1673 | __trace_add_new_event(struct ftrace_event_call *call, | |
1674 | struct trace_array *tr, | |
1675 | const struct file_operations *id, | |
1676 | const struct file_operations *enable, | |
1677 | const struct file_operations *filter, | |
1678 | const struct file_operations *format) | |
1679 | { | |
1680 | struct ftrace_event_file *file; | |
1681 | ||
da511bf3 | 1682 | file = trace_create_new_event(call, tr); |
ae63b31e SR |
1683 | if (!file) |
1684 | return -ENOMEM; | |
1685 | ||
ae63b31e SR |
1686 | return event_create_dir(tr->event_dir, file, id, enable, filter, format); |
1687 | } | |
1688 | ||
77248221 SR |
1689 | /* |
1690 | * Just create a decriptor for early init. A descriptor is required | |
1691 | * for enabling events at boot. We want to enable events before | |
1692 | * the filesystem is initialized. | |
1693 | */ | |
1694 | static __init int | |
1695 | __trace_early_add_new_event(struct ftrace_event_call *call, | |
1696 | struct trace_array *tr) | |
1697 | { | |
1698 | struct ftrace_event_file *file; | |
1699 | ||
da511bf3 | 1700 | file = trace_create_new_event(call, tr); |
77248221 SR |
1701 | if (!file) |
1702 | return -ENOMEM; | |
1703 | ||
77248221 SR |
1704 | return 0; |
1705 | } | |
1706 | ||
ae63b31e SR |
1707 | struct ftrace_module_file_ops; |
1708 | static void __add_event_to_tracers(struct ftrace_event_call *call, | |
1709 | struct ftrace_module_file_ops *file_ops); | |
1710 | ||
bd1a5c84 MH |
1711 | /* Add an additional event_call dynamically */ |
1712 | int trace_add_event_call(struct ftrace_event_call *call) | |
1713 | { | |
1714 | int ret; | |
9713f785 | 1715 | mutex_lock(&trace_types_lock); |
bd1a5c84 | 1716 | mutex_lock(&event_mutex); |
701970b3 | 1717 | |
ae63b31e SR |
1718 | ret = __register_event(call, NULL); |
1719 | if (ret >= 0) | |
1720 | __add_event_to_tracers(call, NULL); | |
a2ca5e03 | 1721 | |
ae63b31e | 1722 | mutex_unlock(&event_mutex); |
9713f785 | 1723 | mutex_unlock(&trace_types_lock); |
ae63b31e | 1724 | return ret; |
a2ca5e03 FW |
1725 | } |
1726 | ||
4fead8e4 | 1727 | /* |
9713f785 AL |
1728 | * Must be called under locking of trace_types_lock, event_mutex and |
1729 | * trace_event_sem. | |
4fead8e4 | 1730 | */ |
bd1a5c84 MH |
1731 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
1732 | { | |
8781915a | 1733 | event_remove(call); |
bd1a5c84 MH |
1734 | trace_destroy_fields(call); |
1735 | destroy_preds(call); | |
bd1a5c84 MH |
1736 | } |
1737 | ||
1738 | /* Remove an event_call */ | |
1739 | void trace_remove_event_call(struct ftrace_event_call *call) | |
1740 | { | |
9713f785 | 1741 | mutex_lock(&trace_types_lock); |
bd1a5c84 | 1742 | mutex_lock(&event_mutex); |
52f6ad6d | 1743 | down_write(&trace_event_sem); |
bd1a5c84 | 1744 | __trace_remove_event_call(call); |
52f6ad6d | 1745 | up_write(&trace_event_sem); |
bd1a5c84 | 1746 | mutex_unlock(&event_mutex); |
9713f785 | 1747 | mutex_unlock(&trace_types_lock); |
bd1a5c84 MH |
1748 | } |
1749 | ||
1750 | #define for_each_event(event, start, end) \ | |
1751 | for (event = start; \ | |
1752 | (unsigned long)event < (unsigned long)end; \ | |
1753 | event++) | |
1754 | ||
1755 | #ifdef CONFIG_MODULES | |
1756 | ||
1757 | static LIST_HEAD(ftrace_module_file_list); | |
1758 | ||
1759 | /* | |
1760 | * Modules must own their file_operations to keep up with | |
1761 | * reference counting. | |
1762 | */ | |
1763 | struct ftrace_module_file_ops { | |
1764 | struct list_head list; | |
1765 | struct module *mod; | |
1766 | struct file_operations id; | |
1767 | struct file_operations enable; | |
1768 | struct file_operations format; | |
1769 | struct file_operations filter; | |
1770 | }; | |
1771 | ||
315326c1 SRRH |
1772 | static struct ftrace_module_file_ops * |
1773 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) | |
ae63b31e | 1774 | { |
315326c1 SRRH |
1775 | /* |
1776 | * As event_calls are added in groups by module, | |
1777 | * when we find one file_ops, we don't need to search for | |
1778 | * each call in that module, as the rest should be the | |
1779 | * same. Only search for a new one if the last one did | |
1780 | * not match. | |
1781 | */ | |
1782 | if (file_ops && mod == file_ops->mod) | |
1783 | return file_ops; | |
ae63b31e SR |
1784 | |
1785 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { | |
1786 | if (file_ops->mod == mod) | |
1787 | return file_ops; | |
1788 | } | |
1789 | return NULL; | |
1790 | } | |
1791 | ||
701970b3 SR |
1792 | static struct ftrace_module_file_ops * |
1793 | trace_create_file_ops(struct module *mod) | |
1794 | { | |
1795 | struct ftrace_module_file_ops *file_ops; | |
1796 | ||
1797 | /* | |
1798 | * This is a bit of a PITA. To allow for correct reference | |
1799 | * counting, modules must "own" their file_operations. | |
1800 | * To do this, we allocate the file operations that will be | |
1801 | * used in the event directory. | |
1802 | */ | |
1803 | ||
1804 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); | |
1805 | if (!file_ops) | |
1806 | return NULL; | |
1807 | ||
1808 | file_ops->mod = mod; | |
1809 | ||
1810 | file_ops->id = ftrace_event_id_fops; | |
1811 | file_ops->id.owner = mod; | |
1812 | ||
1813 | file_ops->enable = ftrace_enable_fops; | |
1814 | file_ops->enable.owner = mod; | |
1815 | ||
1816 | file_ops->filter = ftrace_event_filter_fops; | |
1817 | file_ops->filter.owner = mod; | |
1818 | ||
1819 | file_ops->format = ftrace_event_format_fops; | |
1820 | file_ops->format.owner = mod; | |
1821 | ||
1822 | list_add(&file_ops->list, &ftrace_module_file_list); | |
1823 | ||
1824 | return file_ops; | |
1825 | } | |
1826 | ||
6d723736 SR |
1827 | static void trace_module_add_events(struct module *mod) |
1828 | { | |
701970b3 | 1829 | struct ftrace_module_file_ops *file_ops = NULL; |
e4a9ea5e | 1830 | struct ftrace_event_call **call, **start, **end; |
6d723736 SR |
1831 | |
1832 | start = mod->trace_events; | |
1833 | end = mod->trace_events + mod->num_trace_events; | |
1834 | ||
1835 | if (start == end) | |
1836 | return; | |
1837 | ||
67ead0a6 LZ |
1838 | file_ops = trace_create_file_ops(mod); |
1839 | if (!file_ops) | |
6d723736 SR |
1840 | return; |
1841 | ||
1842 | for_each_event(call, start, end) { | |
ae63b31e SR |
1843 | __register_event(*call, mod); |
1844 | __add_event_to_tracers(*call, file_ops); | |
6d723736 SR |
1845 | } |
1846 | } | |
1847 | ||
1848 | static void trace_module_remove_events(struct module *mod) | |
1849 | { | |
701970b3 | 1850 | struct ftrace_module_file_ops *file_ops; |
6d723736 | 1851 | struct ftrace_event_call *call, *p; |
575380da | 1852 | bool clear_trace = false; |
6d723736 | 1853 | |
52f6ad6d | 1854 | down_write(&trace_event_sem); |
6d723736 SR |
1855 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
1856 | if (call->mod == mod) { | |
575380da SRRH |
1857 | if (call->flags & TRACE_EVENT_FL_WAS_ENABLED) |
1858 | clear_trace = true; | |
bd1a5c84 | 1859 | __trace_remove_event_call(call); |
6d723736 SR |
1860 | } |
1861 | } | |
701970b3 SR |
1862 | |
1863 | /* Now free the file_operations */ | |
1864 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { | |
1865 | if (file_ops->mod == mod) | |
1866 | break; | |
1867 | } | |
1868 | if (&file_ops->list != &ftrace_module_file_list) { | |
1869 | list_del(&file_ops->list); | |
1870 | kfree(file_ops); | |
1871 | } | |
52f6ad6d | 1872 | up_write(&trace_event_sem); |
9456f0fa SR |
1873 | |
1874 | /* | |
1875 | * It is safest to reset the ring buffer if the module being unloaded | |
873c642f SRRH |
1876 | * registered any events that were used. The only worry is if |
1877 | * a new module gets loaded, and takes on the same id as the events | |
1878 | * of this module. When printing out the buffer, traced events left | |
1879 | * over from this module may be passed to the new module events and | |
1880 | * unexpected results may occur. | |
9456f0fa | 1881 | */ |
575380da | 1882 | if (clear_trace) |
873c642f | 1883 | tracing_reset_all_online_cpus(); |
6d723736 SR |
1884 | } |
1885 | ||
61f919a1 SR |
1886 | static int trace_module_notify(struct notifier_block *self, |
1887 | unsigned long val, void *data) | |
6d723736 SR |
1888 | { |
1889 | struct module *mod = data; | |
1890 | ||
9713f785 | 1891 | mutex_lock(&trace_types_lock); |
6d723736 SR |
1892 | mutex_lock(&event_mutex); |
1893 | switch (val) { | |
1894 | case MODULE_STATE_COMING: | |
1895 | trace_module_add_events(mod); | |
1896 | break; | |
1897 | case MODULE_STATE_GOING: | |
1898 | trace_module_remove_events(mod); | |
1899 | break; | |
1900 | } | |
1901 | mutex_unlock(&event_mutex); | |
9713f785 | 1902 | mutex_unlock(&trace_types_lock); |
fd994989 | 1903 | |
1473e441 SR |
1904 | return 0; |
1905 | } | |
315326c1 SRRH |
1906 | |
1907 | static int | |
1908 | __trace_add_new_mod_event(struct ftrace_event_call *call, | |
1909 | struct trace_array *tr, | |
1910 | struct ftrace_module_file_ops *file_ops) | |
1911 | { | |
1912 | return __trace_add_new_event(call, tr, | |
1913 | &file_ops->id, &file_ops->enable, | |
1914 | &file_ops->filter, &file_ops->format); | |
1915 | } | |
1916 | ||
61f919a1 | 1917 | #else |
315326c1 SRRH |
1918 | static inline struct ftrace_module_file_ops * |
1919 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) | |
ae63b31e SR |
1920 | { |
1921 | return NULL; | |
1922 | } | |
315326c1 SRRH |
1923 | static inline int trace_module_notify(struct notifier_block *self, |
1924 | unsigned long val, void *data) | |
61f919a1 SR |
1925 | { |
1926 | return 0; | |
1927 | } | |
315326c1 SRRH |
1928 | static inline int |
1929 | __trace_add_new_mod_event(struct ftrace_event_call *call, | |
1930 | struct trace_array *tr, | |
1931 | struct ftrace_module_file_ops *file_ops) | |
1932 | { | |
1933 | return -ENODEV; | |
1934 | } | |
61f919a1 | 1935 | #endif /* CONFIG_MODULES */ |
1473e441 | 1936 | |
ae63b31e SR |
1937 | /* Create a new event directory structure for a trace directory. */ |
1938 | static void | |
1939 | __trace_add_event_dirs(struct trace_array *tr) | |
1940 | { | |
1941 | struct ftrace_module_file_ops *file_ops = NULL; | |
1942 | struct ftrace_event_call *call; | |
1943 | int ret; | |
1944 | ||
1945 | list_for_each_entry(call, &ftrace_events, list) { | |
1946 | if (call->mod) { | |
1947 | /* | |
1948 | * Directories for events by modules need to | |
1949 | * keep module ref counts when opened (as we don't | |
1950 | * want the module to disappear when reading one | |
1951 | * of these files). The file_ops keep account of | |
1952 | * the module ref count. | |
ae63b31e | 1953 | */ |
315326c1 | 1954 | file_ops = find_ftrace_file_ops(file_ops, call->mod); |
ae63b31e SR |
1955 | if (!file_ops) |
1956 | continue; /* Warn? */ | |
315326c1 | 1957 | ret = __trace_add_new_mod_event(call, tr, file_ops); |
ae63b31e SR |
1958 | if (ret < 0) |
1959 | pr_warning("Could not create directory for event %s\n", | |
1960 | call->name); | |
1961 | continue; | |
1962 | } | |
1963 | ret = __trace_add_new_event(call, tr, | |
1964 | &ftrace_event_id_fops, | |
1965 | &ftrace_enable_fops, | |
1966 | &ftrace_event_filter_fops, | |
1967 | &ftrace_event_format_fops); | |
1968 | if (ret < 0) | |
1969 | pr_warning("Could not create directory for event %s\n", | |
1970 | call->name); | |
1971 | } | |
1972 | } | |
1973 | ||
3cd715de SRRH |
1974 | #ifdef CONFIG_DYNAMIC_FTRACE |
1975 | ||
1976 | /* Avoid typos */ | |
1977 | #define ENABLE_EVENT_STR "enable_event" | |
1978 | #define DISABLE_EVENT_STR "disable_event" | |
1979 | ||
1980 | struct event_probe_data { | |
1981 | struct ftrace_event_file *file; | |
1982 | unsigned long count; | |
1983 | int ref; | |
1984 | bool enable; | |
1985 | }; | |
1986 | ||
1987 | static struct ftrace_event_file * | |
1988 | find_event_file(struct trace_array *tr, const char *system, const char *event) | |
1989 | { | |
1990 | struct ftrace_event_file *file; | |
1991 | struct ftrace_event_call *call; | |
1992 | ||
1993 | list_for_each_entry(file, &tr->events, list) { | |
1994 | ||
1995 | call = file->event_call; | |
1996 | ||
1997 | if (!call->name || !call->class || !call->class->reg) | |
1998 | continue; | |
1999 | ||
2000 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) | |
2001 | continue; | |
2002 | ||
2003 | if (strcmp(event, call->name) == 0 && | |
2004 | strcmp(system, call->class->system) == 0) | |
2005 | return file; | |
2006 | } | |
2007 | return NULL; | |
2008 | } | |
2009 | ||
2010 | static void | |
2011 | event_enable_probe(unsigned long ip, unsigned long parent_ip, void **_data) | |
2012 | { | |
2013 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2014 | struct event_probe_data *data = *pdata; | |
2015 | ||
2016 | if (!data) | |
2017 | return; | |
2018 | ||
2019 | if (data->enable) | |
2020 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); | |
2021 | else | |
2022 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); | |
2023 | } | |
2024 | ||
2025 | static void | |
2026 | event_enable_count_probe(unsigned long ip, unsigned long parent_ip, void **_data) | |
2027 | { | |
2028 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2029 | struct event_probe_data *data = *pdata; | |
2030 | ||
2031 | if (!data) | |
2032 | return; | |
2033 | ||
2034 | if (!data->count) | |
2035 | return; | |
2036 | ||
2037 | /* Skip if the event is in a state we want to switch to */ | |
2038 | if (data->enable == !(data->file->flags & FTRACE_EVENT_FL_SOFT_DISABLED)) | |
2039 | return; | |
2040 | ||
2041 | if (data->count != -1) | |
2042 | (data->count)--; | |
2043 | ||
2044 | event_enable_probe(ip, parent_ip, _data); | |
2045 | } | |
2046 | ||
2047 | static int | |
2048 | event_enable_print(struct seq_file *m, unsigned long ip, | |
2049 | struct ftrace_probe_ops *ops, void *_data) | |
2050 | { | |
2051 | struct event_probe_data *data = _data; | |
2052 | ||
2053 | seq_printf(m, "%ps:", (void *)ip); | |
2054 | ||
2055 | seq_printf(m, "%s:%s:%s", | |
2056 | data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR, | |
2057 | data->file->event_call->class->system, | |
2058 | data->file->event_call->name); | |
2059 | ||
2060 | if (data->count == -1) | |
2061 | seq_printf(m, ":unlimited\n"); | |
2062 | else | |
2063 | seq_printf(m, ":count=%ld\n", data->count); | |
2064 | ||
2065 | return 0; | |
2066 | } | |
2067 | ||
2068 | static int | |
2069 | event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip, | |
2070 | void **_data) | |
2071 | { | |
2072 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2073 | struct event_probe_data *data = *pdata; | |
2074 | ||
2075 | data->ref++; | |
2076 | return 0; | |
2077 | } | |
2078 | ||
2079 | static void | |
2080 | event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip, | |
2081 | void **_data) | |
2082 | { | |
2083 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2084 | struct event_probe_data *data = *pdata; | |
2085 | ||
2086 | if (WARN_ON_ONCE(data->ref <= 0)) | |
2087 | return; | |
2088 | ||
2089 | data->ref--; | |
2090 | if (!data->ref) { | |
2091 | /* Remove the SOFT_MODE flag */ | |
2092 | __ftrace_event_enable_disable(data->file, 0, 1); | |
2093 | module_put(data->file->event_call->mod); | |
2094 | kfree(data); | |
2095 | } | |
2096 | *pdata = NULL; | |
2097 | } | |
2098 | ||
2099 | static struct ftrace_probe_ops event_enable_probe_ops = { | |
2100 | .func = event_enable_probe, | |
2101 | .print = event_enable_print, | |
2102 | .init = event_enable_init, | |
2103 | .free = event_enable_free, | |
2104 | }; | |
2105 | ||
2106 | static struct ftrace_probe_ops event_enable_count_probe_ops = { | |
2107 | .func = event_enable_count_probe, | |
2108 | .print = event_enable_print, | |
2109 | .init = event_enable_init, | |
2110 | .free = event_enable_free, | |
2111 | }; | |
2112 | ||
2113 | static struct ftrace_probe_ops event_disable_probe_ops = { | |
2114 | .func = event_enable_probe, | |
2115 | .print = event_enable_print, | |
2116 | .init = event_enable_init, | |
2117 | .free = event_enable_free, | |
2118 | }; | |
2119 | ||
2120 | static struct ftrace_probe_ops event_disable_count_probe_ops = { | |
2121 | .func = event_enable_count_probe, | |
2122 | .print = event_enable_print, | |
2123 | .init = event_enable_init, | |
2124 | .free = event_enable_free, | |
2125 | }; | |
2126 | ||
2127 | static int | |
2128 | event_enable_func(struct ftrace_hash *hash, | |
2129 | char *glob, char *cmd, char *param, int enabled) | |
2130 | { | |
2131 | struct trace_array *tr = top_trace_array(); | |
2132 | struct ftrace_event_file *file; | |
2133 | struct ftrace_probe_ops *ops; | |
2134 | struct event_probe_data *data; | |
2135 | const char *system; | |
2136 | const char *event; | |
2137 | char *number; | |
2138 | bool enable; | |
2139 | int ret; | |
2140 | ||
2141 | /* hash funcs only work with set_ftrace_filter */ | |
2142 | if (!enabled) | |
2143 | return -EINVAL; | |
2144 | ||
2145 | if (!param) | |
2146 | return -EINVAL; | |
2147 | ||
2148 | system = strsep(¶m, ":"); | |
2149 | if (!param) | |
2150 | return -EINVAL; | |
2151 | ||
2152 | event = strsep(¶m, ":"); | |
2153 | ||
2154 | mutex_lock(&event_mutex); | |
2155 | ||
2156 | ret = -EINVAL; | |
2157 | file = find_event_file(tr, system, event); | |
2158 | if (!file) | |
2159 | goto out; | |
2160 | ||
2161 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; | |
2162 | ||
2163 | if (enable) | |
2164 | ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops; | |
2165 | else | |
2166 | ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops; | |
2167 | ||
2168 | if (glob[0] == '!') { | |
2169 | unregister_ftrace_function_probe_func(glob+1, ops); | |
2170 | ret = 0; | |
2171 | goto out; | |
2172 | } | |
2173 | ||
2174 | ret = -ENOMEM; | |
2175 | data = kzalloc(sizeof(*data), GFP_KERNEL); | |
2176 | if (!data) | |
2177 | goto out; | |
2178 | ||
2179 | data->enable = enable; | |
2180 | data->count = -1; | |
2181 | data->file = file; | |
2182 | ||
2183 | if (!param) | |
2184 | goto out_reg; | |
2185 | ||
2186 | number = strsep(¶m, ":"); | |
2187 | ||
2188 | ret = -EINVAL; | |
2189 | if (!strlen(number)) | |
2190 | goto out_free; | |
2191 | ||
2192 | /* | |
2193 | * We use the callback data field (which is a pointer) | |
2194 | * as our counter. | |
2195 | */ | |
2196 | ret = kstrtoul(number, 0, &data->count); | |
2197 | if (ret) | |
2198 | goto out_free; | |
2199 | ||
2200 | out_reg: | |
2201 | /* Don't let event modules unload while probe registered */ | |
2202 | ret = try_module_get(file->event_call->mod); | |
6ed01066 MH |
2203 | if (!ret) { |
2204 | ret = -EBUSY; | |
3cd715de | 2205 | goto out_free; |
6ed01066 | 2206 | } |
3cd715de SRRH |
2207 | |
2208 | ret = __ftrace_event_enable_disable(file, 1, 1); | |
2209 | if (ret < 0) | |
2210 | goto out_put; | |
2211 | ret = register_ftrace_function_probe(glob, ops, data); | |
ff305ded SRRH |
2212 | /* |
2213 | * The above returns on success the # of functions enabled, | |
2214 | * but if it didn't find any functions it returns zero. | |
2215 | * Consider no functions a failure too. | |
2216 | */ | |
a5b85bd1 MH |
2217 | if (!ret) { |
2218 | ret = -ENOENT; | |
3cd715de | 2219 | goto out_disable; |
ff305ded SRRH |
2220 | } else if (ret < 0) |
2221 | goto out_disable; | |
2222 | /* Just return zero, not the number of enabled functions */ | |
2223 | ret = 0; | |
3cd715de SRRH |
2224 | out: |
2225 | mutex_unlock(&event_mutex); | |
2226 | return ret; | |
2227 | ||
2228 | out_disable: | |
2229 | __ftrace_event_enable_disable(file, 0, 1); | |
2230 | out_put: | |
2231 | module_put(file->event_call->mod); | |
2232 | out_free: | |
2233 | kfree(data); | |
2234 | goto out; | |
2235 | } | |
2236 | ||
2237 | static struct ftrace_func_command event_enable_cmd = { | |
2238 | .name = ENABLE_EVENT_STR, | |
2239 | .func = event_enable_func, | |
2240 | }; | |
2241 | ||
2242 | static struct ftrace_func_command event_disable_cmd = { | |
2243 | .name = DISABLE_EVENT_STR, | |
2244 | .func = event_enable_func, | |
2245 | }; | |
2246 | ||
2247 | static __init int register_event_cmds(void) | |
2248 | { | |
2249 | int ret; | |
2250 | ||
2251 | ret = register_ftrace_command(&event_enable_cmd); | |
2252 | if (WARN_ON(ret < 0)) | |
2253 | return ret; | |
2254 | ret = register_ftrace_command(&event_disable_cmd); | |
2255 | if (WARN_ON(ret < 0)) | |
2256 | unregister_ftrace_command(&event_enable_cmd); | |
2257 | return ret; | |
2258 | } | |
2259 | #else | |
2260 | static inline int register_event_cmds(void) { return 0; } | |
2261 | #endif /* CONFIG_DYNAMIC_FTRACE */ | |
2262 | ||
77248221 SR |
2263 | /* |
2264 | * The top level array has already had its ftrace_event_file | |
2265 | * descriptors created in order to allow for early events to | |
2266 | * be recorded. This function is called after the debugfs has been | |
2267 | * initialized, and we now have to create the files associated | |
2268 | * to the events. | |
2269 | */ | |
2270 | static __init void | |
2271 | __trace_early_add_event_dirs(struct trace_array *tr) | |
2272 | { | |
2273 | struct ftrace_event_file *file; | |
2274 | int ret; | |
2275 | ||
2276 | ||
2277 | list_for_each_entry(file, &tr->events, list) { | |
2278 | ret = event_create_dir(tr->event_dir, file, | |
2279 | &ftrace_event_id_fops, | |
2280 | &ftrace_enable_fops, | |
2281 | &ftrace_event_filter_fops, | |
2282 | &ftrace_event_format_fops); | |
2283 | if (ret < 0) | |
2284 | pr_warning("Could not create directory for event %s\n", | |
2285 | file->event_call->name); | |
2286 | } | |
2287 | } | |
2288 | ||
2289 | /* | |
2290 | * For early boot up, the top trace array requires to have | |
2291 | * a list of events that can be enabled. This must be done before | |
2292 | * the filesystem is set up in order to allow events to be traced | |
2293 | * early. | |
2294 | */ | |
2295 | static __init void | |
2296 | __trace_early_add_events(struct trace_array *tr) | |
2297 | { | |
2298 | struct ftrace_event_call *call; | |
2299 | int ret; | |
2300 | ||
2301 | list_for_each_entry(call, &ftrace_events, list) { | |
2302 | /* Early boot up should not have any modules loaded */ | |
2303 | if (WARN_ON_ONCE(call->mod)) | |
2304 | continue; | |
2305 | ||
2306 | ret = __trace_early_add_new_event(call, tr); | |
2307 | if (ret < 0) | |
2308 | pr_warning("Could not create early event %s\n", | |
2309 | call->name); | |
2310 | } | |
2311 | } | |
2312 | ||
0c8916c3 SR |
2313 | /* Remove the event directory structure for a trace directory. */ |
2314 | static void | |
2315 | __trace_remove_event_dirs(struct trace_array *tr) | |
2316 | { | |
2317 | struct ftrace_event_file *file, *next; | |
2318 | ||
c6febdf2 ON |
2319 | list_for_each_entry_safe(file, next, &tr->events, list) |
2320 | remove_event_file_dir(file); | |
0c8916c3 SR |
2321 | } |
2322 | ||
ae63b31e SR |
2323 | static void |
2324 | __add_event_to_tracers(struct ftrace_event_call *call, | |
2325 | struct ftrace_module_file_ops *file_ops) | |
2326 | { | |
2327 | struct trace_array *tr; | |
2328 | ||
2329 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { | |
2330 | if (file_ops) | |
315326c1 | 2331 | __trace_add_new_mod_event(call, tr, file_ops); |
ae63b31e SR |
2332 | else |
2333 | __trace_add_new_event(call, tr, | |
2334 | &ftrace_event_id_fops, | |
2335 | &ftrace_enable_fops, | |
2336 | &ftrace_event_filter_fops, | |
2337 | &ftrace_event_format_fops); | |
2338 | } | |
2339 | } | |
2340 | ||
ec827c7e | 2341 | static struct notifier_block trace_module_nb = { |
6d723736 SR |
2342 | .notifier_call = trace_module_notify, |
2343 | .priority = 0, | |
2344 | }; | |
2345 | ||
e4a9ea5e SR |
2346 | extern struct ftrace_event_call *__start_ftrace_events[]; |
2347 | extern struct ftrace_event_call *__stop_ftrace_events[]; | |
a59fd602 | 2348 | |
020e5f85 LZ |
2349 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
2350 | ||
2351 | static __init int setup_trace_event(char *str) | |
2352 | { | |
2353 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); | |
55034cd6 SRRH |
2354 | ring_buffer_expanded = true; |
2355 | tracing_selftest_disabled = true; | |
020e5f85 LZ |
2356 | |
2357 | return 1; | |
2358 | } | |
2359 | __setup("trace_event=", setup_trace_event); | |
2360 | ||
77248221 SR |
2361 | /* Expects to have event_mutex held when called */ |
2362 | static int | |
2363 | create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) | |
ae63b31e SR |
2364 | { |
2365 | struct dentry *d_events; | |
2366 | struct dentry *entry; | |
2367 | ||
2368 | entry = debugfs_create_file("set_event", 0644, parent, | |
2369 | tr, &ftrace_set_event_fops); | |
2370 | if (!entry) { | |
2371 | pr_warning("Could not create debugfs 'set_event' entry\n"); | |
2372 | return -ENOMEM; | |
2373 | } | |
2374 | ||
2375 | d_events = debugfs_create_dir("events", parent); | |
277ba044 | 2376 | if (!d_events) { |
ae63b31e | 2377 | pr_warning("Could not create debugfs 'events' directory\n"); |
277ba044 SR |
2378 | return -ENOMEM; |
2379 | } | |
ae63b31e SR |
2380 | |
2381 | /* ring buffer internal formats */ | |
2382 | trace_create_file("header_page", 0444, d_events, | |
2383 | ring_buffer_print_page_header, | |
2384 | &ftrace_show_header_fops); | |
2385 | ||
2386 | trace_create_file("header_event", 0444, d_events, | |
2387 | ring_buffer_print_entry_header, | |
2388 | &ftrace_show_header_fops); | |
2389 | ||
2390 | trace_create_file("enable", 0644, d_events, | |
2391 | tr, &ftrace_tr_enable_fops); | |
2392 | ||
2393 | tr->event_dir = d_events; | |
77248221 SR |
2394 | |
2395 | return 0; | |
2396 | } | |
2397 | ||
2398 | /** | |
2399 | * event_trace_add_tracer - add a instance of a trace_array to events | |
2400 | * @parent: The parent dentry to place the files/directories for events in | |
2401 | * @tr: The trace array associated with these events | |
2402 | * | |
2403 | * When a new instance is created, it needs to set up its events | |
2404 | * directory, as well as other files associated with events. It also | |
2405 | * creates the event hierachry in the @parent/events directory. | |
2406 | * | |
2407 | * Returns 0 on success. | |
2408 | */ | |
2409 | int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) | |
2410 | { | |
2411 | int ret; | |
2412 | ||
2413 | mutex_lock(&event_mutex); | |
2414 | ||
2415 | ret = create_event_toplevel_files(parent, tr); | |
2416 | if (ret) | |
2417 | goto out_unlock; | |
2418 | ||
52f6ad6d | 2419 | down_write(&trace_event_sem); |
ae63b31e | 2420 | __trace_add_event_dirs(tr); |
52f6ad6d | 2421 | up_write(&trace_event_sem); |
277ba044 | 2422 | |
77248221 | 2423 | out_unlock: |
277ba044 | 2424 | mutex_unlock(&event_mutex); |
ae63b31e | 2425 | |
77248221 SR |
2426 | return ret; |
2427 | } | |
2428 | ||
2429 | /* | |
2430 | * The top trace array already had its file descriptors created. | |
2431 | * Now the files themselves need to be created. | |
2432 | */ | |
2433 | static __init int | |
2434 | early_event_add_tracer(struct dentry *parent, struct trace_array *tr) | |
2435 | { | |
2436 | int ret; | |
2437 | ||
2438 | mutex_lock(&event_mutex); | |
2439 | ||
2440 | ret = create_event_toplevel_files(parent, tr); | |
2441 | if (ret) | |
2442 | goto out_unlock; | |
2443 | ||
52f6ad6d | 2444 | down_write(&trace_event_sem); |
77248221 | 2445 | __trace_early_add_event_dirs(tr); |
52f6ad6d | 2446 | up_write(&trace_event_sem); |
77248221 SR |
2447 | |
2448 | out_unlock: | |
2449 | mutex_unlock(&event_mutex); | |
2450 | ||
2451 | return ret; | |
ae63b31e SR |
2452 | } |
2453 | ||
0c8916c3 SR |
2454 | int event_trace_del_tracer(struct trace_array *tr) |
2455 | { | |
0c8916c3 SR |
2456 | mutex_lock(&event_mutex); |
2457 | ||
68cebd26 SRRH |
2458 | /* Disable any running events */ |
2459 | __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0); | |
2460 | ||
52f6ad6d | 2461 | down_write(&trace_event_sem); |
0c8916c3 SR |
2462 | __trace_remove_event_dirs(tr); |
2463 | debugfs_remove_recursive(tr->event_dir); | |
52f6ad6d | 2464 | up_write(&trace_event_sem); |
0c8916c3 SR |
2465 | |
2466 | tr->event_dir = NULL; | |
2467 | ||
2468 | mutex_unlock(&event_mutex); | |
2469 | ||
2470 | return 0; | |
2471 | } | |
2472 | ||
d1a29143 SR |
2473 | static __init int event_trace_memsetup(void) |
2474 | { | |
2475 | field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC); | |
2476 | file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC); | |
2477 | return 0; | |
2478 | } | |
2479 | ||
8781915a EG |
2480 | static __init int event_trace_enable(void) |
2481 | { | |
ae63b31e | 2482 | struct trace_array *tr = top_trace_array(); |
8781915a EG |
2483 | struct ftrace_event_call **iter, *call; |
2484 | char *buf = bootup_event_buf; | |
2485 | char *token; | |
2486 | int ret; | |
2487 | ||
2488 | for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { | |
2489 | ||
2490 | call = *iter; | |
2491 | ret = event_init(call); | |
2492 | if (!ret) | |
2493 | list_add(&call->list, &ftrace_events); | |
2494 | } | |
2495 | ||
77248221 SR |
2496 | /* |
2497 | * We need the top trace array to have a working set of trace | |
2498 | * points at early init, before the debug files and directories | |
2499 | * are created. Create the file entries now, and attach them | |
2500 | * to the actual file dentries later. | |
2501 | */ | |
2502 | __trace_early_add_events(tr); | |
2503 | ||
8781915a EG |
2504 | while (true) { |
2505 | token = strsep(&buf, ","); | |
2506 | ||
2507 | if (!token) | |
2508 | break; | |
2509 | if (!*token) | |
2510 | continue; | |
2511 | ||
ae63b31e | 2512 | ret = ftrace_set_clr_event(tr, token, 1); |
8781915a EG |
2513 | if (ret) |
2514 | pr_warn("Failed to enable trace event: %s\n", token); | |
2515 | } | |
81698831 SR |
2516 | |
2517 | trace_printk_start_comm(); | |
2518 | ||
3cd715de SRRH |
2519 | register_event_cmds(); |
2520 | ||
8781915a EG |
2521 | return 0; |
2522 | } | |
2523 | ||
b77e38aa SR |
2524 | static __init int event_trace_init(void) |
2525 | { | |
ae63b31e | 2526 | struct trace_array *tr; |
b77e38aa SR |
2527 | struct dentry *d_tracer; |
2528 | struct dentry *entry; | |
6d723736 | 2529 | int ret; |
b77e38aa | 2530 | |
ae63b31e SR |
2531 | tr = top_trace_array(); |
2532 | ||
b77e38aa SR |
2533 | d_tracer = tracing_init_dentry(); |
2534 | if (!d_tracer) | |
2535 | return 0; | |
2536 | ||
2314c4ae | 2537 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
ae63b31e | 2538 | tr, &ftrace_avail_fops); |
2314c4ae SR |
2539 | if (!entry) |
2540 | pr_warning("Could not create debugfs " | |
2541 | "'available_events' entry\n"); | |
2542 | ||
8728fe50 LZ |
2543 | if (trace_define_common_fields()) |
2544 | pr_warning("tracing: Failed to allocate common fields"); | |
2545 | ||
77248221 | 2546 | ret = early_event_add_tracer(d_tracer, tr); |
ae63b31e SR |
2547 | if (ret) |
2548 | return ret; | |
020e5f85 | 2549 | |
6d723736 | 2550 | ret = register_module_notifier(&trace_module_nb); |
55379376 | 2551 | if (ret) |
6d723736 SR |
2552 | pr_warning("Failed to register trace events module notifier\n"); |
2553 | ||
b77e38aa SR |
2554 | return 0; |
2555 | } | |
d1a29143 | 2556 | early_initcall(event_trace_memsetup); |
8781915a | 2557 | core_initcall(event_trace_enable); |
b77e38aa | 2558 | fs_initcall(event_trace_init); |
e6187007 SR |
2559 | |
2560 | #ifdef CONFIG_FTRACE_STARTUP_TEST | |
2561 | ||
2562 | static DEFINE_SPINLOCK(test_spinlock); | |
2563 | static DEFINE_SPINLOCK(test_spinlock_irq); | |
2564 | static DEFINE_MUTEX(test_mutex); | |
2565 | ||
2566 | static __init void test_work(struct work_struct *dummy) | |
2567 | { | |
2568 | spin_lock(&test_spinlock); | |
2569 | spin_lock_irq(&test_spinlock_irq); | |
2570 | udelay(1); | |
2571 | spin_unlock_irq(&test_spinlock_irq); | |
2572 | spin_unlock(&test_spinlock); | |
2573 | ||
2574 | mutex_lock(&test_mutex); | |
2575 | msleep(1); | |
2576 | mutex_unlock(&test_mutex); | |
2577 | } | |
2578 | ||
2579 | static __init int event_test_thread(void *unused) | |
2580 | { | |
2581 | void *test_malloc; | |
2582 | ||
2583 | test_malloc = kmalloc(1234, GFP_KERNEL); | |
2584 | if (!test_malloc) | |
2585 | pr_info("failed to kmalloc\n"); | |
2586 | ||
2587 | schedule_on_each_cpu(test_work); | |
2588 | ||
2589 | kfree(test_malloc); | |
2590 | ||
2591 | set_current_state(TASK_INTERRUPTIBLE); | |
2592 | while (!kthread_should_stop()) | |
2593 | schedule(); | |
2594 | ||
2595 | return 0; | |
2596 | } | |
2597 | ||
2598 | /* | |
2599 | * Do various things that may trigger events. | |
2600 | */ | |
2601 | static __init void event_test_stuff(void) | |
2602 | { | |
2603 | struct task_struct *test_thread; | |
2604 | ||
2605 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); | |
2606 | msleep(1); | |
2607 | kthread_stop(test_thread); | |
2608 | } | |
2609 | ||
2610 | /* | |
2611 | * For every trace event defined, we will test each trace point separately, | |
2612 | * and then by groups, and finally all trace points. | |
2613 | */ | |
9ea21c1e | 2614 | static __init void event_trace_self_tests(void) |
e6187007 | 2615 | { |
ae63b31e SR |
2616 | struct ftrace_subsystem_dir *dir; |
2617 | struct ftrace_event_file *file; | |
e6187007 SR |
2618 | struct ftrace_event_call *call; |
2619 | struct event_subsystem *system; | |
ae63b31e | 2620 | struct trace_array *tr; |
e6187007 SR |
2621 | int ret; |
2622 | ||
ae63b31e SR |
2623 | tr = top_trace_array(); |
2624 | ||
e6187007 SR |
2625 | pr_info("Running tests on trace events:\n"); |
2626 | ||
ae63b31e SR |
2627 | list_for_each_entry(file, &tr->events, list) { |
2628 | ||
2629 | call = file->event_call; | |
e6187007 | 2630 | |
2239291a SR |
2631 | /* Only test those that have a probe */ |
2632 | if (!call->class || !call->class->probe) | |
e6187007 SR |
2633 | continue; |
2634 | ||
1f5a6b45 SR |
2635 | /* |
2636 | * Testing syscall events here is pretty useless, but | |
2637 | * we still do it if configured. But this is time consuming. | |
2638 | * What we really need is a user thread to perform the | |
2639 | * syscalls as we test. | |
2640 | */ | |
2641 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS | |
8f082018 SR |
2642 | if (call->class->system && |
2643 | strcmp(call->class->system, "syscalls") == 0) | |
1f5a6b45 SR |
2644 | continue; |
2645 | #endif | |
2646 | ||
e6187007 SR |
2647 | pr_info("Testing event %s: ", call->name); |
2648 | ||
2649 | /* | |
2650 | * If an event is already enabled, someone is using | |
2651 | * it and the self test should not be on. | |
2652 | */ | |
ae63b31e | 2653 | if (file->flags & FTRACE_EVENT_FL_ENABLED) { |
e6187007 SR |
2654 | pr_warning("Enabled event during self test!\n"); |
2655 | WARN_ON_ONCE(1); | |
2656 | continue; | |
2657 | } | |
2658 | ||
ae63b31e | 2659 | ftrace_event_enable_disable(file, 1); |
e6187007 | 2660 | event_test_stuff(); |
ae63b31e | 2661 | ftrace_event_enable_disable(file, 0); |
e6187007 SR |
2662 | |
2663 | pr_cont("OK\n"); | |
2664 | } | |
2665 | ||
2666 | /* Now test at the sub system level */ | |
2667 | ||
2668 | pr_info("Running tests on trace event systems:\n"); | |
2669 | ||
ae63b31e SR |
2670 | list_for_each_entry(dir, &tr->systems, list) { |
2671 | ||
2672 | system = dir->subsystem; | |
e6187007 SR |
2673 | |
2674 | /* the ftrace system is special, skip it */ | |
2675 | if (strcmp(system->name, "ftrace") == 0) | |
2676 | continue; | |
2677 | ||
2678 | pr_info("Testing event system %s: ", system->name); | |
2679 | ||
ae63b31e | 2680 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1); |
e6187007 SR |
2681 | if (WARN_ON_ONCE(ret)) { |
2682 | pr_warning("error enabling system %s\n", | |
2683 | system->name); | |
2684 | continue; | |
2685 | } | |
2686 | ||
2687 | event_test_stuff(); | |
2688 | ||
ae63b31e | 2689 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0); |
76bab1b7 | 2690 | if (WARN_ON_ONCE(ret)) { |
e6187007 SR |
2691 | pr_warning("error disabling system %s\n", |
2692 | system->name); | |
76bab1b7 YL |
2693 | continue; |
2694 | } | |
e6187007 SR |
2695 | |
2696 | pr_cont("OK\n"); | |
2697 | } | |
2698 | ||
2699 | /* Test with all events enabled */ | |
2700 | ||
2701 | pr_info("Running tests on all trace events:\n"); | |
2702 | pr_info("Testing all events: "); | |
2703 | ||
ae63b31e | 2704 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1); |
e6187007 | 2705 | if (WARN_ON_ONCE(ret)) { |
e6187007 | 2706 | pr_warning("error enabling all events\n"); |
9ea21c1e | 2707 | return; |
e6187007 SR |
2708 | } |
2709 | ||
2710 | event_test_stuff(); | |
2711 | ||
2712 | /* reset sysname */ | |
ae63b31e | 2713 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0); |
e6187007 SR |
2714 | if (WARN_ON_ONCE(ret)) { |
2715 | pr_warning("error disabling all events\n"); | |
9ea21c1e | 2716 | return; |
e6187007 SR |
2717 | } |
2718 | ||
2719 | pr_cont("OK\n"); | |
9ea21c1e SR |
2720 | } |
2721 | ||
2722 | #ifdef CONFIG_FUNCTION_TRACER | |
2723 | ||
245b2e70 | 2724 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
9ea21c1e SR |
2725 | |
2726 | static void | |
2f5f6ad9 | 2727 | function_test_events_call(unsigned long ip, unsigned long parent_ip, |
a1e2e31d | 2728 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
9ea21c1e SR |
2729 | { |
2730 | struct ring_buffer_event *event; | |
e77405ad | 2731 | struct ring_buffer *buffer; |
9ea21c1e SR |
2732 | struct ftrace_entry *entry; |
2733 | unsigned long flags; | |
2734 | long disabled; | |
9ea21c1e SR |
2735 | int cpu; |
2736 | int pc; | |
2737 | ||
2738 | pc = preempt_count(); | |
5168ae50 | 2739 | preempt_disable_notrace(); |
9ea21c1e | 2740 | cpu = raw_smp_processor_id(); |
245b2e70 | 2741 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
9ea21c1e SR |
2742 | |
2743 | if (disabled != 1) | |
2744 | goto out; | |
2745 | ||
2746 | local_save_flags(flags); | |
2747 | ||
e77405ad SR |
2748 | event = trace_current_buffer_lock_reserve(&buffer, |
2749 | TRACE_FN, sizeof(*entry), | |
9ea21c1e SR |
2750 | flags, pc); |
2751 | if (!event) | |
2752 | goto out; | |
2753 | entry = ring_buffer_event_data(event); | |
2754 | entry->ip = ip; | |
2755 | entry->parent_ip = parent_ip; | |
2756 | ||
0d5c6e1c | 2757 | trace_buffer_unlock_commit(buffer, event, flags, pc); |
9ea21c1e SR |
2758 | |
2759 | out: | |
245b2e70 | 2760 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
5168ae50 | 2761 | preempt_enable_notrace(); |
9ea21c1e SR |
2762 | } |
2763 | ||
2764 | static struct ftrace_ops trace_ops __initdata = | |
2765 | { | |
2766 | .func = function_test_events_call, | |
4740974a | 2767 | .flags = FTRACE_OPS_FL_RECURSION_SAFE, |
9ea21c1e SR |
2768 | }; |
2769 | ||
2770 | static __init void event_trace_self_test_with_function(void) | |
2771 | { | |
17bb615a SR |
2772 | int ret; |
2773 | ret = register_ftrace_function(&trace_ops); | |
2774 | if (WARN_ON(ret < 0)) { | |
2775 | pr_info("Failed to enable function tracer for event tests\n"); | |
2776 | return; | |
2777 | } | |
9ea21c1e SR |
2778 | pr_info("Running tests again, along with the function tracer\n"); |
2779 | event_trace_self_tests(); | |
2780 | unregister_ftrace_function(&trace_ops); | |
2781 | } | |
2782 | #else | |
2783 | static __init void event_trace_self_test_with_function(void) | |
2784 | { | |
2785 | } | |
2786 | #endif | |
2787 | ||
2788 | static __init int event_trace_self_tests_init(void) | |
2789 | { | |
020e5f85 LZ |
2790 | if (!tracing_selftest_disabled) { |
2791 | event_trace_self_tests(); | |
2792 | event_trace_self_test_with_function(); | |
2793 | } | |
e6187007 SR |
2794 | |
2795 | return 0; | |
2796 | } | |
2797 | ||
28d20e2d | 2798 | late_initcall(event_trace_self_tests_init); |
e6187007 SR |
2799 | |
2800 | #endif |