ftrace: Fix trace_remove_event_call() to lock trace_event_mutex
[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>
e6187007 18#include <linux/delay.h>
b77e38aa 19
020e5f85
LZ
20#include <asm/setup.h>
21
91729ef9 22#include "trace_output.h"
b77e38aa 23
b628b3e6
SR
24#define TRACE_SYSTEM "TRACE_SYSTEM"
25
20c8928a 26DEFINE_MUTEX(event_mutex);
11a241a3 27
a59fd602
SR
28LIST_HEAD(ftrace_events);
29
aeaeae11
FW
30int trace_define_field(struct ftrace_event_call *call, const char *type,
31 const char *name, int offset, int size, int is_signed,
43b51ead 32 int filter_type)
cf027f64
TZ
33{
34 struct ftrace_event_field *field;
35
fe9f57f2 36 field = kzalloc(sizeof(*field), GFP_KERNEL);
cf027f64
TZ
37 if (!field)
38 goto err;
fe9f57f2 39
cf027f64
TZ
40 field->name = kstrdup(name, GFP_KERNEL);
41 if (!field->name)
42 goto err;
fe9f57f2 43
cf027f64
TZ
44 field->type = kstrdup(type, GFP_KERNEL);
45 if (!field->type)
46 goto err;
fe9f57f2 47
43b51ead
LZ
48 if (filter_type == FILTER_OTHER)
49 field->filter_type = filter_assign_type(type);
50 else
51 field->filter_type = filter_type;
52
cf027f64
TZ
53 field->offset = offset;
54 field->size = size;
a118e4d1 55 field->is_signed = is_signed;
aa38e9fc 56
cf027f64
TZ
57 list_add(&field->link, &call->fields);
58
59 return 0;
fe9f57f2 60
cf027f64
TZ
61err:
62 if (field) {
63 kfree(field->name);
64 kfree(field->type);
65 }
66 kfree(field);
fe9f57f2 67
cf027f64
TZ
68 return -ENOMEM;
69}
17c873ec 70EXPORT_SYMBOL_GPL(trace_define_field);
cf027f64 71
e647d6b3
LZ
72#define __common_field(type, item) \
73 ret = trace_define_field(call, #type, "common_" #item, \
74 offsetof(typeof(ent), item), \
75 sizeof(ent.item), \
43b51ead 76 is_signed_type(type), FILTER_OTHER); \
e647d6b3
LZ
77 if (ret) \
78 return ret;
79
80int trace_define_common_fields(struct ftrace_event_call *call)
81{
82 int ret;
83 struct trace_entry ent;
84
85 __common_field(unsigned short, type);
86 __common_field(unsigned char, flags);
87 __common_field(unsigned char, preempt_count);
88 __common_field(int, pid);
89 __common_field(int, tgid);
90
91 return ret;
92}
540b7b8d 93EXPORT_SYMBOL_GPL(trace_define_common_fields);
e647d6b3 94
bd1a5c84 95void trace_destroy_fields(struct ftrace_event_call *call)
2df75e41
LZ
96{
97 struct ftrace_event_field *field, *next;
98
99 list_for_each_entry_safe(field, next, &call->fields, link) {
100 list_del(&field->link);
101 kfree(field->type);
102 kfree(field->name);
103 kfree(field);
104 }
105}
106
fd994989
SR
107static void ftrace_event_enable_disable(struct ftrace_event_call *call,
108 int enable)
109{
fd994989
SR
110 switch (enable) {
111 case 0:
112 if (call->enabled) {
113 call->enabled = 0;
b11c53e1 114 tracing_stop_cmdline_record();
bd1a5c84 115 call->unregfunc(call);
fd994989 116 }
fd994989
SR
117 break;
118 case 1:
da4d0302 119 if (!call->enabled) {
fd994989 120 call->enabled = 1;
b11c53e1 121 tracing_start_cmdline_record();
bd1a5c84 122 call->regfunc(call);
fd994989 123 }
fd994989
SR
124 break;
125 }
126}
127
0e907c99
Z
128static void ftrace_clear_events(void)
129{
130 struct ftrace_event_call *call;
131
132 mutex_lock(&event_mutex);
133 list_for_each_entry(call, &ftrace_events, list) {
134 ftrace_event_enable_disable(call, 0);
135 }
136 mutex_unlock(&event_mutex);
137}
138
8f31bfe5
LZ
139/*
140 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
141 */
142static int __ftrace_set_clr_event(const char *match, const char *sub,
143 const char *event, int set)
b77e38aa 144{
a59fd602 145 struct ftrace_event_call *call;
29f93943 146 int ret = -EINVAL;
8f31bfe5
LZ
147
148 mutex_lock(&event_mutex);
149 list_for_each_entry(call, &ftrace_events, list) {
150
151 if (!call->name || !call->regfunc)
152 continue;
153
154 if (match &&
155 strcmp(match, call->name) != 0 &&
156 strcmp(match, call->system) != 0)
157 continue;
158
159 if (sub && strcmp(sub, call->system) != 0)
160 continue;
161
162 if (event && strcmp(event, call->name) != 0)
163 continue;
164
165 ftrace_event_enable_disable(call, set);
166
167 ret = 0;
168 }
169 mutex_unlock(&event_mutex);
170
171 return ret;
172}
173
174static int ftrace_set_clr_event(char *buf, int set)
175{
b628b3e6 176 char *event = NULL, *sub = NULL, *match;
b628b3e6
SR
177
178 /*
179 * The buf format can be <subsystem>:<event-name>
180 * *:<event-name> means any event by that name.
181 * :<event-name> is the same.
182 *
183 * <subsystem>:* means all events in that subsystem
184 * <subsystem>: means the same.
185 *
186 * <name> (no ':') means all events in a subsystem with
187 * the name <name> or any event that matches <name>
188 */
189
190 match = strsep(&buf, ":");
191 if (buf) {
192 sub = match;
193 event = buf;
194 match = NULL;
195
196 if (!strlen(sub) || strcmp(sub, "*") == 0)
197 sub = NULL;
198 if (!strlen(event) || strcmp(event, "*") == 0)
199 event = NULL;
200 }
b77e38aa 201
8f31bfe5 202 return __ftrace_set_clr_event(match, sub, event, set);
b77e38aa
SR
203}
204
4671c794
SR
205/**
206 * trace_set_clr_event - enable or disable an event
207 * @system: system name to match (NULL for any system)
208 * @event: event name to match (NULL for all events, within system)
209 * @set: 1 to enable, 0 to disable
210 *
211 * This is a way for other parts of the kernel to enable or disable
212 * event recording.
213 *
214 * Returns 0 on success, -EINVAL if the parameters do not match any
215 * registered events.
216 */
217int trace_set_clr_event(const char *system, const char *event, int set)
218{
219 return __ftrace_set_clr_event(NULL, system, event, set);
220}
221
b77e38aa
SR
222/* 128 should be much more than enough */
223#define EVENT_BUF_SIZE 127
224
225static ssize_t
226ftrace_event_write(struct file *file, const char __user *ubuf,
227 size_t cnt, loff_t *ppos)
228{
229 size_t read = 0;
230 int i, set = 1;
231 ssize_t ret;
232 char *buf;
233 char ch;
234
235 if (!cnt || cnt < 0)
236 return 0;
237
1852fcce
SR
238 ret = tracing_update_buffers();
239 if (ret < 0)
240 return ret;
241
b77e38aa
SR
242 ret = get_user(ch, ubuf++);
243 if (ret)
244 return ret;
245 read++;
246 cnt--;
247
248 /* skip white space */
249 while (cnt && isspace(ch)) {
250 ret = get_user(ch, ubuf++);
251 if (ret)
252 return ret;
253 read++;
254 cnt--;
255 }
256
257 /* Only white space found? */
258 if (isspace(ch)) {
259 file->f_pos += read;
260 ret = read;
261 return ret;
262 }
263
264 buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL);
265 if (!buf)
266 return -ENOMEM;
267
268 if (cnt > EVENT_BUF_SIZE)
269 cnt = EVENT_BUF_SIZE;
270
271 i = 0;
272 while (cnt && !isspace(ch)) {
273 if (!i && ch == '!')
274 set = 0;
275 else
276 buf[i++] = ch;
277
278 ret = get_user(ch, ubuf++);
279 if (ret)
280 goto out_free;
281 read++;
282 cnt--;
283 }
284 buf[i] = 0;
285
286 file->f_pos += read;
287
288 ret = ftrace_set_clr_event(buf, set);
289 if (ret)
290 goto out_free;
291
292 ret = read;
293
294 out_free:
295 kfree(buf);
296
297 return ret;
298}
299
300static void *
301t_next(struct seq_file *m, void *v, loff_t *pos)
302{
a59fd602
SR
303 struct list_head *list = m->private;
304 struct ftrace_event_call *call;
b77e38aa
SR
305
306 (*pos)++;
307
40e26815 308 for (;;) {
a59fd602 309 if (list == &ftrace_events)
40e26815
SR
310 return NULL;
311
a59fd602
SR
312 call = list_entry(list, struct ftrace_event_call, list);
313
40e26815
SR
314 /*
315 * The ftrace subsystem is for showing formats only.
316 * They can not be enabled or disabled via the event files.
317 */
318 if (call->regfunc)
319 break;
320
a59fd602 321 list = list->next;
40e26815 322 }
b77e38aa 323
a59fd602 324 m->private = list->next;
b77e38aa
SR
325
326 return call;
327}
328
329static void *t_start(struct seq_file *m, loff_t *pos)
330{
e1c7e2a6
LZ
331 struct ftrace_event_call *call = NULL;
332 loff_t l;
333
20c8928a 334 mutex_lock(&event_mutex);
e1c7e2a6
LZ
335
336 m->private = ftrace_events.next;
337 for (l = 0; l <= *pos; ) {
338 call = t_next(m, NULL, &l);
339 if (!call)
340 break;
341 }
342 return call;
b77e38aa
SR
343}
344
345static void *
346s_next(struct seq_file *m, void *v, loff_t *pos)
347{
a59fd602
SR
348 struct list_head *list = m->private;
349 struct ftrace_event_call *call;
b77e38aa
SR
350
351 (*pos)++;
352
353 retry:
a59fd602 354 if (list == &ftrace_events)
b77e38aa
SR
355 return NULL;
356
a59fd602
SR
357 call = list_entry(list, struct ftrace_event_call, list);
358
b77e38aa 359 if (!call->enabled) {
a59fd602 360 list = list->next;
b77e38aa
SR
361 goto retry;
362 }
363
a59fd602 364 m->private = list->next;
b77e38aa
SR
365
366 return call;
367}
368
369static void *s_start(struct seq_file *m, loff_t *pos)
370{
e1c7e2a6
LZ
371 struct ftrace_event_call *call = NULL;
372 loff_t l;
373
20c8928a 374 mutex_lock(&event_mutex);
e1c7e2a6
LZ
375
376 m->private = ftrace_events.next;
377 for (l = 0; l <= *pos; ) {
378 call = s_next(m, NULL, &l);
379 if (!call)
380 break;
381 }
382 return call;
b77e38aa
SR
383}
384
385static int t_show(struct seq_file *m, void *v)
386{
387 struct ftrace_event_call *call = v;
388
b628b3e6
SR
389 if (strcmp(call->system, TRACE_SYSTEM) != 0)
390 seq_printf(m, "%s:", call->system);
b77e38aa
SR
391 seq_printf(m, "%s\n", call->name);
392
393 return 0;
394}
395
396static void t_stop(struct seq_file *m, void *p)
397{
20c8928a 398 mutex_unlock(&event_mutex);
b77e38aa
SR
399}
400
401static int
402ftrace_event_seq_open(struct inode *inode, struct file *file)
403{
b77e38aa
SR
404 const struct seq_operations *seq_ops;
405
406 if ((file->f_mode & FMODE_WRITE) &&
8650ae32 407 (file->f_flags & O_TRUNC))
b77e38aa
SR
408 ftrace_clear_events();
409
410 seq_ops = inode->i_private;
20c8928a 411 return seq_open(file, seq_ops);
b77e38aa
SR
412}
413
1473e441
SR
414static ssize_t
415event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
416 loff_t *ppos)
417{
418 struct ftrace_event_call *call = filp->private_data;
419 char *buf;
420
da4d0302 421 if (call->enabled)
1473e441
SR
422 buf = "1\n";
423 else
424 buf = "0\n";
425
426 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
427}
428
429static ssize_t
430event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
431 loff_t *ppos)
432{
433 struct ftrace_event_call *call = filp->private_data;
434 char buf[64];
435 unsigned long val;
436 int ret;
437
438 if (cnt >= sizeof(buf))
439 return -EINVAL;
440
441 if (copy_from_user(&buf, ubuf, cnt))
442 return -EFAULT;
443
444 buf[cnt] = 0;
445
446 ret = strict_strtoul(buf, 10, &val);
447 if (ret < 0)
448 return ret;
449
1852fcce
SR
450 ret = tracing_update_buffers();
451 if (ret < 0)
452 return ret;
453
1473e441
SR
454 switch (val) {
455 case 0:
1473e441 456 case 1:
11a241a3 457 mutex_lock(&event_mutex);
fd994989 458 ftrace_event_enable_disable(call, val);
11a241a3 459 mutex_unlock(&event_mutex);
1473e441
SR
460 break;
461
462 default:
463 return -EINVAL;
464 }
465
466 *ppos += cnt;
467
468 return cnt;
469}
470
8ae79a13
SR
471static ssize_t
472system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
473 loff_t *ppos)
474{
c142b15d 475 const char set_to_char[4] = { '?', '0', '1', 'X' };
8ae79a13
SR
476 const char *system = filp->private_data;
477 struct ftrace_event_call *call;
478 char buf[2];
c142b15d 479 int set = 0;
8ae79a13
SR
480 int ret;
481
8ae79a13
SR
482 mutex_lock(&event_mutex);
483 list_for_each_entry(call, &ftrace_events, list) {
484 if (!call->name || !call->regfunc)
485 continue;
486
8f31bfe5 487 if (system && strcmp(call->system, system) != 0)
8ae79a13
SR
488 continue;
489
490 /*
491 * We need to find out if all the events are set
492 * or if all events or cleared, or if we have
493 * a mixture.
494 */
c142b15d
LZ
495 set |= (1 << !!call->enabled);
496
8ae79a13
SR
497 /*
498 * If we have a mixture, no need to look further.
499 */
c142b15d 500 if (set == 3)
8ae79a13
SR
501 break;
502 }
503 mutex_unlock(&event_mutex);
504
c142b15d 505 buf[0] = set_to_char[set];
8ae79a13 506 buf[1] = '\n';
8ae79a13
SR
507
508 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
509
510 return ret;
511}
512
513static ssize_t
514system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
515 loff_t *ppos)
516{
517 const char *system = filp->private_data;
518 unsigned long val;
8ae79a13
SR
519 char buf[64];
520 ssize_t ret;
521
522 if (cnt >= sizeof(buf))
523 return -EINVAL;
524
525 if (copy_from_user(&buf, ubuf, cnt))
526 return -EFAULT;
527
528 buf[cnt] = 0;
529
530 ret = strict_strtoul(buf, 10, &val);
531 if (ret < 0)
532 return ret;
533
534 ret = tracing_update_buffers();
535 if (ret < 0)
536 return ret;
537
8f31bfe5 538 if (val != 0 && val != 1)
8ae79a13 539 return -EINVAL;
8ae79a13 540
8f31bfe5 541 ret = __ftrace_set_clr_event(NULL, system, NULL, val);
8ae79a13 542 if (ret)
8f31bfe5 543 goto out;
8ae79a13
SR
544
545 ret = cnt;
546
8f31bfe5 547out:
8ae79a13
SR
548 *ppos += cnt;
549
550 return ret;
551}
552
75db37d2
SR
553extern char *__bad_type_size(void);
554
91729ef9 555#undef FIELD
156b5f17 556#define FIELD(type, name) \
75db37d2 557 sizeof(type) != sizeof(field.name) ? __bad_type_size() : \
cf027f64
TZ
558 #type, "common_" #name, offsetof(typeof(field), name), \
559 sizeof(field.name)
91729ef9
SR
560
561static int trace_write_header(struct trace_seq *s)
562{
563 struct trace_entry field;
564
565 /* struct trace_entry */
566 return trace_seq_printf(s,
ce8eb2bf
SR
567 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
568 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
569 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
570 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
571 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
91729ef9 572 "\n",
89ec0dee 573 FIELD(unsigned short, type),
91729ef9
SR
574 FIELD(unsigned char, flags),
575 FIELD(unsigned char, preempt_count),
576 FIELD(int, pid),
577 FIELD(int, tgid));
578}
da4d0302 579
981d081e
SR
580static ssize_t
581event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
582 loff_t *ppos)
583{
584 struct ftrace_event_call *call = filp->private_data;
585 struct trace_seq *s;
586 char *buf;
587 int r;
588
c269fc8c
TZ
589 if (*ppos)
590 return 0;
591
981d081e
SR
592 s = kmalloc(sizeof(*s), GFP_KERNEL);
593 if (!s)
594 return -ENOMEM;
595
596 trace_seq_init(s);
597
c5e4e192
SR
598 /* If any of the first writes fail, so will the show_format. */
599
600 trace_seq_printf(s, "name: %s\n", call->name);
601 trace_seq_printf(s, "ID: %d\n", call->id);
602 trace_seq_printf(s, "format:\n");
91729ef9
SR
603 trace_write_header(s);
604
e8f9f4d7 605 r = call->show_format(call, s);
981d081e
SR
606 if (!r) {
607 /*
608 * ug! The format output is bigger than a PAGE!!
609 */
610 buf = "FORMAT TOO BIG\n";
611 r = simple_read_from_buffer(ubuf, cnt, ppos,
612 buf, strlen(buf));
613 goto out;
614 }
615
616 r = simple_read_from_buffer(ubuf, cnt, ppos,
617 s->buffer, s->len);
618 out:
619 kfree(s);
620 return r;
621}
622
23725aee
PZ
623static ssize_t
624event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
625{
626 struct ftrace_event_call *call = filp->private_data;
627 struct trace_seq *s;
628 int r;
629
630 if (*ppos)
631 return 0;
632
633 s = kmalloc(sizeof(*s), GFP_KERNEL);
634 if (!s)
635 return -ENOMEM;
636
637 trace_seq_init(s);
638 trace_seq_printf(s, "%d\n", call->id);
639
640 r = simple_read_from_buffer(ubuf, cnt, ppos,
641 s->buffer, s->len);
642 kfree(s);
643 return r;
644}
645
7ce7e424
TZ
646static ssize_t
647event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
648 loff_t *ppos)
649{
650 struct ftrace_event_call *call = filp->private_data;
651 struct trace_seq *s;
652 int r;
653
654 if (*ppos)
655 return 0;
656
657 s = kmalloc(sizeof(*s), GFP_KERNEL);
658 if (!s)
659 return -ENOMEM;
660
661 trace_seq_init(s);
662
8b372562 663 print_event_filter(call, s);
4bda2d51 664 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
7ce7e424
TZ
665
666 kfree(s);
667
668 return r;
669}
670
671static ssize_t
672event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
673 loff_t *ppos)
674{
675 struct ftrace_event_call *call = filp->private_data;
8b372562 676 char *buf;
7ce7e424
TZ
677 int err;
678
8b372562 679 if (cnt >= PAGE_SIZE)
7ce7e424
TZ
680 return -EINVAL;
681
8b372562
TZ
682 buf = (char *)__get_free_page(GFP_TEMPORARY);
683 if (!buf)
7ce7e424
TZ
684 return -ENOMEM;
685
8b372562
TZ
686 if (copy_from_user(buf, ubuf, cnt)) {
687 free_page((unsigned long) buf);
688 return -EFAULT;
7ce7e424 689 }
8b372562 690 buf[cnt] = '\0';
7ce7e424 691
8b372562
TZ
692 err = apply_event_filter(call, buf);
693 free_page((unsigned long) buf);
694 if (err < 0)
44e9c8b7 695 return err;
0a19e53c 696
7ce7e424
TZ
697 *ppos += cnt;
698
699 return cnt;
700}
701
cfb180f3
TZ
702static ssize_t
703subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
704 loff_t *ppos)
705{
706 struct event_subsystem *system = filp->private_data;
707 struct trace_seq *s;
708 int r;
709
710 if (*ppos)
711 return 0;
712
713 s = kmalloc(sizeof(*s), GFP_KERNEL);
714 if (!s)
715 return -ENOMEM;
716
717 trace_seq_init(s);
718
8b372562 719 print_subsystem_event_filter(system, s);
4bda2d51 720 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
cfb180f3
TZ
721
722 kfree(s);
723
724 return r;
725}
726
727static ssize_t
728subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
729 loff_t *ppos)
730{
731 struct event_subsystem *system = filp->private_data;
8b372562 732 char *buf;
cfb180f3
TZ
733 int err;
734
8b372562 735 if (cnt >= PAGE_SIZE)
cfb180f3
TZ
736 return -EINVAL;
737
8b372562
TZ
738 buf = (char *)__get_free_page(GFP_TEMPORARY);
739 if (!buf)
cfb180f3
TZ
740 return -ENOMEM;
741
8b372562
TZ
742 if (copy_from_user(buf, ubuf, cnt)) {
743 free_page((unsigned long) buf);
744 return -EFAULT;
cfb180f3 745 }
8b372562 746 buf[cnt] = '\0';
cfb180f3 747
8b372562
TZ
748 err = apply_subsystem_event_filter(system, buf);
749 free_page((unsigned long) buf);
750 if (err < 0)
44e9c8b7 751 return err;
cfb180f3
TZ
752
753 *ppos += cnt;
754
755 return cnt;
756}
757
d1b182a8
SR
758static ssize_t
759show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
760{
761 int (*func)(struct trace_seq *s) = filp->private_data;
762 struct trace_seq *s;
763 int r;
764
765 if (*ppos)
766 return 0;
767
768 s = kmalloc(sizeof(*s), GFP_KERNEL);
769 if (!s)
770 return -ENOMEM;
771
772 trace_seq_init(s);
773
774 func(s);
775 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
776
777 kfree(s);
778
779 return r;
780}
781
b77e38aa
SR
782static const struct seq_operations show_event_seq_ops = {
783 .start = t_start,
784 .next = t_next,
785 .show = t_show,
786 .stop = t_stop,
787};
788
789static const struct seq_operations show_set_event_seq_ops = {
790 .start = s_start,
791 .next = s_next,
792 .show = t_show,
793 .stop = t_stop,
794};
795
2314c4ae
SR
796static const struct file_operations ftrace_avail_fops = {
797 .open = ftrace_event_seq_open,
798 .read = seq_read,
799 .llseek = seq_lseek,
800 .release = seq_release,
801};
802
b77e38aa
SR
803static const struct file_operations ftrace_set_event_fops = {
804 .open = ftrace_event_seq_open,
805 .read = seq_read,
806 .write = ftrace_event_write,
807 .llseek = seq_lseek,
808 .release = seq_release,
809};
810
1473e441
SR
811static const struct file_operations ftrace_enable_fops = {
812 .open = tracing_open_generic,
813 .read = event_enable_read,
814 .write = event_enable_write,
815};
816
981d081e
SR
817static const struct file_operations ftrace_event_format_fops = {
818 .open = tracing_open_generic,
819 .read = event_format_read,
820};
821
23725aee
PZ
822static const struct file_operations ftrace_event_id_fops = {
823 .open = tracing_open_generic,
824 .read = event_id_read,
825};
826
7ce7e424
TZ
827static const struct file_operations ftrace_event_filter_fops = {
828 .open = tracing_open_generic,
829 .read = event_filter_read,
830 .write = event_filter_write,
831};
832
cfb180f3
TZ
833static const struct file_operations ftrace_subsystem_filter_fops = {
834 .open = tracing_open_generic,
835 .read = subsystem_filter_read,
836 .write = subsystem_filter_write,
837};
838
8ae79a13
SR
839static const struct file_operations ftrace_system_enable_fops = {
840 .open = tracing_open_generic,
841 .read = system_enable_read,
842 .write = system_enable_write,
843};
844
d1b182a8
SR
845static const struct file_operations ftrace_show_header_fops = {
846 .open = tracing_open_generic,
847 .read = show_header,
848};
849
1473e441
SR
850static struct dentry *event_trace_events_dir(void)
851{
852 static struct dentry *d_tracer;
853 static struct dentry *d_events;
854
855 if (d_events)
856 return d_events;
857
858 d_tracer = tracing_init_dentry();
859 if (!d_tracer)
860 return NULL;
861
862 d_events = debugfs_create_dir("events", d_tracer);
863 if (!d_events)
864 pr_warning("Could not create debugfs "
865 "'events' directory\n");
866
867 return d_events;
868}
869
6ecc2d1c
SR
870static LIST_HEAD(event_subsystems);
871
872static struct dentry *
873event_subsystem_dir(const char *name, struct dentry *d_events)
874{
875 struct event_subsystem *system;
e1112b4d 876 struct dentry *entry;
6ecc2d1c
SR
877
878 /* First see if we did not already create this dir */
879 list_for_each_entry(system, &event_subsystems, list) {
dc82ec98
XG
880 if (strcmp(system->name, name) == 0) {
881 system->nr_events++;
6ecc2d1c 882 return system->entry;
dc82ec98 883 }
6ecc2d1c
SR
884 }
885
886 /* need to create new entry */
887 system = kmalloc(sizeof(*system), GFP_KERNEL);
888 if (!system) {
889 pr_warning("No memory to create event subsystem %s\n",
890 name);
891 return d_events;
892 }
893
894 system->entry = debugfs_create_dir(name, d_events);
895 if (!system->entry) {
896 pr_warning("Could not create event subsystem %s\n",
897 name);
898 kfree(system);
899 return d_events;
900 }
901
dc82ec98 902 system->nr_events = 1;
6d723736
SR
903 system->name = kstrdup(name, GFP_KERNEL);
904 if (!system->name) {
905 debugfs_remove(system->entry);
906 kfree(system);
907 return d_events;
908 }
909
6ecc2d1c
SR
910 list_add(&system->list, &event_subsystems);
911
30e673b2 912 system->filter = NULL;
cfb180f3 913
8b372562
TZ
914 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
915 if (!system->filter) {
916 pr_warning("Could not allocate filter for subsystem "
917 "'%s'\n", name);
918 return system->entry;
919 }
920
e1112b4d
TZ
921 entry = debugfs_create_file("filter", 0644, system->entry, system,
922 &ftrace_subsystem_filter_fops);
8b372562
TZ
923 if (!entry) {
924 kfree(system->filter);
925 system->filter = NULL;
e1112b4d
TZ
926 pr_warning("Could not create debugfs "
927 "'%s/filter' entry\n", name);
8b372562 928 }
e1112b4d 929
8ae79a13
SR
930 entry = trace_create_file("enable", 0644, system->entry,
931 (void *)system->name,
932 &ftrace_system_enable_fops);
933
6ecc2d1c
SR
934 return system->entry;
935}
936
1473e441 937static int
701970b3
SR
938event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
939 const struct file_operations *id,
940 const struct file_operations *enable,
941 const struct file_operations *filter,
942 const struct file_operations *format)
1473e441
SR
943{
944 struct dentry *entry;
fd994989 945 int ret;
1473e441 946
6ecc2d1c
SR
947 /*
948 * If the trace point header did not define TRACE_SYSTEM
949 * then the system would be called "TRACE_SYSTEM".
950 */
6d723736 951 if (strcmp(call->system, TRACE_SYSTEM) != 0)
6ecc2d1c
SR
952 d_events = event_subsystem_dir(call->system, d_events);
953
1473e441
SR
954 call->dir = debugfs_create_dir(call->name, d_events);
955 if (!call->dir) {
956 pr_warning("Could not create debugfs "
957 "'%s' directory\n", call->name);
958 return -1;
959 }
960
6d723736
SR
961 if (call->regfunc)
962 entry = trace_create_file("enable", 0644, call->dir, call,
701970b3 963 enable);
1473e441 964
af6af30c 965 if (call->id && call->profile_enable)
6d723736 966 entry = trace_create_file("id", 0444, call->dir, call,
701970b3 967 id);
23725aee 968
cf027f64 969 if (call->define_fields) {
14be96c9 970 ret = call->define_fields(call);
cf027f64
TZ
971 if (ret < 0) {
972 pr_warning("Could not initialize trace point"
973 " events/%s\n", call->name);
974 return ret;
975 }
6d723736 976 entry = trace_create_file("filter", 0644, call->dir, call,
701970b3 977 filter);
cf027f64
TZ
978 }
979
981d081e
SR
980 /* A trace may not want to export its format */
981 if (!call->show_format)
982 return 0;
983
6d723736 984 entry = trace_create_file("format", 0444, call->dir, call,
701970b3 985 format);
6d723736
SR
986
987 return 0;
988}
989
bd1a5c84
MH
990static int __trace_add_event_call(struct ftrace_event_call *call)
991{
992 struct dentry *d_events;
993 int ret;
6d723736 994
bd1a5c84
MH
995 if (!call->name)
996 return -EINVAL;
701970b3 997
bd1a5c84
MH
998 if (call->raw_init) {
999 ret = call->raw_init(call);
1000 if (ret < 0) {
1001 if (ret != -ENOSYS)
1002 pr_warning("Could not initialize trace "
1003 "events/%s\n", call->name);
1004 return ret;
1005 }
1006 }
701970b3 1007
bd1a5c84
MH
1008 d_events = event_trace_events_dir();
1009 if (!d_events)
1010 return -ENOENT;
1011
1012 list_add(&call->list, &ftrace_events);
588bebb7 1013 ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
bd1a5c84
MH
1014 &ftrace_enable_fops, &ftrace_event_filter_fops,
1015 &ftrace_event_format_fops);
588bebb7
MH
1016 if (ret < 0)
1017 list_del(&call->list);
1018 return ret;
bd1a5c84
MH
1019}
1020
1021/* Add an additional event_call dynamically */
1022int trace_add_event_call(struct ftrace_event_call *call)
1023{
1024 int ret;
1025 mutex_lock(&event_mutex);
1026 ret = __trace_add_event_call(call);
1027 mutex_unlock(&event_mutex);
1028 return ret;
1029}
701970b3 1030
a2ca5e03
FW
1031static void remove_subsystem_dir(const char *name)
1032{
1033 struct event_subsystem *system;
1034
1035 if (strcmp(name, TRACE_SYSTEM) == 0)
1036 return;
1037
1038 list_for_each_entry(system, &event_subsystems, list) {
1039 if (strcmp(system->name, name) == 0) {
1040 if (!--system->nr_events) {
1041 struct event_filter *filter = system->filter;
1042
1043 debugfs_remove_recursive(system->entry);
1044 list_del(&system->list);
1045 if (filter) {
1046 kfree(filter->filter_string);
1047 kfree(filter);
1048 }
1049 kfree(system->name);
1050 kfree(system);
1051 }
1052 break;
1053 }
1054 }
1055}
1056
4fead8e4
MH
1057/*
1058 * Must be called under locking both of event_mutex and trace_event_mutex.
1059 */
bd1a5c84
MH
1060static void __trace_remove_event_call(struct ftrace_event_call *call)
1061{
1062 ftrace_event_enable_disable(call, 0);
1063 if (call->event)
1064 __unregister_ftrace_event(call->event);
1065 debugfs_remove_recursive(call->dir);
1066 list_del(&call->list);
1067 trace_destroy_fields(call);
1068 destroy_preds(call);
1069 remove_subsystem_dir(call->system);
1070}
1071
1072/* Remove an event_call */
1073void trace_remove_event_call(struct ftrace_event_call *call)
1074{
1075 mutex_lock(&event_mutex);
4fead8e4 1076 down_write(&trace_event_mutex);
bd1a5c84 1077 __trace_remove_event_call(call);
4fead8e4 1078 up_write(&trace_event_mutex);
bd1a5c84
MH
1079 mutex_unlock(&event_mutex);
1080}
1081
1082#define for_each_event(event, start, end) \
1083 for (event = start; \
1084 (unsigned long)event < (unsigned long)end; \
1085 event++)
1086
1087#ifdef CONFIG_MODULES
1088
1089static LIST_HEAD(ftrace_module_file_list);
1090
1091/*
1092 * Modules must own their file_operations to keep up with
1093 * reference counting.
1094 */
1095struct ftrace_module_file_ops {
1096 struct list_head list;
1097 struct module *mod;
1098 struct file_operations id;
1099 struct file_operations enable;
1100 struct file_operations format;
1101 struct file_operations filter;
1102};
1103
701970b3
SR
1104static struct ftrace_module_file_ops *
1105trace_create_file_ops(struct module *mod)
1106{
1107 struct ftrace_module_file_ops *file_ops;
1108
1109 /*
1110 * This is a bit of a PITA. To allow for correct reference
1111 * counting, modules must "own" their file_operations.
1112 * To do this, we allocate the file operations that will be
1113 * used in the event directory.
1114 */
1115
1116 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1117 if (!file_ops)
1118 return NULL;
1119
1120 file_ops->mod = mod;
1121
1122 file_ops->id = ftrace_event_id_fops;
1123 file_ops->id.owner = mod;
1124
1125 file_ops->enable = ftrace_enable_fops;
1126 file_ops->enable.owner = mod;
1127
1128 file_ops->filter = ftrace_event_filter_fops;
1129 file_ops->filter.owner = mod;
1130
1131 file_ops->format = ftrace_event_format_fops;
1132 file_ops->format.owner = mod;
1133
1134 list_add(&file_ops->list, &ftrace_module_file_list);
1135
1136 return file_ops;
1137}
1138
6d723736
SR
1139static void trace_module_add_events(struct module *mod)
1140{
701970b3 1141 struct ftrace_module_file_ops *file_ops = NULL;
6d723736
SR
1142 struct ftrace_event_call *call, *start, *end;
1143 struct dentry *d_events;
f744bd57 1144 int ret;
6d723736
SR
1145
1146 start = mod->trace_events;
1147 end = mod->trace_events + mod->num_trace_events;
1148
1149 if (start == end)
1150 return;
1151
1152 d_events = event_trace_events_dir();
1153 if (!d_events)
1154 return;
1155
1156 for_each_event(call, start, end) {
1157 /* The linker may leave blanks */
1158 if (!call->name)
1159 continue;
f744bd57 1160 if (call->raw_init) {
bd1a5c84 1161 ret = call->raw_init(call);
f744bd57
JB
1162 if (ret < 0) {
1163 if (ret != -ENOSYS)
1164 pr_warning("Could not initialize trace "
1165 "point events/%s\n", call->name);
1166 continue;
1167 }
1168 }
701970b3
SR
1169 /*
1170 * This module has events, create file ops for this module
1171 * if not already done.
1172 */
1173 if (!file_ops) {
1174 file_ops = trace_create_file_ops(mod);
1175 if (!file_ops)
1176 return;
1177 }
6d723736
SR
1178 call->mod = mod;
1179 list_add(&call->list, &ftrace_events);
701970b3
SR
1180 event_create_dir(call, d_events,
1181 &file_ops->id, &file_ops->enable,
1182 &file_ops->filter, &file_ops->format);
6d723736
SR
1183 }
1184}
1185
1186static void trace_module_remove_events(struct module *mod)
1187{
701970b3 1188 struct ftrace_module_file_ops *file_ops;
6d723736 1189 struct ftrace_event_call *call, *p;
9456f0fa 1190 bool found = false;
6d723736 1191
110bf2b7 1192 down_write(&trace_event_mutex);
6d723736
SR
1193 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1194 if (call->mod == mod) {
9456f0fa 1195 found = true;
bd1a5c84 1196 __trace_remove_event_call(call);
6d723736
SR
1197 }
1198 }
701970b3
SR
1199
1200 /* Now free the file_operations */
1201 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1202 if (file_ops->mod == mod)
1203 break;
1204 }
1205 if (&file_ops->list != &ftrace_module_file_list) {
1206 list_del(&file_ops->list);
1207 kfree(file_ops);
1208 }
9456f0fa
SR
1209
1210 /*
1211 * It is safest to reset the ring buffer if the module being unloaded
1212 * registered any events.
1213 */
1214 if (found)
1215 tracing_reset_current_online_cpus();
110bf2b7 1216 up_write(&trace_event_mutex);
6d723736
SR
1217}
1218
61f919a1
SR
1219static int trace_module_notify(struct notifier_block *self,
1220 unsigned long val, void *data)
6d723736
SR
1221{
1222 struct module *mod = data;
1223
1224 mutex_lock(&event_mutex);
1225 switch (val) {
1226 case MODULE_STATE_COMING:
1227 trace_module_add_events(mod);
1228 break;
1229 case MODULE_STATE_GOING:
1230 trace_module_remove_events(mod);
1231 break;
1232 }
1233 mutex_unlock(&event_mutex);
fd994989 1234
1473e441
SR
1235 return 0;
1236}
61f919a1
SR
1237#else
1238static int trace_module_notify(struct notifier_block *self,
1239 unsigned long val, void *data)
1240{
1241 return 0;
1242}
1243#endif /* CONFIG_MODULES */
1473e441 1244
6d723736
SR
1245struct notifier_block trace_module_nb = {
1246 .notifier_call = trace_module_notify,
1247 .priority = 0,
1248};
1249
a59fd602
SR
1250extern struct ftrace_event_call __start_ftrace_events[];
1251extern struct ftrace_event_call __stop_ftrace_events[];
1252
020e5f85
LZ
1253static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1254
1255static __init int setup_trace_event(char *str)
1256{
1257 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1258 ring_buffer_expanded = 1;
1259 tracing_selftest_disabled = 1;
1260
1261 return 1;
1262}
1263__setup("trace_event=", setup_trace_event);
1264
b77e38aa
SR
1265static __init int event_trace_init(void)
1266{
a59fd602 1267 struct ftrace_event_call *call;
b77e38aa
SR
1268 struct dentry *d_tracer;
1269 struct dentry *entry;
1473e441 1270 struct dentry *d_events;
6d723736 1271 int ret;
020e5f85
LZ
1272 char *buf = bootup_event_buf;
1273 char *token;
b77e38aa
SR
1274
1275 d_tracer = tracing_init_dentry();
1276 if (!d_tracer)
1277 return 0;
1278
2314c4ae
SR
1279 entry = debugfs_create_file("available_events", 0444, d_tracer,
1280 (void *)&show_event_seq_ops,
1281 &ftrace_avail_fops);
1282 if (!entry)
1283 pr_warning("Could not create debugfs "
1284 "'available_events' entry\n");
1285
b77e38aa
SR
1286 entry = debugfs_create_file("set_event", 0644, d_tracer,
1287 (void *)&show_set_event_seq_ops,
1288 &ftrace_set_event_fops);
1289 if (!entry)
1290 pr_warning("Could not create debugfs "
1291 "'set_event' entry\n");
1292
1473e441
SR
1293 d_events = event_trace_events_dir();
1294 if (!d_events)
1295 return 0;
1296
d1b182a8
SR
1297 /* ring buffer internal formats */
1298 trace_create_file("header_page", 0444, d_events,
1299 ring_buffer_print_page_header,
1300 &ftrace_show_header_fops);
1301
1302 trace_create_file("header_event", 0444, d_events,
1303 ring_buffer_print_entry_header,
1304 &ftrace_show_header_fops);
1305
8ae79a13 1306 trace_create_file("enable", 0644, d_events,
8f31bfe5 1307 NULL, &ftrace_system_enable_fops);
8ae79a13 1308
6d723736 1309 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
1473e441
SR
1310 /* The linker may leave blanks */
1311 if (!call->name)
1312 continue;
f744bd57 1313 if (call->raw_init) {
bd1a5c84 1314 ret = call->raw_init(call);
f744bd57
JB
1315 if (ret < 0) {
1316 if (ret != -ENOSYS)
1317 pr_warning("Could not initialize trace "
1318 "point events/%s\n", call->name);
1319 continue;
1320 }
1321 }
a59fd602 1322 list_add(&call->list, &ftrace_events);
701970b3
SR
1323 event_create_dir(call, d_events, &ftrace_event_id_fops,
1324 &ftrace_enable_fops, &ftrace_event_filter_fops,
1325 &ftrace_event_format_fops);
1473e441
SR
1326 }
1327
020e5f85
LZ
1328 while (true) {
1329 token = strsep(&buf, ",");
1330
1331 if (!token)
1332 break;
1333 if (!*token)
1334 continue;
1335
1336 ret = ftrace_set_clr_event(token, 1);
1337 if (ret)
1338 pr_warning("Failed to enable trace event: %s\n", token);
1339 }
1340
6d723736 1341 ret = register_module_notifier(&trace_module_nb);
55379376 1342 if (ret)
6d723736
SR
1343 pr_warning("Failed to register trace events module notifier\n");
1344
b77e38aa
SR
1345 return 0;
1346}
1347fs_initcall(event_trace_init);
e6187007
SR
1348
1349#ifdef CONFIG_FTRACE_STARTUP_TEST
1350
1351static DEFINE_SPINLOCK(test_spinlock);
1352static DEFINE_SPINLOCK(test_spinlock_irq);
1353static DEFINE_MUTEX(test_mutex);
1354
1355static __init void test_work(struct work_struct *dummy)
1356{
1357 spin_lock(&test_spinlock);
1358 spin_lock_irq(&test_spinlock_irq);
1359 udelay(1);
1360 spin_unlock_irq(&test_spinlock_irq);
1361 spin_unlock(&test_spinlock);
1362
1363 mutex_lock(&test_mutex);
1364 msleep(1);
1365 mutex_unlock(&test_mutex);
1366}
1367
1368static __init int event_test_thread(void *unused)
1369{
1370 void *test_malloc;
1371
1372 test_malloc = kmalloc(1234, GFP_KERNEL);
1373 if (!test_malloc)
1374 pr_info("failed to kmalloc\n");
1375
1376 schedule_on_each_cpu(test_work);
1377
1378 kfree(test_malloc);
1379
1380 set_current_state(TASK_INTERRUPTIBLE);
1381 while (!kthread_should_stop())
1382 schedule();
1383
1384 return 0;
1385}
1386
1387/*
1388 * Do various things that may trigger events.
1389 */
1390static __init void event_test_stuff(void)
1391{
1392 struct task_struct *test_thread;
1393
1394 test_thread = kthread_run(event_test_thread, NULL, "test-events");
1395 msleep(1);
1396 kthread_stop(test_thread);
1397}
1398
1399/*
1400 * For every trace event defined, we will test each trace point separately,
1401 * and then by groups, and finally all trace points.
1402 */
9ea21c1e 1403static __init void event_trace_self_tests(void)
e6187007
SR
1404{
1405 struct ftrace_event_call *call;
1406 struct event_subsystem *system;
e6187007
SR
1407 int ret;
1408
1409 pr_info("Running tests on trace events:\n");
1410
1411 list_for_each_entry(call, &ftrace_events, list) {
1412
1413 /* Only test those that have a regfunc */
1414 if (!call->regfunc)
1415 continue;
1416
1417 pr_info("Testing event %s: ", call->name);
1418
1419 /*
1420 * If an event is already enabled, someone is using
1421 * it and the self test should not be on.
1422 */
1423 if (call->enabled) {
1424 pr_warning("Enabled event during self test!\n");
1425 WARN_ON_ONCE(1);
1426 continue;
1427 }
1428
0e907c99 1429 ftrace_event_enable_disable(call, 1);
e6187007 1430 event_test_stuff();
0e907c99 1431 ftrace_event_enable_disable(call, 0);
e6187007
SR
1432
1433 pr_cont("OK\n");
1434 }
1435
1436 /* Now test at the sub system level */
1437
1438 pr_info("Running tests on trace event systems:\n");
1439
1440 list_for_each_entry(system, &event_subsystems, list) {
1441
1442 /* the ftrace system is special, skip it */
1443 if (strcmp(system->name, "ftrace") == 0)
1444 continue;
1445
1446 pr_info("Testing event system %s: ", system->name);
1447
8f31bfe5 1448 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
e6187007
SR
1449 if (WARN_ON_ONCE(ret)) {
1450 pr_warning("error enabling system %s\n",
1451 system->name);
1452 continue;
1453 }
1454
1455 event_test_stuff();
1456
8f31bfe5 1457 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
e6187007
SR
1458 if (WARN_ON_ONCE(ret))
1459 pr_warning("error disabling system %s\n",
1460 system->name);
1461
1462 pr_cont("OK\n");
1463 }
1464
1465 /* Test with all events enabled */
1466
1467 pr_info("Running tests on all trace events:\n");
1468 pr_info("Testing all events: ");
1469
8f31bfe5 1470 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
e6187007 1471 if (WARN_ON_ONCE(ret)) {
e6187007 1472 pr_warning("error enabling all events\n");
9ea21c1e 1473 return;
e6187007
SR
1474 }
1475
1476 event_test_stuff();
1477
1478 /* reset sysname */
8f31bfe5 1479 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
e6187007
SR
1480 if (WARN_ON_ONCE(ret)) {
1481 pr_warning("error disabling all events\n");
9ea21c1e 1482 return;
e6187007
SR
1483 }
1484
1485 pr_cont("OK\n");
9ea21c1e
SR
1486}
1487
1488#ifdef CONFIG_FUNCTION_TRACER
1489
1490static DEFINE_PER_CPU(atomic_t, test_event_disable);
1491
1492static void
1493function_test_events_call(unsigned long ip, unsigned long parent_ip)
1494{
1495 struct ring_buffer_event *event;
e77405ad 1496 struct ring_buffer *buffer;
9ea21c1e
SR
1497 struct ftrace_entry *entry;
1498 unsigned long flags;
1499 long disabled;
1500 int resched;
1501 int cpu;
1502 int pc;
1503
1504 pc = preempt_count();
1505 resched = ftrace_preempt_disable();
1506 cpu = raw_smp_processor_id();
1507 disabled = atomic_inc_return(&per_cpu(test_event_disable, cpu));
1508
1509 if (disabled != 1)
1510 goto out;
1511
1512 local_save_flags(flags);
1513
e77405ad
SR
1514 event = trace_current_buffer_lock_reserve(&buffer,
1515 TRACE_FN, sizeof(*entry),
9ea21c1e
SR
1516 flags, pc);
1517 if (!event)
1518 goto out;
1519 entry = ring_buffer_event_data(event);
1520 entry->ip = ip;
1521 entry->parent_ip = parent_ip;
1522
e77405ad 1523 trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
9ea21c1e
SR
1524
1525 out:
1526 atomic_dec(&per_cpu(test_event_disable, cpu));
1527 ftrace_preempt_enable(resched);
1528}
1529
1530static struct ftrace_ops trace_ops __initdata =
1531{
1532 .func = function_test_events_call,
1533};
1534
1535static __init void event_trace_self_test_with_function(void)
1536{
1537 register_ftrace_function(&trace_ops);
1538 pr_info("Running tests again, along with the function tracer\n");
1539 event_trace_self_tests();
1540 unregister_ftrace_function(&trace_ops);
1541}
1542#else
1543static __init void event_trace_self_test_with_function(void)
1544{
1545}
1546#endif
1547
1548static __init int event_trace_self_tests_init(void)
1549{
020e5f85
LZ
1550 if (!tracing_selftest_disabled) {
1551 event_trace_self_tests();
1552 event_trace_self_test_with_function();
1553 }
e6187007
SR
1554
1555 return 0;
1556}
1557
28d20e2d 1558late_initcall(event_trace_self_tests_init);
e6187007
SR
1559
1560#endif
This page took 0.121613 seconds and 5 git commands to generate.