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