Commit 80decc70 authored by Steven Rostedt's avatar Steven Rostedt Committed by Steven Rostedt

tracing: Move print functions into event class

Currently, every event has its own trace_event structure. This is
fine since the structure is needed anyway. But the print function
structure (trace_event_functions) is now separate. Since the output
of the trace event is done by the class (with the exception of events
defined by DEFINE_EVENT_PRINT), it makes sense to have the class
define the print functions that all events in the class can use.

This makes a bigger deal with the syscall events since all syscall events
use the same class. The savings here is another 30K.

   text	   data	    bss	    dec	    hex	filename
4913961	1088356	 861512	6863829	 68bbd5	vmlinux.orig
4900382	1048964	 861512	6810858	 67ecea	vmlinux.init
4900446	1049028	 861512	6810986	 67ed6a	vmlinux.preprint
4895024	1023812	 861512	6780348	 6775bc	vmlinux.print

To accomplish this, and to let the class know what event is being
printed, the event structure is embedded in the ftrace_event_call
structure. This should not be an issues since the event structure
was created for each event anyway.
Acked-by: default avatarMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Acked-by: default avatarFrederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent a9a57763
...@@ -148,7 +148,7 @@ struct ftrace_event_call { ...@@ -148,7 +148,7 @@ struct ftrace_event_call {
struct ftrace_event_class *class; struct ftrace_event_class *class;
char *name; char *name;
struct dentry *dir; struct dentry *dir;
struct trace_event *event; struct trace_event event;
int enabled; int enabled;
int id; int id;
const char *print_fmt; const char *print_fmt;
......
...@@ -120,24 +120,20 @@ struct perf_event_attr; ...@@ -120,24 +120,20 @@ struct perf_event_attr;
extern struct ftrace_event_class event_class_syscall_enter; extern struct ftrace_event_class event_class_syscall_enter;
extern struct ftrace_event_class event_class_syscall_exit; extern struct ftrace_event_class event_class_syscall_exit;
extern struct trace_event_functions enter_syscall_print_funcs;
extern struct trace_event_functions exit_syscall_print_funcs;
#define SYSCALL_TRACE_ENTER_EVENT(sname) \ #define SYSCALL_TRACE_ENTER_EVENT(sname) \
static struct syscall_metadata __syscall_meta_##sname; \ static struct syscall_metadata __syscall_meta_##sname; \
static struct ftrace_event_call \ static struct ftrace_event_call \
__attribute__((__aligned__(4))) event_enter_##sname; \ __attribute__((__aligned__(4))) event_enter_##sname; \
static struct trace_event_functions enter_syscall_print_funcs_##sname = { \
.trace = print_syscall_enter, \
}; \
static struct trace_event enter_syscall_print_##sname = { \
.funcs = &enter_syscall_print_funcs_##sname, \
}; \
static struct ftrace_event_call __used \ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \ __attribute__((section("_ftrace_events"))) \
event_enter_##sname = { \ event_enter_##sname = { \
.name = "sys_enter"#sname, \ .name = "sys_enter"#sname, \
.class = &event_class_syscall_enter, \ .class = &event_class_syscall_enter, \
.event = &enter_syscall_print_##sname, \ .event.funcs = &enter_syscall_print_funcs, \
.data = (void *)&__syscall_meta_##sname,\ .data = (void *)&__syscall_meta_##sname,\
} }
...@@ -145,19 +141,13 @@ extern struct ftrace_event_class event_class_syscall_exit; ...@@ -145,19 +141,13 @@ extern struct ftrace_event_class event_class_syscall_exit;
static struct syscall_metadata __syscall_meta_##sname; \ static struct syscall_metadata __syscall_meta_##sname; \
static struct ftrace_event_call \ static struct ftrace_event_call \
__attribute__((__aligned__(4))) event_exit_##sname; \ __attribute__((__aligned__(4))) event_exit_##sname; \
static struct trace_event_functions exit_syscall_print_funcs_##sname = { \
.trace = print_syscall_exit, \
}; \
static struct trace_event exit_syscall_print_##sname = { \
.funcs = &exit_syscall_print_funcs_##sname, \
}; \
static struct ftrace_event_call __used \ static struct ftrace_event_call __used \
__attribute__((__aligned__(4))) \ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) \ __attribute__((section("_ftrace_events"))) \
event_exit_##sname = { \ event_exit_##sname = { \
.name = "sys_exit"#sname, \ .name = "sys_exit"#sname, \
.class = &event_class_syscall_exit, \ .class = &event_class_syscall_exit, \
.event = &exit_syscall_print_##sname, \ .event.funcs = &exit_syscall_print_funcs, \
.data = (void *)&__syscall_meta_##sname,\ .data = (void *)&__syscall_meta_##sname,\
} }
......
...@@ -206,18 +206,22 @@ ...@@ -206,18 +206,22 @@
#undef DECLARE_EVENT_CLASS #undef DECLARE_EVENT_CLASS
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
static notrace enum print_line_t \ static notrace enum print_line_t \
ftrace_raw_output_id_##call(int event_id, const char *name, \ ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
struct trace_iterator *iter, int flags) \ struct trace_event *trace_event) \
{ \ { \
struct ftrace_event_call *event; \
struct trace_seq *s = &iter->seq; \ struct trace_seq *s = &iter->seq; \
struct ftrace_raw_##call *field; \ struct ftrace_raw_##call *field; \
struct trace_entry *entry; \ struct trace_entry *entry; \
struct trace_seq *p; \ struct trace_seq *p; \
int ret; \ int ret; \
\ \
event = container_of(trace_event, struct ftrace_event_call, \
event); \
\
entry = iter->ent; \ entry = iter->ent; \
\ \
if (entry->type != event_id) { \ if (entry->type != event->id) { \
WARN_ON_ONCE(1); \ WARN_ON_ONCE(1); \
return TRACE_TYPE_UNHANDLED; \ return TRACE_TYPE_UNHANDLED; \
} \ } \
...@@ -226,7 +230,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ ...@@ -226,7 +230,7 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \
\ \
p = &get_cpu_var(ftrace_event_seq); \ p = &get_cpu_var(ftrace_event_seq); \
trace_seq_init(p); \ trace_seq_init(p); \
ret = trace_seq_printf(s, "%s: ", name); \ ret = trace_seq_printf(s, "%s: ", event->name); \
if (ret) \ if (ret) \
ret = trace_seq_printf(s, print); \ ret = trace_seq_printf(s, print); \
put_cpu(); \ put_cpu(); \
...@@ -234,17 +238,10 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \ ...@@ -234,17 +238,10 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \
return TRACE_TYPE_PARTIAL_LINE; \ return TRACE_TYPE_PARTIAL_LINE; \
\ \
return TRACE_TYPE_HANDLED; \ return TRACE_TYPE_HANDLED; \
} } \
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
#undef DEFINE_EVENT .trace = ftrace_raw_output_##call, \
#define DEFINE_EVENT(template, name, proto, args) \ };
static notrace enum print_line_t \
ftrace_raw_output_##name(struct trace_iterator *iter, int flags, \
struct trace_event *event) \
{ \
return ftrace_raw_output_id_##template(event_##name.id, \
#name, iter, flags); \
}
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
...@@ -277,7 +274,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \ ...@@ -277,7 +274,10 @@ ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
return TRACE_TYPE_PARTIAL_LINE; \ return TRACE_TYPE_PARTIAL_LINE; \
\ \
return TRACE_TYPE_HANDLED; \ return TRACE_TYPE_HANDLED; \
} } \
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
.trace = ftrace_raw_output_##call, \
};
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
...@@ -533,20 +533,13 @@ ftrace_raw_event_##call(void *__data, proto) \ ...@@ -533,20 +533,13 @@ ftrace_raw_event_##call(void *__data, proto) \
#undef DEFINE_EVENT #undef DEFINE_EVENT
#define DEFINE_EVENT(template, call, proto, args) \ #define DEFINE_EVENT(template, call, proto, args) \
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
.trace = ftrace_raw_output_##call, \
}; \
static struct trace_event ftrace_event_type_##call = { \
.funcs = &ftrace_event_type_funcs_##call, \
}; \
static inline void ftrace_test_probe_##call(void) \ static inline void ftrace_test_probe_##call(void) \
{ \ { \
check_trace_callback_type_##call(ftrace_raw_event_##template); \ check_trace_callback_type_##call(ftrace_raw_event_##template); \
} }
#undef DEFINE_EVENT_PRINT #undef DEFINE_EVENT_PRINT
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \ #define DEFINE_EVENT_PRINT(template, name, proto, args, print)
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
...@@ -582,7 +575,7 @@ __attribute__((__aligned__(4))) \ ...@@ -582,7 +575,7 @@ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) event_##call = { \ __attribute__((section("_ftrace_events"))) event_##call = { \
.name = #call, \ .name = #call, \
.class = &event_class_##template, \ .class = &event_class_##template, \
.event = &ftrace_event_type_##call, \ .event.funcs = &ftrace_event_type_funcs_##template, \
.print_fmt = print_fmt_##template, \ .print_fmt = print_fmt_##template, \
}; };
...@@ -596,7 +589,7 @@ __attribute__((__aligned__(4))) \ ...@@ -596,7 +589,7 @@ __attribute__((__aligned__(4))) \
__attribute__((section("_ftrace_events"))) event_##call = { \ __attribute__((section("_ftrace_events"))) event_##call = { \
.name = #call, \ .name = #call, \
.class = &event_class_##template, \ .class = &event_class_##template, \
.event = &ftrace_event_type_##call, \ .event.funcs = &ftrace_event_type_funcs_##call, \
.print_fmt = print_fmt_##call, \ .print_fmt = print_fmt_##call, \
} }
......
...@@ -122,7 +122,7 @@ int trace_event_raw_init(struct ftrace_event_call *call) ...@@ -122,7 +122,7 @@ int trace_event_raw_init(struct ftrace_event_call *call)
{ {
int id; int id;
id = register_ftrace_event(call->event); id = register_ftrace_event(&call->event);
if (!id) if (!id)
return -ENODEV; return -ENODEV;
call->id = id; call->id = id;
...@@ -1073,8 +1073,8 @@ static void remove_subsystem_dir(const char *name) ...@@ -1073,8 +1073,8 @@ static void remove_subsystem_dir(const char *name)
static void __trace_remove_event_call(struct ftrace_event_call *call) static void __trace_remove_event_call(struct ftrace_event_call *call)
{ {
ftrace_event_enable_disable(call, 0); ftrace_event_enable_disable(call, 0);
if (call->event) if (call->event.funcs)
__unregister_ftrace_event(call->event); __unregister_ftrace_event(&call->event);
debugfs_remove_recursive(call->dir); debugfs_remove_recursive(call->dir);
list_del(&call->list); list_del(&call->list);
trace_destroy_fields(call); trace_destroy_fields(call);
......
...@@ -204,7 +204,6 @@ struct trace_probe { ...@@ -204,7 +204,6 @@ struct trace_probe {
const char *symbol; /* symbol name */ const char *symbol; /* symbol name */
struct ftrace_event_class class; struct ftrace_event_class class;
struct ftrace_event_call call; struct ftrace_event_call call;
struct trace_event event;
unsigned int nr_args; unsigned int nr_args;
struct probe_arg args[]; struct probe_arg args[];
}; };
...@@ -1020,7 +1019,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags, ...@@ -1020,7 +1019,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags,
int i; int i;
field = (struct kprobe_trace_entry *)iter->ent; field = (struct kprobe_trace_entry *)iter->ent;
tp = container_of(event, struct trace_probe, event); tp = container_of(event, struct trace_probe, call.event);
if (!trace_seq_printf(s, "%s: (", tp->call.name)) if (!trace_seq_printf(s, "%s: (", tp->call.name))
goto partial; goto partial;
...@@ -1054,7 +1053,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, ...@@ -1054,7 +1053,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,
int i; int i;
field = (struct kretprobe_trace_entry *)iter->ent; field = (struct kretprobe_trace_entry *)iter->ent;
tp = container_of(event, struct trace_probe, event); tp = container_of(event, struct trace_probe, call.event);
if (!trace_seq_printf(s, "%s: (", tp->call.name)) if (!trace_seq_printf(s, "%s: (", tp->call.name))
goto partial; goto partial;
...@@ -1364,20 +1363,19 @@ static int register_probe_event(struct trace_probe *tp) ...@@ -1364,20 +1363,19 @@ static int register_probe_event(struct trace_probe *tp)
/* Initialize ftrace_event_call */ /* Initialize ftrace_event_call */
if (probe_is_return(tp)) { if (probe_is_return(tp)) {
tp->event.funcs = &kretprobe_funcs;
INIT_LIST_HEAD(&call->class->fields); INIT_LIST_HEAD(&call->class->fields);
call->event.funcs = &kretprobe_funcs;
call->class->raw_init = probe_event_raw_init; call->class->raw_init = probe_event_raw_init;
call->class->define_fields = kretprobe_event_define_fields; call->class->define_fields = kretprobe_event_define_fields;
} else { } else {
INIT_LIST_HEAD(&call->class->fields); INIT_LIST_HEAD(&call->class->fields);
tp->event.funcs = &kprobe_funcs; call->event.funcs = &kprobe_funcs;
call->class->raw_init = probe_event_raw_init; call->class->raw_init = probe_event_raw_init;
call->class->define_fields = kprobe_event_define_fields; call->class->define_fields = kprobe_event_define_fields;
} }
if (set_print_fmt(tp) < 0) if (set_print_fmt(tp) < 0)
return -ENOMEM; return -ENOMEM;
call->event = &tp->event; call->id = register_ftrace_event(&call->event);
call->id = register_ftrace_event(&tp->event);
if (!call->id) { if (!call->id) {
kfree(call->print_fmt); kfree(call->print_fmt);
return -ENODEV; return -ENODEV;
...@@ -1389,7 +1387,7 @@ static int register_probe_event(struct trace_probe *tp) ...@@ -1389,7 +1387,7 @@ static int register_probe_event(struct trace_probe *tp)
if (ret) { if (ret) {
pr_info("Failed to register kprobe event: %s\n", call->name); pr_info("Failed to register kprobe event: %s\n", call->name);
kfree(call->print_fmt); kfree(call->print_fmt);
unregister_ftrace_event(&tp->event); unregister_ftrace_event(&call->event);
} }
return ret; return ret;
} }
......
...@@ -39,6 +39,14 @@ syscall_get_exit_fields(struct ftrace_event_call *call) ...@@ -39,6 +39,14 @@ syscall_get_exit_fields(struct ftrace_event_call *call)
return &entry->exit_fields; return &entry->exit_fields;
} }
struct trace_event_functions enter_syscall_print_funcs = {
.trace = print_syscall_enter,
};
struct trace_event_functions exit_syscall_print_funcs = {
.trace = print_syscall_exit,
};
struct ftrace_event_class event_class_syscall_enter = { struct ftrace_event_class event_class_syscall_enter = {
.system = "syscalls", .system = "syscalls",
.reg = syscall_enter_register, .reg = syscall_enter_register,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment