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>.
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"
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 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 /* Double loops, do not use break, only goto's work */
45 #define do_for_each_event_file(tr, file) \
46 list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
47 list_for_each_entry(file, &tr->events, list)
49 #define do_for_each_event_file_safe(tr, file) \
50 list_for_each_entry(tr, &ftrace_trace_arrays, list) { \
51 struct ftrace_event_file *___n; \
52 list_for_each_entry_safe(file, ___n, &tr->events, list)
54 #define while_for_each_event_file() \
58 trace_get_fields(struct ftrace_event_call *event_call)
60 if (!event_call->class->get_fields)
61 return &event_call->class->fields;
62 return event_call->class->get_fields(event_call);
65 static int __trace_define_field(struct list_head *head, const char *type,
66 const char *name, int offset, int size,
67 int is_signed, int filter_type)
69 struct ftrace_event_field *field;
71 field = kmem_cache_alloc(field_cachep, GFP_TRACE);
78 if (filter_type == FILTER_OTHER)
79 field->filter_type = filter_assign_type(type);
81 field->filter_type = filter_type;
83 field->offset = offset;
85 field->is_signed = is_signed;
87 list_add(&field->link, head);
92 kmem_cache_free(field_cachep, field);
97 int trace_define_field(struct ftrace_event_call *call, const char *type,
98 const char *name, int offset, int size, int is_signed,
101 struct list_head *head;
103 if (WARN_ON(!call->class))
106 head = trace_get_fields(call);
107 return __trace_define_field(head, type, name, offset, size,
108 is_signed, filter_type);
110 EXPORT_SYMBOL_GPL(trace_define_field);
112 #define __common_field(type, item) \
113 ret = __trace_define_field(&ftrace_common_fields, #type, \
115 offsetof(typeof(ent), item), \
117 is_signed_type(type), FILTER_OTHER); \
121 static int trace_define_common_fields(void)
124 struct trace_entry ent;
126 __common_field(unsigned short, type);
127 __common_field(unsigned char, flags);
128 __common_field(unsigned char, preempt_count);
129 __common_field(int, pid);
134 void trace_destroy_fields(struct ftrace_event_call *call)
136 struct ftrace_event_field *field, *next;
137 struct list_head *head;
139 head = trace_get_fields(call);
140 list_for_each_entry_safe(field, next, head, link) {
141 list_del(&field->link);
142 kmem_cache_free(field_cachep, field);
146 int trace_event_raw_init(struct ftrace_event_call *call)
150 id = register_ftrace_event(&call->event);
156 EXPORT_SYMBOL_GPL(trace_event_raw_init);
158 int ftrace_event_reg(struct ftrace_event_call *call,
159 enum trace_reg type, void *data)
161 struct ftrace_event_file *file = data;
164 case TRACE_REG_REGISTER:
165 return tracepoint_probe_register(call->name,
168 case TRACE_REG_UNREGISTER:
169 tracepoint_probe_unregister(call->name,
174 #ifdef CONFIG_PERF_EVENTS
175 case TRACE_REG_PERF_REGISTER:
176 return tracepoint_probe_register(call->name,
177 call->class->perf_probe,
179 case TRACE_REG_PERF_UNREGISTER:
180 tracepoint_probe_unregister(call->name,
181 call->class->perf_probe,
184 case TRACE_REG_PERF_OPEN:
185 case TRACE_REG_PERF_CLOSE:
186 case TRACE_REG_PERF_ADD:
187 case TRACE_REG_PERF_DEL:
193 EXPORT_SYMBOL_GPL(ftrace_event_reg);
195 void trace_event_enable_cmd_record(bool enable)
197 struct ftrace_event_file *file;
198 struct trace_array *tr;
200 mutex_lock(&event_mutex);
201 do_for_each_event_file(tr, file) {
203 if (!(file->flags & FTRACE_EVENT_FL_ENABLED))
207 tracing_start_cmdline_record();
208 set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
210 tracing_stop_cmdline_record();
211 clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
213 } while_for_each_event_file();
214 mutex_unlock(&event_mutex);
217 static int __ftrace_event_enable_disable(struct ftrace_event_file *file,
218 int enable, int soft_disable)
220 struct ftrace_event_call *call = file->event_call;
227 * When soft_disable is set and enable is cleared, we want
228 * to clear the SOFT_DISABLED flag but leave the event in the
229 * state that it was. That is, if the event was enabled and
230 * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED
231 * is set we do not want the event to be enabled before we
234 * When soft_disable is not set but the SOFT_MODE flag is,
235 * we do nothing. Do not disable the tracepoint, otherwise
236 * "soft enable"s (clearing the SOFT_DISABLED bit) wont work.
239 disable = file->flags & FTRACE_EVENT_FL_SOFT_DISABLED;
240 clear_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags);
242 disable = !(file->flags & FTRACE_EVENT_FL_SOFT_MODE);
244 if (disable && (file->flags & FTRACE_EVENT_FL_ENABLED)) {
245 clear_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags);
246 if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) {
247 tracing_stop_cmdline_record();
248 clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
250 call->class->reg(call, TRACE_REG_UNREGISTER, file);
252 /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT */
253 if (file->flags & FTRACE_EVENT_FL_SOFT_MODE)
254 set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
258 * When soft_disable is set and enable is set, we want to
259 * register the tracepoint for the event, but leave the event
260 * as is. That means, if the event was already enabled, we do
261 * nothing (but set SOFT_MODE). If the event is disabled, we
262 * set SOFT_DISABLED before enabling the event tracepoint, so
263 * it still seems to be disabled.
266 clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
268 set_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags);
270 if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) {
272 /* Keep the event disabled, when going to SOFT_MODE. */
274 set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags);
276 if (trace_flags & TRACE_ITER_RECORD_CMD) {
277 tracing_start_cmdline_record();
278 set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags);
280 ret = call->class->reg(call, TRACE_REG_REGISTER, file);
282 tracing_stop_cmdline_record();
283 pr_info("event trace: Could not enable event "
287 set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags);
289 /* WAS_ENABLED gets set but never cleared. */
290 call->flags |= TRACE_EVENT_FL_WAS_ENABLED;
298 static int ftrace_event_enable_disable(struct ftrace_event_file *file,
301 return __ftrace_event_enable_disable(file, enable, 0);
304 static void ftrace_clear_events(struct trace_array *tr)
306 struct ftrace_event_file *file;
308 mutex_lock(&event_mutex);
309 list_for_each_entry(file, &tr->events, list) {
310 ftrace_event_enable_disable(file, 0);
312 mutex_unlock(&event_mutex);
315 static void __put_system(struct event_subsystem *system)
317 struct event_filter *filter = system->filter;
319 WARN_ON_ONCE(system->ref_count == 0);
320 if (--system->ref_count)
323 list_del(&system->list);
326 kfree(filter->filter_string);
332 static void __get_system(struct event_subsystem *system)
334 WARN_ON_ONCE(system->ref_count == 0);
338 static void __get_system_dir(struct ftrace_subsystem_dir *dir)
340 WARN_ON_ONCE(dir->ref_count == 0);
342 __get_system(dir->subsystem);
345 static void __put_system_dir(struct ftrace_subsystem_dir *dir)
347 WARN_ON_ONCE(dir->ref_count == 0);
348 /* If the subsystem is about to be freed, the dir must be too */
349 WARN_ON_ONCE(dir->subsystem->ref_count == 1 && dir->ref_count != 1);
351 __put_system(dir->subsystem);
352 if (!--dir->ref_count)
356 static void put_system(struct ftrace_subsystem_dir *dir)
358 mutex_lock(&event_mutex);
359 __put_system_dir(dir);
360 mutex_unlock(&event_mutex);
364 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
366 static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
367 const char *sub, const char *event, int set)
369 struct ftrace_event_file *file;
370 struct ftrace_event_call *call;
373 mutex_lock(&event_mutex);
374 list_for_each_entry(file, &tr->events, list) {
376 call = file->event_call;
378 if (!call->name || !call->class || !call->class->reg)
381 if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
385 strcmp(match, call->name) != 0 &&
386 strcmp(match, call->class->system) != 0)
389 if (sub && strcmp(sub, call->class->system) != 0)
392 if (event && strcmp(event, call->name) != 0)
395 ftrace_event_enable_disable(file, set);
399 mutex_unlock(&event_mutex);
404 static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
406 char *event = NULL, *sub = NULL, *match;
409 * The buf format can be <subsystem>:<event-name>
410 * *:<event-name> means any event by that name.
411 * :<event-name> is the same.
413 * <subsystem>:* means all events in that subsystem
414 * <subsystem>: means the same.
416 * <name> (no ':') means all events in a subsystem with
417 * the name <name> or any event that matches <name>
420 match = strsep(&buf, ":");
426 if (!strlen(sub) || strcmp(sub, "*") == 0)
428 if (!strlen(event) || strcmp(event, "*") == 0)
432 return __ftrace_set_clr_event(tr, match, sub, event, set);
436 * trace_set_clr_event - enable or disable an event
437 * @system: system name to match (NULL for any system)
438 * @event: event name to match (NULL for all events, within system)
439 * @set: 1 to enable, 0 to disable
441 * This is a way for other parts of the kernel to enable or disable
444 * Returns 0 on success, -EINVAL if the parameters do not match any
447 int trace_set_clr_event(const char *system, const char *event, int set)
449 struct trace_array *tr = top_trace_array();
451 return __ftrace_set_clr_event(tr, NULL, system, event, set);
453 EXPORT_SYMBOL_GPL(trace_set_clr_event);
455 /* 128 should be much more than enough */
456 #define EVENT_BUF_SIZE 127
459 ftrace_event_write(struct file *file, const char __user *ubuf,
460 size_t cnt, loff_t *ppos)
462 struct trace_parser parser;
463 struct seq_file *m = file->private_data;
464 struct trace_array *tr = m->private;
470 ret = tracing_update_buffers();
474 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
477 read = trace_get_user(&parser, ubuf, cnt, ppos);
479 if (read >= 0 && trace_parser_loaded((&parser))) {
482 if (*parser.buffer == '!')
485 parser.buffer[parser.idx] = 0;
487 ret = ftrace_set_clr_event(tr, parser.buffer + !set, set);
495 trace_parser_put(&parser);
501 t_next(struct seq_file *m, void *v, loff_t *pos)
503 struct ftrace_event_file *file = v;
504 struct ftrace_event_call *call;
505 struct trace_array *tr = m->private;
509 list_for_each_entry_continue(file, &tr->events, list) {
510 call = file->event_call;
512 * The ftrace subsystem is for showing formats only.
513 * They can not be enabled or disabled via the event files.
515 if (call->class && call->class->reg)
522 static void *t_start(struct seq_file *m, loff_t *pos)
524 struct ftrace_event_file *file;
525 struct trace_array *tr = m->private;
528 mutex_lock(&event_mutex);
530 file = list_entry(&tr->events, struct ftrace_event_file, list);
531 for (l = 0; l <= *pos; ) {
532 file = t_next(m, file, &l);
540 s_next(struct seq_file *m, void *v, loff_t *pos)
542 struct ftrace_event_file *file = v;
543 struct trace_array *tr = m->private;
547 list_for_each_entry_continue(file, &tr->events, list) {
548 if (file->flags & FTRACE_EVENT_FL_ENABLED)
555 static void *s_start(struct seq_file *m, loff_t *pos)
557 struct ftrace_event_file *file;
558 struct trace_array *tr = m->private;
561 mutex_lock(&event_mutex);
563 file = list_entry(&tr->events, struct ftrace_event_file, list);
564 for (l = 0; l <= *pos; ) {
565 file = s_next(m, file, &l);
572 static int t_show(struct seq_file *m, void *v)
574 struct ftrace_event_file *file = v;
575 struct ftrace_event_call *call = file->event_call;
577 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
578 seq_printf(m, "%s:", call->class->system);
579 seq_printf(m, "%s\n", call->name);
584 static void t_stop(struct seq_file *m, void *p)
586 mutex_unlock(&event_mutex);
590 event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
593 struct ftrace_event_file *file = filp->private_data;
596 if (file->flags & FTRACE_EVENT_FL_ENABLED) {
597 if (file->flags & FTRACE_EVENT_FL_SOFT_DISABLED)
604 return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf));
608 event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
611 struct ftrace_event_file *file = filp->private_data;
618 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
622 ret = tracing_update_buffers();
629 mutex_lock(&event_mutex);
630 ret = ftrace_event_enable_disable(file, val);
631 mutex_unlock(&event_mutex);
640 return ret ? ret : cnt;
644 system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
647 const char set_to_char[4] = { '?', '0', '1', 'X' };
648 struct ftrace_subsystem_dir *dir = filp->private_data;
649 struct event_subsystem *system = dir->subsystem;
650 struct ftrace_event_call *call;
651 struct ftrace_event_file *file;
652 struct trace_array *tr = dir->tr;
657 mutex_lock(&event_mutex);
658 list_for_each_entry(file, &tr->events, list) {
659 call = file->event_call;
660 if (!call->name || !call->class || !call->class->reg)
663 if (system && strcmp(call->class->system, system->name) != 0)
667 * We need to find out if all the events are set
668 * or if all events or cleared, or if we have
671 set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED));
674 * If we have a mixture, no need to look further.
679 mutex_unlock(&event_mutex);
681 buf[0] = set_to_char[set];
684 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
690 system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
693 struct ftrace_subsystem_dir *dir = filp->private_data;
694 struct event_subsystem *system = dir->subsystem;
695 const char *name = NULL;
699 ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
703 ret = tracing_update_buffers();
707 if (val != 0 && val != 1)
711 * Opening of "enable" adds a ref count to system,
712 * so the name is safe to use.
717 ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val);
731 FORMAT_FIELD_SEPERATOR = 2,
735 static void *f_next(struct seq_file *m, void *v, loff_t *pos)
737 struct ftrace_event_call *call = m->private;
738 struct ftrace_event_field *field;
739 struct list_head *common_head = &ftrace_common_fields;
740 struct list_head *head = trace_get_fields(call);
744 switch ((unsigned long)v) {
746 if (unlikely(list_empty(common_head)))
749 field = list_entry(common_head->prev,
750 struct ftrace_event_field, link);
753 case FORMAT_FIELD_SEPERATOR:
754 if (unlikely(list_empty(head)))
757 field = list_entry(head->prev, struct ftrace_event_field, link);
760 case FORMAT_PRINTFMT:
766 if (field->link.prev == common_head)
767 return (void *)FORMAT_FIELD_SEPERATOR;
768 else if (field->link.prev == head)
769 return (void *)FORMAT_PRINTFMT;
771 field = list_entry(field->link.prev, struct ftrace_event_field, link);
776 static void *f_start(struct seq_file *m, loff_t *pos)
781 /* Start by showing the header */
783 return (void *)FORMAT_HEADER;
785 p = (void *)FORMAT_HEADER;
787 p = f_next(m, p, &l);
788 } while (p && l < *pos);
793 static int f_show(struct seq_file *m, void *v)
795 struct ftrace_event_call *call = m->private;
796 struct ftrace_event_field *field;
797 const char *array_descriptor;
799 switch ((unsigned long)v) {
801 seq_printf(m, "name: %s\n", call->name);
802 seq_printf(m, "ID: %d\n", call->event.type);
803 seq_printf(m, "format:\n");
806 case FORMAT_FIELD_SEPERATOR:
810 case FORMAT_PRINTFMT:
811 seq_printf(m, "\nprint fmt: %s\n",
819 * Smartly shows the array type(except dynamic array).
822 * If TYPE := TYPE[LEN], it is shown:
823 * field:TYPE VAR[LEN]
825 array_descriptor = strchr(field->type, '[');
827 if (!strncmp(field->type, "__data_loc", 10))
828 array_descriptor = NULL;
830 if (!array_descriptor)
831 seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
832 field->type, field->name, field->offset,
833 field->size, !!field->is_signed);
835 seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
836 (int)(array_descriptor - field->type),
837 field->type, field->name,
838 array_descriptor, field->offset,
839 field->size, !!field->is_signed);
844 static void f_stop(struct seq_file *m, void *p)
848 static const struct seq_operations trace_format_seq_ops = {
855 static int trace_format_open(struct inode *inode, struct file *file)
857 struct ftrace_event_call *call = inode->i_private;
861 ret = seq_open(file, &trace_format_seq_ops);
865 m = file->private_data;
872 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
874 struct ftrace_event_call *call = filp->private_data;
881 s = kmalloc(sizeof(*s), GFP_KERNEL);
886 trace_seq_printf(s, "%d\n", call->event.type);
888 r = simple_read_from_buffer(ubuf, cnt, ppos,
895 event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
898 struct ftrace_event_call *call = filp->private_data;
905 s = kmalloc(sizeof(*s), GFP_KERNEL);
911 print_event_filter(call, s);
912 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
920 event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
923 struct ftrace_event_call *call = filp->private_data;
927 if (cnt >= PAGE_SIZE)
930 buf = (char *)__get_free_page(GFP_TEMPORARY);
934 if (copy_from_user(buf, ubuf, cnt)) {
935 free_page((unsigned long) buf);
940 err = apply_event_filter(call, buf);
941 free_page((unsigned long) buf);
950 static LIST_HEAD(event_subsystems);
952 static int subsystem_open(struct inode *inode, struct file *filp)
954 struct event_subsystem *system = NULL;
955 struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */
956 struct trace_array *tr;
959 /* Make sure the system still exists */
960 mutex_lock(&event_mutex);
961 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
962 list_for_each_entry(dir, &tr->systems, list) {
963 if (dir == inode->i_private) {
964 /* Don't open systems with no events */
965 if (dir->nr_events) {
966 __get_system_dir(dir);
967 system = dir->subsystem;
974 mutex_unlock(&event_mutex);
979 /* Some versions of gcc think dir can be uninitialized here */
982 ret = tracing_open_generic(inode, filp);
989 static int system_tr_open(struct inode *inode, struct file *filp)
991 struct ftrace_subsystem_dir *dir;
992 struct trace_array *tr = inode->i_private;
995 /* Make a temporary dir that has no system but points to tr */
996 dir = kzalloc(sizeof(*dir), GFP_KERNEL);
1002 ret = tracing_open_generic(inode, filp);
1006 filp->private_data = dir;
1011 static int subsystem_release(struct inode *inode, struct file *file)
1013 struct ftrace_subsystem_dir *dir = file->private_data;
1016 * If dir->subsystem is NULL, then this is a temporary
1017 * descriptor that was made for a trace_array to enable
1029 subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
1032 struct ftrace_subsystem_dir *dir = filp->private_data;
1033 struct event_subsystem *system = dir->subsystem;
1034 struct trace_seq *s;
1040 s = kmalloc(sizeof(*s), GFP_KERNEL);
1046 print_subsystem_event_filter(system, s);
1047 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
1055 subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
1058 struct ftrace_subsystem_dir *dir = filp->private_data;
1062 if (cnt >= PAGE_SIZE)
1065 buf = (char *)__get_free_page(GFP_TEMPORARY);
1069 if (copy_from_user(buf, ubuf, cnt)) {
1070 free_page((unsigned long) buf);
1075 err = apply_subsystem_event_filter(dir, buf);
1076 free_page((unsigned long) buf);
1086 show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1088 int (*func)(struct trace_seq *s) = filp->private_data;
1089 struct trace_seq *s;
1095 s = kmalloc(sizeof(*s), GFP_KERNEL);
1102 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
1109 static int ftrace_event_avail_open(struct inode *inode, struct file *file);
1110 static int ftrace_event_set_open(struct inode *inode, struct file *file);
1112 static const struct seq_operations show_event_seq_ops = {
1119 static const struct seq_operations show_set_event_seq_ops = {
1126 static const struct file_operations ftrace_avail_fops = {
1127 .open = ftrace_event_avail_open,
1129 .llseek = seq_lseek,
1130 .release = seq_release,
1133 static const struct file_operations ftrace_set_event_fops = {
1134 .open = ftrace_event_set_open,
1136 .write = ftrace_event_write,
1137 .llseek = seq_lseek,
1138 .release = seq_release,
1141 static const struct file_operations ftrace_enable_fops = {
1142 .open = tracing_open_generic,
1143 .read = event_enable_read,
1144 .write = event_enable_write,
1145 .llseek = default_llseek,
1148 static const struct file_operations ftrace_event_format_fops = {
1149 .open = trace_format_open,
1151 .llseek = seq_lseek,
1152 .release = seq_release,
1155 static const struct file_operations ftrace_event_id_fops = {
1156 .open = tracing_open_generic,
1157 .read = event_id_read,
1158 .llseek = default_llseek,
1161 static const struct file_operations ftrace_event_filter_fops = {
1162 .open = tracing_open_generic,
1163 .read = event_filter_read,
1164 .write = event_filter_write,
1165 .llseek = default_llseek,
1168 static const struct file_operations ftrace_subsystem_filter_fops = {
1169 .open = subsystem_open,
1170 .read = subsystem_filter_read,
1171 .write = subsystem_filter_write,
1172 .llseek = default_llseek,
1173 .release = subsystem_release,
1176 static const struct file_operations ftrace_system_enable_fops = {
1177 .open = subsystem_open,
1178 .read = system_enable_read,
1179 .write = system_enable_write,
1180 .llseek = default_llseek,
1181 .release = subsystem_release,
1184 static const struct file_operations ftrace_tr_enable_fops = {
1185 .open = system_tr_open,
1186 .read = system_enable_read,
1187 .write = system_enable_write,
1188 .llseek = default_llseek,
1189 .release = subsystem_release,
1192 static const struct file_operations ftrace_show_header_fops = {
1193 .open = tracing_open_generic,
1194 .read = show_header,
1195 .llseek = default_llseek,
1199 ftrace_event_open(struct inode *inode, struct file *file,
1200 const struct seq_operations *seq_ops)
1205 ret = seq_open(file, seq_ops);
1208 m = file->private_data;
1209 /* copy tr over to seq ops */
1210 m->private = inode->i_private;
1216 ftrace_event_avail_open(struct inode *inode, struct file *file)
1218 const struct seq_operations *seq_ops = &show_event_seq_ops;
1220 return ftrace_event_open(inode, file, seq_ops);
1224 ftrace_event_set_open(struct inode *inode, struct file *file)
1226 const struct seq_operations *seq_ops = &show_set_event_seq_ops;
1227 struct trace_array *tr = inode->i_private;
1229 if ((file->f_mode & FMODE_WRITE) &&
1230 (file->f_flags & O_TRUNC))
1231 ftrace_clear_events(tr);
1233 return ftrace_event_open(inode, file, seq_ops);
1236 static struct event_subsystem *
1237 create_new_subsystem(const char *name)
1239 struct event_subsystem *system;
1241 /* need to create new entry */
1242 system = kmalloc(sizeof(*system), GFP_KERNEL);
1246 system->ref_count = 1;
1247 system->name = name;
1249 system->filter = NULL;
1251 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
1252 if (!system->filter)
1255 list_add(&system->list, &event_subsystems);
1264 static struct dentry *
1265 event_subsystem_dir(struct trace_array *tr, const char *name,
1266 struct ftrace_event_file *file, struct dentry *parent)
1268 struct ftrace_subsystem_dir *dir;
1269 struct event_subsystem *system;
1270 struct dentry *entry;
1272 /* First see if we did not already create this dir */
1273 list_for_each_entry(dir, &tr->systems, list) {
1274 system = dir->subsystem;
1275 if (strcmp(system->name, name) == 0) {
1282 /* Now see if the system itself exists. */
1283 list_for_each_entry(system, &event_subsystems, list) {
1284 if (strcmp(system->name, name) == 0)
1287 /* Reset system variable when not found */
1288 if (&system->list == &event_subsystems)
1291 dir = kmalloc(sizeof(*dir), GFP_KERNEL);
1296 system = create_new_subsystem(name);
1300 __get_system(system);
1302 dir->entry = debugfs_create_dir(name, parent);
1304 pr_warning("Failed to create system directory %s\n", name);
1305 __put_system(system);
1312 dir->subsystem = system;
1315 entry = debugfs_create_file("filter", 0644, dir->entry, dir,
1316 &ftrace_subsystem_filter_fops);
1318 kfree(system->filter);
1319 system->filter = NULL;
1320 pr_warning("Could not create debugfs '%s/filter' entry\n", name);
1323 trace_create_file("enable", 0644, dir->entry, dir,
1324 &ftrace_system_enable_fops);
1326 list_add(&dir->list, &tr->systems);
1333 /* Only print this message if failed on memory allocation */
1334 if (!dir || !system)
1335 pr_warning("No memory to create event subsystem %s\n",
1341 event_create_dir(struct dentry *parent,
1342 struct ftrace_event_file *file,
1343 const struct file_operations *id,
1344 const struct file_operations *enable,
1345 const struct file_operations *filter,
1346 const struct file_operations *format)
1348 struct ftrace_event_call *call = file->event_call;
1349 struct trace_array *tr = file->tr;
1350 struct list_head *head;
1351 struct dentry *d_events;
1355 * If the trace point header did not define TRACE_SYSTEM
1356 * then the system would be called "TRACE_SYSTEM".
1358 if (strcmp(call->class->system, TRACE_SYSTEM) != 0) {
1359 d_events = event_subsystem_dir(tr, call->class->system, file, parent);
1365 file->dir = debugfs_create_dir(call->name, d_events);
1367 pr_warning("Could not create debugfs '%s' directory\n",
1372 if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
1373 trace_create_file("enable", 0644, file->dir, file,
1376 #ifdef CONFIG_PERF_EVENTS
1377 if (call->event.type && call->class->reg)
1378 trace_create_file("id", 0444, file->dir, call,
1383 * Other events may have the same class. Only update
1384 * the fields if they are not already defined.
1386 head = trace_get_fields(call);
1387 if (list_empty(head)) {
1388 ret = call->class->define_fields(call);
1390 pr_warning("Could not initialize trace point"
1391 " events/%s\n", call->name);
1395 trace_create_file("filter", 0644, file->dir, call,
1398 trace_create_file("format", 0444, file->dir, call,
1404 static void remove_subsystem(struct ftrace_subsystem_dir *dir)
1409 if (!--dir->nr_events) {
1410 debugfs_remove_recursive(dir->entry);
1411 list_del(&dir->list);
1412 __put_system_dir(dir);
1416 static void remove_event_from_tracers(struct ftrace_event_call *call)
1418 struct ftrace_event_file *file;
1419 struct trace_array *tr;
1421 do_for_each_event_file_safe(tr, file) {
1423 if (file->event_call != call)
1426 list_del(&file->list);
1427 debugfs_remove_recursive(file->dir);
1428 remove_subsystem(file->system);
1429 kmem_cache_free(file_cachep, file);
1432 * The do_for_each_event_file_safe() is
1433 * a double loop. After finding the call for this
1434 * trace_array, we use break to jump to the next
1438 } while_for_each_event_file();
1441 static void event_remove(struct ftrace_event_call *call)
1443 struct trace_array *tr;
1444 struct ftrace_event_file *file;
1446 do_for_each_event_file(tr, file) {
1447 if (file->event_call != call)
1449 ftrace_event_enable_disable(file, 0);
1451 * The do_for_each_event_file() is
1452 * a double loop. After finding the call for this
1453 * trace_array, we use break to jump to the next
1457 } while_for_each_event_file();
1459 if (call->event.funcs)
1460 __unregister_ftrace_event(&call->event);
1461 remove_event_from_tracers(call);
1462 list_del(&call->list);
1465 static int event_init(struct ftrace_event_call *call)
1469 if (WARN_ON(!call->name))
1472 if (call->class->raw_init) {
1473 ret = call->class->raw_init(call);
1474 if (ret < 0 && ret != -ENOSYS)
1475 pr_warn("Could not initialize trace events/%s\n",
1483 __register_event(struct ftrace_event_call *call, struct module *mod)
1487 ret = event_init(call);
1491 list_add(&call->list, &ftrace_events);
1497 /* Add an event to a trace directory */
1499 __trace_add_new_event(struct ftrace_event_call *call,
1500 struct trace_array *tr,
1501 const struct file_operations *id,
1502 const struct file_operations *enable,
1503 const struct file_operations *filter,
1504 const struct file_operations *format)
1506 struct ftrace_event_file *file;
1508 file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1512 file->event_call = call;
1514 list_add(&file->list, &tr->events);
1516 return event_create_dir(tr->event_dir, file, id, enable, filter, format);
1520 * Just create a decriptor for early init. A descriptor is required
1521 * for enabling events at boot. We want to enable events before
1522 * the filesystem is initialized.
1525 __trace_early_add_new_event(struct ftrace_event_call *call,
1526 struct trace_array *tr)
1528 struct ftrace_event_file *file;
1530 file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1534 file->event_call = call;
1536 list_add(&file->list, &tr->events);
1541 struct ftrace_module_file_ops;
1542 static void __add_event_to_tracers(struct ftrace_event_call *call,
1543 struct ftrace_module_file_ops *file_ops);
1545 /* Add an additional event_call dynamically */
1546 int trace_add_event_call(struct ftrace_event_call *call)
1549 mutex_lock(&event_mutex);
1551 ret = __register_event(call, NULL);
1553 __add_event_to_tracers(call, NULL);
1555 mutex_unlock(&event_mutex);
1560 * Must be called under locking both of event_mutex and trace_event_mutex.
1562 static void __trace_remove_event_call(struct ftrace_event_call *call)
1565 trace_destroy_fields(call);
1566 destroy_preds(call);
1569 /* Remove an event_call */
1570 void trace_remove_event_call(struct ftrace_event_call *call)
1572 mutex_lock(&event_mutex);
1573 down_write(&trace_event_mutex);
1574 __trace_remove_event_call(call);
1575 up_write(&trace_event_mutex);
1576 mutex_unlock(&event_mutex);
1579 #define for_each_event(event, start, end) \
1580 for (event = start; \
1581 (unsigned long)event < (unsigned long)end; \
1584 #ifdef CONFIG_MODULES
1586 static LIST_HEAD(ftrace_module_file_list);
1589 * Modules must own their file_operations to keep up with
1590 * reference counting.
1592 struct ftrace_module_file_ops {
1593 struct list_head list;
1595 struct file_operations id;
1596 struct file_operations enable;
1597 struct file_operations format;
1598 struct file_operations filter;
1601 static struct ftrace_module_file_ops *
1602 find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
1605 * As event_calls are added in groups by module,
1606 * when we find one file_ops, we don't need to search for
1607 * each call in that module, as the rest should be the
1608 * same. Only search for a new one if the last one did
1611 if (file_ops && mod == file_ops->mod)
1614 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1615 if (file_ops->mod == mod)
1621 static struct ftrace_module_file_ops *
1622 trace_create_file_ops(struct module *mod)
1624 struct ftrace_module_file_ops *file_ops;
1627 * This is a bit of a PITA. To allow for correct reference
1628 * counting, modules must "own" their file_operations.
1629 * To do this, we allocate the file operations that will be
1630 * used in the event directory.
1633 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1637 file_ops->mod = mod;
1639 file_ops->id = ftrace_event_id_fops;
1640 file_ops->id.owner = mod;
1642 file_ops->enable = ftrace_enable_fops;
1643 file_ops->enable.owner = mod;
1645 file_ops->filter = ftrace_event_filter_fops;
1646 file_ops->filter.owner = mod;
1648 file_ops->format = ftrace_event_format_fops;
1649 file_ops->format.owner = mod;
1651 list_add(&file_ops->list, &ftrace_module_file_list);
1656 static void trace_module_add_events(struct module *mod)
1658 struct ftrace_module_file_ops *file_ops = NULL;
1659 struct ftrace_event_call **call, **start, **end;
1661 start = mod->trace_events;
1662 end = mod->trace_events + mod->num_trace_events;
1667 file_ops = trace_create_file_ops(mod);
1671 for_each_event(call, start, end) {
1672 __register_event(*call, mod);
1673 __add_event_to_tracers(*call, file_ops);
1677 static void trace_module_remove_events(struct module *mod)
1679 struct ftrace_module_file_ops *file_ops;
1680 struct ftrace_event_call *call, *p;
1681 bool clear_trace = false;
1683 down_write(&trace_event_mutex);
1684 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1685 if (call->mod == mod) {
1686 if (call->flags & TRACE_EVENT_FL_WAS_ENABLED)
1688 __trace_remove_event_call(call);
1692 /* Now free the file_operations */
1693 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1694 if (file_ops->mod == mod)
1697 if (&file_ops->list != &ftrace_module_file_list) {
1698 list_del(&file_ops->list);
1701 up_write(&trace_event_mutex);
1704 * It is safest to reset the ring buffer if the module being unloaded
1705 * registered any events that were used. The only worry is if
1706 * a new module gets loaded, and takes on the same id as the events
1707 * of this module. When printing out the buffer, traced events left
1708 * over from this module may be passed to the new module events and
1709 * unexpected results may occur.
1712 tracing_reset_all_online_cpus();
1715 static int trace_module_notify(struct notifier_block *self,
1716 unsigned long val, void *data)
1718 struct module *mod = data;
1720 mutex_lock(&event_mutex);
1722 case MODULE_STATE_COMING:
1723 trace_module_add_events(mod);
1725 case MODULE_STATE_GOING:
1726 trace_module_remove_events(mod);
1729 mutex_unlock(&event_mutex);
1735 __trace_add_new_mod_event(struct ftrace_event_call *call,
1736 struct trace_array *tr,
1737 struct ftrace_module_file_ops *file_ops)
1739 return __trace_add_new_event(call, tr,
1740 &file_ops->id, &file_ops->enable,
1741 &file_ops->filter, &file_ops->format);
1745 static inline struct ftrace_module_file_ops *
1746 find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod)
1750 static inline int trace_module_notify(struct notifier_block *self,
1751 unsigned long val, void *data)
1756 __trace_add_new_mod_event(struct ftrace_event_call *call,
1757 struct trace_array *tr,
1758 struct ftrace_module_file_ops *file_ops)
1762 #endif /* CONFIG_MODULES */
1764 /* Create a new event directory structure for a trace directory. */
1766 __trace_add_event_dirs(struct trace_array *tr)
1768 struct ftrace_module_file_ops *file_ops = NULL;
1769 struct ftrace_event_call *call;
1772 list_for_each_entry(call, &ftrace_events, list) {
1775 * Directories for events by modules need to
1776 * keep module ref counts when opened (as we don't
1777 * want the module to disappear when reading one
1778 * of these files). The file_ops keep account of
1779 * the module ref count.
1781 file_ops = find_ftrace_file_ops(file_ops, call->mod);
1783 continue; /* Warn? */
1784 ret = __trace_add_new_mod_event(call, tr, file_ops);
1786 pr_warning("Could not create directory for event %s\n",
1790 ret = __trace_add_new_event(call, tr,
1791 &ftrace_event_id_fops,
1792 &ftrace_enable_fops,
1793 &ftrace_event_filter_fops,
1794 &ftrace_event_format_fops);
1796 pr_warning("Could not create directory for event %s\n",
1802 * The top level array has already had its ftrace_event_file
1803 * descriptors created in order to allow for early events to
1804 * be recorded. This function is called after the debugfs has been
1805 * initialized, and we now have to create the files associated
1809 __trace_early_add_event_dirs(struct trace_array *tr)
1811 struct ftrace_event_file *file;
1815 list_for_each_entry(file, &tr->events, list) {
1816 ret = event_create_dir(tr->event_dir, file,
1817 &ftrace_event_id_fops,
1818 &ftrace_enable_fops,
1819 &ftrace_event_filter_fops,
1820 &ftrace_event_format_fops);
1822 pr_warning("Could not create directory for event %s\n",
1823 file->event_call->name);
1828 * For early boot up, the top trace array requires to have
1829 * a list of events that can be enabled. This must be done before
1830 * the filesystem is set up in order to allow events to be traced
1834 __trace_early_add_events(struct trace_array *tr)
1836 struct ftrace_event_call *call;
1839 list_for_each_entry(call, &ftrace_events, list) {
1840 /* Early boot up should not have any modules loaded */
1841 if (WARN_ON_ONCE(call->mod))
1844 ret = __trace_early_add_new_event(call, tr);
1846 pr_warning("Could not create early event %s\n",
1851 /* Remove the event directory structure for a trace directory. */
1853 __trace_remove_event_dirs(struct trace_array *tr)
1855 struct ftrace_event_file *file, *next;
1857 list_for_each_entry_safe(file, next, &tr->events, list) {
1858 list_del(&file->list);
1859 debugfs_remove_recursive(file->dir);
1860 remove_subsystem(file->system);
1861 kmem_cache_free(file_cachep, file);
1866 __add_event_to_tracers(struct ftrace_event_call *call,
1867 struct ftrace_module_file_ops *file_ops)
1869 struct trace_array *tr;
1871 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
1873 __trace_add_new_mod_event(call, tr, file_ops);
1875 __trace_add_new_event(call, tr,
1876 &ftrace_event_id_fops,
1877 &ftrace_enable_fops,
1878 &ftrace_event_filter_fops,
1879 &ftrace_event_format_fops);
1883 static struct notifier_block trace_module_nb = {
1884 .notifier_call = trace_module_notify,
1888 extern struct ftrace_event_call *__start_ftrace_events[];
1889 extern struct ftrace_event_call *__stop_ftrace_events[];
1891 static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1893 static __init int setup_trace_event(char *str)
1895 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1896 ring_buffer_expanded = true;
1897 tracing_selftest_disabled = true;
1901 __setup("trace_event=", setup_trace_event);
1903 /* Expects to have event_mutex held when called */
1905 create_event_toplevel_files(struct dentry *parent, struct trace_array *tr)
1907 struct dentry *d_events;
1908 struct dentry *entry;
1910 entry = debugfs_create_file("set_event", 0644, parent,
1911 tr, &ftrace_set_event_fops);
1913 pr_warning("Could not create debugfs 'set_event' entry\n");
1917 d_events = debugfs_create_dir("events", parent);
1919 pr_warning("Could not create debugfs 'events' directory\n");
1923 /* ring buffer internal formats */
1924 trace_create_file("header_page", 0444, d_events,
1925 ring_buffer_print_page_header,
1926 &ftrace_show_header_fops);
1928 trace_create_file("header_event", 0444, d_events,
1929 ring_buffer_print_entry_header,
1930 &ftrace_show_header_fops);
1932 trace_create_file("enable", 0644, d_events,
1933 tr, &ftrace_tr_enable_fops);
1935 tr->event_dir = d_events;
1941 * event_trace_add_tracer - add a instance of a trace_array to events
1942 * @parent: The parent dentry to place the files/directories for events in
1943 * @tr: The trace array associated with these events
1945 * When a new instance is created, it needs to set up its events
1946 * directory, as well as other files associated with events. It also
1947 * creates the event hierachry in the @parent/events directory.
1949 * Returns 0 on success.
1951 int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr)
1955 mutex_lock(&event_mutex);
1957 ret = create_event_toplevel_files(parent, tr);
1961 down_write(&trace_event_mutex);
1962 __trace_add_event_dirs(tr);
1963 up_write(&trace_event_mutex);
1966 mutex_unlock(&event_mutex);
1972 * The top trace array already had its file descriptors created.
1973 * Now the files themselves need to be created.
1976 early_event_add_tracer(struct dentry *parent, struct trace_array *tr)
1980 mutex_lock(&event_mutex);
1982 ret = create_event_toplevel_files(parent, tr);
1986 down_write(&trace_event_mutex);
1987 __trace_early_add_event_dirs(tr);
1988 up_write(&trace_event_mutex);
1991 mutex_unlock(&event_mutex);
1996 int event_trace_del_tracer(struct trace_array *tr)
1998 /* Disable any running events */
1999 __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
2001 mutex_lock(&event_mutex);
2003 down_write(&trace_event_mutex);
2004 __trace_remove_event_dirs(tr);
2005 debugfs_remove_recursive(tr->event_dir);
2006 up_write(&trace_event_mutex);
2008 tr->event_dir = NULL;
2010 mutex_unlock(&event_mutex);
2015 static __init int event_trace_memsetup(void)
2017 field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC);
2018 file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC);
2022 static __init int event_trace_enable(void)
2024 struct trace_array *tr = top_trace_array();
2025 struct ftrace_event_call **iter, *call;
2026 char *buf = bootup_event_buf;
2030 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
2033 ret = event_init(call);
2035 list_add(&call->list, &ftrace_events);
2039 * We need the top trace array to have a working set of trace
2040 * points at early init, before the debug files and directories
2041 * are created. Create the file entries now, and attach them
2042 * to the actual file dentries later.
2044 __trace_early_add_events(tr);
2047 token = strsep(&buf, ",");
2054 ret = ftrace_set_clr_event(tr, token, 1);
2056 pr_warn("Failed to enable trace event: %s\n", token);
2059 trace_printk_start_comm();
2064 static __init int event_trace_init(void)
2066 struct trace_array *tr;
2067 struct dentry *d_tracer;
2068 struct dentry *entry;
2071 tr = top_trace_array();
2073 d_tracer = tracing_init_dentry();
2077 entry = debugfs_create_file("available_events", 0444, d_tracer,
2078 tr, &ftrace_avail_fops);
2080 pr_warning("Could not create debugfs "
2081 "'available_events' entry\n");
2083 if (trace_define_common_fields())
2084 pr_warning("tracing: Failed to allocate common fields");
2086 ret = early_event_add_tracer(d_tracer, tr);
2090 ret = register_module_notifier(&trace_module_nb);
2092 pr_warning("Failed to register trace events module notifier\n");
2096 early_initcall(event_trace_memsetup);
2097 core_initcall(event_trace_enable);
2098 fs_initcall(event_trace_init);
2100 #ifdef CONFIG_FTRACE_STARTUP_TEST
2102 static DEFINE_SPINLOCK(test_spinlock);
2103 static DEFINE_SPINLOCK(test_spinlock_irq);
2104 static DEFINE_MUTEX(test_mutex);
2106 static __init void test_work(struct work_struct *dummy)
2108 spin_lock(&test_spinlock);
2109 spin_lock_irq(&test_spinlock_irq);
2111 spin_unlock_irq(&test_spinlock_irq);
2112 spin_unlock(&test_spinlock);
2114 mutex_lock(&test_mutex);
2116 mutex_unlock(&test_mutex);
2119 static __init int event_test_thread(void *unused)
2123 test_malloc = kmalloc(1234, GFP_KERNEL);
2125 pr_info("failed to kmalloc\n");
2127 schedule_on_each_cpu(test_work);
2131 set_current_state(TASK_INTERRUPTIBLE);
2132 while (!kthread_should_stop())
2139 * Do various things that may trigger events.
2141 static __init void event_test_stuff(void)
2143 struct task_struct *test_thread;
2145 test_thread = kthread_run(event_test_thread, NULL, "test-events");
2147 kthread_stop(test_thread);
2151 * For every trace event defined, we will test each trace point separately,
2152 * and then by groups, and finally all trace points.
2154 static __init void event_trace_self_tests(void)
2156 struct ftrace_subsystem_dir *dir;
2157 struct ftrace_event_file *file;
2158 struct ftrace_event_call *call;
2159 struct event_subsystem *system;
2160 struct trace_array *tr;
2163 tr = top_trace_array();
2165 pr_info("Running tests on trace events:\n");
2167 list_for_each_entry(file, &tr->events, list) {
2169 call = file->event_call;
2171 /* Only test those that have a probe */
2172 if (!call->class || !call->class->probe)
2176 * Testing syscall events here is pretty useless, but
2177 * we still do it if configured. But this is time consuming.
2178 * What we really need is a user thread to perform the
2179 * syscalls as we test.
2181 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
2182 if (call->class->system &&
2183 strcmp(call->class->system, "syscalls") == 0)
2187 pr_info("Testing event %s: ", call->name);
2190 * If an event is already enabled, someone is using
2191 * it and the self test should not be on.
2193 if (file->flags & FTRACE_EVENT_FL_ENABLED) {
2194 pr_warning("Enabled event during self test!\n");
2199 ftrace_event_enable_disable(file, 1);
2201 ftrace_event_enable_disable(file, 0);
2206 /* Now test at the sub system level */
2208 pr_info("Running tests on trace event systems:\n");
2210 list_for_each_entry(dir, &tr->systems, list) {
2212 system = dir->subsystem;
2214 /* the ftrace system is special, skip it */
2215 if (strcmp(system->name, "ftrace") == 0)
2218 pr_info("Testing event system %s: ", system->name);
2220 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1);
2221 if (WARN_ON_ONCE(ret)) {
2222 pr_warning("error enabling system %s\n",
2229 ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0);
2230 if (WARN_ON_ONCE(ret)) {
2231 pr_warning("error disabling system %s\n",
2239 /* Test with all events enabled */
2241 pr_info("Running tests on all trace events:\n");
2242 pr_info("Testing all events: ");
2244 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1);
2245 if (WARN_ON_ONCE(ret)) {
2246 pr_warning("error enabling all events\n");
2253 ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0);
2254 if (WARN_ON_ONCE(ret)) {
2255 pr_warning("error disabling all events\n");
2262 #ifdef CONFIG_FUNCTION_TRACER
2264 static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
2267 function_test_events_call(unsigned long ip, unsigned long parent_ip,
2268 struct ftrace_ops *op, struct pt_regs *pt_regs)
2270 struct ring_buffer_event *event;
2271 struct ring_buffer *buffer;
2272 struct ftrace_entry *entry;
2273 unsigned long flags;
2278 pc = preempt_count();
2279 preempt_disable_notrace();
2280 cpu = raw_smp_processor_id();
2281 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
2286 local_save_flags(flags);
2288 event = trace_current_buffer_lock_reserve(&buffer,
2289 TRACE_FN, sizeof(*entry),
2293 entry = ring_buffer_event_data(event);
2295 entry->parent_ip = parent_ip;
2297 trace_buffer_unlock_commit(buffer, event, flags, pc);
2300 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
2301 preempt_enable_notrace();
2304 static struct ftrace_ops trace_ops __initdata =
2306 .func = function_test_events_call,
2307 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
2310 static __init void event_trace_self_test_with_function(void)
2313 ret = register_ftrace_function(&trace_ops);
2314 if (WARN_ON(ret < 0)) {
2315 pr_info("Failed to enable function tracer for event tests\n");
2318 pr_info("Running tests again, along with the function tracer\n");
2319 event_trace_self_tests();
2320 unregister_ftrace_function(&trace_ops);
2323 static __init void event_trace_self_test_with_function(void)
2328 static __init int event_trace_self_tests_init(void)
2330 if (!tracing_selftest_disabled) {
2331 event_trace_self_tests();
2332 event_trace_self_test_with_function();
2338 late_initcall(event_trace_self_tests_init);