16 #include <linux/module.h>
17 #include <linux/ctype.h>
18 #include <linux/slab.h>
21 #include <asm/setup.h>
26 #define TRACE_SYSTEM "TRACE_SYSTEM"
42 if (!event_call->
class->get_fields)
43 return &event_call->
class->fields;
44 return event_call->
class->get_fields(event_call);
74 list_add(&field->
link, head);
87 const char *name,
int offset,
int size,
int is_signed,
96 return __trace_define_field(head, type, name, offset, size,
97 is_signed, filter_type);
101 #define __common_field(type, item) \
102 ret = __trace_define_field(&ftrace_common_fields, #type, \
104 offsetof(typeof(ent), item), \
106 is_signed_type(type), FILTER_OTHER); \
110 static int trace_define_common_fields(
void)
164 #ifdef CONFIG_PERF_EVENTS
165 case TRACE_REG_PERF_REGISTER:
167 call->
class->perf_probe,
169 case TRACE_REG_PERF_UNREGISTER:
171 call->
class->perf_probe,
174 case TRACE_REG_PERF_OPEN:
175 case TRACE_REG_PERF_CLOSE:
176 case TRACE_REG_PERF_ADD:
177 case TRACE_REG_PERF_DEL:
230 pr_info(
"event trace: Could not enable event "
242 static void ftrace_clear_events(
void)
248 ftrace_event_enable_disable(call, 0);
278 __put_system(system);
285 static int __ftrace_set_clr_event(
const char *
match,
const char *sub,
286 const char *
event,
int set)
311 ftrace_event_enable_disable(call,
set);
320 static int ftrace_set_clr_event(
char *
buf,
int set)
336 match =
strsep(&buf,
":");
348 return __ftrace_set_clr_event(match, sub, event,
set);
365 return __ftrace_set_clr_event(
NULL, system, event,
set);
370 #define EVENT_BUF_SIZE 127
373 ftrace_event_write(
struct file *
file,
const char __user *ubuf,
374 size_t cnt, loff_t *ppos)
391 if (read >= 0 && trace_parser_loaded((&parser))) {
394 if (*parser.
buffer ==
'!')
399 ret = ftrace_set_clr_event(parser.
buffer + !
set,
set);
431 static void *t_start(
struct seq_file *m, loff_t *pos)
439 for (l = 0; l <= *
pos; ) {
440 call = t_next(m, call, &l);
448 s_next(
struct seq_file *m,
void *v, loff_t *pos)
462 static void *s_start(
struct seq_file *m, loff_t *pos)
470 for (l = 0; l <= *
pos; ) {
471 call = s_next(m, call, &l);
478 static int t_show(
struct seq_file *m,
void *v)
489 static void t_stop(
struct seq_file *m,
void *
p)
501 ftrace_clear_events();
508 event_enable_read(
struct file *filp,
char __user *ubuf,
size_t cnt,
523 event_enable_write(
struct file *filp,
const char __user *ubuf,
size_t cnt,
542 ret = ftrace_event_enable_disable(call, val);
552 return ret ? ret :
cnt;
556 system_enable_read(
struct file *filp,
char __user *ubuf,
size_t cnt,
559 const char set_to_char[4] = {
'?',
'0',
'1',
'X' };
589 buf[0] = set_to_char[
set];
598 system_enable_write(
struct file *filp,
const char __user *ubuf,
size_t cnt,
602 const char *name =
NULL;
614 if (val != 0 && val != 1)
624 ret = __ftrace_set_clr_event(
NULL, name,
NULL, val);
642 static void *f_next(
struct seq_file *m,
void *v, loff_t *pos)
651 switch ((
unsigned long)v) {
653 if (
unlikely(list_empty(common_head)))
673 if (field->
link.prev == common_head)
675 else if (field->
link.prev == head)
683 static void *f_start(
struct seq_file *m, loff_t *pos)
694 p = f_next(m, p, &l);
695 }
while (p && l < *pos);
700 static int f_show(
struct seq_file *m,
void *v)
704 const char *array_descriptor;
706 switch ((
unsigned long)v) {
735 array_descriptor =
NULL;
737 if (!array_descriptor)
738 seq_printf(m,
"\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
742 seq_printf(m,
"\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n",
743 (
int)(array_descriptor - field->
type),
745 array_descriptor, field->
offset,
751 static void f_stop(
struct seq_file *m,
void *p)
762 static int trace_format_open(
struct inode *inode,
struct file *file)
768 ret =
seq_open(file, &trace_format_seq_ops);
779 event_id_read(
struct file *filp,
char __user *ubuf,
size_t cnt, loff_t *ppos)
802 event_filter_read(
struct file *filp,
char __user *ubuf,
size_t cnt,
827 event_filter_write(
struct file *filp,
const char __user *ubuf,
size_t cnt,
859 static int subsystem_open(
struct inode *inode,
struct file *filp)
876 __get_system(system);
887 if (ret < 0 && system)
893 static int subsystem_release(
struct inode *inode,
struct file *file)
904 subsystem_filter_read(
struct file *filp,
char __user *ubuf,
size_t cnt,
929 subsystem_filter_write(
struct file *filp,
const char __user *ubuf,
size_t cnt,
960 show_header(
struct file *filp,
char __user *ubuf,
size_t cnt, loff_t *ppos)
998 .open = ftrace_event_seq_open,
1005 .open = ftrace_event_seq_open,
1007 .write = ftrace_event_write,
1014 .read = event_enable_read,
1015 .write = event_enable_write,
1020 .open = trace_format_open,
1028 .read = event_id_read,
1034 .read = event_filter_read,
1035 .write = event_filter_write,
1040 .open = subsystem_open,
1041 .read = subsystem_filter_read,
1042 .write = subsystem_filter_write,
1044 .release = subsystem_release,
1048 .open = subsystem_open,
1049 .read = system_enable_read,
1050 .write = system_enable_write,
1052 .release = subsystem_release,
1057 .read = show_header,
1061 static struct dentry *event_trace_events_dir(
void)
1063 static struct dentry *d_tracer;
1064 static struct dentry *d_events;
1076 "'events' directory\n");
1082 event_subsystem_dir(
const char *name,
struct dentry *d_events)
1091 return system->
entry;
1098 pr_warning(
"No memory to create event subsystem %s\n",
1104 if (!system->
entry) {
1105 pr_warning(
"Could not create event subsystem %s\n",
1114 if (!system->
name) {
1120 list_add(&system->
list, &event_subsystems);
1126 pr_warning(
"Could not allocate filter for subsystem "
1128 return system->
entry;
1132 &ftrace_subsystem_filter_fops);
1137 "'%s/filter' entry\n", name);
1141 &ftrace_system_enable_fops);
1143 return system->
entry;
1161 d_events = event_subsystem_dir(call->
class->system, d_events);
1166 "'%s' directory\n", call->
name);
1174 #ifdef CONFIG_PERF_EVENTS
1185 if (list_empty(head)) {
1186 ret = call->
class->define_fields(call);
1188 pr_warning(
"Could not initialize trace point"
1189 " events/%s\n", call->
name);
1204 ftrace_event_enable_disable(call, 0);
1205 if (call->
event.funcs)
1217 if (call->
class->raw_init) {
1218 ret = call->
class->raw_init(call);
1219 if (ret < 0 && ret != -
ENOSYS)
1220 pr_warn(
"Could not initialize trace events/%s\n",
1237 ret = event_init(call);
1241 d_events = event_trace_events_dir();
1245 ret = event_create_dir(call, d_events,
id, enable, filter, format);
1247 list_add(&call->
list, &ftrace_events);
1258 ret = __trace_add_event_call(call,
NULL, &ftrace_event_id_fops,
1259 &ftrace_enable_fops,
1260 &ftrace_event_filter_fops,
1261 &ftrace_event_format_fops);
1266 static void remove_subsystem_dir(
const char *name)
1278 __put_system(system);
1294 remove_subsystem_dir(call->
class->system);
1302 __trace_remove_event_call(call);
1307 #define for_each_event(event, start, end) \
1308 for (event = start; \
1309 (unsigned long)event < (unsigned long)end; \
1312 #ifdef CONFIG_MODULES
1314 static LIST_HEAD(ftrace_module_file_list);
1320 struct ftrace_module_file_ops {
1329 static struct ftrace_module_file_ops *
1330 trace_create_file_ops(
struct module *mod)
1332 struct ftrace_module_file_ops *file_ops;
1345 file_ops->mod =
mod;
1347 file_ops->id = ftrace_event_id_fops;
1348 file_ops->id.owner =
mod;
1350 file_ops->enable = ftrace_enable_fops;
1351 file_ops->enable.owner =
mod;
1353 file_ops->filter = ftrace_event_filter_fops;
1354 file_ops->filter.owner =
mod;
1356 file_ops->format = ftrace_event_format_fops;
1357 file_ops->format.owner =
mod;
1359 list_add(&file_ops->list, &ftrace_module_file_list);
1364 static void trace_module_add_events(
struct module *mod)
1366 struct ftrace_module_file_ops *file_ops =
NULL;
1369 start = mod->trace_events;
1370 end = mod->trace_events + mod->num_trace_events;
1375 file_ops = trace_create_file_ops(mod);
1380 __trace_add_event_call(*call, mod,
1381 &file_ops->id, &file_ops->enable,
1382 &file_ops->filter, &file_ops->format);
1386 static void trace_module_remove_events(
struct module *mod)
1388 struct ftrace_module_file_ops *file_ops;
1394 if (call->
mod == mod) {
1396 __trace_remove_event_call(call);
1402 if (file_ops->mod == mod)
1405 if (&file_ops->list != &ftrace_module_file_list) {
1420 unsigned long val,
void *
data)
1426 case MODULE_STATE_COMING:
1427 trace_module_add_events(mod);
1429 case MODULE_STATE_GOING:
1430 trace_module_remove_events(mod);
1439 unsigned long val,
void *data)
1446 .notifier_call = trace_module_notify,
1455 static __init int setup_trace_event(
char *
str)
1463 __setup(
"trace_event=", setup_trace_event);
1465 static __init int event_trace_enable(
void)
1468 char *buf = bootup_event_buf;
1472 for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) {
1475 ret = event_init(call);
1477 list_add(&call->
list, &ftrace_events);
1481 token =
strsep(&buf,
",");
1488 ret = ftrace_set_clr_event(token, 1);
1490 pr_warn(
"Failed to enable trace event: %s\n", token);
1495 static __init int event_trace_init(
void)
1508 (
void *)&show_event_seq_ops,
1509 &ftrace_avail_fops);
1512 "'available_events' entry\n");
1515 (
void *)&show_set_event_seq_ops,
1516 &ftrace_set_event_fops);
1519 "'set_event' entry\n");
1521 d_events = event_trace_events_dir();
1528 &ftrace_show_header_fops);
1532 &ftrace_show_header_fops);
1535 NULL, &ftrace_system_enable_fops);
1537 if (trace_define_common_fields())
1538 pr_warning(
"tracing: Failed to allocate common fields");
1546 ret = event_create_dir(call, d_events,
1547 &ftrace_event_id_fops,
1548 &ftrace_enable_fops,
1549 &ftrace_event_filter_fops,
1550 &ftrace_event_format_fops);
1557 pr_warning(
"Failed to register trace events module notifier\n");
1564 #ifdef CONFIG_FTRACE_STARTUP_TEST
1572 spin_lock(&test_spinlock);
1573 spin_lock_irq(&test_spinlock_irq);
1575 spin_unlock_irq(&test_spinlock_irq);
1576 spin_unlock(&test_spinlock);
1589 pr_info(
"failed to kmalloc\n");
1605 static __init void event_test_stuff(
void)
1618 static __init void event_trace_self_tests(
void)
1624 pr_info(
"Running tests on trace events:\n");
1638 #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
1639 if (call->
class->system &&
1651 pr_warning(
"Enabled event during self test!\n");
1656 ftrace_event_enable_disable(call, 1);
1658 ftrace_event_enable_disable(call, 0);
1665 pr_info(
"Running tests on trace event systems:\n");
1673 pr_info(
"Testing event system %s: ", system->
name);
1675 ret = __ftrace_set_clr_event(
NULL, system->
name,
NULL, 1);
1684 ret = __ftrace_set_clr_event(
NULL, system->
name,
NULL, 0);
1696 pr_info(
"Running tests on all trace events:\n");
1697 pr_info(
"Testing all events: ");
1717 #ifdef CONFIG_FUNCTION_TRACER
1722 function_test_events_call(
unsigned long ip,
unsigned long parent_ip,
1727 struct ftrace_entry *
entry;
1728 unsigned long flags;
1750 entry->parent_ip = parent_ip;
1759 static struct ftrace_ops trace_ops __initdata =
1761 .func = function_test_events_call,
1762 .flags = FTRACE_OPS_FL_RECURSION_SAFE,
1765 static __init void event_trace_self_test_with_function(
void)
1770 pr_info(
"Failed to enable function tracer for event tests\n");
1773 pr_info(
"Running tests again, along with the function tracer\n");
1774 event_trace_self_tests();
1778 static __init void event_trace_self_test_with_function(
void)
1783 static __init int event_trace_self_tests_init(
void)
1786 event_trace_self_tests();
1787 event_trace_self_test_with_function();