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/delay.h>
20 #include <asm/setup.h>
22 #include "trace_output.h"
25 #define TRACE_SYSTEM "TRACE_SYSTEM"
27 DEFINE_MUTEX(event_mutex
);
29 LIST_HEAD(ftrace_events
);
31 int trace_define_field(struct ftrace_event_call
*call
, const char *type
,
32 const char *name
, int offset
, int size
, int is_signed
,
35 struct ftrace_event_field
*field
;
37 field
= kzalloc(sizeof(*field
), GFP_KERNEL
);
41 field
->name
= kstrdup(name
, GFP_KERNEL
);
45 field
->type
= kstrdup(type
, GFP_KERNEL
);
49 if (filter_type
== FILTER_OTHER
)
50 field
->filter_type
= filter_assign_type(type
);
52 field
->filter_type
= filter_type
;
54 field
->offset
= offset
;
56 field
->is_signed
= is_signed
;
58 list_add(&field
->link
, &call
->fields
);
71 EXPORT_SYMBOL_GPL(trace_define_field
);
73 #define __common_field(type, item) \
74 ret = trace_define_field(call, #type, "common_" #item, \
75 offsetof(typeof(ent), item), \
77 is_signed_type(type), FILTER_OTHER); \
81 int trace_define_common_fields(struct ftrace_event_call
*call
)
84 struct trace_entry ent
;
86 __common_field(unsigned short, type
);
87 __common_field(unsigned char, flags
);
88 __common_field(unsigned char, preempt_count
);
89 __common_field(int, pid
);
90 __common_field(int, lock_depth
);
94 EXPORT_SYMBOL_GPL(trace_define_common_fields
);
98 static void trace_destroy_fields(struct ftrace_event_call
*call
)
100 struct ftrace_event_field
*field
, *next
;
102 list_for_each_entry_safe(field
, next
, &call
->fields
, link
) {
103 list_del(&field
->link
);
110 #endif /* CONFIG_MODULES */
112 static void ftrace_event_enable_disable(struct ftrace_event_call
*call
,
119 tracing_stop_cmdline_record();
120 call
->unregfunc(call
->data
);
124 if (!call
->enabled
) {
126 tracing_start_cmdline_record();
127 call
->regfunc(call
->data
);
133 static void ftrace_clear_events(void)
135 struct ftrace_event_call
*call
;
137 mutex_lock(&event_mutex
);
138 list_for_each_entry(call
, &ftrace_events
, list
) {
139 ftrace_event_enable_disable(call
, 0);
141 mutex_unlock(&event_mutex
);
145 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
147 static int __ftrace_set_clr_event(const char *match
, const char *sub
,
148 const char *event
, int set
)
150 struct ftrace_event_call
*call
;
153 mutex_lock(&event_mutex
);
154 list_for_each_entry(call
, &ftrace_events
, list
) {
156 if (!call
->name
|| !call
->regfunc
)
160 strcmp(match
, call
->name
) != 0 &&
161 strcmp(match
, call
->system
) != 0)
164 if (sub
&& strcmp(sub
, call
->system
) != 0)
167 if (event
&& strcmp(event
, call
->name
) != 0)
170 ftrace_event_enable_disable(call
, set
);
174 mutex_unlock(&event_mutex
);
179 static int ftrace_set_clr_event(char *buf
, int set
)
181 char *event
= NULL
, *sub
= NULL
, *match
;
184 * The buf format can be <subsystem>:<event-name>
185 * *:<event-name> means any event by that name.
186 * :<event-name> is the same.
188 * <subsystem>:* means all events in that subsystem
189 * <subsystem>: means the same.
191 * <name> (no ':') means all events in a subsystem with
192 * the name <name> or any event that matches <name>
195 match
= strsep(&buf
, ":");
201 if (!strlen(sub
) || strcmp(sub
, "*") == 0)
203 if (!strlen(event
) || strcmp(event
, "*") == 0)
207 return __ftrace_set_clr_event(match
, sub
, event
, set
);
211 * trace_set_clr_event - enable or disable an event
212 * @system: system name to match (NULL for any system)
213 * @event: event name to match (NULL for all events, within system)
214 * @set: 1 to enable, 0 to disable
216 * This is a way for other parts of the kernel to enable or disable
219 * Returns 0 on success, -EINVAL if the parameters do not match any
222 int trace_set_clr_event(const char *system
, const char *event
, int set
)
224 return __ftrace_set_clr_event(NULL
, system
, event
, set
);
227 /* 128 should be much more than enough */
228 #define EVENT_BUF_SIZE 127
231 ftrace_event_write(struct file
*file
, const char __user
*ubuf
,
232 size_t cnt
, loff_t
*ppos
)
234 struct trace_parser parser
;
241 ret
= tracing_update_buffers();
245 if (trace_parser_get_init(&parser
, EVENT_BUF_SIZE
+ 1))
248 read
= trace_get_user(&parser
, ubuf
, cnt
, ppos
);
250 if (trace_parser_loaded((&parser
))) {
253 if (*parser
.buffer
== '!')
256 parser
.buffer
[parser
.idx
] = 0;
258 ret
= ftrace_set_clr_event(parser
.buffer
+ !set
, set
);
266 trace_parser_put(&parser
);
272 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
274 struct list_head
*list
= m
->private;
275 struct ftrace_event_call
*call
;
280 if (list
== &ftrace_events
)
283 call
= list_entry(list
, struct ftrace_event_call
, list
);
286 * The ftrace subsystem is for showing formats only.
287 * They can not be enabled or disabled via the event files.
295 m
->private = list
->next
;
300 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
302 struct ftrace_event_call
*call
= NULL
;
305 mutex_lock(&event_mutex
);
307 m
->private = ftrace_events
.next
;
308 for (l
= 0; l
<= *pos
; ) {
309 call
= t_next(m
, NULL
, &l
);
317 s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
319 struct list_head
*list
= m
->private;
320 struct ftrace_event_call
*call
;
325 if (list
== &ftrace_events
)
328 call
= list_entry(list
, struct ftrace_event_call
, list
);
330 if (!call
->enabled
) {
335 m
->private = list
->next
;
340 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
342 struct ftrace_event_call
*call
= NULL
;
345 mutex_lock(&event_mutex
);
347 m
->private = ftrace_events
.next
;
348 for (l
= 0; l
<= *pos
; ) {
349 call
= s_next(m
, NULL
, &l
);
356 static int t_show(struct seq_file
*m
, void *v
)
358 struct ftrace_event_call
*call
= v
;
360 if (strcmp(call
->system
, TRACE_SYSTEM
) != 0)
361 seq_printf(m
, "%s:", call
->system
);
362 seq_printf(m
, "%s\n", call
->name
);
367 static void t_stop(struct seq_file
*m
, void *p
)
369 mutex_unlock(&event_mutex
);
373 ftrace_event_seq_open(struct inode
*inode
, struct file
*file
)
375 const struct seq_operations
*seq_ops
;
377 if ((file
->f_mode
& FMODE_WRITE
) &&
378 (file
->f_flags
& O_TRUNC
))
379 ftrace_clear_events();
381 seq_ops
= inode
->i_private
;
382 return seq_open(file
, seq_ops
);
386 event_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
389 struct ftrace_event_call
*call
= filp
->private_data
;
397 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
401 event_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
404 struct ftrace_event_call
*call
= filp
->private_data
;
409 if (cnt
>= sizeof(buf
))
412 if (copy_from_user(&buf
, ubuf
, cnt
))
417 ret
= strict_strtoul(buf
, 10, &val
);
421 ret
= tracing_update_buffers();
428 mutex_lock(&event_mutex
);
429 ftrace_event_enable_disable(call
, val
);
430 mutex_unlock(&event_mutex
);
443 system_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
446 const char set_to_char
[4] = { '?', '0', '1', 'X' };
447 const char *system
= filp
->private_data
;
448 struct ftrace_event_call
*call
;
453 mutex_lock(&event_mutex
);
454 list_for_each_entry(call
, &ftrace_events
, list
) {
455 if (!call
->name
|| !call
->regfunc
)
458 if (system
&& strcmp(call
->system
, system
) != 0)
462 * We need to find out if all the events are set
463 * or if all events or cleared, or if we have
466 set
|= (1 << !!call
->enabled
);
469 * If we have a mixture, no need to look further.
474 mutex_unlock(&event_mutex
);
476 buf
[0] = set_to_char
[set
];
479 ret
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
485 system_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
488 const char *system
= filp
->private_data
;
493 if (cnt
>= sizeof(buf
))
496 if (copy_from_user(&buf
, ubuf
, cnt
))
501 ret
= strict_strtoul(buf
, 10, &val
);
505 ret
= tracing_update_buffers();
509 if (val
!= 0 && val
!= 1)
512 ret
= __ftrace_set_clr_event(NULL
, system
, NULL
, val
);
524 extern char *__bad_type_size(void);
527 #define FIELD(type, name) \
528 sizeof(type) != sizeof(field.name) ? __bad_type_size() : \
529 #type, "common_" #name, offsetof(typeof(field), name), \
532 static int trace_write_header(struct trace_seq
*s
)
534 struct trace_entry field
;
536 /* struct trace_entry */
537 return trace_seq_printf(s
,
538 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
539 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
540 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
541 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
542 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
544 FIELD(unsigned short, type
),
545 FIELD(unsigned char, flags
),
546 FIELD(unsigned char, preempt_count
),
548 FIELD(int, lock_depth
));
552 event_format_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
555 struct ftrace_event_call
*call
= filp
->private_data
;
563 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
569 /* If any of the first writes fail, so will the show_format. */
571 trace_seq_printf(s
, "name: %s\n", call
->name
);
572 trace_seq_printf(s
, "ID: %d\n", call
->id
);
573 trace_seq_printf(s
, "format:\n");
574 trace_write_header(s
);
576 r
= call
->show_format(call
, s
);
579 * ug! The format output is bigger than a PAGE!!
581 buf
= "FORMAT TOO BIG\n";
582 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
587 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
595 event_id_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
597 struct ftrace_event_call
*call
= filp
->private_data
;
604 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
609 trace_seq_printf(s
, "%d\n", call
->id
);
611 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
618 event_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
621 struct ftrace_event_call
*call
= filp
->private_data
;
628 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
634 print_event_filter(call
, s
);
635 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
643 event_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
646 struct ftrace_event_call
*call
= filp
->private_data
;
650 if (cnt
>= PAGE_SIZE
)
653 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
657 if (copy_from_user(buf
, ubuf
, cnt
)) {
658 free_page((unsigned long) buf
);
663 err
= apply_event_filter(call
, buf
);
664 free_page((unsigned long) buf
);
674 subsystem_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
677 struct event_subsystem
*system
= filp
->private_data
;
684 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
690 print_subsystem_event_filter(system
, s
);
691 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
699 subsystem_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
702 struct event_subsystem
*system
= filp
->private_data
;
706 if (cnt
>= PAGE_SIZE
)
709 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
713 if (copy_from_user(buf
, ubuf
, cnt
)) {
714 free_page((unsigned long) buf
);
719 err
= apply_subsystem_event_filter(system
, buf
);
720 free_page((unsigned long) buf
);
730 show_header(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
732 int (*func
)(struct trace_seq
*s
) = filp
->private_data
;
739 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
746 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
753 static const struct seq_operations show_event_seq_ops
= {
760 static const struct seq_operations show_set_event_seq_ops
= {
767 static const struct file_operations ftrace_avail_fops
= {
768 .open
= ftrace_event_seq_open
,
771 .release
= seq_release
,
774 static const struct file_operations ftrace_set_event_fops
= {
775 .open
= ftrace_event_seq_open
,
777 .write
= ftrace_event_write
,
779 .release
= seq_release
,
782 static const struct file_operations ftrace_enable_fops
= {
783 .open
= tracing_open_generic
,
784 .read
= event_enable_read
,
785 .write
= event_enable_write
,
788 static const struct file_operations ftrace_event_format_fops
= {
789 .open
= tracing_open_generic
,
790 .read
= event_format_read
,
793 static const struct file_operations ftrace_event_id_fops
= {
794 .open
= tracing_open_generic
,
795 .read
= event_id_read
,
798 static const struct file_operations ftrace_event_filter_fops
= {
799 .open
= tracing_open_generic
,
800 .read
= event_filter_read
,
801 .write
= event_filter_write
,
804 static const struct file_operations ftrace_subsystem_filter_fops
= {
805 .open
= tracing_open_generic
,
806 .read
= subsystem_filter_read
,
807 .write
= subsystem_filter_write
,
810 static const struct file_operations ftrace_system_enable_fops
= {
811 .open
= tracing_open_generic
,
812 .read
= system_enable_read
,
813 .write
= system_enable_write
,
816 static const struct file_operations ftrace_show_header_fops
= {
817 .open
= tracing_open_generic
,
821 static struct dentry
*event_trace_events_dir(void)
823 static struct dentry
*d_tracer
;
824 static struct dentry
*d_events
;
829 d_tracer
= tracing_init_dentry();
833 d_events
= debugfs_create_dir("events", d_tracer
);
835 pr_warning("Could not create debugfs "
836 "'events' directory\n");
841 static LIST_HEAD(event_subsystems
);
843 static struct dentry
*
844 event_subsystem_dir(const char *name
, struct dentry
*d_events
)
846 struct event_subsystem
*system
;
847 struct dentry
*entry
;
849 /* First see if we did not already create this dir */
850 list_for_each_entry(system
, &event_subsystems
, list
) {
851 if (strcmp(system
->name
, name
) == 0) {
853 return system
->entry
;
857 /* need to create new entry */
858 system
= kmalloc(sizeof(*system
), GFP_KERNEL
);
860 pr_warning("No memory to create event subsystem %s\n",
865 system
->entry
= debugfs_create_dir(name
, d_events
);
866 if (!system
->entry
) {
867 pr_warning("Could not create event subsystem %s\n",
873 system
->nr_events
= 1;
874 system
->name
= kstrdup(name
, GFP_KERNEL
);
876 debugfs_remove(system
->entry
);
881 list_add(&system
->list
, &event_subsystems
);
883 system
->filter
= NULL
;
885 system
->filter
= kzalloc(sizeof(struct event_filter
), GFP_KERNEL
);
886 if (!system
->filter
) {
887 pr_warning("Could not allocate filter for subsystem "
889 return system
->entry
;
892 entry
= debugfs_create_file("filter", 0644, system
->entry
, system
,
893 &ftrace_subsystem_filter_fops
);
895 kfree(system
->filter
);
896 system
->filter
= NULL
;
897 pr_warning("Could not create debugfs "
898 "'%s/filter' entry\n", name
);
901 entry
= trace_create_file("enable", 0644, system
->entry
,
902 (void *)system
->name
,
903 &ftrace_system_enable_fops
);
905 return system
->entry
;
909 event_create_dir(struct ftrace_event_call
*call
, struct dentry
*d_events
,
910 const struct file_operations
*id
,
911 const struct file_operations
*enable
,
912 const struct file_operations
*filter
,
913 const struct file_operations
*format
)
915 struct dentry
*entry
;
919 * If the trace point header did not define TRACE_SYSTEM
920 * then the system would be called "TRACE_SYSTEM".
922 if (strcmp(call
->system
, TRACE_SYSTEM
) != 0)
923 d_events
= event_subsystem_dir(call
->system
, d_events
);
925 call
->dir
= debugfs_create_dir(call
->name
, d_events
);
927 pr_warning("Could not create debugfs "
928 "'%s' directory\n", call
->name
);
933 entry
= trace_create_file("enable", 0644, call
->dir
, call
,
936 if (call
->id
&& call
->profile_enable
)
937 entry
= trace_create_file("id", 0444, call
->dir
, call
,
940 if (call
->define_fields
) {
941 ret
= call
->define_fields(call
);
943 pr_warning("Could not initialize trace point"
944 " events/%s\n", call
->name
);
947 entry
= trace_create_file("filter", 0644, call
->dir
, call
,
951 /* A trace may not want to export its format */
952 if (!call
->show_format
)
955 entry
= trace_create_file("format", 0444, call
->dir
, call
,
961 #define for_each_event(event, start, end) \
962 for (event = start; \
963 (unsigned long)event < (unsigned long)end; \
966 #ifdef CONFIG_MODULES
968 static LIST_HEAD(ftrace_module_file_list
);
971 * Modules must own their file_operations to keep up with
972 * reference counting.
974 struct ftrace_module_file_ops
{
975 struct list_head list
;
977 struct file_operations id
;
978 struct file_operations enable
;
979 struct file_operations format
;
980 struct file_operations filter
;
983 static void remove_subsystem_dir(const char *name
)
985 struct event_subsystem
*system
;
987 if (strcmp(name
, TRACE_SYSTEM
) == 0)
990 list_for_each_entry(system
, &event_subsystems
, list
) {
991 if (strcmp(system
->name
, name
) == 0) {
992 if (!--system
->nr_events
) {
993 struct event_filter
*filter
= system
->filter
;
995 debugfs_remove_recursive(system
->entry
);
996 list_del(&system
->list
);
998 kfree(filter
->filter_string
);
1001 kfree(system
->name
);
1009 static struct ftrace_module_file_ops
*
1010 trace_create_file_ops(struct module
*mod
)
1012 struct ftrace_module_file_ops
*file_ops
;
1015 * This is a bit of a PITA. To allow for correct reference
1016 * counting, modules must "own" their file_operations.
1017 * To do this, we allocate the file operations that will be
1018 * used in the event directory.
1021 file_ops
= kmalloc(sizeof(*file_ops
), GFP_KERNEL
);
1025 file_ops
->mod
= mod
;
1027 file_ops
->id
= ftrace_event_id_fops
;
1028 file_ops
->id
.owner
= mod
;
1030 file_ops
->enable
= ftrace_enable_fops
;
1031 file_ops
->enable
.owner
= mod
;
1033 file_ops
->filter
= ftrace_event_filter_fops
;
1034 file_ops
->filter
.owner
= mod
;
1036 file_ops
->format
= ftrace_event_format_fops
;
1037 file_ops
->format
.owner
= mod
;
1039 list_add(&file_ops
->list
, &ftrace_module_file_list
);
1044 static void trace_module_add_events(struct module
*mod
)
1046 struct ftrace_module_file_ops
*file_ops
= NULL
;
1047 struct ftrace_event_call
*call
, *start
, *end
;
1048 struct dentry
*d_events
;
1051 start
= mod
->trace_events
;
1052 end
= mod
->trace_events
+ mod
->num_trace_events
;
1057 d_events
= event_trace_events_dir();
1061 for_each_event(call
, start
, end
) {
1062 /* The linker may leave blanks */
1065 if (call
->raw_init
) {
1066 ret
= call
->raw_init();
1069 pr_warning("Could not initialize trace "
1070 "point events/%s\n", call
->name
);
1075 * This module has events, create file ops for this module
1076 * if not already done.
1079 file_ops
= trace_create_file_ops(mod
);
1084 list_add(&call
->list
, &ftrace_events
);
1085 event_create_dir(call
, d_events
,
1086 &file_ops
->id
, &file_ops
->enable
,
1087 &file_ops
->filter
, &file_ops
->format
);
1091 static void trace_module_remove_events(struct module
*mod
)
1093 struct ftrace_module_file_ops
*file_ops
;
1094 struct ftrace_event_call
*call
, *p
;
1097 down_write(&trace_event_mutex
);
1098 list_for_each_entry_safe(call
, p
, &ftrace_events
, list
) {
1099 if (call
->mod
== mod
) {
1101 ftrace_event_enable_disable(call
, 0);
1103 __unregister_ftrace_event(call
->event
);
1104 debugfs_remove_recursive(call
->dir
);
1105 list_del(&call
->list
);
1106 trace_destroy_fields(call
);
1107 destroy_preds(call
);
1108 remove_subsystem_dir(call
->system
);
1112 /* Now free the file_operations */
1113 list_for_each_entry(file_ops
, &ftrace_module_file_list
, list
) {
1114 if (file_ops
->mod
== mod
)
1117 if (&file_ops
->list
!= &ftrace_module_file_list
) {
1118 list_del(&file_ops
->list
);
1123 * It is safest to reset the ring buffer if the module being unloaded
1124 * registered any events.
1127 tracing_reset_current_online_cpus();
1128 up_write(&trace_event_mutex
);
1131 static int trace_module_notify(struct notifier_block
*self
,
1132 unsigned long val
, void *data
)
1134 struct module
*mod
= data
;
1136 mutex_lock(&event_mutex
);
1138 case MODULE_STATE_COMING
:
1139 trace_module_add_events(mod
);
1141 case MODULE_STATE_GOING
:
1142 trace_module_remove_events(mod
);
1145 mutex_unlock(&event_mutex
);
1150 static int trace_module_notify(struct notifier_block
*self
,
1151 unsigned long val
, void *data
)
1155 #endif /* CONFIG_MODULES */
1157 static struct notifier_block trace_module_nb
= {
1158 .notifier_call
= trace_module_notify
,
1162 extern struct ftrace_event_call __start_ftrace_events
[];
1163 extern struct ftrace_event_call __stop_ftrace_events
[];
1165 static char bootup_event_buf
[COMMAND_LINE_SIZE
] __initdata
;
1167 static __init
int setup_trace_event(char *str
)
1169 strlcpy(bootup_event_buf
, str
, COMMAND_LINE_SIZE
);
1170 ring_buffer_expanded
= 1;
1171 tracing_selftest_disabled
= 1;
1175 __setup("trace_event=", setup_trace_event
);
1177 static __init
int event_trace_init(void)
1179 struct ftrace_event_call
*call
;
1180 struct dentry
*d_tracer
;
1181 struct dentry
*entry
;
1182 struct dentry
*d_events
;
1184 char *buf
= bootup_event_buf
;
1187 d_tracer
= tracing_init_dentry();
1191 entry
= debugfs_create_file("available_events", 0444, d_tracer
,
1192 (void *)&show_event_seq_ops
,
1193 &ftrace_avail_fops
);
1195 pr_warning("Could not create debugfs "
1196 "'available_events' entry\n");
1198 entry
= debugfs_create_file("set_event", 0644, d_tracer
,
1199 (void *)&show_set_event_seq_ops
,
1200 &ftrace_set_event_fops
);
1202 pr_warning("Could not create debugfs "
1203 "'set_event' entry\n");
1205 d_events
= event_trace_events_dir();
1209 /* ring buffer internal formats */
1210 trace_create_file("header_page", 0444, d_events
,
1211 ring_buffer_print_page_header
,
1212 &ftrace_show_header_fops
);
1214 trace_create_file("header_event", 0444, d_events
,
1215 ring_buffer_print_entry_header
,
1216 &ftrace_show_header_fops
);
1218 trace_create_file("enable", 0644, d_events
,
1219 NULL
, &ftrace_system_enable_fops
);
1221 for_each_event(call
, __start_ftrace_events
, __stop_ftrace_events
) {
1222 /* The linker may leave blanks */
1225 if (call
->raw_init
) {
1226 ret
= call
->raw_init();
1229 pr_warning("Could not initialize trace "
1230 "point events/%s\n", call
->name
);
1234 list_add(&call
->list
, &ftrace_events
);
1235 event_create_dir(call
, d_events
, &ftrace_event_id_fops
,
1236 &ftrace_enable_fops
, &ftrace_event_filter_fops
,
1237 &ftrace_event_format_fops
);
1241 token
= strsep(&buf
, ",");
1248 ret
= ftrace_set_clr_event(token
, 1);
1250 pr_warning("Failed to enable trace event: %s\n", token
);
1253 ret
= register_module_notifier(&trace_module_nb
);
1255 pr_warning("Failed to register trace events module notifier\n");
1259 fs_initcall(event_trace_init
);
1261 #ifdef CONFIG_FTRACE_STARTUP_TEST
1263 static DEFINE_SPINLOCK(test_spinlock
);
1264 static DEFINE_SPINLOCK(test_spinlock_irq
);
1265 static DEFINE_MUTEX(test_mutex
);
1267 static __init
void test_work(struct work_struct
*dummy
)
1269 spin_lock(&test_spinlock
);
1270 spin_lock_irq(&test_spinlock_irq
);
1272 spin_unlock_irq(&test_spinlock_irq
);
1273 spin_unlock(&test_spinlock
);
1275 mutex_lock(&test_mutex
);
1277 mutex_unlock(&test_mutex
);
1280 static __init
int event_test_thread(void *unused
)
1284 test_malloc
= kmalloc(1234, GFP_KERNEL
);
1286 pr_info("failed to kmalloc\n");
1288 schedule_on_each_cpu(test_work
);
1292 set_current_state(TASK_INTERRUPTIBLE
);
1293 while (!kthread_should_stop())
1300 * Do various things that may trigger events.
1302 static __init
void event_test_stuff(void)
1304 struct task_struct
*test_thread
;
1306 test_thread
= kthread_run(event_test_thread
, NULL
, "test-events");
1308 kthread_stop(test_thread
);
1312 * For every trace event defined, we will test each trace point separately,
1313 * and then by groups, and finally all trace points.
1315 static __init
void event_trace_self_tests(void)
1317 struct ftrace_event_call
*call
;
1318 struct event_subsystem
*system
;
1321 pr_info("Running tests on trace events:\n");
1323 list_for_each_entry(call
, &ftrace_events
, list
) {
1325 /* Only test those that have a regfunc */
1330 * Testing syscall events here is pretty useless, but
1331 * we still do it if configured. But this is time consuming.
1332 * What we really need is a user thread to perform the
1333 * syscalls as we test.
1335 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
1337 strcmp(call
->system
, "syscalls") == 0)
1341 pr_info("Testing event %s: ", call
->name
);
1344 * If an event is already enabled, someone is using
1345 * it and the self test should not be on.
1347 if (call
->enabled
) {
1348 pr_warning("Enabled event during self test!\n");
1353 ftrace_event_enable_disable(call
, 1);
1355 ftrace_event_enable_disable(call
, 0);
1360 /* Now test at the sub system level */
1362 pr_info("Running tests on trace event systems:\n");
1364 list_for_each_entry(system
, &event_subsystems
, list
) {
1366 /* the ftrace system is special, skip it */
1367 if (strcmp(system
->name
, "ftrace") == 0)
1370 pr_info("Testing event system %s: ", system
->name
);
1372 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 1);
1373 if (WARN_ON_ONCE(ret
)) {
1374 pr_warning("error enabling system %s\n",
1381 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 0);
1382 if (WARN_ON_ONCE(ret
))
1383 pr_warning("error disabling system %s\n",
1389 /* Test with all events enabled */
1391 pr_info("Running tests on all trace events:\n");
1392 pr_info("Testing all events: ");
1394 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 1);
1395 if (WARN_ON_ONCE(ret
)) {
1396 pr_warning("error enabling all events\n");
1403 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 0);
1404 if (WARN_ON_ONCE(ret
)) {
1405 pr_warning("error disabling all events\n");
1412 #ifdef CONFIG_FUNCTION_TRACER
1414 static DEFINE_PER_CPU(atomic_t
, ftrace_test_event_disable
);
1417 function_test_events_call(unsigned long ip
, unsigned long parent_ip
)
1419 struct ring_buffer_event
*event
;
1420 struct ring_buffer
*buffer
;
1421 struct ftrace_entry
*entry
;
1422 unsigned long flags
;
1428 pc
= preempt_count();
1429 resched
= ftrace_preempt_disable();
1430 cpu
= raw_smp_processor_id();
1431 disabled
= atomic_inc_return(&per_cpu(ftrace_test_event_disable
, cpu
));
1436 local_save_flags(flags
);
1438 event
= trace_current_buffer_lock_reserve(&buffer
,
1439 TRACE_FN
, sizeof(*entry
),
1443 entry
= ring_buffer_event_data(event
);
1445 entry
->parent_ip
= parent_ip
;
1447 trace_nowake_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1450 atomic_dec(&per_cpu(ftrace_test_event_disable
, cpu
));
1451 ftrace_preempt_enable(resched
);
1454 static struct ftrace_ops trace_ops __initdata
=
1456 .func
= function_test_events_call
,
1459 static __init
void event_trace_self_test_with_function(void)
1461 register_ftrace_function(&trace_ops
);
1462 pr_info("Running tests again, along with the function tracer\n");
1463 event_trace_self_tests();
1464 unregister_ftrace_function(&trace_ops
);
1467 static __init
void event_trace_self_test_with_function(void)
1472 static __init
int event_trace_self_tests_init(void)
1474 if (!tracing_selftest_disabled
) {
1475 event_trace_self_tests();
1476 event_trace_self_test_with_function();
1482 late_initcall(event_trace_self_tests_init
);