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