tracing: Simplify code for showing of soft disabled flag
[linux-2.6.git] / kernel / trace / trace_events.c
blob7ee08b95c384536922dd760c3d2497a77aeb6508
1 /*
2 * event tracer
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
6 * - Added format output of fields of the trace point.
7 * This was based off of work by Tom Zanussi <tzanussi@gmail.com>.
9 */
11 #include <linux/workqueue.h>
12 #include <linux/spinlock.h>
13 #include <linux/kthread.h>
14 #include <linux/debugfs.h>
15 #include <linux/uaccess.h>
16 #include <linux/module.h>
17 #include <linux/ctype.h>
18 #include <linux/slab.h>
19 #include <linux/delay.h>
21 #include <asm/setup.h>
23 #include "trace_output.h"
25 #undef TRACE_SYSTEM
26 #define TRACE_SYSTEM "TRACE_SYSTEM"
28 DEFINE_MUTEX(event_mutex);
30 DEFINE_MUTEX(event_storage_mutex);
31 EXPORT_SYMBOL_GPL(event_storage_mutex);
33 char event_storage[EVENT_STORAGE_SIZE];
34 EXPORT_SYMBOL_GPL(event_storage);
36 LIST_HEAD(ftrace_events);
37 static LIST_HEAD(ftrace_common_fields);
39 #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO)
41 static struct kmem_cache *field_cachep;
42 static struct kmem_cache *file_cachep;
44 #define SYSTEM_FL_FREE_NAME (1 << 31)
46 static inline int system_refcount(struct event_subsystem *system)
48 return system->ref_count & ~SYSTEM_FL_FREE_NAME;
51 static int system_refcount_inc(struct event_subsystem *system)
53 return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME;
56 static int system_refcount_dec(struct event_subsystem *system)
58 return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME;
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)
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)
71 #define while_for_each_event_file() \
74 static struct list_head *
75 trace_get_fields(struct ftrace_event_call *event_call)
77 if (!event_call->class->get_fields)
78 return &event_call->class->fields;
79 return event_call->class->get_fields(event_call);
82 static struct ftrace_event_field *
83 __find_event_field(struct list_head *head, char *name)
85 struct ftrace_event_field *field;
87 list_for_each_entry(field, head, link) {
88 if (!strcmp(field->name, name))
89 return field;
92 return NULL;
95 struct ftrace_event_field *
96 trace_find_event_field(struct ftrace_event_call *call, char *name)
98 struct ftrace_event_field *field;
99 struct list_head *head;
101 field = __find_event_field(&ftrace_common_fields, name);
102 if (field)
103 return field;
105 head = trace_get_fields(call);
106 return __find_event_field(head, name);
109 static int __trace_define_field(struct list_head *head, const char *type,
110 const char *name, int offset, int size,
111 int is_signed, int filter_type)
113 struct ftrace_event_field *field;
115 field = kmem_cache_alloc(field_cachep, GFP_TRACE);
116 if (!field)
117 return -ENOMEM;
119 field->name = name;
120 field->type = type;
122 if (filter_type == FILTER_OTHER)
123 field->filter_type = filter_assign_type(type);
124 else
125 field->filter_type = filter_type;
127 field->offset = offset;
128 field->size = size;
129 field->is_signed = is_signed;
131 list_add(&field->link, head);
133 return 0;
136 int trace_define_field(struct ftrace_event_call *call, const char *type,
137 const char *name, int offset, int size, int is_signed,
138 int filter_type)
140 struct list_head *head;
142 if (WARN_ON(!call->class))
143 return 0;
145 head = trace_get_fields(call);
146 return __trace_define_field(head, type, name, offset, size,
147 is_signed, filter_type);
149 EXPORT_SYMBOL_GPL(trace_define_field);
151 #define __common_field(type, item) \
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); \
157 if (ret) \
158 return ret;
160 static int trace_define_common_fields(void)
162 int ret;
163 struct trace_entry ent;
165 __common_field(unsigned short, type);
166 __common_field(unsigned char, flags);
167 __common_field(unsigned char, preempt_count);
168 __common_field(int, pid);
170 return ret;
173 static void trace_destroy_fields(struct ftrace_event_call *call)
175 struct ftrace_event_field *field, *next;
176 struct list_head *head;
178 head = trace_get_fields(call);
179 list_for_each_entry_safe(field, next, head, link) {
180 list_del(&field->link);
181 kmem_cache_free(field_cachep, field);
185 int trace_event_raw_init(struct ftrace_event_call *call)
187 int id;
189 id = register_ftrace_event(&call->event);
190 if (!id)
191 return -ENODEV;
193 return 0;
195 EXPORT_SYMBOL_GPL(trace_event_raw_init);
197 int ftrace_event_reg(struct ftrace_event_call *call,
198 enum trace_reg type, void *data)
200 struct ftrace_event_file *file = data;
202 switch (type) {
203 case TRACE_REG_REGISTER:
204 return tracepoint_probe_register(call->name,
205 call->class->probe,
206 file);
207 case TRACE_REG_UNREGISTER:
208 tracepoint_probe_unregister(call->name,
209 call->class->probe,
210 file);
211 return 0;
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;
223 case TRACE_REG_PERF_OPEN:
224 case TRACE_REG_PERF_CLOSE:
225 case TRACE_REG_PERF_ADD:
226 case TRACE_REG_PERF_DEL:
227 return 0;
228 #endif
230 return 0;
232 EXPORT_SYMBOL_GPL(ftrace_event_reg);
234 void trace_event_enable_cmd_record(bool enable)
236 struct ftrace_event_file *file;
237 struct trace_array *tr;
239 mutex_lock(&event_mutex);
240 do_for_each_event_file(tr, file) {
242 if (!(file->flags & FTRACE_EVENT_FL_ENABLED))
243 continue;
245 if (enable) {
246 tracing_start_cmdline_record();
247 set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
248 } else {
249 tracing_stop_cmdline_record();
250 clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
252 } while_for_each_event_file();
253 mutex_unlock(&event_mutex);
256 static int __ftrace_event_enable_disable(struct ftrace_event_file *file,
257 int enable, int soft_disable)
259 struct ftrace_event_call *call = file->event_call;
260 int ret = 0;
261 int disable;
263 switch (enable) {
264 case 0:
266 * When soft_disable is set and enable is cleared, the sm_ref
267 * reference counter is decremented. If it reaches 0, we want
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.
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.
278 if (soft_disable) {
279 if (atomic_dec_return(&file->sm_ref) > 0)
280 break;
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);
286 if (disable && (file->flags & FTRACE_EVENT_FL_ENABLED)) {
287 clear_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags);
288 if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) {
289 tracing_stop_cmdline_record();
290 clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
292 call->class->reg(call, TRACE_REG_UNREGISTER, file);
294 /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT */
295 if (file->flags & FTRACE_EVENT_FL_SOFT_MODE)
296 set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
297 break;
298 case 1:
300 * When soft_disable is set and enable is set, we want to
301 * register the tracepoint for the event, but leave the event
302 * as is. That means, if the event was already enabled, we do
303 * nothing (but set SOFT_MODE). If the event is disabled, we
304 * set SOFT_DISABLED before enabling the event tracepoint, so
305 * it still seems to be disabled.
307 if (!soft_disable)
308 clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
309 else {
310 if (atomic_inc_return(&file->sm_ref) > 1)
311 break;
312 set_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags);
315 if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) {
317 /* Keep the event disabled, when going to SOFT_MODE. */
318 if (soft_disable)
319 set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
321 if (trace_flags & TRACE_ITER_RECORD_CMD) {
322 tracing_start_cmdline_record();
323 set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
325 ret = call->class->reg(call, TRACE_REG_REGISTER, file);
326 if (ret) {
327 tracing_stop_cmdline_record();
328 pr_info("event trace: Could not enable event "
329 "%s\n", call->name);
330 break;
332 set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags);
334 /* WAS_ENABLED gets set but never cleared. */
335 call->flags |= TRACE_EVENT_FL_WAS_ENABLED;
337 break;
340 return ret;
343 static int ftrace_event_enable_disable(struct ftrace_event_file *file,
344 int enable)
346 return __ftrace_event_enable_disable(file, enable, 0);
349 static void ftrace_clear_events(struct trace_array *tr)
351 struct ftrace_event_file *file;
353 mutex_lock(&event_mutex);
354 list_for_each_entry(file, &tr->events, list) {
355 ftrace_event_enable_disable(file, 0);
357 mutex_unlock(&event_mutex);
360 static void __put_system(struct event_subsystem *system)
362 struct event_filter *filter = system->filter;
364 WARN_ON_ONCE(system_refcount(system) == 0);
365 if (system_refcount_dec(system))
366 return;
368 list_del(&system->list);
370 if (filter) {
371 kfree(filter->filter_string);
372 kfree(filter);
374 if (system->ref_count & SYSTEM_FL_FREE_NAME)
375 kfree(system->name);
376 kfree(system);
379 static void __get_system(struct event_subsystem *system)
381 WARN_ON_ONCE(system_refcount(system) == 0);
382 system_refcount_inc(system);
385 static void __get_system_dir(struct ftrace_subsystem_dir *dir)
387 WARN_ON_ONCE(dir->ref_count == 0);
388 dir->ref_count++;
389 __get_system(dir->subsystem);
392 static void __put_system_dir(struct ftrace_subsystem_dir *dir)
394 WARN_ON_ONCE(dir->ref_count == 0);
395 /* If the subsystem is about to be freed, the dir must be too */
396 WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1);
398 __put_system(dir->subsystem);
399 if (!--dir->ref_count)
400 kfree(dir);
403 static void put_system(struct ftrace_subsystem_dir *dir)
405 mutex_lock(&event_mutex);
406 __put_system_dir(dir);
407 mutex_unlock(&event_mutex);
411 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
413 static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
414 const char *sub, const char *event, int set)
416 struct ftrace_event_file *file;
417 struct ftrace_event_call *call;
418 int ret = -EINVAL;
420 mutex_lock(&event_mutex);
421 list_for_each_entry(file, &tr->events, list) {
423 call = file->event_call;
425 if (!call->name || !call->class || !call->class->reg)
426 continue;
428 if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
429 continue;
431 if (match &&
432 strcmp(match, call->name) != 0 &&
433 strcmp(match, call->class->system) != 0)
434 continue;
436 if (sub && strcmp(sub, call->class->system) != 0)
437 continue;
439 if (event && strcmp(event, call->name) != 0)
440 continue;
442 ftrace_event_enable_disable(file, set);
444 ret = 0;
446 mutex_unlock(&event_mutex);
448 return ret;
451 static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
453 char *event = NULL, *sub = NULL, *match;
456 * The buf format can be <subsystem>:<event-name>
457 * *:<event-name> means any event by that name.
458 * :<event-name> is the same.
460 * <subsystem>:* means all events in that subsystem
461 * <subsystem>: means the same.
463 * <name> (no ':') means all events in a subsystem with
464 * the name <name> or any event that matches <name>
467 match = strsep(&buf, ":");
468 if (buf) {
469 sub = match;
470 event = buf;
471 match = NULL;
473 if (!strlen(sub) || strcmp(sub, "*") == 0)
474 sub = NULL;
475 if (!strlen(event) || strcmp(event, "*") == 0)
476 event = NULL;
479 return __ftrace_set_clr_event(tr, match, sub, event, set);
483 * trace_set_clr_event - enable or disable an event
484 * @system: system name to match (NULL for any system)
485 * @event: event name to match (NULL for all events, within system)
486 * @set: 1 to enable, 0 to disable
488 * This is a way for other parts of the kernel to enable or disable
489 * event recording.
491 * Returns 0 on success, -EINVAL if the parameters do not match any
492 * registered events.
494 int trace_set_clr_event(const char *system, const char *event, int set)
496 struct trace_array *tr = top_trace_array();
498 return __ftrace_set_clr_event(tr, NULL, system, event, set);
500 EXPORT_SYMBOL_GPL(trace_set_clr_event);
502 /* 128 should be much more than enough */
503 #define EVENT_BUF_SIZE 127
505 static ssize_t
506 ftrace_event_write(struct file *file, const char __user *ubuf,
507 size_t cnt, loff_t *ppos)
509 struct trace_parser parser;
510 struct seq_file *m = file->private_data;
511 struct trace_array *tr = m->private;
512 ssize_t read, ret;
514 if (!cnt)
515 return 0;
517 ret = tracing_update_buffers();
518 if (ret < 0)
519 return ret;
521 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
522 return -ENOMEM;
524 read = trace_get_user(&parser, ubuf, cnt, ppos);
526 if (read >= 0 && trace_parser_loaded((&parser))) {
527 int set = 1;
529 if (*parser.buffer == '!')
530 set = 0;
532 parser.buffer[parser.idx] = 0;
534 ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
535 if (ret)
536 goto out_put;
539 ret = read;
541 out_put:
542 trace_parser_put(&parser);
544 return ret;
547 static void *
548 t_next(struct seq_file *m, void *v, loff_t *pos)
550 struct ftrace_event_file *file = v;
551 struct ftrace_event_call *call;
552 struct trace_array *tr = m->private;
554 (*pos)++;
556 list_for_each_entry_continue(file, &tr->events, list) {
557 call = file->event_call;
559 * The ftrace subsystem is for showing formats only.
560 * They can not be enabled or disabled via the event files.
562 if (call->class && call->class->reg)
563 return file;
566 return NULL;
569 static void *t_start(struct seq_file *m, loff_t *pos)
571 struct ftrace_event_file *file;
572 struct trace_array *tr = m->private;
573 loff_t l;
575 mutex_lock(&event_mutex);
577 file = list_entry(&tr->events, struct ftrace_event_file, list);
578 for (l = 0; l <= *pos; ) {
579 file = t_next(m, file, &l);
580 if (!file)
581 break;
583 return file;
586 static void *
587 s_next(struct seq_file *m, void *v, loff_t *pos)
589 struct ftrace_event_file *file = v;
590 struct trace_array *tr = m->private;
592 (*pos)++;
594 list_for_each_entry_continue(file, &tr->events, list) {
595 if (file->flags & FTRACE_EVENT_FL_ENABLED)
596 return file;
599 return NULL;
602 static void *s_start(struct seq_file *m, loff_t *pos)
604 struct ftrace_event_file *file;
605 struct trace_array *tr = m->private;
606 loff_t l;
608 mutex_lock(&event_mutex);
610 file = list_entry(&tr->events, struct ftrace_event_file, list);
611 for (l = 0; l <= *pos; ) {
612 file = s_next(m, file, &l);
613 if (!file)
614 break;
616 return file;
619 static int t_show(struct seq_file *m, void *v)
621 struct ftrace_event_file *file = v;
622 struct ftrace_event_call *call = file->event_call;
624 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
625 seq_printf(m, "%s:", call->class->system);
626 seq_printf(m, "%s\n", call->name);
628 return 0;
631 static void t_stop(struct seq_file *m, void *p)
633 mutex_unlock(&event_mutex);
636 static ssize_t
637 event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
638 loff_t *ppos)
640 struct ftrace_event_file *file = filp->private_data;
641 char buf[4] = "0";
643 if (file->flags & FTRACE_EVENT_FL_ENABLED &&
644 !(file->flags & FTRACE_EVENT_FL_SOFT_DISABLED))
645 strcpy(buf, "1");
647 if (file->flags & FTRACE_EVENT_FL_SOFT_DISABLED ||
648 file->flags & FTRACE_EVENT_FL_SOFT_MODE)
649 strcat(buf, "*");
651 strcat(buf, "\n");
653 return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf));
656 static ssize_t
657 event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
658 loff_t *ppos)
660 struct ftrace_event_file *file = filp->private_data;
661 unsigned long val;
662 int ret;
664 if (!file)
665 return -EINVAL;
667 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
668 if (ret)
669 return ret;
671 ret = tracing_update_buffers();
672 if (ret < 0)
673 return ret;
675 switch (val) {
676 case 0:
677 case 1:
678 mutex_lock(&event_mutex);
679 ret = ftrace_event_enable_disable(file, val);
680 mutex_unlock(&event_mutex);
681 break;
683 default:
684 return -EINVAL;
687 *ppos += cnt;
689 return ret ? ret : cnt;
692 static ssize_t
693 system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
694 loff_t *ppos)
696 const char set_to_char[4] = { '?', '0', '1', 'X' };
697 struct ftrace_subsystem_dir *dir = filp->private_data;
698 struct event_subsystem *system = dir->subsystem;
699 struct ftrace_event_call *call;
700 struct ftrace_event_file *file;
701 struct trace_array *tr = dir->tr;
702 char buf[2];
703 int set = 0;
704 int ret;
706 mutex_lock(&event_mutex);
707 list_for_each_entry(file, &tr->events, list) {
708 call = file->event_call;
709 if (!call->name || !call->class || !call->class->reg)
710 continue;
712 if (system && strcmp(call->class->system, system->name) != 0)
713 continue;
716 * We need to find out if all the events are set
717 * or if all events or cleared, or if we have
718 * a mixture.
720 set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED));
723 * If we have a mixture, no need to look further.
725 if (set == 3)
726 break;
728 mutex_unlock(&event_mutex);
730 buf[0] = set_to_char[set];
731 buf[1] = '\n';
733 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
735 return ret;
738 static ssize_t
739 system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
740 loff_t *ppos)
742 struct ftrace_subsystem_dir *dir = filp->private_data;
743 struct event_subsystem *system = dir->subsystem;
744 const char *name = NULL;
745 unsigned long val;
746 ssize_t ret;
748 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
749 if (ret)
750 return ret;
752 ret = tracing_update_buffers();
753 if (ret < 0)
754 return ret;
756 if (val != 0 && val != 1)
757 return -EINVAL;
760 * Opening of "enable" adds a ref count to system,
761 * so the name is safe to use.
763 if (system)
764 name = system->name;
766 ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val);
767 if (ret)
768 goto out;
770 ret = cnt;
772 out:
773 *ppos += cnt;
775 return ret;
778 enum {
779 FORMAT_HEADER = 1,
780 FORMAT_FIELD_SEPERATOR = 2,
781 FORMAT_PRINTFMT = 3,
784 static void *f_next(struct seq_file *m, void *v, loff_t *pos)
786 struct ftrace_event_call *call = m->private;
787 struct ftrace_event_field *field;
788 struct list_head *common_head = &ftrace_common_fields;
789 struct list_head *head = trace_get_fields(call);
791 (*pos)++;
793 switch ((unsigned long)v) {
794 case FORMAT_HEADER:
795 if (unlikely(list_empty(common_head)))
796 return NULL;
798 field = list_entry(common_head->prev,
799 struct ftrace_event_field, link);
800 return field;
802 case FORMAT_FIELD_SEPERATOR:
803 if (unlikely(list_empty(head)))
804 return NULL;
806 field = list_entry(head->prev, struct ftrace_event_field, link);
807 return field;
809 case FORMAT_PRINTFMT:
810 /* all done */
811 return NULL;
814 field = v;
815 if (field->link.prev == common_head)
816 return (void *)FORMAT_FIELD_SEPERATOR;
817 else if (field->link.prev == head)
818 return (void *)FORMAT_PRINTFMT;
820 field = list_entry(field->link.prev, struct ftrace_event_field, link);
822 return field;
825 static void *f_start(struct seq_file *m, loff_t *pos)
827 loff_t l = 0;
828 void *p;
830 /* Start by showing the header */
831 if (!*pos)
832 return (void *)FORMAT_HEADER;
834 p = (void *)FORMAT_HEADER;
835 do {
836 p = f_next(m, p, &l);
837 } while (p && l < *pos);
839 return p;
842 static int f_show(struct seq_file *m, void *v)
844 struct ftrace_event_call *call = m->private;
845 struct ftrace_event_field *field;
846 const char *array_descriptor;
848 switch ((unsigned long)v) {
849 case FORMAT_HEADER:
850 seq_printf(m, "name: %s\n", call->name);
851 seq_printf(m, "ID: %d\n", call->event.type);
852 seq_printf(m, "format:\n");
853 return 0;
855 case FORMAT_FIELD_SEPERATOR:
856 seq_putc(m, '\n');
857 return 0;
859 case FORMAT_PRINTFMT:
860 seq_printf(m, "\nprint fmt: %s\n",
861 call->print_fmt);
862 return 0;
865 field = v;
868 * Smartly shows the array type(except dynamic array).
869 * Normal:
870 * field:TYPE VAR
871 * If TYPE := TYPE[LEN], it is shown:
872 * field:TYPE VAR[LEN]
874 array_descriptor = strchr(field->type, '[');
876 if (!strncmp(field->type, "__data_loc", 10))
877 array_descriptor = NULL;
879 if (!array_descriptor)
880 seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
881 field->type, field->name, field->offset,
882 field->size, !!field->is_signed);
883 else
884 seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
885 (int)(array_descriptor - field->type),
886 field->type, field->name,
887 array_descriptor, field->offset,
888 field->size, !!field->is_signed);
890 return 0;
893 static void f_stop(struct seq_file *m, void *p)
897 static const struct seq_operations trace_format_seq_ops = {
898 .start = f_start,
899 .next = f_next,
900 .stop = f_stop,
901 .show = f_show,
904 static int trace_format_open(struct inode *inode, struct file *file)
906 struct ftrace_event_call *call = inode->i_private;
907 struct seq_file *m;
908 int ret;
910 ret = seq_open(file, &trace_format_seq_ops);
911 if (ret < 0)
912 return ret;
914 m = file->private_data;
915 m->private = call;
917 return 0;
920 static ssize_t
921 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
923 struct ftrace_event_call *call = filp->private_data;
924 struct trace_seq *s;
925 int r;
927 if (*ppos)
928 return 0;
930 s = kmalloc(sizeof(*s), GFP_KERNEL);
931 if (!s)
932 return -ENOMEM;
934 trace_seq_init(s);
935 trace_seq_printf(s, "%d\n", call->event.type);
937 r = simple_read_from_buffer(ubuf, cnt, ppos,
938 s->buffer, s->len);
939 kfree(s);
940 return r;
943 static ssize_t
944 event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
945 loff_t *ppos)
947 struct ftrace_event_call *call = filp->private_data;
948 struct trace_seq *s;
949 int r;
951 if (*ppos)
952 return 0;
954 s = kmalloc(sizeof(*s), GFP_KERNEL);
955 if (!s)
956 return -ENOMEM;
958 trace_seq_init(s);
960 print_event_filter(call, s);
961 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
963 kfree(s);
965 return r;
968 static ssize_t
969 event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
970 loff_t *ppos)
972 struct ftrace_event_call *call = filp->private_data;
973 char *buf;
974 int err;
976 if (cnt >= PAGE_SIZE)
977 return -EINVAL;
979 buf = (char *)__get_free_page(GFP_TEMPORARY);
980 if (!buf)
981 return -ENOMEM;
983 if (copy_from_user(buf, ubuf, cnt)) {
984 free_page((unsigned long) buf);
985 return -EFAULT;
987 buf[cnt] = '\0';
989 err = apply_event_filter(call, buf);
990 free_page((unsigned long) buf);
991 if (err < 0)
992 return err;
994 *ppos += cnt;
996 return cnt;
999 static LIST_HEAD(event_subsystems);
1001 static int subsystem_open(struct inode *inode, struct file *filp)
1003 struct event_subsystem *system = NULL;
1004 struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */
1005 struct trace_array *tr;
1006 int ret;
1008 /* Make sure the system still exists */
1009 mutex_lock(&event_mutex);
1010 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
1011 list_for_each_entry(dir, &tr->systems, list) {
1012 if (dir == inode->i_private) {
1013 /* Don't open systems with no events */
1014 if (dir->nr_events) {
1015 __get_system_dir(dir);
1016 system = dir->subsystem;
1018 goto exit_loop;
1022 exit_loop:
1023 mutex_unlock(&event_mutex);
1025 if (!system)
1026 return -ENODEV;
1028 /* Some versions of gcc think dir can be uninitialized here */
1029 WARN_ON(!dir);
1031 ret = tracing_open_generic(inode, filp);
1032 if (ret < 0)
1033 put_system(dir);
1035 return ret;
1038 static int system_tr_open(struct inode *inode, struct file *filp)
1040 struct ftrace_subsystem_dir *dir;
1041 struct trace_array *tr = inode->i_private;
1042 int ret;
1044 /* Make a temporary dir that has no system but points to tr */
1045 dir = kzalloc(sizeof(*dir), GFP_KERNEL);
1046 if (!dir)
1047 return -ENOMEM;
1049 dir->tr = tr;
1051 ret = tracing_open_generic(inode, filp);
1052 if (ret < 0)
1053 kfree(dir);
1055 filp->private_data = dir;
1057 return ret;
1060 static int subsystem_release(struct inode *inode, struct file *file)
1062 struct ftrace_subsystem_dir *dir = file->private_data;
1065 * If dir->subsystem is NULL, then this is a temporary
1066 * descriptor that was made for a trace_array to enable
1067 * all subsystems.
1069 if (dir->subsystem)
1070 put_system(dir);
1071 else
1072 kfree(dir);
1074 return 0;
1077 static ssize_t
1078 subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
1079 loff_t *ppos)
1081 struct ftrace_subsystem_dir *dir = filp->private_data;
1082 struct event_subsystem *system = dir->subsystem;
1083 struct trace_seq *s;
1084 int r;
1086 if (*ppos)
1087 return 0;
1089 s = kmalloc(sizeof(*s), GFP_KERNEL);
1090 if (!s)
1091 return -ENOMEM;
1093 trace_seq_init(s);
1095 print_subsystem_event_filter(system, s);
1096 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
1098 kfree(s);
1100 return r;
1103 static ssize_t
1104 subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
1105 loff_t *ppos)
1107 struct ftrace_subsystem_dir *dir = filp->private_data;
1108 char *buf;
1109 int err;
1111 if (cnt >= PAGE_SIZE)
1112 return -EINVAL;
1114 buf = (char *)__get_free_page(GFP_TEMPORARY);
1115 if (!buf)
1116 return -ENOMEM;
1118 if (copy_from_user(buf, ubuf, cnt)) {
1119 free_page((unsigned long) buf);
1120 return -EFAULT;
1122 buf[cnt] = '\0';
1124 err = apply_subsystem_event_filter(dir, buf);
1125 free_page((unsigned long) buf);
1126 if (err < 0)
1127 return err;
1129 *ppos += cnt;
1131 return cnt;
1134 static ssize_t
1135 show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1137 int (*func)(struct trace_seq *s) = filp->private_data;
1138 struct trace_seq *s;
1139 int r;
1141 if (*ppos)
1142 return 0;
1144 s = kmalloc(sizeof(*s), GFP_KERNEL);
1145 if (!s)
1146 return -ENOMEM;
1148 trace_seq_init(s);
1150 func(s);
1151 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
1153 kfree(s);
1155 return r;
1158 static int ftrace_event_avail_open(struct inode *inode, struct file *file);
1159 static int ftrace_event_set_open(struct inode *inode, struct file *file);
1161 static const struct seq_operations show_event_seq_ops = {
1162 .start = t_start,
1163 .next = t_next,
1164 .show = t_show,
1165 .stop = t_stop,
1168 static const struct seq_operations show_set_event_seq_ops = {
1169 .start = s_start,
1170 .next = s_next,
1171 .show = t_show,
1172 .stop = t_stop,
1175 static const struct file_operations ftrace_avail_fops = {
1176 .open = ftrace_event_avail_open,
1177 .read = seq_read,
1178 .llseek = seq_lseek,
1179 .release = seq_release,
1182 static const struct file_operations ftrace_set_event_fops = {
1183 .open = ftrace_event_set_open,
1184 .read = seq_read,
1185 .write = ftrace_event_write,
1186 .llseek = seq_lseek,
1187 .release = seq_release,
1190 static const struct file_operations ftrace_enable_fops = {
1191 .open = tracing_open_generic,
1192 .read = event_enable_read,
1193 .write = event_enable_write,
1194 .llseek = default_llseek,
1197 static const struct file_operations ftrace_event_format_fops = {
1198 .open = trace_format_open,
1199 .read = seq_read,
1200 .llseek = seq_lseek,
1201 .release = seq_release,
1204 static const struct file_operations ftrace_event_id_fops = {
1205 .open = tracing_open_generic,
1206 .read = event_id_read,
1207 .llseek = default_llseek,
1210 static const struct file_operations ftrace_event_filter_fops = {
1211 .open = tracing_open_generic,
1212 .read = event_filter_read,
1213 .write = event_filter_write,
1214 .llseek = default_llseek,
1217 static const struct file_operations ftrace_subsystem_filter_fops = {
1218 .open = subsystem_open,
1219 .read = subsystem_filter_read,
1220 .write = subsystem_filter_write,
1221 .llseek = default_llseek,
1222 .release = subsystem_release,
1225 static const struct file_operations ftrace_system_enable_fops = {
1226 .open = subsystem_open,
1227 .read = system_enable_read,
1228 .write = system_enable_write,
1229 .llseek = default_llseek,
1230 .release = subsystem_release,
1233 static const struct file_operations ftrace_tr_enable_fops = {
1234 .open = system_tr_open,
1235 .read = system_enable_read,
1236 .write = system_enable_write,
1237 .llseek = default_llseek,
1238 .release = subsystem_release,
1241 static const struct file_operations ftrace_show_header_fops = {
1242 .open = tracing_open_generic,
1243 .read = show_header,
1244 .llseek = default_llseek,
1247 static int
1248 ftrace_event_open(struct inode *inode, struct file *file,
1249 const struct seq_operations *seq_ops)
1251 struct seq_file *m;
1252 int ret;
1254 ret = seq_open(file, seq_ops);
1255 if (ret < 0)
1256 return ret;
1257 m = file->private_data;
1258 /* copy tr over to seq ops */
1259 m->private = inode->i_private;
1261 return ret;
1264 static int
1265 ftrace_event_avail_open(struct inode *inode, struct file *file)
1267 const struct seq_operations *seq_ops = &show_event_seq_ops;
1269 return ftrace_event_open(inode, file, seq_ops);
1272 static int
1273 ftrace_event_set_open(struct inode *inode, struct file *file)
1275 const struct seq_operations *seq_ops = &show_set_event_seq_ops;
1276 struct trace_array *tr = inode->i_private;
1278 if ((file->f_mode & FMODE_WRITE) &&
1279 (file->f_flags & O_TRUNC))
1280 ftrace_clear_events(tr);
1282 return ftrace_event_open(inode, file, seq_ops);
1285 static struct event_subsystem *
1286 create_new_subsystem(const char *name)
1288 struct event_subsystem *system;
1290 /* need to create new entry */
1291 system = kmalloc(sizeof(*system), GFP_KERNEL);
1292 if (!system)
1293 return NULL;
1295 system->ref_count = 1;
1297 /* Only allocate if dynamic (kprobes and modules) */
1298 if (!core_kernel_data((unsigned long)name)) {
1299 system->ref_count |= SYSTEM_FL_FREE_NAME;
1300 system->name = kstrdup(name, GFP_KERNEL);
1301 if (!system->name)
1302 goto out_free;
1303 } else
1304 system->name = name;
1306 system->filter = NULL;
1308 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
1309 if (!system->filter)
1310 goto out_free;
1312 list_add(&system->list, &event_subsystems);
1314 return system;
1316 out_free:
1317 if (system->ref_count & SYSTEM_FL_FREE_NAME)
1318 kfree(system->name);
1319 kfree(system);
1320 return NULL;
1323 static struct dentry *
1324 event_subsystem_dir(struct trace_array *tr, const char *name,
1325 struct ftrace_event_file *file, struct dentry *parent)
1327 struct ftrace_subsystem_dir *dir;
1328 struct event_subsystem *system;
1329 struct dentry *entry;
1331 /* First see if we did not already create this dir */
1332 list_for_each_entry(dir, &tr->systems, list) {
1333 system = dir->subsystem;
1334 if (strcmp(system->name, name) == 0) {
1335 dir->nr_events++;
1336 file->system = dir;
1337 return dir->entry;
1341 /* Now see if the system itself exists. */
1342 list_for_each_entry(system, &event_subsystems, list) {
1343 if (strcmp(system->name, name) == 0)
1344 break;
1346 /* Reset system variable when not found */
1347 if (&system->list == &event_subsystems)
1348 system = NULL;
1350 dir = kmalloc(sizeof(*dir), GFP_KERNEL);
1351 if (!dir)
1352 goto out_fail;
1354 if (!system) {
1355 system = create_new_subsystem(name);
1356 if (!system)
1357 goto out_free;
1358 } else
1359 __get_system(system);
1361 dir->entry = debugfs_create_dir(name, parent);
1362 if (!dir->entry) {
1363 pr_warning("Failed to create system directory %s\n", name);
1364 __put_system(system);
1365 goto out_free;
1368 dir->tr = tr;
1369 dir->ref_count = 1;
1370 dir->nr_events = 1;
1371 dir->subsystem = system;
1372 file->system = dir;
1374 entry = debugfs_create_file("filter", 0644, dir->entry, dir,
1375 &ftrace_subsystem_filter_fops);
1376 if (!entry) {
1377 kfree(system->filter);
1378 system->filter = NULL;
1379 pr_warning("Could not create debugfs '%s/filter' entry\n", name);
1382 trace_create_file("enable", 0644, dir->entry, dir,
1383 &ftrace_system_enable_fops);
1385 list_add(&dir->list, &tr->systems);
1387 return dir->entry;
1389 out_free:
1390 kfree(dir);
1391 out_fail:
1392 /* Only print this message if failed on memory allocation */
1393 if (!dir || !system)
1394 pr_warning("No memory to create event subsystem %s\n",
1395 name);
1396 return NULL;
1399 static int
1400 event_create_dir(struct dentry *parent,
1401 struct ftrace_event_file *file,
1402 const struct file_operations *id,
1403 const struct file_operations *enable,
1404 const struct file_operations *filter,
1405 const struct file_operations *format)
1407 struct ftrace_event_call *call = file->event_call;
1408 struct trace_array *tr = file->tr;
1409 struct list_head *head;
1410 struct dentry *d_events;
1411 int ret;
1414 * If the trace point header did not define TRACE_SYSTEM
1415 * then the system would be called "TRACE_SYSTEM".
1417 if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
1418 d_events = event_subsystem_dir(tr, call->class->system, file, parent);
1419 if (!d_events)
1420 return -ENOMEM;
1421 } else
1422 d_events = parent;
1424 file->dir = debugfs_create_dir(call->name, d_events);
1425 if (!file->dir) {
1426 pr_warning("Could not create debugfs '%s' directory\n",
1427 call->name);
1428 return -1;
1431 if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
1432 trace_create_file("enable", 0644, file->dir, file,
1433 enable);
1435 #ifdef CONFIG_PERF_EVENTS
1436 if (call->event.type && call->class->reg)
1437 trace_create_file("id", 0444, file->dir, call,
1438 id);
1439 #endif
1442 * Other events may have the same class. Only update
1443 * the fields if they are not already defined.
1445 head = trace_get_fields(call);
1446 if (list_empty(head)) {
1447 ret = call->class->define_fields(call);
1448 if (ret < 0) {
1449 pr_warning("Could not initialize trace point"
1450 " events/%s\n", call->name);
1451 return -1;
1454 trace_create_file("filter", 0644, file->dir, call,
1455 filter);
1457 trace_create_file("format", 0444, file->dir, call,
1458 format);
1460 return 0;
1463 static void remove_subsystem(struct ftrace_subsystem_dir *dir)
1465 if (!dir)
1466 return;
1468 if (!--dir->nr_events) {
1469 debugfs_remove_recursive(dir->entry);
1470 list_del(&dir->list);
1471 __put_system_dir(dir);
1475 static void remove_event_from_tracers(struct ftrace_event_call *call)
1477 struct ftrace_event_file *file;
1478 struct trace_array *tr;
1480 do_for_each_event_file_safe(tr, file) {
1482 if (file->event_call != call)
1483 continue;
1485 list_del(&file->list);
1486 debugfs_remove_recursive(file->dir);
1487 remove_subsystem(file->system);
1488 kmem_cache_free(file_cachep, file);
1491 * The do_for_each_event_file_safe() is
1492 * a double loop. After finding the call for this
1493 * trace_array, we use break to jump to the next
1494 * trace_array.
1496 break;
1497 } while_for_each_event_file();
1500 static void event_remove(struct ftrace_event_call *call)
1502 struct trace_array *tr;
1503 struct ftrace_event_file *file;
1505 do_for_each_event_file(tr, file) {
1506 if (file->event_call != call)
1507 continue;
1508 ftrace_event_enable_disable(file, 0);
1510 * The do_for_each_event_file() is
1511 * a double loop. After finding the call for this
1512 * trace_array, we use break to jump to the next
1513 * trace_array.
1515 break;
1516 } while_for_each_event_file();
1518 if (call->event.funcs)
1519 __unregister_ftrace_event(&call->event);
1520 remove_event_from_tracers(call);
1521 list_del(&call->list);
1524 static int event_init(struct ftrace_event_call *call)
1526 int ret = 0;
1528 if (WARN_ON(!call->name))
1529 return -EINVAL;
1531 if (call->class->raw_init) {
1532 ret = call->class->raw_init(call);
1533 if (ret < 0 && ret != -ENOSYS)
1534 pr_warn("Could not initialize trace events/%s\n",
1535 call->name);
1538 return ret;
1541 static int
1542 __register_event(struct ftrace_event_call *call, struct module *mod)
1544 int ret;
1546 ret = event_init(call);
1547 if (ret < 0)
1548 return ret;
1550 list_add(&call->list, &ftrace_events);
1551 call->mod = mod;
1553 return 0;
1556 static struct ftrace_event_file *
1557 trace_create_new_event(struct ftrace_event_call *call,
1558 struct trace_array *tr)
1560 struct ftrace_event_file *file;
1562 file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1563 if (!file)
1564 return NULL;
1566 file->event_call = call;
1567 file->tr = tr;
1568 atomic_set(&file->sm_ref, 0);
1569 list_add(&file->list, &tr->events);
1571 return file;
1574 /* Add an event to a trace directory */
1575 static int
1576 __trace_add_new_event(struct ftrace_event_call *call,
1577 struct trace_array *tr,
1578 const struct file_operations *id,
1579 const struct file_operations *enable,
1580 const struct file_operations *filter,
1581 const struct file_operations *format)
1583 struct ftrace_event_file *file;
1585 file = trace_create_new_event(call, tr);
1586 if (!file)
1587 return -ENOMEM;
1589 return event_create_dir(tr->event_dir, file, id, enable, filter, format);
1593 * Just create a decriptor for early init. A descriptor is required
1594 * for enabling events at boot. We want to enable events before
1595 * the filesystem is initialized.
1597 static __init int
1598 __trace_early_add_new_event(struct ftrace_event_call *call,
1599 struct trace_array *tr)
1601 struct ftrace_event_file *file;
1603 file = trace_create_new_event(call, tr);
1604 if (!file)
1605 return -ENOMEM;
1607 return 0;
1610 struct ftrace_module_file_ops;
1611 static void __add_event_to_tracers(struct ftrace_event_call *call,
1612 struct ftrace_module_file_ops *file_ops);
1614 /* Add an additional event_call dynamically */
1615 int trace_add_event_call(struct ftrace_event_call *call)
1617 int ret;
1618 mutex_lock(&event_mutex);
1620 ret = __register_event(call, NULL);
1621 if (ret >= 0)
1622 __add_event_to_tracers(call, NULL);
1624 mutex_unlock(&event_mutex);
1625 return ret;
1629 * Must be called under locking both of event_mutex and trace_event_sem.
1631 static void __trace_remove_event_call(struct ftrace_event_call *call)
1633 event_remove(call);
1634 trace_destroy_fields(call);
1635 destroy_preds(call);
1638 /* Remove an event_call */
1639 void trace_remove_event_call(struct ftrace_event_call *call)
1641 mutex_lock(&event_mutex);
1642 down_write(&trace_event_sem);
1643 __trace_remove_event_call(call);
1644 up_write(&trace_event_sem);
1645 mutex_unlock(&event_mutex);
1648 #define for_each_event(event, start, end) \
1649 for (event = start; \
1650 (unsigned long)event < (unsigned long)end; \
1651 event++)
1653 #ifdef CONFIG_MODULES
1655 static LIST_HEAD(ftrace_module_file_list);
1658 * Modules must own their file_operations to keep up with
1659 * reference counting.
1661 struct ftrace_module_file_ops {
1662 struct list_head list;
1663 struct module *mod;
1664 struct file_operations id;
1665 struct file_operations enable;
1666 struct file_operations format;
1667 struct file_operations filter;
1670 static struct ftrace_module_file_ops *
1671 find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
1674 * As event_calls are added in groups by module,
1675 * when we find one file_ops, we don't need to search for
1676 * each call in that module, as the rest should be the
1677 * same. Only search for a new one if the last one did
1678 * not match.
1680 if (file_ops && mod == file_ops->mod)
1681 return file_ops;
1683 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1684 if (file_ops->mod == mod)
1685 return file_ops;
1687 return NULL;
1690 static struct ftrace_module_file_ops *
1691 trace_create_file_ops(struct module *mod)
1693 struct ftrace_module_file_ops *file_ops;
1696 * This is a bit of a PITA. To allow for correct reference
1697 * counting, modules must "own" their file_operations.
1698 * To do this, we allocate the file operations that will be
1699 * used in the event directory.
1702 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1703 if (!file_ops)
1704 return NULL;
1706 file_ops->mod = mod;
1708 file_ops->id = ftrace_event_id_fops;
1709 file_ops->id.owner = mod;
1711 file_ops->enable = ftrace_enable_fops;
1712 file_ops->enable.owner = mod;
1714 file_ops->filter = ftrace_event_filter_fops;
1715 file_ops->filter.owner = mod;
1717 file_ops->format = ftrace_event_format_fops;
1718 file_ops->format.owner = mod;
1720 list_add(&file_ops->list, &ftrace_module_file_list);
1722 return file_ops;
1725 static void trace_module_add_events(struct module *mod)
1727 struct ftrace_module_file_ops *file_ops = NULL;
1728 struct ftrace_event_call **call, **start, **end;
1730 start = mod->trace_events;
1731 end = mod->trace_events + mod->num_trace_events;
1733 if (start == end)
1734 return;
1736 file_ops = trace_create_file_ops(mod);
1737 if (!file_ops)
1738 return;
1740 for_each_event(call, start, end) {
1741 __register_event(*call, mod);
1742 __add_event_to_tracers(*call, file_ops);
1746 static void trace_module_remove_events(struct module *mod)
1748 struct ftrace_module_file_ops *file_ops;
1749 struct ftrace_event_call *call, *p;
1750 bool clear_trace = false;
1752 down_write(&trace_event_sem);
1753 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1754 if (call->mod == mod) {
1755 if (call->flags & TRACE_EVENT_FL_WAS_ENABLED)
1756 clear_trace = true;
1757 __trace_remove_event_call(call);
1761 /* Now free the file_operations */
1762 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1763 if (file_ops->mod == mod)
1764 break;
1766 if (&file_ops->list != &ftrace_module_file_list) {
1767 list_del(&file_ops->list);
1768 kfree(file_ops);
1770 up_write(&trace_event_sem);
1773 * It is safest to reset the ring buffer if the module being unloaded
1774 * registered any events that were used. The only worry is if
1775 * a new module gets loaded, and takes on the same id as the events
1776 * of this module. When printing out the buffer, traced events left
1777 * over from this module may be passed to the new module events and
1778 * unexpected results may occur.
1780 if (clear_trace)
1781 tracing_reset_all_online_cpus();
1784 static int trace_module_notify(struct notifier_block *self,
1785 unsigned long val, void *data)
1787 struct module *mod = data;
1789 mutex_lock(&event_mutex);
1790 switch (val) {
1791 case MODULE_STATE_COMING:
1792 trace_module_add_events(mod);
1793 break;
1794 case MODULE_STATE_GOING:
1795 trace_module_remove_events(mod);
1796 break;
1798 mutex_unlock(&event_mutex);
1800 return 0;
1803 static int
1804 __trace_add_new_mod_event(struct ftrace_event_call *call,
1805 struct trace_array *tr,
1806 struct ftrace_module_file_ops *file_ops)
1808 return __trace_add_new_event(call, tr,
1809 &file_ops->id, &file_ops->enable,
1810 &file_ops->filter, &file_ops->format);
1813 #else
1814 static inline struct ftrace_module_file_ops *
1815 find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
1817 return NULL;
1819 static inline int trace_module_notify(struct notifier_block *self,
1820 unsigned long val, void *data)
1822 return 0;
1824 static inline int
1825 __trace_add_new_mod_event(struct ftrace_event_call *call,
1826 struct trace_array *tr,
1827 struct ftrace_module_file_ops *file_ops)
1829 return -ENODEV;
1831 #endif /* CONFIG_MODULES */
1833 /* Create a new event directory structure for a trace directory. */
1834 static void
1835 __trace_add_event_dirs(struct trace_array *tr)
1837 struct ftrace_module_file_ops *file_ops = NULL;
1838 struct ftrace_event_call *call;
1839 int ret;
1841 list_for_each_entry(call, &ftrace_events, list) {
1842 if (call->mod) {
1844 * Directories for events by modules need to
1845 * keep module ref counts when opened (as we don't
1846 * want the module to disappear when reading one
1847 * of these files). The file_ops keep account of
1848 * the module ref count.
1850 file_ops = find_ftrace_file_ops(file_ops, call->mod);
1851 if (!file_ops)
1852 continue; /* Warn? */
1853 ret = __trace_add_new_mod_event(call, tr, file_ops);
1854 if (ret < 0)
1855 pr_warning("Could not create directory for event %s\n",
1856 call->name);
1857 continue;
1859 ret = __trace_add_new_event(call, tr,
1860 &ftrace_event_id_fops,
1861 &ftrace_enable_fops,
1862 &ftrace_event_filter_fops,
1863 &ftrace_event_format_fops);
1864 if (ret < 0)
1865 pr_warning("Could not create directory for event %s\n",
1866 call->name);
1870 #ifdef CONFIG_DYNAMIC_FTRACE
1872 /* Avoid typos */
1873 #define ENABLE_EVENT_STR "enable_event"
1874 #define DISABLE_EVENT_STR "disable_event"
1876 struct event_probe_data {
1877 struct ftrace_event_file *file;
1878 unsigned long count;
1879 int ref;
1880 bool enable;
1883 static struct ftrace_event_file *
1884 find_event_file(struct trace_array *tr, const char *system, const char *event)
1886 struct ftrace_event_file *file;
1887 struct ftrace_event_call *call;
1889 list_for_each_entry(file, &tr->events, list) {
1891 call = file->event_call;
1893 if (!call->name || !call->class || !call->class->reg)
1894 continue;
1896 if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
1897 continue;
1899 if (strcmp(event, call->name) == 0 &&
1900 strcmp(system, call->class->system) == 0)
1901 return file;
1903 return NULL;
1906 static void
1907 event_enable_probe(unsigned long ip, unsigned long parent_ip, void **_data)
1909 struct event_probe_data **pdata = (struct event_probe_data **)_data;
1910 struct event_probe_data *data = *pdata;
1912 if (!data)
1913 return;
1915 if (data->enable)
1916 clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags);
1917 else
1918 set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags);
1921 static void
1922 event_enable_count_probe(unsigned long ip, unsigned long parent_ip, void **_data)
1924 struct event_probe_data **pdata = (struct event_probe_data **)_data;
1925 struct event_probe_data *data = *pdata;
1927 if (!data)
1928 return;
1930 if (!data->count)
1931 return;
1933 /* Skip if the event is in a state we want to switch to */
1934 if (data->enable == !(data->file->flags & FTRACE_EVENT_FL_SOFT_DISABLED))
1935 return;
1937 if (data->count != -1)
1938 (data->count)--;
1940 event_enable_probe(ip, parent_ip, _data);
1943 static int
1944 event_enable_print(struct seq_file *m, unsigned long ip,
1945 struct ftrace_probe_ops *ops, void *_data)
1947 struct event_probe_data *data = _data;
1949 seq_printf(m, "%ps:", (void *)ip);
1951 seq_printf(m, "%s:%s:%s",
1952 data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR,
1953 data->file->event_call->class->system,
1954 data->file->event_call->name);
1956 if (data->count == -1)
1957 seq_printf(m, ":unlimited\n");
1958 else
1959 seq_printf(m, ":count=%ld\n", data->count);
1961 return 0;
1964 static int
1965 event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip,
1966 void **_data)
1968 struct event_probe_data **pdata = (struct event_probe_data **)_data;
1969 struct event_probe_data *data = *pdata;
1971 data->ref++;
1972 return 0;
1975 static void
1976 event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip,
1977 void **_data)
1979 struct event_probe_data **pdata = (struct event_probe_data **)_data;
1980 struct event_probe_data *data = *pdata;
1982 if (WARN_ON_ONCE(data->ref <= 0))
1983 return;
1985 data->ref--;
1986 if (!data->ref) {
1987 /* Remove the SOFT_MODE flag */
1988 __ftrace_event_enable_disable(data->file, 0, 1);
1989 module_put(data->file->event_call->mod);
1990 kfree(data);
1992 *pdata = NULL;
1995 static struct ftrace_probe_ops event_enable_probe_ops = {
1996 .func = event_enable_probe,
1997 .print = event_enable_print,
1998 .init = event_enable_init,
1999 .free = event_enable_free,
2002 static struct ftrace_probe_ops event_enable_count_probe_ops = {
2003 .func = event_enable_count_probe,
2004 .print = event_enable_print,
2005 .init = event_enable_init,
2006 .free = event_enable_free,
2009 static struct ftrace_probe_ops event_disable_probe_ops = {
2010 .func = event_enable_probe,
2011 .print = event_enable_print,
2012 .init = event_enable_init,
2013 .free = event_enable_free,
2016 static struct ftrace_probe_ops event_disable_count_probe_ops = {
2017 .func = event_enable_count_probe,
2018 .print = event_enable_print,
2019 .init = event_enable_init,
2020 .free = event_enable_free,
2023 static int
2024 event_enable_func(struct ftrace_hash *hash,
2025 char *glob, char *cmd, char *param, int enabled)
2027 struct trace_array *tr = top_trace_array();
2028 struct ftrace_event_file *file;
2029 struct ftrace_probe_ops *ops;
2030 struct event_probe_data *data;
2031 const char *system;
2032 const char *event;
2033 char *number;
2034 bool enable;
2035 int ret;
2037 /* hash funcs only work with set_ftrace_filter */
2038 if (!enabled || !param)
2039 return -EINVAL;
2041 system = strsep(&param, ":");
2042 if (!param)
2043 return -EINVAL;
2045 event = strsep(&param, ":");
2047 mutex_lock(&event_mutex);
2049 ret = -EINVAL;
2050 file = find_event_file(tr, system, event);
2051 if (!file)
2052 goto out;
2054 enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
2056 if (enable)
2057 ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops;
2058 else
2059 ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops;
2061 if (glob[0] == '!') {
2062 unregister_ftrace_function_probe_func(glob+1, ops);
2063 ret = 0;
2064 goto out;
2067 ret = -ENOMEM;
2068 data = kzalloc(sizeof(*data), GFP_KERNEL);
2069 if (!data)
2070 goto out;
2072 data->enable = enable;
2073 data->count = -1;
2074 data->file = file;
2076 if (!param)
2077 goto out_reg;
2079 number = strsep(&param, ":");
2081 ret = -EINVAL;
2082 if (!strlen(number))
2083 goto out_free;
2086 * We use the callback data field (which is a pointer)
2087 * as our counter.
2089 ret = kstrtoul(number, 0, &data->count);
2090 if (ret)
2091 goto out_free;
2093 out_reg:
2094 /* Don't let event modules unload while probe registered */
2095 ret = try_module_get(file->event_call->mod);
2096 if (!ret) {
2097 ret = -EBUSY;
2098 goto out_free;
2101 ret = __ftrace_event_enable_disable(file, 1, 1);
2102 if (ret < 0)
2103 goto out_put;
2104 ret = register_ftrace_function_probe(glob, ops, data);
2106 * The above returns on success the # of functions enabled,
2107 * but if it didn't find any functions it returns zero.
2108 * Consider no functions a failure too.
2110 if (!ret) {
2111 ret = -ENOENT;
2112 goto out_disable;
2113 } else if (ret < 0)
2114 goto out_disable;
2115 /* Just return zero, not the number of enabled functions */
2116 ret = 0;
2117 out:
2118 mutex_unlock(&event_mutex);
2119 return ret;
2121 out_disable:
2122 __ftrace_event_enable_disable(file, 0, 1);
2123 out_put:
2124 module_put(file->event_call->mod);
2125 out_free:
2126 kfree(data);
2127 goto out;
2130 static struct ftrace_func_command event_enable_cmd = {
2131 .name = ENABLE_EVENT_STR,
2132 .func = event_enable_func,
2135 static struct ftrace_func_command event_disable_cmd = {
2136 .name = DISABLE_EVENT_STR,
2137 .func = event_enable_func,
2140 static __init int register_event_cmds(void)
2142 int ret;
2144 ret = register_ftrace_command(&event_enable_cmd);
2145 if (WARN_ON(ret < 0))
2146 return ret;
2147 ret = register_ftrace_command(&event_disable_cmd);
2148 if (WARN_ON(ret < 0))
2149 unregister_ftrace_command(&event_enable_cmd);
2150 return ret;
2152 #else
2153 static inline int register_event_cmds(void) { return 0; }
2154 #endif /* CONFIG_DYNAMIC_FTRACE */
2157 * The top level array has already had its ftrace_event_file
2158 * descriptors created in order to allow for early events to
2159 * be recorded. This function is called after the debugfs has been
2160 * initialized, and we now have to create the files associated
2161 * to the events.
2163 static __init void
2164 __trace_early_add_event_dirs(struct trace_array *tr)
2166 struct ftrace_event_file *file;
2167 int ret;
2170 list_for_each_entry(file, &tr->events, list) {
2171 ret = event_create_dir(tr->event_dir, file,
2172 &ftrace_event_id_fops,
2173 &ftrace_enable_fops,
2174 &ftrace_event_filter_fops,
2175 &ftrace_event_format_fops);
2176 if (ret < 0)
2177 pr_warning("Could not create directory for event %s\n",
2178 file->event_call->name);
2183 * For early boot up, the top trace array requires to have
2184 * a list of events that can be enabled. This must be done before
2185 * the filesystem is set up in order to allow events to be traced
2186 * early.
2188 static __init void
2189 __trace_early_add_events(struct trace_array *tr)
2191 struct ftrace_event_call *call;
2192 int ret;
2194 list_for_each_entry(call, &ftrace_events, list) {
2195 /* Early boot up should not have any modules loaded */
2196 if (WARN_ON_ONCE(call->mod))
2197 continue;
2199 ret = __trace_early_add_new_event(call, tr);
2200 if (ret < 0)
2201 pr_warning("Could not create early event %s\n",
2202 call->name);
2206 /* Remove the event directory structure for a trace directory. */
2207 static void
2208 __trace_remove_event_dirs(struct trace_array *tr)
2210 struct ftrace_event_file *file, *next;
2212 list_for_each_entry_safe(file, next, &tr->events, list) {
2213 list_del(&file->list);
2214 debugfs_remove_recursive(file->dir);
2215 remove_subsystem(file->system);
2216 kmem_cache_free(file_cachep, file);
2220 static void
2221 __add_event_to_tracers(struct ftrace_event_call *call,
2222 struct ftrace_module_file_ops *file_ops)
2224 struct trace_array *tr;
2226 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
2227 if (file_ops)
2228 __trace_add_new_mod_event(call, tr, file_ops);
2229 else
2230 __trace_add_new_event(call, tr,
2231 &ftrace_event_id_fops,
2232 &ftrace_enable_fops,
2233 &ftrace_event_filter_fops,
2234 &ftrace_event_format_fops);
2238 static struct notifier_block trace_module_nb = {
2239 .notifier_call = trace_module_notify,
2240 .priority = 0,
2243 extern struct ftrace_event_call *__start_ftrace_events[];
2244 extern struct ftrace_event_call *__stop_ftrace_events[];
2246 static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
2248 static __init int setup_trace_event(char *str)
2250 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
2251 ring_buffer_expanded = true;
2252 tracing_selftest_disabled = true;
2254 return 1;
2256 __setup("trace_event=", setup_trace_event);
2258 /* Expects to have event_mutex held when called */
2259 static int
2260 create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
2262 struct dentry *d_events;
2263 struct dentry *entry;
2265 entry = debugfs_create_file("set_event", 0644, parent,
2266 tr, &ftrace_set_event_fops);
2267 if (!entry) {
2268 pr_warning("Could not create debugfs 'set_event' entry\n");
2269 return -ENOMEM;
2272 d_events = debugfs_create_dir("events", parent);
2273 if (!d_events) {
2274 pr_warning("Could not create debugfs 'events' directory\n");
2275 return -ENOMEM;
2278 /* ring buffer internal formats */
2279 trace_create_file("header_page", 0444, d_events,
2280 ring_buffer_print_page_header,
2281 &ftrace_show_header_fops);
2283 trace_create_file("header_event", 0444, d_events,
2284 ring_buffer_print_entry_header,
2285 &ftrace_show_header_fops);
2287 trace_create_file("enable", 0644, d_events,
2288 tr, &ftrace_tr_enable_fops);
2290 tr->event_dir = d_events;
2292 return 0;
2296 * event_trace_add_tracer - add a instance of a trace_array to events
2297 * @parent: The parent dentry to place the files/directories for events in
2298 * @tr: The trace array associated with these events
2300 * When a new instance is created, it needs to set up its events
2301 * directory, as well as other files associated with events. It also
2302 * creates the event hierachry in the @parent/events directory.
2304 * Returns 0 on success.
2306 int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
2308 int ret;
2310 mutex_lock(&event_mutex);
2312 ret = create_event_toplevel_files(parent, tr);
2313 if (ret)
2314 goto out_unlock;
2316 down_write(&trace_event_sem);
2317 __trace_add_event_dirs(tr);
2318 up_write(&trace_event_sem);
2320 out_unlock:
2321 mutex_unlock(&event_mutex);
2323 return ret;
2327 * The top trace array already had its file descriptors created.
2328 * Now the files themselves need to be created.
2330 static __init int
2331 early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
2333 int ret;
2335 mutex_lock(&event_mutex);
2337 ret = create_event_toplevel_files(parent, tr);
2338 if (ret)
2339 goto out_unlock;
2341 down_write(&trace_event_sem);
2342 __trace_early_add_event_dirs(tr);
2343 up_write(&trace_event_sem);
2345 out_unlock:
2346 mutex_unlock(&event_mutex);
2348 return ret;
2351 int event_trace_del_tracer(struct trace_array *tr)
2353 /* Disable any running events */
2354 __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
2356 mutex_lock(&event_mutex);
2358 down_write(&trace_event_sem);
2359 __trace_remove_event_dirs(tr);
2360 debugfs_remove_recursive(tr->event_dir);
2361 up_write(&trace_event_sem);
2363 tr->event_dir = NULL;
2365 mutex_unlock(&event_mutex);
2367 return 0;
2370 static __init int event_trace_memsetup(void)
2372 field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC);
2373 file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC);
2374 return 0;
2377 static __init int event_trace_enable(void)
2379 struct trace_array *tr = top_trace_array();
2380 struct ftrace_event_call **iter, *call;
2381 char *buf = bootup_event_buf;
2382 char *token;
2383 int ret;
2385 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
2387 call = *iter;
2388 ret = event_init(call);
2389 if (!ret)
2390 list_add(&call->list, &ftrace_events);
2394 * We need the top trace array to have a working set of trace
2395 * points at early init, before the debug files and directories
2396 * are created. Create the file entries now, and attach them
2397 * to the actual file dentries later.
2399 __trace_early_add_events(tr);
2401 while (true) {
2402 token = strsep(&buf, ",");
2404 if (!token)
2405 break;
2406 if (!*token)
2407 continue;
2409 ret = ftrace_set_clr_event(tr, token, 1);
2410 if (ret)
2411 pr_warn("Failed to enable trace event: %s\n", token);
2414 trace_printk_start_comm();
2416 register_event_cmds();
2418 return 0;
2421 static __init int event_trace_init(void)
2423 struct trace_array *tr;
2424 struct dentry *d_tracer;
2425 struct dentry *entry;
2426 int ret;
2428 tr = top_trace_array();
2430 d_tracer = tracing_init_dentry();
2431 if (!d_tracer)
2432 return 0;
2434 entry = debugfs_create_file("available_events", 0444, d_tracer,
2435 tr, &ftrace_avail_fops);
2436 if (!entry)
2437 pr_warning("Could not create debugfs "
2438 "'available_events' entry\n");
2440 if (trace_define_common_fields())
2441 pr_warning("tracing: Failed to allocate common fields");
2443 ret = early_event_add_tracer(d_tracer, tr);
2444 if (ret)
2445 return ret;
2447 ret = register_module_notifier(&trace_module_nb);
2448 if (ret)
2449 pr_warning("Failed to register trace events module notifier\n");
2451 return 0;
2453 early_initcall(event_trace_memsetup);
2454 core_initcall(event_trace_enable);
2455 fs_initcall(event_trace_init);
2457 #ifdef CONFIG_FTRACE_STARTUP_TEST
2459 static DEFINE_SPINLOCK(test_spinlock);
2460 static DEFINE_SPINLOCK(test_spinlock_irq);
2461 static DEFINE_MUTEX(test_mutex);
2463 static __init void test_work(struct work_struct *dummy)
2465 spin_lock(&test_spinlock);
2466 spin_lock_irq(&test_spinlock_irq);
2467 udelay(1);
2468 spin_unlock_irq(&test_spinlock_irq);
2469 spin_unlock(&test_spinlock);
2471 mutex_lock(&test_mutex);
2472 msleep(1);
2473 mutex_unlock(&test_mutex);
2476 static __init int event_test_thread(void *unused)
2478 void *test_malloc;
2480 test_malloc = kmalloc(1234, GFP_KERNEL);
2481 if (!test_malloc)
2482 pr_info("failed to kmalloc\n");
2484 schedule_on_each_cpu(test_work);
2486 kfree(test_malloc);
2488 set_current_state(TASK_INTERRUPTIBLE);
2489 while (!kthread_should_stop())
2490 schedule();
2492 return 0;
2496 * Do various things that may trigger events.
2498 static __init void event_test_stuff(void)
2500 struct task_struct *test_thread;
2502 test_thread = kthread_run(event_test_thread, NULL, "test-events");
2503 msleep(1);
2504 kthread_stop(test_thread);
2508 * For every trace event defined, we will test each trace point separately,
2509 * and then by groups, and finally all trace points.
2511 static __init void event_trace_self_tests(void)
2513 struct ftrace_subsystem_dir *dir;
2514 struct ftrace_event_file *file;
2515 struct ftrace_event_call *call;
2516 struct event_subsystem *system;
2517 struct trace_array *tr;
2518 int ret;
2520 tr = top_trace_array();
2522 pr_info("Running tests on trace events:\n");
2524 list_for_each_entry(file, &tr->events, list) {
2526 call = file->event_call;
2528 /* Only test those that have a probe */
2529 if (!call->class || !call->class->probe)
2530 continue;
2533 * Testing syscall events here is pretty useless, but
2534 * we still do it if configured. But this is time consuming.
2535 * What we really need is a user thread to perform the
2536 * syscalls as we test.
2538 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
2539 if (call->class->system &&
2540 strcmp(call->class->system, "syscalls") == 0)
2541 continue;
2542 #endif
2544 pr_info("Testing event %s: ", call->name);
2547 * If an event is already enabled, someone is using
2548 * it and the self test should not be on.
2550 if (file->flags & FTRACE_EVENT_FL_ENABLED) {
2551 pr_warning("Enabled event during self test!\n");
2552 WARN_ON_ONCE(1);
2553 continue;
2556 ftrace_event_enable_disable(file, 1);
2557 event_test_stuff();
2558 ftrace_event_enable_disable(file, 0);
2560 pr_cont("OK\n");
2563 /* Now test at the sub system level */
2565 pr_info("Running tests on trace event systems:\n");
2567 list_for_each_entry(dir, &tr->systems, list) {
2569 system = dir->subsystem;
2571 /* the ftrace system is special, skip it */
2572 if (strcmp(system->name, "ftrace") == 0)
2573 continue;
2575 pr_info("Testing event system %s: ", system->name);
2577 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1);
2578 if (WARN_ON_ONCE(ret)) {
2579 pr_warning("error enabling system %s\n",
2580 system->name);
2581 continue;
2584 event_test_stuff();
2586 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0);
2587 if (WARN_ON_ONCE(ret)) {
2588 pr_warning("error disabling system %s\n",
2589 system->name);
2590 continue;
2593 pr_cont("OK\n");
2596 /* Test with all events enabled */
2598 pr_info("Running tests on all trace events:\n");
2599 pr_info("Testing all events: ");
2601 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1);
2602 if (WARN_ON_ONCE(ret)) {
2603 pr_warning("error enabling all events\n");
2604 return;
2607 event_test_stuff();
2609 /* reset sysname */
2610 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
2611 if (WARN_ON_ONCE(ret)) {
2612 pr_warning("error disabling all events\n");
2613 return;
2616 pr_cont("OK\n");
2619 #ifdef CONFIG_FUNCTION_TRACER
2621 static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
2623 static void
2624 function_test_events_call(unsigned long ip, unsigned long parent_ip,
2625 struct ftrace_ops *op, struct pt_regs *pt_regs)
2627 struct ring_buffer_event *event;
2628 struct ring_buffer *buffer;
2629 struct ftrace_entry *entry;
2630 unsigned long flags;
2631 long disabled;
2632 int cpu;
2633 int pc;
2635 pc = preempt_count();
2636 preempt_disable_notrace();
2637 cpu = raw_smp_processor_id();
2638 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
2640 if (disabled != 1)
2641 goto out;
2643 local_save_flags(flags);
2645 event = trace_current_buffer_lock_reserve(&buffer,
2646 TRACE_FN, sizeof(*entry),
2647 flags, pc);
2648 if (!event)
2649 goto out;
2650 entry = ring_buffer_event_data(event);
2651 entry->ip = ip;
2652 entry->parent_ip = parent_ip;
2654 trace_buffer_unlock_commit(buffer, event, flags, pc);
2656 out:
2657 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
2658 preempt_enable_notrace();
2661 static struct ftrace_ops trace_ops __initdata =
2663 .func = function_test_events_call,
2664 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
2667 static __init void event_trace_self_test_with_function(void)
2669 int ret;
2670 ret = register_ftrace_function(&trace_ops);
2671 if (WARN_ON(ret < 0)) {
2672 pr_info("Failed to enable function tracer for event tests\n");
2673 return;
2675 pr_info("Running tests again, along with the function tracer\n");
2676 event_trace_self_tests();
2677 unregister_ftrace_function(&trace_ops);
2679 #else
2680 static __init void event_trace_self_test_with_function(void)
2683 #endif
2685 static __init int event_trace_self_tests_init(void)
2687 if (!tracing_selftest_disabled) {
2688 event_trace_self_tests();
2689 event_trace_self_test_with_function();
2692 return 0;
2695 late_initcall(event_trace_self_tests_init);
2697 #endif