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 LIST_HEAD(ftrace_events
);
32 int trace_define_field(struct ftrace_event_call
*call
, const char *type
,
33 const char *name
, int offset
, int size
, int is_signed
,
36 struct ftrace_event_field
*field
;
38 field
= kzalloc(sizeof(*field
), GFP_KERNEL
);
42 field
->name
= kstrdup(name
, GFP_KERNEL
);
46 field
->type
= kstrdup(type
, GFP_KERNEL
);
50 if (filter_type
== FILTER_OTHER
)
51 field
->filter_type
= filter_assign_type(type
);
53 field
->filter_type
= filter_type
;
55 field
->offset
= offset
;
57 field
->is_signed
= is_signed
;
59 list_add(&field
->link
, &call
->fields
);
70 EXPORT_SYMBOL_GPL(trace_define_field
);
72 #define __common_field(type, item) \
73 ret = trace_define_field(call, #type, "common_" #item, \
74 offsetof(typeof(ent), item), \
76 is_signed_type(type), FILTER_OTHER); \
80 static int trace_define_common_fields(struct ftrace_event_call
*call
)
83 struct trace_entry ent
;
85 __common_field(unsigned short, type
);
86 __common_field(unsigned char, flags
);
87 __common_field(unsigned char, preempt_count
);
88 __common_field(int, pid
);
89 __common_field(int, lock_depth
);
94 void trace_destroy_fields(struct ftrace_event_call
*call
)
96 struct ftrace_event_field
*field
, *next
;
98 list_for_each_entry_safe(field
, next
, &call
->fields
, link
) {
99 list_del(&field
->link
);
106 int trace_event_raw_init(struct ftrace_event_call
*call
)
110 id
= register_ftrace_event(call
->event
);
114 INIT_LIST_HEAD(&call
->fields
);
118 EXPORT_SYMBOL_GPL(trace_event_raw_init
);
120 static int ftrace_event_enable_disable(struct ftrace_event_call
*call
,
129 tracing_stop_cmdline_record();
130 if (call
->class->reg
)
131 call
->class->reg(call
, TRACE_REG_UNREGISTER
);
133 tracepoint_probe_unregister(call
->name
,
139 if (!call
->enabled
) {
140 tracing_start_cmdline_record();
141 if (call
->class->reg
)
142 ret
= call
->class->reg(call
, TRACE_REG_REGISTER
);
144 ret
= tracepoint_probe_register(call
->name
,
148 tracing_stop_cmdline_record();
149 pr_info("event trace: Could not enable event "
161 static void ftrace_clear_events(void)
163 struct ftrace_event_call
*call
;
165 mutex_lock(&event_mutex
);
166 list_for_each_entry(call
, &ftrace_events
, list
) {
167 ftrace_event_enable_disable(call
, 0);
169 mutex_unlock(&event_mutex
);
173 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
175 static int __ftrace_set_clr_event(const char *match
, const char *sub
,
176 const char *event
, int set
)
178 struct ftrace_event_call
*call
;
181 mutex_lock(&event_mutex
);
182 list_for_each_entry(call
, &ftrace_events
, list
) {
184 if (!call
->name
|| !call
->class ||
185 (!call
->class->probe
&& !call
->class->reg
))
189 strcmp(match
, call
->name
) != 0 &&
190 strcmp(match
, call
->class->system
) != 0)
193 if (sub
&& strcmp(sub
, call
->class->system
) != 0)
196 if (event
&& strcmp(event
, call
->name
) != 0)
199 ftrace_event_enable_disable(call
, set
);
203 mutex_unlock(&event_mutex
);
208 static int ftrace_set_clr_event(char *buf
, int set
)
210 char *event
= NULL
, *sub
= NULL
, *match
;
213 * The buf format can be <subsystem>:<event-name>
214 * *:<event-name> means any event by that name.
215 * :<event-name> is the same.
217 * <subsystem>:* means all events in that subsystem
218 * <subsystem>: means the same.
220 * <name> (no ':') means all events in a subsystem with
221 * the name <name> or any event that matches <name>
224 match
= strsep(&buf
, ":");
230 if (!strlen(sub
) || strcmp(sub
, "*") == 0)
232 if (!strlen(event
) || strcmp(event
, "*") == 0)
236 return __ftrace_set_clr_event(match
, sub
, event
, set
);
240 * trace_set_clr_event - enable or disable an event
241 * @system: system name to match (NULL for any system)
242 * @event: event name to match (NULL for all events, within system)
243 * @set: 1 to enable, 0 to disable
245 * This is a way for other parts of the kernel to enable or disable
248 * Returns 0 on success, -EINVAL if the parameters do not match any
251 int trace_set_clr_event(const char *system
, const char *event
, int set
)
253 return __ftrace_set_clr_event(NULL
, system
, event
, set
);
256 /* 128 should be much more than enough */
257 #define EVENT_BUF_SIZE 127
260 ftrace_event_write(struct file
*file
, const char __user
*ubuf
,
261 size_t cnt
, loff_t
*ppos
)
263 struct trace_parser parser
;
269 ret
= tracing_update_buffers();
273 if (trace_parser_get_init(&parser
, EVENT_BUF_SIZE
+ 1))
276 read
= trace_get_user(&parser
, ubuf
, cnt
, ppos
);
278 if (read
>= 0 && trace_parser_loaded((&parser
))) {
281 if (*parser
.buffer
== '!')
284 parser
.buffer
[parser
.idx
] = 0;
286 ret
= ftrace_set_clr_event(parser
.buffer
+ !set
, set
);
294 trace_parser_put(&parser
);
300 t_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
302 struct ftrace_event_call
*call
= v
;
306 list_for_each_entry_continue(call
, &ftrace_events
, list
) {
308 * The ftrace subsystem is for showing formats only.
309 * They can not be enabled or disabled via the event files.
311 if (call
->class && (call
->class->probe
|| call
->class->reg
))
318 static void *t_start(struct seq_file
*m
, loff_t
*pos
)
320 struct ftrace_event_call
*call
;
323 mutex_lock(&event_mutex
);
325 call
= list_entry(&ftrace_events
, struct ftrace_event_call
, list
);
326 for (l
= 0; l
<= *pos
; ) {
327 call
= t_next(m
, call
, &l
);
335 s_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
337 struct ftrace_event_call
*call
= v
;
341 list_for_each_entry_continue(call
, &ftrace_events
, list
) {
349 static void *s_start(struct seq_file
*m
, loff_t
*pos
)
351 struct ftrace_event_call
*call
;
354 mutex_lock(&event_mutex
);
356 call
= list_entry(&ftrace_events
, struct ftrace_event_call
, list
);
357 for (l
= 0; l
<= *pos
; ) {
358 call
= s_next(m
, call
, &l
);
365 static int t_show(struct seq_file
*m
, void *v
)
367 struct ftrace_event_call
*call
= v
;
369 if (strcmp(call
->class->system
, TRACE_SYSTEM
) != 0)
370 seq_printf(m
, "%s:", call
->class->system
);
371 seq_printf(m
, "%s\n", call
->name
);
376 static void t_stop(struct seq_file
*m
, void *p
)
378 mutex_unlock(&event_mutex
);
382 ftrace_event_seq_open(struct inode
*inode
, struct file
*file
)
384 const struct seq_operations
*seq_ops
;
386 if ((file
->f_mode
& FMODE_WRITE
) &&
387 (file
->f_flags
& O_TRUNC
))
388 ftrace_clear_events();
390 seq_ops
= inode
->i_private
;
391 return seq_open(file
, seq_ops
);
395 event_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
398 struct ftrace_event_call
*call
= filp
->private_data
;
406 return simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
410 event_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
413 struct ftrace_event_call
*call
= filp
->private_data
;
418 if (cnt
>= sizeof(buf
))
421 if (copy_from_user(&buf
, ubuf
, cnt
))
426 ret
= strict_strtoul(buf
, 10, &val
);
430 ret
= tracing_update_buffers();
437 mutex_lock(&event_mutex
);
438 ret
= ftrace_event_enable_disable(call
, val
);
439 mutex_unlock(&event_mutex
);
448 return ret
? ret
: cnt
;
452 system_enable_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
455 const char set_to_char
[4] = { '?', '0', '1', 'X' };
456 const char *system
= filp
->private_data
;
457 struct ftrace_event_call
*call
;
462 mutex_lock(&event_mutex
);
463 list_for_each_entry(call
, &ftrace_events
, list
) {
464 if (!call
->name
|| !call
->class ||
465 (!call
->class->probe
&& !call
->class->reg
))
468 if (system
&& strcmp(call
->class->system
, system
) != 0)
472 * We need to find out if all the events are set
473 * or if all events or cleared, or if we have
476 set
|= (1 << !!call
->enabled
);
479 * If we have a mixture, no need to look further.
484 mutex_unlock(&event_mutex
);
486 buf
[0] = set_to_char
[set
];
489 ret
= simple_read_from_buffer(ubuf
, cnt
, ppos
, buf
, 2);
495 system_enable_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
498 const char *system
= filp
->private_data
;
503 if (cnt
>= sizeof(buf
))
506 if (copy_from_user(&buf
, ubuf
, cnt
))
511 ret
= strict_strtoul(buf
, 10, &val
);
515 ret
= tracing_update_buffers();
519 if (val
!= 0 && val
!= 1)
522 ret
= __ftrace_set_clr_event(NULL
, system
, NULL
, val
);
535 event_format_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
538 struct ftrace_event_call
*call
= filp
->private_data
;
539 struct ftrace_event_field
*field
;
541 int common_field_count
= 5;
548 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
554 trace_seq_printf(s
, "name: %s\n", call
->name
);
555 trace_seq_printf(s
, "ID: %d\n", call
->id
);
556 trace_seq_printf(s
, "format:\n");
558 list_for_each_entry_reverse(field
, &call
->fields
, link
) {
560 * Smartly shows the array type(except dynamic array).
563 * If TYPE := TYPE[LEN], it is shown:
564 * field:TYPE VAR[LEN]
566 const char *array_descriptor
= strchr(field
->type
, '[');
568 if (!strncmp(field
->type
, "__data_loc", 10))
569 array_descriptor
= NULL
;
571 if (!array_descriptor
) {
572 r
= trace_seq_printf(s
, "\tfield:%s %s;\toffset:%u;"
573 "\tsize:%u;\tsigned:%d;\n",
574 field
->type
, field
->name
, field
->offset
,
575 field
->size
, !!field
->is_signed
);
577 r
= trace_seq_printf(s
, "\tfield:%.*s %s%s;\toffset:%u;"
578 "\tsize:%u;\tsigned:%d;\n",
579 (int)(array_descriptor
- field
->type
),
580 field
->type
, field
->name
,
581 array_descriptor
, field
->offset
,
582 field
->size
, !!field
->is_signed
);
585 if (--common_field_count
== 0)
586 r
= trace_seq_printf(s
, "\n");
593 r
= trace_seq_printf(s
, "\nprint fmt: %s\n",
598 * ug! The format output is bigger than a PAGE!!
600 buf
= "FORMAT TOO BIG\n";
601 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
606 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
614 event_id_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
616 struct ftrace_event_call
*call
= filp
->private_data
;
623 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
628 trace_seq_printf(s
, "%d\n", call
->id
);
630 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
,
637 event_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
640 struct ftrace_event_call
*call
= filp
->private_data
;
647 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
653 print_event_filter(call
, s
);
654 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
662 event_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
665 struct ftrace_event_call
*call
= filp
->private_data
;
669 if (cnt
>= PAGE_SIZE
)
672 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
676 if (copy_from_user(buf
, ubuf
, cnt
)) {
677 free_page((unsigned long) buf
);
682 err
= apply_event_filter(call
, buf
);
683 free_page((unsigned long) buf
);
693 subsystem_filter_read(struct file
*filp
, char __user
*ubuf
, size_t cnt
,
696 struct event_subsystem
*system
= filp
->private_data
;
703 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
709 print_subsystem_event_filter(system
, s
);
710 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
718 subsystem_filter_write(struct file
*filp
, const char __user
*ubuf
, size_t cnt
,
721 struct event_subsystem
*system
= filp
->private_data
;
725 if (cnt
>= PAGE_SIZE
)
728 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
732 if (copy_from_user(buf
, ubuf
, cnt
)) {
733 free_page((unsigned long) buf
);
738 err
= apply_subsystem_event_filter(system
, buf
);
739 free_page((unsigned long) buf
);
749 show_header(struct file
*filp
, char __user
*ubuf
, size_t cnt
, loff_t
*ppos
)
751 int (*func
)(struct trace_seq
*s
) = filp
->private_data
;
758 s
= kmalloc(sizeof(*s
), GFP_KERNEL
);
765 r
= simple_read_from_buffer(ubuf
, cnt
, ppos
, s
->buffer
, s
->len
);
772 static const struct seq_operations show_event_seq_ops
= {
779 static const struct seq_operations show_set_event_seq_ops
= {
786 static const struct file_operations ftrace_avail_fops
= {
787 .open
= ftrace_event_seq_open
,
790 .release
= seq_release
,
793 static const struct file_operations ftrace_set_event_fops
= {
794 .open
= ftrace_event_seq_open
,
796 .write
= ftrace_event_write
,
798 .release
= seq_release
,
801 static const struct file_operations ftrace_enable_fops
= {
802 .open
= tracing_open_generic
,
803 .read
= event_enable_read
,
804 .write
= event_enable_write
,
807 static const struct file_operations ftrace_event_format_fops
= {
808 .open
= tracing_open_generic
,
809 .read
= event_format_read
,
812 static const struct file_operations ftrace_event_id_fops
= {
813 .open
= tracing_open_generic
,
814 .read
= event_id_read
,
817 static const struct file_operations ftrace_event_filter_fops
= {
818 .open
= tracing_open_generic
,
819 .read
= event_filter_read
,
820 .write
= event_filter_write
,
823 static const struct file_operations ftrace_subsystem_filter_fops
= {
824 .open
= tracing_open_generic
,
825 .read
= subsystem_filter_read
,
826 .write
= subsystem_filter_write
,
829 static const struct file_operations ftrace_system_enable_fops
= {
830 .open
= tracing_open_generic
,
831 .read
= system_enable_read
,
832 .write
= system_enable_write
,
835 static const struct file_operations ftrace_show_header_fops
= {
836 .open
= tracing_open_generic
,
840 static struct dentry
*event_trace_events_dir(void)
842 static struct dentry
*d_tracer
;
843 static struct dentry
*d_events
;
848 d_tracer
= tracing_init_dentry();
852 d_events
= debugfs_create_dir("events", d_tracer
);
854 pr_warning("Could not create debugfs "
855 "'events' directory\n");
860 static LIST_HEAD(event_subsystems
);
862 static struct dentry
*
863 event_subsystem_dir(const char *name
, struct dentry
*d_events
)
865 struct event_subsystem
*system
;
866 struct dentry
*entry
;
868 /* First see if we did not already create this dir */
869 list_for_each_entry(system
, &event_subsystems
, list
) {
870 if (strcmp(system
->name
, name
) == 0) {
872 return system
->entry
;
876 /* need to create new entry */
877 system
= kmalloc(sizeof(*system
), GFP_KERNEL
);
879 pr_warning("No memory to create event subsystem %s\n",
884 system
->entry
= debugfs_create_dir(name
, d_events
);
885 if (!system
->entry
) {
886 pr_warning("Could not create event subsystem %s\n",
892 system
->nr_events
= 1;
893 system
->name
= kstrdup(name
, GFP_KERNEL
);
895 debugfs_remove(system
->entry
);
900 list_add(&system
->list
, &event_subsystems
);
902 system
->filter
= NULL
;
904 system
->filter
= kzalloc(sizeof(struct event_filter
), GFP_KERNEL
);
905 if (!system
->filter
) {
906 pr_warning("Could not allocate filter for subsystem "
908 return system
->entry
;
911 entry
= debugfs_create_file("filter", 0644, system
->entry
, system
,
912 &ftrace_subsystem_filter_fops
);
914 kfree(system
->filter
);
915 system
->filter
= NULL
;
916 pr_warning("Could not create debugfs "
917 "'%s/filter' entry\n", name
);
920 trace_create_file("enable", 0644, system
->entry
,
921 (void *)system
->name
,
922 &ftrace_system_enable_fops
);
924 return system
->entry
;
928 event_create_dir(struct ftrace_event_call
*call
, struct dentry
*d_events
,
929 const struct file_operations
*id
,
930 const struct file_operations
*enable
,
931 const struct file_operations
*filter
,
932 const struct file_operations
*format
)
937 * If the trace point header did not define TRACE_SYSTEM
938 * then the system would be called "TRACE_SYSTEM".
940 if (strcmp(call
->class->system
, TRACE_SYSTEM
) != 0)
941 d_events
= event_subsystem_dir(call
->class->system
, d_events
);
943 call
->dir
= debugfs_create_dir(call
->name
, d_events
);
945 pr_warning("Could not create debugfs "
946 "'%s' directory\n", call
->name
);
950 if (call
->class->probe
|| call
->class->reg
)
951 trace_create_file("enable", 0644, call
->dir
, call
,
954 #ifdef CONFIG_PERF_EVENTS
955 if (call
->id
&& (call
->class->perf_probe
|| call
->class->reg
))
956 trace_create_file("id", 0444, call
->dir
, call
,
960 if (call
->define_fields
) {
961 ret
= trace_define_common_fields(call
);
963 ret
= call
->define_fields(call
);
965 pr_warning("Could not initialize trace point"
966 " events/%s\n", call
->name
);
969 trace_create_file("filter", 0644, call
->dir
, call
,
973 trace_create_file("format", 0444, call
->dir
, call
,
979 static int __trace_add_event_call(struct ftrace_event_call
*call
)
981 struct dentry
*d_events
;
987 if (call
->raw_init
) {
988 ret
= call
->raw_init(call
);
991 pr_warning("Could not initialize trace "
992 "events/%s\n", call
->name
);
997 d_events
= event_trace_events_dir();
1001 ret
= event_create_dir(call
, d_events
, &ftrace_event_id_fops
,
1002 &ftrace_enable_fops
, &ftrace_event_filter_fops
,
1003 &ftrace_event_format_fops
);
1005 list_add(&call
->list
, &ftrace_events
);
1010 /* Add an additional event_call dynamically */
1011 int trace_add_event_call(struct ftrace_event_call
*call
)
1014 mutex_lock(&event_mutex
);
1015 ret
= __trace_add_event_call(call
);
1016 mutex_unlock(&event_mutex
);
1020 static void remove_subsystem_dir(const char *name
)
1022 struct event_subsystem
*system
;
1024 if (strcmp(name
, TRACE_SYSTEM
) == 0)
1027 list_for_each_entry(system
, &event_subsystems
, list
) {
1028 if (strcmp(system
->name
, name
) == 0) {
1029 if (!--system
->nr_events
) {
1030 struct event_filter
*filter
= system
->filter
;
1032 debugfs_remove_recursive(system
->entry
);
1033 list_del(&system
->list
);
1035 kfree(filter
->filter_string
);
1038 kfree(system
->name
);
1047 * Must be called under locking both of event_mutex and trace_event_mutex.
1049 static void __trace_remove_event_call(struct ftrace_event_call
*call
)
1051 ftrace_event_enable_disable(call
, 0);
1053 __unregister_ftrace_event(call
->event
);
1054 debugfs_remove_recursive(call
->dir
);
1055 list_del(&call
->list
);
1056 trace_destroy_fields(call
);
1057 destroy_preds(call
);
1058 remove_subsystem_dir(call
->class->system
);
1061 /* Remove an event_call */
1062 void trace_remove_event_call(struct ftrace_event_call
*call
)
1064 mutex_lock(&event_mutex
);
1065 down_write(&trace_event_mutex
);
1066 __trace_remove_event_call(call
);
1067 up_write(&trace_event_mutex
);
1068 mutex_unlock(&event_mutex
);
1071 #define for_each_event(event, start, end) \
1072 for (event = start; \
1073 (unsigned long)event < (unsigned long)end; \
1076 #ifdef CONFIG_MODULES
1078 static LIST_HEAD(ftrace_module_file_list
);
1081 * Modules must own their file_operations to keep up with
1082 * reference counting.
1084 struct ftrace_module_file_ops
{
1085 struct list_head list
;
1087 struct file_operations id
;
1088 struct file_operations enable
;
1089 struct file_operations format
;
1090 struct file_operations filter
;
1093 static struct ftrace_module_file_ops
*
1094 trace_create_file_ops(struct module
*mod
)
1096 struct ftrace_module_file_ops
*file_ops
;
1099 * This is a bit of a PITA. To allow for correct reference
1100 * counting, modules must "own" their file_operations.
1101 * To do this, we allocate the file operations that will be
1102 * used in the event directory.
1105 file_ops
= kmalloc(sizeof(*file_ops
), GFP_KERNEL
);
1109 file_ops
->mod
= mod
;
1111 file_ops
->id
= ftrace_event_id_fops
;
1112 file_ops
->id
.owner
= mod
;
1114 file_ops
->enable
= ftrace_enable_fops
;
1115 file_ops
->enable
.owner
= mod
;
1117 file_ops
->filter
= ftrace_event_filter_fops
;
1118 file_ops
->filter
.owner
= mod
;
1120 file_ops
->format
= ftrace_event_format_fops
;
1121 file_ops
->format
.owner
= mod
;
1123 list_add(&file_ops
->list
, &ftrace_module_file_list
);
1128 static void trace_module_add_events(struct module
*mod
)
1130 struct ftrace_module_file_ops
*file_ops
= NULL
;
1131 struct ftrace_event_call
*call
, *start
, *end
;
1132 struct dentry
*d_events
;
1135 start
= mod
->trace_events
;
1136 end
= mod
->trace_events
+ mod
->num_trace_events
;
1141 d_events
= event_trace_events_dir();
1145 for_each_event(call
, start
, end
) {
1146 /* The linker may leave blanks */
1149 if (call
->raw_init
) {
1150 ret
= call
->raw_init(call
);
1153 pr_warning("Could not initialize trace "
1154 "point events/%s\n", call
->name
);
1159 * This module has events, create file ops for this module
1160 * if not already done.
1163 file_ops
= trace_create_file_ops(mod
);
1168 ret
= event_create_dir(call
, d_events
,
1169 &file_ops
->id
, &file_ops
->enable
,
1170 &file_ops
->filter
, &file_ops
->format
);
1172 list_add(&call
->list
, &ftrace_events
);
1176 static void trace_module_remove_events(struct module
*mod
)
1178 struct ftrace_module_file_ops
*file_ops
;
1179 struct ftrace_event_call
*call
, *p
;
1182 down_write(&trace_event_mutex
);
1183 list_for_each_entry_safe(call
, p
, &ftrace_events
, list
) {
1184 if (call
->mod
== mod
) {
1186 __trace_remove_event_call(call
);
1190 /* Now free the file_operations */
1191 list_for_each_entry(file_ops
, &ftrace_module_file_list
, list
) {
1192 if (file_ops
->mod
== mod
)
1195 if (&file_ops
->list
!= &ftrace_module_file_list
) {
1196 list_del(&file_ops
->list
);
1201 * It is safest to reset the ring buffer if the module being unloaded
1202 * registered any events.
1205 tracing_reset_current_online_cpus();
1206 up_write(&trace_event_mutex
);
1209 static int trace_module_notify(struct notifier_block
*self
,
1210 unsigned long val
, void *data
)
1212 struct module
*mod
= data
;
1214 mutex_lock(&event_mutex
);
1216 case MODULE_STATE_COMING
:
1217 trace_module_add_events(mod
);
1219 case MODULE_STATE_GOING
:
1220 trace_module_remove_events(mod
);
1223 mutex_unlock(&event_mutex
);
1228 static int trace_module_notify(struct notifier_block
*self
,
1229 unsigned long val
, void *data
)
1233 #endif /* CONFIG_MODULES */
1235 static struct notifier_block trace_module_nb
= {
1236 .notifier_call
= trace_module_notify
,
1240 extern struct ftrace_event_call __start_ftrace_events
[];
1241 extern struct ftrace_event_call __stop_ftrace_events
[];
1243 static char bootup_event_buf
[COMMAND_LINE_SIZE
] __initdata
;
1245 static __init
int setup_trace_event(char *str
)
1247 strlcpy(bootup_event_buf
, str
, COMMAND_LINE_SIZE
);
1248 ring_buffer_expanded
= 1;
1249 tracing_selftest_disabled
= 1;
1253 __setup("trace_event=", setup_trace_event
);
1255 static __init
int event_trace_init(void)
1257 struct ftrace_event_call
*call
;
1258 struct dentry
*d_tracer
;
1259 struct dentry
*entry
;
1260 struct dentry
*d_events
;
1262 char *buf
= bootup_event_buf
;
1265 d_tracer
= tracing_init_dentry();
1269 entry
= debugfs_create_file("available_events", 0444, d_tracer
,
1270 (void *)&show_event_seq_ops
,
1271 &ftrace_avail_fops
);
1273 pr_warning("Could not create debugfs "
1274 "'available_events' entry\n");
1276 entry
= debugfs_create_file("set_event", 0644, d_tracer
,
1277 (void *)&show_set_event_seq_ops
,
1278 &ftrace_set_event_fops
);
1280 pr_warning("Could not create debugfs "
1281 "'set_event' entry\n");
1283 d_events
= event_trace_events_dir();
1287 /* ring buffer internal formats */
1288 trace_create_file("header_page", 0444, d_events
,
1289 ring_buffer_print_page_header
,
1290 &ftrace_show_header_fops
);
1292 trace_create_file("header_event", 0444, d_events
,
1293 ring_buffer_print_entry_header
,
1294 &ftrace_show_header_fops
);
1296 trace_create_file("enable", 0644, d_events
,
1297 NULL
, &ftrace_system_enable_fops
);
1299 for_each_event(call
, __start_ftrace_events
, __stop_ftrace_events
) {
1300 /* The linker may leave blanks */
1303 if (call
->raw_init
) {
1304 ret
= call
->raw_init(call
);
1307 pr_warning("Could not initialize trace "
1308 "point events/%s\n", call
->name
);
1312 ret
= event_create_dir(call
, d_events
, &ftrace_event_id_fops
,
1313 &ftrace_enable_fops
,
1314 &ftrace_event_filter_fops
,
1315 &ftrace_event_format_fops
);
1317 list_add(&call
->list
, &ftrace_events
);
1321 token
= strsep(&buf
, ",");
1328 ret
= ftrace_set_clr_event(token
, 1);
1330 pr_warning("Failed to enable trace event: %s\n", token
);
1333 ret
= register_module_notifier(&trace_module_nb
);
1335 pr_warning("Failed to register trace events module notifier\n");
1339 fs_initcall(event_trace_init
);
1341 #ifdef CONFIG_FTRACE_STARTUP_TEST
1343 static DEFINE_SPINLOCK(test_spinlock
);
1344 static DEFINE_SPINLOCK(test_spinlock_irq
);
1345 static DEFINE_MUTEX(test_mutex
);
1347 static __init
void test_work(struct work_struct
*dummy
)
1349 spin_lock(&test_spinlock
);
1350 spin_lock_irq(&test_spinlock_irq
);
1352 spin_unlock_irq(&test_spinlock_irq
);
1353 spin_unlock(&test_spinlock
);
1355 mutex_lock(&test_mutex
);
1357 mutex_unlock(&test_mutex
);
1360 static __init
int event_test_thread(void *unused
)
1364 test_malloc
= kmalloc(1234, GFP_KERNEL
);
1366 pr_info("failed to kmalloc\n");
1368 schedule_on_each_cpu(test_work
);
1372 set_current_state(TASK_INTERRUPTIBLE
);
1373 while (!kthread_should_stop())
1380 * Do various things that may trigger events.
1382 static __init
void event_test_stuff(void)
1384 struct task_struct
*test_thread
;
1386 test_thread
= kthread_run(event_test_thread
, NULL
, "test-events");
1388 kthread_stop(test_thread
);
1392 * For every trace event defined, we will test each trace point separately,
1393 * and then by groups, and finally all trace points.
1395 static __init
void event_trace_self_tests(void)
1397 struct ftrace_event_call
*call
;
1398 struct event_subsystem
*system
;
1401 pr_info("Running tests on trace events:\n");
1403 list_for_each_entry(call
, &ftrace_events
, list
) {
1405 /* Only test those that have a probe */
1406 if (!call
->class || !call
->class->probe
)
1410 * Testing syscall events here is pretty useless, but
1411 * we still do it if configured. But this is time consuming.
1412 * What we really need is a user thread to perform the
1413 * syscalls as we test.
1415 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
1416 if (call
->class->system
&&
1417 strcmp(call
->class->system
, "syscalls") == 0)
1421 pr_info("Testing event %s: ", call
->name
);
1424 * If an event is already enabled, someone is using
1425 * it and the self test should not be on.
1427 if (call
->enabled
) {
1428 pr_warning("Enabled event during self test!\n");
1433 ftrace_event_enable_disable(call
, 1);
1435 ftrace_event_enable_disable(call
, 0);
1440 /* Now test at the sub system level */
1442 pr_info("Running tests on trace event systems:\n");
1444 list_for_each_entry(system
, &event_subsystems
, list
) {
1446 /* the ftrace system is special, skip it */
1447 if (strcmp(system
->name
, "ftrace") == 0)
1450 pr_info("Testing event system %s: ", system
->name
);
1452 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 1);
1453 if (WARN_ON_ONCE(ret
)) {
1454 pr_warning("error enabling system %s\n",
1461 ret
= __ftrace_set_clr_event(NULL
, system
->name
, NULL
, 0);
1462 if (WARN_ON_ONCE(ret
))
1463 pr_warning("error disabling system %s\n",
1469 /* Test with all events enabled */
1471 pr_info("Running tests on all trace events:\n");
1472 pr_info("Testing all events: ");
1474 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 1);
1475 if (WARN_ON_ONCE(ret
)) {
1476 pr_warning("error enabling all events\n");
1483 ret
= __ftrace_set_clr_event(NULL
, NULL
, NULL
, 0);
1484 if (WARN_ON_ONCE(ret
)) {
1485 pr_warning("error disabling all events\n");
1492 #ifdef CONFIG_FUNCTION_TRACER
1494 static DEFINE_PER_CPU(atomic_t
, ftrace_test_event_disable
);
1497 function_test_events_call(unsigned long ip
, unsigned long parent_ip
)
1499 struct ring_buffer_event
*event
;
1500 struct ring_buffer
*buffer
;
1501 struct ftrace_entry
*entry
;
1502 unsigned long flags
;
1508 pc
= preempt_count();
1509 resched
= ftrace_preempt_disable();
1510 cpu
= raw_smp_processor_id();
1511 disabled
= atomic_inc_return(&per_cpu(ftrace_test_event_disable
, cpu
));
1516 local_save_flags(flags
);
1518 event
= trace_current_buffer_lock_reserve(&buffer
,
1519 TRACE_FN
, sizeof(*entry
),
1523 entry
= ring_buffer_event_data(event
);
1525 entry
->parent_ip
= parent_ip
;
1527 trace_nowake_buffer_unlock_commit(buffer
, event
, flags
, pc
);
1530 atomic_dec(&per_cpu(ftrace_test_event_disable
, cpu
));
1531 ftrace_preempt_enable(resched
);
1534 static struct ftrace_ops trace_ops __initdata
=
1536 .func
= function_test_events_call
,
1539 static __init
void event_trace_self_test_with_function(void)
1541 register_ftrace_function(&trace_ops
);
1542 pr_info("Running tests again, along with the function tracer\n");
1543 event_trace_self_tests();
1544 unregister_ftrace_function(&trace_ops
);
1547 static __init
void event_trace_self_test_with_function(void)
1552 static __init
int event_trace_self_tests_init(void)
1554 if (!tracing_selftest_disabled
) {
1555 event_trace_self_tests();
1556 event_trace_self_test_with_function();
1562 late_initcall(event_trace_self_tests_init
);