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 "trace_output.h"
22 #define TRACE_SYSTEM "TRACE_SYSTEM"
24 DEFINE_MUTEX(event_mutex);
26 LIST_HEAD(ftrace_events);
28 int trace_define_field(struct ftrace_event_call *call, char *type,
29 char *name, int offset, int size, int is_signed)
31 struct ftrace_event_field *field;
33 field = kzalloc(sizeof(*field), GFP_KERNEL);
37 field->name = kstrdup(name, GFP_KERNEL);
41 field->type = kstrdup(type, GFP_KERNEL);
45 field->offset = offset;
47 field->is_signed = is_signed;
48 list_add(&field->link, &call->fields);
61 EXPORT_SYMBOL_GPL(trace_define_field);
65 static void trace_destroy_fields(struct ftrace_event_call *call)
67 struct ftrace_event_field *field, *next;
69 list_for_each_entry_safe(field, next, &call->fields, link) {
70 list_del(&field->link);
77 #endif /* CONFIG_MODULES */
79 static void ftrace_clear_events(void)
81 struct ftrace_event_call *call;
83 mutex_lock(&event_mutex);
84 list_for_each_entry(call, &ftrace_events, list) {
91 mutex_unlock(&event_mutex);
94 static void ftrace_event_enable_disable(struct ftrace_event_call *call,
106 if (!call->enabled) {
114 static int ftrace_set_clr_event(char *buf, int set)
116 struct ftrace_event_call *call;
117 char *event = NULL, *sub = NULL, *match;
121 * The buf format can be <subsystem>:<event-name>
122 * *:<event-name> means any event by that name.
123 * :<event-name> is the same.
125 * <subsystem>:* means all events in that subsystem
126 * <subsystem>: means the same.
128 * <name> (no ':') means all events in a subsystem with
129 * the name <name> or any event that matches <name>
132 match = strsep(&buf, ":");
138 if (!strlen(sub) || strcmp(sub, "*") == 0)
140 if (!strlen(event) || strcmp(event, "*") == 0)
144 mutex_lock(&event_mutex);
145 list_for_each_entry(call, &ftrace_events, list) {
147 if (!call->name || !call->regfunc)
151 strcmp(match, call->name) != 0 &&
152 strcmp(match, call->system) != 0)
155 if (sub && strcmp(sub, call->system) != 0)
158 if (event && strcmp(event, call->name) != 0)
161 ftrace_event_enable_disable(call, set);
165 mutex_unlock(&event_mutex);
170 /* 128 should be much more than enough */
171 #define EVENT_BUF_SIZE 127
174 ftrace_event_write(struct file *file, const char __user *ubuf,
175 size_t cnt, loff_t *ppos)
186 ret = tracing_update_buffers();
190 ret = get_user(ch, ubuf++);
196 /* skip white space */
197 while (cnt && isspace(ch)) {
198 ret = get_user(ch, ubuf++);
205 /* Only white space found? */
212 buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL);
216 if (cnt > EVENT_BUF_SIZE)
217 cnt = EVENT_BUF_SIZE;
220 while (cnt && !isspace(ch)) {
226 ret = get_user(ch, ubuf++);
236 ret = ftrace_set_clr_event(buf, set);
249 t_next(struct seq_file *m, void *v, loff_t *pos)
251 struct list_head *list = m->private;
252 struct ftrace_event_call *call;
257 if (list == &ftrace_events)
260 call = list_entry(list, struct ftrace_event_call, list);
263 * The ftrace subsystem is for showing formats only.
264 * They can not be enabled or disabled via the event files.
272 m->private = list->next;
277 static void *t_start(struct seq_file *m, loff_t *pos)
279 mutex_lock(&event_mutex);
281 m->private = ftrace_events.next;
282 return t_next(m, NULL, pos);
286 s_next(struct seq_file *m, void *v, loff_t *pos)
288 struct list_head *list = m->private;
289 struct ftrace_event_call *call;
294 if (list == &ftrace_events)
297 call = list_entry(list, struct ftrace_event_call, list);
299 if (!call->enabled) {
304 m->private = list->next;
309 static void *s_start(struct seq_file *m, loff_t *pos)
311 mutex_lock(&event_mutex);
313 m->private = ftrace_events.next;
314 return s_next(m, NULL, pos);
317 static int t_show(struct seq_file *m, void *v)
319 struct ftrace_event_call *call = v;
321 if (strcmp(call->system, TRACE_SYSTEM) != 0)
322 seq_printf(m, "%s:", call->system);
323 seq_printf(m, "%s\n", call->name);
328 static void t_stop(struct seq_file *m, void *p)
330 mutex_unlock(&event_mutex);
334 ftrace_event_seq_open(struct inode *inode, struct file *file)
336 const struct seq_operations *seq_ops;
338 if ((file->f_mode & FMODE_WRITE) &&
339 !(file->f_flags & O_APPEND))
340 ftrace_clear_events();
342 seq_ops = inode->i_private;
343 return seq_open(file, seq_ops);
347 event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
350 struct ftrace_event_call *call = filp->private_data;
358 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
362 event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
365 struct ftrace_event_call *call = filp->private_data;
370 if (cnt >= sizeof(buf))
373 if (copy_from_user(&buf, ubuf, cnt))
378 ret = strict_strtoul(buf, 10, &val);
382 ret = tracing_update_buffers();
389 mutex_lock(&event_mutex);
390 ftrace_event_enable_disable(call, val);
391 mutex_unlock(&event_mutex);
404 system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
407 const char *system = filp->private_data;
408 struct ftrace_event_call *call;
414 if (system[0] == '*')
417 mutex_lock(&event_mutex);
418 list_for_each_entry(call, &ftrace_events, list) {
419 if (!call->name || !call->regfunc)
422 if (!all && strcmp(call->system, system) != 0)
426 * We need to find out if all the events are set
427 * or if all events or cleared, or if we have
450 * If we have a mixture, no need to look further.
455 mutex_unlock(&event_mutex);
472 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
478 system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
481 const char *system = filp->private_data;
487 if (cnt >= sizeof(buf))
490 if (copy_from_user(&buf, ubuf, cnt))
495 ret = strict_strtoul(buf, 10, &val);
499 ret = tracing_update_buffers();
512 /* +3 for the ":*\0" */
513 command = kmalloc(strlen(system)+3, GFP_KERNEL);
516 sprintf(command, "%s:*", system);
518 ret = ftrace_set_clr_event(command, val);
532 extern char *__bad_type_size(void);
535 #define FIELD(type, name) \
536 sizeof(type) != sizeof(field.name) ? __bad_type_size() : \
537 #type, "common_" #name, offsetof(typeof(field), name), \
540 static int trace_write_header(struct trace_seq *s)
542 struct trace_entry field;
544 /* struct trace_entry */
545 return trace_seq_printf(s,
546 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
547 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
548 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
549 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
550 "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
552 FIELD(unsigned short, type),
553 FIELD(unsigned char, flags),
554 FIELD(unsigned char, preempt_count),
560 event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
563 struct ftrace_event_call *call = filp->private_data;
571 s = kmalloc(sizeof(*s), GFP_KERNEL);
577 /* If any of the first writes fail, so will the show_format. */
579 trace_seq_printf(s, "name: %s\n", call->name);
580 trace_seq_printf(s, "ID: %d\n", call->id);
581 trace_seq_printf(s, "format:\n");
582 trace_write_header(s);
584 r = call->show_format(s);
587 * ug! The format output is bigger than a PAGE!!
589 buf = "FORMAT TOO BIG\n";
590 r = simple_read_from_buffer(ubuf, cnt, ppos,
595 r = simple_read_from_buffer(ubuf, cnt, ppos,
603 event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
605 struct ftrace_event_call *call = filp->private_data;
612 s = kmalloc(sizeof(*s), GFP_KERNEL);
617 trace_seq_printf(s, "%d\n", call->id);
619 r = simple_read_from_buffer(ubuf, cnt, ppos,
626 event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
629 struct ftrace_event_call *call = filp->private_data;
636 s = kmalloc(sizeof(*s), GFP_KERNEL);
642 print_event_filter(call, s);
643 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
651 event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
654 struct ftrace_event_call *call = filp->private_data;
658 if (cnt >= PAGE_SIZE)
661 buf = (char *)__get_free_page(GFP_TEMPORARY);
665 if (copy_from_user(buf, ubuf, cnt)) {
666 free_page((unsigned long) buf);
671 err = apply_event_filter(call, buf);
672 free_page((unsigned long) buf);
682 subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
685 struct event_subsystem *system = filp->private_data;
692 s = kmalloc(sizeof(*s), GFP_KERNEL);
698 print_subsystem_event_filter(system, s);
699 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
707 subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
710 struct event_subsystem *system = filp->private_data;
714 if (cnt >= PAGE_SIZE)
717 buf = (char *)__get_free_page(GFP_TEMPORARY);
721 if (copy_from_user(buf, ubuf, cnt)) {
722 free_page((unsigned long) buf);
727 err = apply_subsystem_event_filter(system, buf);
728 free_page((unsigned long) buf);
738 show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
740 int (*func)(struct trace_seq *s) = filp->private_data;
747 s = kmalloc(sizeof(*s), GFP_KERNEL);
754 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
761 static const struct seq_operations show_event_seq_ops = {
768 static const struct seq_operations show_set_event_seq_ops = {
775 static const struct file_operations ftrace_avail_fops = {
776 .open = ftrace_event_seq_open,
779 .release = seq_release,
782 static const struct file_operations ftrace_set_event_fops = {
783 .open = ftrace_event_seq_open,
785 .write = ftrace_event_write,
787 .release = seq_release,
790 static const struct file_operations ftrace_enable_fops = {
791 .open = tracing_open_generic,
792 .read = event_enable_read,
793 .write = event_enable_write,
796 static const struct file_operations ftrace_event_format_fops = {
797 .open = tracing_open_generic,
798 .read = event_format_read,
801 static const struct file_operations ftrace_event_id_fops = {
802 .open = tracing_open_generic,
803 .read = event_id_read,
806 static const struct file_operations ftrace_event_filter_fops = {
807 .open = tracing_open_generic,
808 .read = event_filter_read,
809 .write = event_filter_write,
812 static const struct file_operations ftrace_subsystem_filter_fops = {
813 .open = tracing_open_generic,
814 .read = subsystem_filter_read,
815 .write = subsystem_filter_write,
818 static const struct file_operations ftrace_system_enable_fops = {
819 .open = tracing_open_generic,
820 .read = system_enable_read,
821 .write = system_enable_write,
824 static const struct file_operations ftrace_show_header_fops = {
825 .open = tracing_open_generic,
829 static struct dentry *event_trace_events_dir(void)
831 static struct dentry *d_tracer;
832 static struct dentry *d_events;
837 d_tracer = tracing_init_dentry();
841 d_events = debugfs_create_dir("events", d_tracer);
843 pr_warning("Could not create debugfs "
844 "'events' directory\n");
849 static LIST_HEAD(event_subsystems);
851 static struct dentry *
852 event_subsystem_dir(const char *name, struct dentry *d_events)
854 struct event_subsystem *system;
855 struct dentry *entry;
857 /* First see if we did not already create this dir */
858 list_for_each_entry(system, &event_subsystems, list) {
859 if (strcmp(system->name, name) == 0)
860 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->name = kstrdup(name, GFP_KERNEL);
881 debugfs_remove(system->entry);
886 list_add(&system->list, &event_subsystems);
888 system->filter = NULL;
890 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
891 if (!system->filter) {
892 pr_warning("Could not allocate filter for subsystem "
894 return system->entry;
897 entry = debugfs_create_file("filter", 0644, system->entry, system,
898 &ftrace_subsystem_filter_fops);
900 kfree(system->filter);
901 system->filter = NULL;
902 pr_warning("Could not create debugfs "
903 "'%s/filter' entry\n", name);
906 entry = trace_create_file("enable", 0644, system->entry,
907 (void *)system->name,
908 &ftrace_system_enable_fops);
910 return system->entry;
914 event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
915 const struct file_operations *id,
916 const struct file_operations *enable,
917 const struct file_operations *filter,
918 const struct file_operations *format)
920 struct dentry *entry;
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 if (call->raw_init) {
931 ret = call->raw_init();
933 pr_warning("Could not initialize trace point"
934 " events/%s\n", call->name);
939 call->dir = debugfs_create_dir(call->name, d_events);
941 pr_warning("Could not create debugfs "
942 "'%s' directory\n", call->name);
947 entry = trace_create_file("enable", 0644, call->dir, call,
951 entry = trace_create_file("id", 0444, call->dir, call,
954 if (call->define_fields) {
955 ret = call->define_fields();
957 pr_warning("Could not initialize trace point"
958 " events/%s\n", call->name);
961 entry = trace_create_file("filter", 0644, call->dir, call,
965 /* A trace may not want to export its format */
966 if (!call->show_format)
969 entry = trace_create_file("format", 0444, call->dir, call,
975 #define for_each_event(event, start, end) \
976 for (event = start; \
977 (unsigned long)event < (unsigned long)end; \
980 #ifdef CONFIG_MODULES
982 static LIST_HEAD(ftrace_module_file_list);
985 * Modules must own their file_operations to keep up with
986 * reference counting.
988 struct ftrace_module_file_ops {
989 struct list_head list;
991 struct file_operations id;
992 struct file_operations enable;
993 struct file_operations format;
994 struct file_operations filter;
997 static struct ftrace_module_file_ops *
998 trace_create_file_ops(struct module *mod)
1000 struct ftrace_module_file_ops *file_ops;
1003 * This is a bit of a PITA. To allow for correct reference
1004 * counting, modules must "own" their file_operations.
1005 * To do this, we allocate the file operations that will be
1006 * used in the event directory.
1009 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1013 file_ops->mod = mod;
1015 file_ops->id = ftrace_event_id_fops;
1016 file_ops->id.owner = mod;
1018 file_ops->enable = ftrace_enable_fops;
1019 file_ops->enable.owner = mod;
1021 file_ops->filter = ftrace_event_filter_fops;
1022 file_ops->filter.owner = mod;
1024 file_ops->format = ftrace_event_format_fops;
1025 file_ops->format.owner = mod;
1027 list_add(&file_ops->list, &ftrace_module_file_list);
1032 static void trace_module_add_events(struct module *mod)
1034 struct ftrace_module_file_ops *file_ops = NULL;
1035 struct ftrace_event_call *call, *start, *end;
1036 struct dentry *d_events;
1038 start = mod->trace_events;
1039 end = mod->trace_events + mod->num_trace_events;
1044 d_events = event_trace_events_dir();
1048 for_each_event(call, start, end) {
1049 /* The linker may leave blanks */
1054 * This module has events, create file ops for this module
1055 * if not already done.
1058 file_ops = trace_create_file_ops(mod);
1063 list_add(&call->list, &ftrace_events);
1064 event_create_dir(call, d_events,
1065 &file_ops->id, &file_ops->enable,
1066 &file_ops->filter, &file_ops->format);
1070 static void trace_module_remove_events(struct module *mod)
1072 struct ftrace_module_file_ops *file_ops;
1073 struct ftrace_event_call *call, *p;
1076 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1077 if (call->mod == mod) {
1079 if (call->enabled) {
1084 unregister_ftrace_event(call->event);
1085 debugfs_remove_recursive(call->dir);
1086 list_del(&call->list);
1087 trace_destroy_fields(call);
1088 destroy_preds(call);
1092 /* Now free the file_operations */
1093 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1094 if (file_ops->mod == mod)
1097 if (&file_ops->list != &ftrace_module_file_list) {
1098 list_del(&file_ops->list);
1103 * It is safest to reset the ring buffer if the module being unloaded
1104 * registered any events.
1107 tracing_reset_current_online_cpus();
1110 static int trace_module_notify(struct notifier_block *self,
1111 unsigned long val, void *data)
1113 struct module *mod = data;
1115 mutex_lock(&event_mutex);
1117 case MODULE_STATE_COMING:
1118 trace_module_add_events(mod);
1120 case MODULE_STATE_GOING:
1121 trace_module_remove_events(mod);
1124 mutex_unlock(&event_mutex);
1129 static int trace_module_notify(struct notifier_block *self,
1130 unsigned long val, void *data)
1134 #endif /* CONFIG_MODULES */
1136 struct notifier_block trace_module_nb = {
1137 .notifier_call = trace_module_notify,
1141 extern struct ftrace_event_call __start_ftrace_events[];
1142 extern struct ftrace_event_call __stop_ftrace_events[];
1144 static __init int event_trace_init(void)
1146 struct ftrace_event_call *call;
1147 struct dentry *d_tracer;
1148 struct dentry *entry;
1149 struct dentry *d_events;
1152 d_tracer = tracing_init_dentry();
1156 entry = debugfs_create_file("available_events", 0444, d_tracer,
1157 (void *)&show_event_seq_ops,
1158 &ftrace_avail_fops);
1160 pr_warning("Could not create debugfs "
1161 "'available_events' entry\n");
1163 entry = debugfs_create_file("set_event", 0644, d_tracer,
1164 (void *)&show_set_event_seq_ops,
1165 &ftrace_set_event_fops);
1167 pr_warning("Could not create debugfs "
1168 "'set_event' entry\n");
1170 d_events = event_trace_events_dir();
1174 /* ring buffer internal formats */
1175 trace_create_file("header_page", 0444, d_events,
1176 ring_buffer_print_page_header,
1177 &ftrace_show_header_fops);
1179 trace_create_file("header_event", 0444, d_events,
1180 ring_buffer_print_entry_header,
1181 &ftrace_show_header_fops);
1183 trace_create_file("enable", 0644, d_events,
1184 "*", &ftrace_system_enable_fops);
1186 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
1187 /* The linker may leave blanks */
1190 list_add(&call->list, &ftrace_events);
1191 event_create_dir(call, d_events, &ftrace_event_id_fops,
1192 &ftrace_enable_fops, &ftrace_event_filter_fops,
1193 &ftrace_event_format_fops);
1196 ret = register_module_notifier(&trace_module_nb);
1198 pr_warning("Failed to register trace events module notifier\n");
1202 fs_initcall(event_trace_init);
1204 #ifdef CONFIG_FTRACE_STARTUP_TEST
1206 static DEFINE_SPINLOCK(test_spinlock);
1207 static DEFINE_SPINLOCK(test_spinlock_irq);
1208 static DEFINE_MUTEX(test_mutex);
1210 static __init void test_work(struct work_struct *dummy)
1212 spin_lock(&test_spinlock);
1213 spin_lock_irq(&test_spinlock_irq);
1215 spin_unlock_irq(&test_spinlock_irq);
1216 spin_unlock(&test_spinlock);
1218 mutex_lock(&test_mutex);
1220 mutex_unlock(&test_mutex);
1223 static __init int event_test_thread(void *unused)
1227 test_malloc = kmalloc(1234, GFP_KERNEL);
1229 pr_info("failed to kmalloc\n");
1231 schedule_on_each_cpu(test_work);
1235 set_current_state(TASK_INTERRUPTIBLE);
1236 while (!kthread_should_stop())
1243 * Do various things that may trigger events.
1245 static __init void event_test_stuff(void)
1247 struct task_struct *test_thread;
1249 test_thread = kthread_run(event_test_thread, NULL, "test-events");
1251 kthread_stop(test_thread);
1255 * For every trace event defined, we will test each trace point separately,
1256 * and then by groups, and finally all trace points.
1258 static __init void event_trace_self_tests(void)
1260 struct ftrace_event_call *call;
1261 struct event_subsystem *system;
1265 pr_info("Running tests on trace events:\n");
1267 list_for_each_entry(call, &ftrace_events, list) {
1269 /* Only test those that have a regfunc */
1273 pr_info("Testing event %s: ", call->name);
1276 * If an event is already enabled, someone is using
1277 * it and the self test should not be on.
1279 if (call->enabled) {
1280 pr_warning("Enabled event during self test!\n");
1296 /* Now test at the sub system level */
1298 pr_info("Running tests on trace event systems:\n");
1300 list_for_each_entry(system, &event_subsystems, list) {
1302 /* the ftrace system is special, skip it */
1303 if (strcmp(system->name, "ftrace") == 0)
1306 pr_info("Testing event system %s: ", system->name);
1308 /* ftrace_set_clr_event can modify the name passed in. */
1309 sysname = kstrdup(system->name, GFP_KERNEL);
1310 if (WARN_ON(!sysname)) {
1311 pr_warning("Can't allocate memory, giving up!\n");
1314 ret = ftrace_set_clr_event(sysname, 1);
1316 if (WARN_ON_ONCE(ret)) {
1317 pr_warning("error enabling system %s\n",
1324 sysname = kstrdup(system->name, GFP_KERNEL);
1325 if (WARN_ON(!sysname)) {
1326 pr_warning("Can't allocate memory, giving up!\n");
1329 ret = ftrace_set_clr_event(sysname, 0);
1332 if (WARN_ON_ONCE(ret))
1333 pr_warning("error disabling system %s\n",
1339 /* Test with all events enabled */
1341 pr_info("Running tests on all trace events:\n");
1342 pr_info("Testing all events: ");
1344 sysname = kmalloc(4, GFP_KERNEL);
1345 if (WARN_ON(!sysname)) {
1346 pr_warning("Can't allocate memory, giving up!\n");
1349 memcpy(sysname, "*:*", 4);
1350 ret = ftrace_set_clr_event(sysname, 1);
1351 if (WARN_ON_ONCE(ret)) {
1353 pr_warning("error enabling all events\n");
1360 memcpy(sysname, "*:*", 4);
1361 ret = ftrace_set_clr_event(sysname, 0);
1364 if (WARN_ON_ONCE(ret)) {
1365 pr_warning("error disabling all events\n");
1372 #ifdef CONFIG_FUNCTION_TRACER
1374 static DEFINE_PER_CPU(atomic_t, test_event_disable);
1377 function_test_events_call(unsigned long ip, unsigned long parent_ip)
1379 struct ring_buffer_event *event;
1380 struct ftrace_entry *entry;
1381 unsigned long flags;
1387 pc = preempt_count();
1388 resched = ftrace_preempt_disable();
1389 cpu = raw_smp_processor_id();
1390 disabled = atomic_inc_return(&per_cpu(test_event_disable, cpu));
1395 local_save_flags(flags);
1397 event = trace_current_buffer_lock_reserve(TRACE_FN, sizeof(*entry),
1401 entry = ring_buffer_event_data(event);
1403 entry->parent_ip = parent_ip;
1405 trace_nowake_buffer_unlock_commit(event, flags, pc);
1408 atomic_dec(&per_cpu(test_event_disable, cpu));
1409 ftrace_preempt_enable(resched);
1412 static struct ftrace_ops trace_ops __initdata =
1414 .func = function_test_events_call,
1417 static __init void event_trace_self_test_with_function(void)
1419 register_ftrace_function(&trace_ops);
1420 pr_info("Running tests again, along with the function tracer\n");
1421 event_trace_self_tests();
1422 unregister_ftrace_function(&trace_ops);
1425 static __init void event_trace_self_test_with_function(void)
1430 static __init int event_trace_self_tests_init(void)
1433 event_trace_self_tests();
1435 event_trace_self_test_with_function();
1440 late_initcall(event_trace_self_tests_init);