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
);
69 EXPORT_SYMBOL_GPL(trace_define_field
);
71 #define __common_field(type, item) \
72 ret = trace_define_field(call, #type, "common_" #item, \
73 offsetof(typeof(ent), item), \
75 is_signed_type(type), FILTER_OTHER); \
79 static int trace_define_common_fields(struct ftrace_event_call
*call
)
82 struct trace_entry ent
;
84 __common_field(unsigned short, type
);
85 __common_field(unsigned char, flags
);
86 __common_field(unsigned char, preempt_count
);
87 __common_field(int, pid
);
88 __common_field(int, lock_depth
);
93 void trace_destroy_fields(struct ftrace_event_call
*call
)
95 struct ftrace_event_field
*field
, *next
;
97 list_for_each_entry_safe(field
, next
, &call
->fields
, link
) {
98 list_del(&field
->link
);
105 int trace_event_raw_init(struct ftrace_event_call
*call
)
109 id
= register_ftrace_event(call
->event
);
113 INIT_LIST_HEAD(&call
->fields
);
117 EXPORT_SYMBOL_GPL(trace_event_raw_init
);
119 static int ftrace_event_enable_disable(struct ftrace_event_call
*call
,
128 tracing_stop_cmdline_record();
129 call
->unregfunc(call
);
133 if (!call
->enabled
) {
134 tracing_start_cmdline_record();
135 ret
= call
->regfunc(call
);
137 tracing_stop_cmdline_record();
138 pr_info("event trace: Could not enable event "
150 static void ftrace_clear_events(void)
152 struct ftrace_event_call
*call
;
154 mutex_lock(&event_mutex
);
155 list_for_each_entry(call
, &ftrace_events
, list
) {
156 ftrace_event_enable_disable(call
, 0);
158 mutex_unlock(&event_mutex
);
162 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
164 static int __ftrace_set_clr_event(const char *match
, const char *sub
,
165 const char *event
, int set
)
167 struct ftrace_event_call
*call
;
170 mutex_lock(&event_mutex
);
171 list_for_each_entry(call
, &ftrace_events
, list
) {
173 if (!call
->name
|| !call
->regfunc
)
177 strcmp(match
, call
->name
) != 0 &&
178 strcmp(match
, call
->system
) != 0)
181 if (sub
&& strcmp(sub
, call
->system
) != 0)
184 if (event
&& strcmp(event
, call
->name
) != 0)
187 ftrace_event_enable_disable(call
, set
);
191 mutex_unlock(&event_mutex
);
196 static int ftrace_set_clr_event(char *buf
, int set
)
198 char *event
= NULL
, *sub
= NULL
, *match
;
201 * The buf format can be <subsystem>:<event-name>
202 * *:<event-name> means any event by that name.
203 * :<event-name> is the same.
205 * <subsystem>:* means all events in that subsystem
206 * <subsystem>: means the same.
208 * <name> (no ':') means all events in a subsystem with
209 * the name <name> or any event that matches <name>
212 match
= strsep(&buf
, ":");
218 if (!strlen(sub
) || strcmp(sub
, "*") == 0)
220 if (!strlen(event
) || strcmp(event
, "*") == 0)
224 return __ftrace_set_clr_event(match
, sub
, event
, set
);
228 * trace_set_clr_event - enable or disable an event
229 * @system: system name to match (NULL for any system)
230 * @event: event name to match (NULL for all events, within system)
231 * @set: 1 to enable, 0 to disable
233 * This is a way for other parts of the kernel to enable or disable
236 * Returns 0 on success, -EINVAL if the parameters do not match any
239 int trace_set_clr_event(const char *system
, const char *event
, int set
)
241 return __ftrace_set_clr_event(NULL
, system
, event
, set
);
244 /* 128 should be much more than enough */
245 #define EVENT_BUF_SIZE 127
248 ftrace_event_write(struct file
*file
, const char __user
*ubuf
,
249 size_t cnt
, loff_t
*ppos
)
251 struct trace_parser parser
;
257 ret
= tracing_update_buffers();
261 if (trace_parser_get_init(&parser
, EVENT_BUF_SIZE
+ 1))
264 read
= trace_get_user(&parser
, ubuf
, cnt
, ppos
);
266 if (read
>= 0 && trace_parser_loaded((&parser
))) {
269 if (*parser
.buffer
== '!')
272 parser
.buffer
[parser
.idx
] = 0;
274 ret
= ftrace_set_clr_event(parser
.buffer
+ !set
, set
);
282 trace_parser_put(&parser
);
288 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
290 struct ftrace_event_call
*call
= v
;
294 list_for_each_entry_continue(call
, &ftrace_events
, list
) {
296 * The ftrace subsystem is for showing formats only.
297 * They can not be enabled or disabled via the event files.
306 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
308 struct ftrace_event_call
*call
;
311 mutex_lock(&event_mutex
);
313 call
= list_entry(&ftrace_events
, struct ftrace_event_call
, list
);
314 for (l
= 0; l
<= *pos
; ) {
315 call
= t_next(m
, call
, &l
);
323 s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
325 struct ftrace_event_call
*call
= v
;
329 list_for_each_entry_continue(call
, &ftrace_events
, list
) {
337 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
339 struct ftrace_event_call
*call
;
342 mutex_lock(&event_mutex
);
344 call
= list_entry(&ftrace_events
, struct ftrace_event_call
, list
);
345 for (l
= 0; l
<= *pos
; ) {
346 call
= s_next(m
, call
, &l
);
353 static int t_show(struct seq_file
*m
, void *v
)
355 struct ftrace_event_call
*call
= v
;
357 if (strcmp(call
->system
, TRACE_SYSTEM
) != 0)
358 seq_printf(m
, "%s:", call
->system
);
359 seq_printf(m
, "%s\n", call
->name
);
364 static void t_stop(struct seq_file
*m
, void *p
)
366 mutex_unlock(&event_mutex
);
370 ftrace_event_seq_open(struct inode
*inode
, struct file
*file
)
372 const struct seq_operations
*seq_ops
;
374 if ((file
->f_mode
& FMODE_WRITE
) &&
375 (file
->f_flags
& O_TRUNC
))
376 ftrace_clear_events();
378 seq_ops
= inode
->i_private
;
379 return seq_open(file
, seq_ops
);
383 event_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
386 struct ftrace_event_call
*call
= filp
->private_data
;
394 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
398 event_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
401 struct ftrace_event_call
*call
= filp
->private_data
;
406 if (cnt
>= sizeof(buf
))
409 if (copy_from_user(&buf
, ubuf
, cnt
))
414 ret
= strict_strtoul(buf
, 10, &val
);
418 ret
= tracing_update_buffers();
425 mutex_lock(&event_mutex
);
426 ret
= ftrace_event_enable_disable(call
, val
);
427 mutex_unlock(&event_mutex
);
436 return ret
? ret
: cnt
;
440 system_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
443 const char set_to_char
[4] = { '?', '0', '1', 'X' };
444 const char *system
= filp
->private_data
;
445 struct ftrace_event_call
*call
;
450 mutex_lock(&event_mutex
);
451 list_for_each_entry(call
, &ftrace_events
, list
) {
452 if (!call
->name
|| !call
->regfunc
)
455 if (system
&& strcmp(call
->system
, system
) != 0)
459 * We need to find out if all the events are set
460 * or if all events or cleared, or if we have
463 set
|= (1 << !!call
->enabled
);
466 * If we have a mixture, no need to look further.
471 mutex_unlock(&event_mutex
);
473 buf
[0] = set_to_char
[set
];
476 ret
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
482 system_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
485 const char *system
= filp
->private_data
;
490 if (cnt
>= sizeof(buf
))
493 if (copy_from_user(&buf
, ubuf
, cnt
))
498 ret
= strict_strtoul(buf
, 10, &val
);
502 ret
= tracing_update_buffers();
506 if (val
!= 0 && val
!= 1)
509 ret
= __ftrace_set_clr_event(NULL
, system
, NULL
, val
);
522 event_format_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
525 struct ftrace_event_call
*call
= filp
->private_data
;
526 struct ftrace_event_field
*field
;
528 int common_field_count
= 5;
535 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
541 trace_seq_printf(s
, "name: %s\n", call
->name
);
542 trace_seq_printf(s
, "ID: %d\n", call
->id
);
543 trace_seq_printf(s
, "format:\n");
545 list_for_each_entry_reverse(field
, &call
->fields
, link
) {
547 * Smartly shows the array type(except dynamic array).
550 * If TYPE := TYPE[LEN], it is shown:
551 * field:TYPE VAR[LEN]
553 const char *array_descriptor
= strchr(field
->type
, '[');
555 if (!strncmp(field
->type
, "__data_loc", 10))
556 array_descriptor
= NULL
;
558 if (!array_descriptor
) {
559 r
= trace_seq_printf(s
, "\tfield:%s %s;\toffset:%u;"
560 "\tsize:%u;\tsigned:%d;\n",
561 field
->type
, field
->name
, field
->offset
,
562 field
->size
, !!field
->is_signed
);
564 r
= trace_seq_printf(s
, "\tfield:%.*s %s%s;\toffset:%u;"
565 "\tsize:%u;\tsigned:%d;\n",
566 (int)(array_descriptor
- field
->type
),
567 field
->type
, field
->name
,
568 array_descriptor
, field
->offset
,
569 field
->size
, !!field
->is_signed
);
572 if (--common_field_count
== 0)
573 r
= trace_seq_printf(s
, "\n");
580 r
= trace_seq_printf(s
, "\nprint fmt: %s\n",
585 * ug! The format output is bigger than a PAGE!!
587 buf
= "FORMAT TOO BIG\n";
588 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
593 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
601 event_id_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
603 struct ftrace_event_call
*call
= filp
->private_data
;
610 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
615 trace_seq_printf(s
, "%d\n", call
->id
);
617 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
624 event_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
627 struct ftrace_event_call
*call
= filp
->private_data
;
634 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
640 print_event_filter(call
, s
);
641 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
649 event_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
652 struct ftrace_event_call
*call
= filp
->private_data
;
656 if (cnt
>= PAGE_SIZE
)
659 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
663 if (copy_from_user(buf
, ubuf
, cnt
)) {
664 free_page((unsigned long) buf
);
669 err
= apply_event_filter(call
, buf
);
670 free_page((unsigned long) buf
);
680 subsystem_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
683 struct event_subsystem
*system
= filp
->private_data
;
690 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
696 print_subsystem_event_filter(system
, s
);
697 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
705 subsystem_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
708 struct event_subsystem
*system
= filp
->private_data
;
712 if (cnt
>= PAGE_SIZE
)
715 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
719 if (copy_from_user(buf
, ubuf
, cnt
)) {
720 free_page((unsigned long) buf
);
725 err
= apply_subsystem_event_filter(system
, buf
);
726 free_page((unsigned long) buf
);
736 show_header(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
738 int (*func
)(struct trace_seq
*s
) = filp
->private_data
;
745 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
752 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
759 static const struct seq_operations show_event_seq_ops
= {
766 static const struct seq_operations show_set_event_seq_ops
= {
773 static const struct file_operations ftrace_avail_fops
= {
774 .open
= ftrace_event_seq_open
,
777 .release
= seq_release
,
780 static const struct file_operations ftrace_set_event_fops
= {
781 .open
= ftrace_event_seq_open
,
783 .write
= ftrace_event_write
,
785 .release
= seq_release
,
788 static const struct file_operations ftrace_enable_fops
= {
789 .open
= tracing_open_generic
,
790 .read
= event_enable_read
,
791 .write
= event_enable_write
,
794 static const struct file_operations ftrace_event_format_fops
= {
795 .open
= tracing_open_generic
,
796 .read
= event_format_read
,
799 static const struct file_operations ftrace_event_id_fops
= {
800 .open
= tracing_open_generic
,
801 .read
= event_id_read
,
804 static const struct file_operations ftrace_event_filter_fops
= {
805 .open
= tracing_open_generic
,
806 .read
= event_filter_read
,
807 .write
= event_filter_write
,
810 static const struct file_operations ftrace_subsystem_filter_fops
= {
811 .open
= tracing_open_generic
,
812 .read
= subsystem_filter_read
,
813 .write
= subsystem_filter_write
,
816 static const struct file_operations ftrace_system_enable_fops
= {
817 .open
= tracing_open_generic
,
818 .read
= system_enable_read
,
819 .write
= system_enable_write
,
822 static const struct file_operations ftrace_show_header_fops
= {
823 .open
= tracing_open_generic
,
827 static struct dentry
*event_trace_events_dir(void)
829 static struct dentry
*d_tracer
;
830 static struct dentry
*d_events
;
835 d_tracer
= tracing_init_dentry();
839 d_events
= debugfs_create_dir("events", d_tracer
);
841 pr_warning("Could not create debugfs "
842 "'events' directory\n");
847 static LIST_HEAD(event_subsystems
);
849 static struct dentry
*
850 event_subsystem_dir(const char *name
, struct dentry
*d_events
)
852 struct event_subsystem
*system
;
853 struct dentry
*entry
;
855 /* First see if we did not already create this dir */
856 list_for_each_entry(system
, &event_subsystems
, list
) {
857 if (strcmp(system
->name
, name
) == 0) {
859 return system
->entry
;
863 /* need to create new entry */
864 system
= kmalloc(sizeof(*system
), GFP_KERNEL
);
866 pr_warning("No memory to create event subsystem %s\n",
871 system
->entry
= debugfs_create_dir(name
, d_events
);
872 if (!system
->entry
) {
873 pr_warning("Could not create event subsystem %s\n",
879 system
->nr_events
= 1;
880 system
->name
= kstrdup(name
, GFP_KERNEL
);
882 debugfs_remove(system
->entry
);
887 list_add(&system
->list
, &event_subsystems
);
889 system
->filter
= NULL
;
891 system
->filter
= kzalloc(sizeof(struct event_filter
), GFP_KERNEL
);
892 if (!system
->filter
) {
893 pr_warning("Could not allocate filter for subsystem "
895 return system
->entry
;
898 entry
= debugfs_create_file("filter", 0644, system
->entry
, system
,
899 &ftrace_subsystem_filter_fops
);
901 kfree(system
->filter
);
902 system
->filter
= NULL
;
903 pr_warning("Could not create debugfs "
904 "'%s/filter' entry\n", name
);
907 trace_create_file("enable", 0644, system
->entry
,
908 (void *)system
->name
,
909 &ftrace_system_enable_fops
);
911 return system
->entry
;
915 event_create_dir(struct ftrace_event_call
*call
, struct dentry
*d_events
,
916 const struct file_operations
*id
,
917 const struct file_operations
*enable
,
918 const struct file_operations
*filter
,
919 const struct file_operations
*format
)
924 * If the trace point header did not define TRACE_SYSTEM
925 * then the system would be called "TRACE_SYSTEM".
927 if (strcmp(call
->system
, TRACE_SYSTEM
) != 0)
928 d_events
= event_subsystem_dir(call
->system
, d_events
);
930 call
->dir
= debugfs_create_dir(call
->name
, d_events
);
932 pr_warning("Could not create debugfs "
933 "'%s' directory\n", call
->name
);
938 trace_create_file("enable", 0644, call
->dir
, call
,
941 if (call
->id
&& call
->profile_enable
)
942 trace_create_file("id", 0444, call
->dir
, call
,
945 if (call
->define_fields
) {
946 ret
= trace_define_common_fields(call
);
948 ret
= call
->define_fields(call
);
950 pr_warning("Could not initialize trace point"
951 " events/%s\n", call
->name
);
954 trace_create_file("filter", 0644, call
->dir
, call
,
958 trace_create_file("format", 0444, call
->dir
, call
,
964 static int __trace_add_event_call(struct ftrace_event_call
*call
)
966 struct dentry
*d_events
;
972 if (call
->raw_init
) {
973 ret
= call
->raw_init(call
);
976 pr_warning("Could not initialize trace "
977 "events/%s\n", call
->name
);
982 d_events
= event_trace_events_dir();
986 ret
= event_create_dir(call
, d_events
, &ftrace_event_id_fops
,
987 &ftrace_enable_fops
, &ftrace_event_filter_fops
,
988 &ftrace_event_format_fops
);
990 list_add(&call
->list
, &ftrace_events
);
995 /* Add an additional event_call dynamically */
996 int trace_add_event_call(struct ftrace_event_call
*call
)
999 mutex_lock(&event_mutex
);
1000 ret
= __trace_add_event_call(call
);
1001 mutex_unlock(&event_mutex
);
1005 static void remove_subsystem_dir(const char *name
)
1007 struct event_subsystem
*system
;
1009 if (strcmp(name
, TRACE_SYSTEM
) == 0)
1012 list_for_each_entry(system
, &event_subsystems
, list
) {
1013 if (strcmp(system
->name
, name
) == 0) {
1014 if (!--system
->nr_events
) {
1015 struct event_filter
*filter
= system
->filter
;
1017 debugfs_remove_recursive(system
->entry
);
1018 list_del(&system
->list
);
1020 kfree(filter
->filter_string
);
1023 kfree(system
->name
);
1032 * Must be called under locking both of event_mutex and trace_event_mutex.
1034 static void __trace_remove_event_call(struct ftrace_event_call
*call
)
1036 ftrace_event_enable_disable(call
, 0);
1038 __unregister_ftrace_event(call
->event
);
1039 debugfs_remove_recursive(call
->dir
);
1040 list_del(&call
->list
);
1041 trace_destroy_fields(call
);
1042 destroy_preds(call
);
1043 remove_subsystem_dir(call
->system
);
1046 /* Remove an event_call */
1047 void trace_remove_event_call(struct ftrace_event_call
*call
)
1049 mutex_lock(&event_mutex
);
1050 down_write(&trace_event_mutex
);
1051 __trace_remove_event_call(call
);
1052 up_write(&trace_event_mutex
);
1053 mutex_unlock(&event_mutex
);
1056 #define for_each_event(event, start, end) \
1057 for (event = start; \
1058 (unsigned long)event < (unsigned long)end; \
1061 #ifdef CONFIG_MODULES
1063 static LIST_HEAD(ftrace_module_file_list
);
1066 * Modules must own their file_operations to keep up with
1067 * reference counting.
1069 struct ftrace_module_file_ops
{
1070 struct list_head list
;
1072 struct file_operations id
;
1073 struct file_operations enable
;
1074 struct file_operations format
;
1075 struct file_operations filter
;
1078 static struct ftrace_module_file_ops
*
1079 trace_create_file_ops(struct module
*mod
)
1081 struct ftrace_module_file_ops
*file_ops
;
1084 * This is a bit of a PITA. To allow for correct reference
1085 * counting, modules must "own" their file_operations.
1086 * To do this, we allocate the file operations that will be
1087 * used in the event directory.
1090 file_ops
= kmalloc(sizeof(*file_ops
), GFP_KERNEL
);
1094 file_ops
->mod
= mod
;
1096 file_ops
->id
= ftrace_event_id_fops
;
1097 file_ops
->id
.owner
= mod
;
1099 file_ops
->enable
= ftrace_enable_fops
;
1100 file_ops
->enable
.owner
= mod
;
1102 file_ops
->filter
= ftrace_event_filter_fops
;
1103 file_ops
->filter
.owner
= mod
;
1105 file_ops
->format
= ftrace_event_format_fops
;
1106 file_ops
->format
.owner
= mod
;
1108 list_add(&file_ops
->list
, &ftrace_module_file_list
);
1113 static void trace_module_add_events(struct module
*mod
)
1115 struct ftrace_module_file_ops
*file_ops
= NULL
;
1116 struct ftrace_event_call
*call
, *start
, *end
;
1117 struct dentry
*d_events
;
1120 start
= mod
->trace_events
;
1121 end
= mod
->trace_events
+ mod
->num_trace_events
;
1126 d_events
= event_trace_events_dir();
1130 for_each_event(call
, start
, end
) {
1131 /* The linker may leave blanks */
1134 if (call
->raw_init
) {
1135 ret
= call
->raw_init(call
);
1138 pr_warning("Could not initialize trace "
1139 "point events/%s\n", call
->name
);
1144 * This module has events, create file ops for this module
1145 * if not already done.
1148 file_ops
= trace_create_file_ops(mod
);
1153 ret
= event_create_dir(call
, d_events
,
1154 &file_ops
->id
, &file_ops
->enable
,
1155 &file_ops
->filter
, &file_ops
->format
);
1157 list_add(&call
->list
, &ftrace_events
);
1161 static void trace_module_remove_events(struct module
*mod
)
1163 struct ftrace_module_file_ops
*file_ops
;
1164 struct ftrace_event_call
*call
, *p
;
1167 down_write(&trace_event_mutex
);
1168 list_for_each_entry_safe(call
, p
, &ftrace_events
, list
) {
1169 if (call
->mod
== mod
) {
1171 __trace_remove_event_call(call
);
1175 /* Now free the file_operations */
1176 list_for_each_entry(file_ops
, &ftrace_module_file_list
, list
) {
1177 if (file_ops
->mod
== mod
)
1180 if (&file_ops
->list
!= &ftrace_module_file_list
) {
1181 list_del(&file_ops
->list
);
1186 * It is safest to reset the ring buffer if the module being unloaded
1187 * registered any events.
1190 tracing_reset_current_online_cpus();
1191 up_write(&trace_event_mutex
);
1194 static int trace_module_notify(struct notifier_block
*self
,
1195 unsigned long val
, void *data
)
1197 struct module
*mod
= data
;
1199 mutex_lock(&event_mutex
);
1201 case MODULE_STATE_COMING
:
1202 trace_module_add_events(mod
);
1204 case MODULE_STATE_GOING
:
1205 trace_module_remove_events(mod
);
1208 mutex_unlock(&event_mutex
);
1213 static int trace_module_notify(struct notifier_block
*self
,
1214 unsigned long val
, void *data
)
1218 #endif /* CONFIG_MODULES */
1220 static struct notifier_block trace_module_nb
= {
1221 .notifier_call
= trace_module_notify
,
1225 extern struct ftrace_event_call __start_ftrace_events
[];
1226 extern struct ftrace_event_call __stop_ftrace_events
[];
1228 static char bootup_event_buf
[COMMAND_LINE_SIZE
] __initdata
;
1230 static __init
int setup_trace_event(char *str
)
1232 strlcpy(bootup_event_buf
, str
, COMMAND_LINE_SIZE
);
1233 ring_buffer_expanded
= 1;
1234 tracing_selftest_disabled
= 1;
1238 __setup("trace_event=", setup_trace_event
);
1240 static __init
int event_trace_init(void)
1242 struct ftrace_event_call
*call
;
1243 struct dentry
*d_tracer
;
1244 struct dentry
*entry
;
1245 struct dentry
*d_events
;
1247 char *buf
= bootup_event_buf
;
1250 d_tracer
= tracing_init_dentry();
1254 entry
= debugfs_create_file("available_events", 0444, d_tracer
,
1255 (void *)&show_event_seq_ops
,
1256 &ftrace_avail_fops
);
1258 pr_warning("Could not create debugfs "
1259 "'available_events' entry\n");
1261 entry
= debugfs_create_file("set_event", 0644, d_tracer
,
1262 (void *)&show_set_event_seq_ops
,
1263 &ftrace_set_event_fops
);
1265 pr_warning("Could not create debugfs "
1266 "'set_event' entry\n");
1268 d_events
= event_trace_events_dir();
1272 /* ring buffer internal formats */
1273 trace_create_file("header_page", 0444, d_events
,
1274 ring_buffer_print_page_header
,
1275 &ftrace_show_header_fops
);
1277 trace_create_file("header_event", 0444, d_events
,
1278 ring_buffer_print_entry_header
,
1279 &ftrace_show_header_fops
);
1281 trace_create_file("enable", 0644, d_events
,
1282 NULL
, &ftrace_system_enable_fops
);
1284 for_each_event(call
, __start_ftrace_events
, __stop_ftrace_events
) {
1285 /* The linker may leave blanks */
1288 if (call
->raw_init
) {
1289 ret
= call
->raw_init(call
);
1292 pr_warning("Could not initialize trace "
1293 "point events/%s\n", call
->name
);
1297 ret
= event_create_dir(call
, d_events
, &ftrace_event_id_fops
,
1298 &ftrace_enable_fops
,
1299 &ftrace_event_filter_fops
,
1300 &ftrace_event_format_fops
);
1302 list_add(&call
->list
, &ftrace_events
);
1306 token
= strsep(&buf
, ",");
1313 ret
= ftrace_set_clr_event(token
, 1);
1315 pr_warning("Failed to enable trace event: %s\n", token
);
1318 ret
= register_module_notifier(&trace_module_nb
);
1320 pr_warning("Failed to register trace events module notifier\n");
1324 fs_initcall(event_trace_init
);
1326 #ifdef CONFIG_FTRACE_STARTUP_TEST
1328 static DEFINE_SPINLOCK(test_spinlock
);
1329 static DEFINE_SPINLOCK(test_spinlock_irq
);
1330 static DEFINE_MUTEX(test_mutex
);
1332 static __init
void test_work(struct work_struct
*dummy
)
1334 spin_lock(&test_spinlock
);
1335 spin_lock_irq(&test_spinlock_irq
);
1337 spin_unlock_irq(&test_spinlock_irq
);
1338 spin_unlock(&test_spinlock
);
1340 mutex_lock(&test_mutex
);
1342 mutex_unlock(&test_mutex
);
1345 static __init
int event_test_thread(void *unused
)
1349 test_malloc
= kmalloc(1234, GFP_KERNEL
);
1351 pr_info("failed to kmalloc\n");
1353 schedule_on_each_cpu(test_work
);
1357 set_current_state(TASK_INTERRUPTIBLE
);
1358 while (!kthread_should_stop())
1365 * Do various things that may trigger events.
1367 static __init
void event_test_stuff(void)
1369 struct task_struct
*test_thread
;
1371 test_thread
= kthread_run(event_test_thread
, NULL
, "test-events");
1373 kthread_stop(test_thread
);
1377 * For every trace event defined, we will test each trace point separately,
1378 * and then by groups, and finally all trace points.
1380 static __init
void event_trace_self_tests(void)
1382 struct ftrace_event_call
*call
;
1383 struct event_subsystem
*system
;
1386 pr_info("Running tests on trace events:\n");
1388 list_for_each_entry(call
, &ftrace_events
, list
) {
1390 /* Only test those that have a regfunc */
1395 * Testing syscall events here is pretty useless, but
1396 * we still do it if configured. But this is time consuming.
1397 * What we really need is a user thread to perform the
1398 * syscalls as we test.
1400 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
1402 strcmp(call
->system
, "syscalls") == 0)
1406 pr_info("Testing event %s: ", call
->name
);
1409 * If an event is already enabled, someone is using
1410 * it and the self test should not be on.
1412 if (call
->enabled
) {
1413 pr_warning("Enabled event during self test!\n");
1418 ftrace_event_enable_disable(call
, 1);
1420 ftrace_event_enable_disable(call
, 0);
1425 /* Now test at the sub system level */
1427 pr_info("Running tests on trace event systems:\n");
1429 list_for_each_entry(system
, &event_subsystems
, list
) {
1431 /* the ftrace system is special, skip it */
1432 if (strcmp(system
->name
, "ftrace") == 0)
1435 pr_info("Testing event system %s: ", system
->name
);
1437 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 1);
1438 if (WARN_ON_ONCE(ret
)) {
1439 pr_warning("error enabling system %s\n",
1446 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 0);
1447 if (WARN_ON_ONCE(ret
))
1448 pr_warning("error disabling system %s\n",
1454 /* Test with all events enabled */
1456 pr_info("Running tests on all trace events:\n");
1457 pr_info("Testing all events: ");
1459 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 1);
1460 if (WARN_ON_ONCE(ret
)) {
1461 pr_warning("error enabling all events\n");
1468 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 0);
1469 if (WARN_ON_ONCE(ret
)) {
1470 pr_warning("error disabling all events\n");
1477 #ifdef CONFIG_FUNCTION_TRACER
1479 static DEFINE_PER_CPU(atomic_t
, ftrace_test_event_disable
);
1482 function_test_events_call(unsigned long ip
, unsigned long parent_ip
)
1484 struct ring_buffer_event
*event
;
1485 struct ring_buffer
*buffer
;
1486 struct ftrace_entry
*entry
;
1487 unsigned long flags
;
1493 pc
= preempt_count();
1494 resched
= ftrace_preempt_disable();
1495 cpu
= raw_smp_processor_id();
1496 disabled
= atomic_inc_return(&per_cpu(ftrace_test_event_disable
, cpu
));
1501 local_save_flags(flags
);
1503 event
= trace_current_buffer_lock_reserve(&buffer
,
1504 TRACE_FN
, sizeof(*entry
),
1508 entry
= ring_buffer_event_data(event
);
1510 entry
->parent_ip
= parent_ip
;
1512 trace_nowake_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1515 atomic_dec(&per_cpu(ftrace_test_event_disable
, cpu
));
1516 ftrace_preempt_enable(resched
);
1519 static struct ftrace_ops trace_ops __initdata
=
1521 .func
= function_test_events_call
,
1524 static __init
void event_trace_self_test_with_function(void)
1526 register_ftrace_function(&trace_ops
);
1527 pr_info("Running tests again, along with the function tracer\n");
1528 event_trace_self_tests();
1529 unregister_ftrace_function(&trace_ops
);
1532 static __init
void event_trace_self_test_with_function(void)
1537 static __init
int event_trace_self_tests_init(void)
1539 if (!tracing_selftest_disabled
) {
1540 event_trace_self_tests();
1541 event_trace_self_test_with_function();
1547 late_initcall(event_trace_self_tests_init
);