tracing: more shrinking of TRACE_EVENT() code
Subsystems (3)
Steven Rostedt
maintainerIngo,
This is built on my last pull request, and both would be good for 2.6.35.
Please pull the latest tip/perf/core-2 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/perf/core-2
Li Zefan (7):
tracing: Use a global field list for all syscall exit events
tracing: Don't allocate common fields for every trace events
tracing: Convert some timer events to DEFINE_EVENT
tracing: Conver more sched events to DEFINE_EVENT
tracing: Remove test of NULL define_fields callback
tracing: Remove redundant raw_init callbacks
tracing: Remove open-coded __trace_add_event_call()
----
include/linux/syscalls.h | 2 - include/trace/events/sched.h | 32 ++----- include/trace/events/timer.h | 80 ++++++-------- include/trace/syscall.h | 1 - kernel/trace/trace.h | 2 + kernel/trace/trace_events.c | 209 ++++++++++++++++-------------------- kernel/trace/trace_events_filter.c | 27 +++-- kernel/trace/trace_export.c | 8 +-- kernel/trace/trace_kprobe.c | 10 +-- kernel/trace/trace_syscalls.c | 7 +- 10 files changed, 157 insertions(+), 221 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 tracing: Use a global field list for all syscall exit events
From: Li Zefan <[email protected]>
All syscall exit events have the same fields.
The kernel size drops 2.5K:
text data bss dec hex filename
7018612 2034376 7251132 16304120 f8c7f8 vmlinux.o.orig
7018612 2031888 7251132 16301632 f8be40 vmlinux.o
LKML-Reference: <[email protected]>
--- include/linux/syscalls.h | 2 -- include/trace/syscall.h | 1 - kernel/trace/trace_syscalls.c | 7 ++++--- 3 files changed, 4 insertions(+), 6 deletions(-)
include/linux/syscalls.h +0 -2
@@ -165,7 +165,6 @@ extern struct trace_event_functions exit_syscall_print_funcs; .enter_event = &event_enter_##sname, \ .exit_event = &event_exit_##sname, \ .enter_fields = LIST_HEAD_INIT(__syscall_meta_##sname.enter_fields), \ - .exit_fields = LIST_HEAD_INIT(__syscall_meta_##sname.exit_fields), \ };#define SYSCALL_DEFINE0 (sname) \
@@ -180,7 +179,6 @@ extern struct trace_event_functions exit_syscall_print_funcs; .enter_event = &event_enter__##sname, \ .exit_event = &event_exit__##sname, \ .enter_fields = LIST_HEAD_INIT(__syscall_meta__##sname.enter_fields), \ - .exit_fields = LIST_HEAD_INIT(__syscall_meta__##sname.exit_fields), \ }; \ asmlinkage long sys_##sname(void)#else
include/trace/syscall.h +0 -1
@@ -26,7 +26,6 @@ struct syscall_metadata {const char **types;const char **args;struct list_head enter_fields; -struct list_head exit_fields;struct ftrace_event_call *enter_event;struct ftrace_event_call *exit_event;
kernel/trace/trace_syscalls.c +4 -3
@@ -23,6 +23,9 @@ static int syscall_exit_register(struct ftrace_event_call *event,static int syscall_enter_define_fields (struct ftrace_event_call *call);static int syscall_exit_define_fields (struct ftrace_event_call *call); +/* All syscall exit events have the same fields */ +static LIST_HEAD (syscall_exit_fields); +static struct list_head *syscall_get_enter_fields (struct ftrace_event_call *call) {
@@ -34,9 +37,7 @@ syscall_get_enter_fields(struct ftrace_event_call *call)static struct list_head *syscall_get_exit_fields (struct ftrace_event_call *call) { -struct syscall_metadata *entry = call->data; - -return &entry->exit_fields; +return &syscall_exit_fields; }struct trace_event_functions enter_syscall_print_funcs = {
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 2/7 tracing: Dont allocate common fields for every trace events
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Every event has the same common fields, so it's a big waste of memory to have a copy of those fields for every event.
LKML-Reference: <[email protected]>
--- kernel/trace/trace.h | 2 + kernel/trace/trace_events.c | 113 ++++++++++++++++++++---------------- kernel/trace/trace_events_filter.c | 18 +++++- 3 files changed, 81 insertions(+), 52 deletions(-)
kernel/trace/trace.h +2 -0
@@ -766,6 +766,8 @@ struct filter_pred {int pop_n; }; +extern struct list_head ftrace_common_fields; +extern enum regex_type filter_parse_regex (char *buff,int len,char **search,int *not); extern void print_event_filter(struct ftrace_event_call *call,
kernel/trace/trace_events.c +64 -49
185 lines not on this page · raw message
kernel/trace/trace_events_filter.c +15 -3
@@ -497,12 +497,10 @@ void print_subsystem_event_filter(struct event_subsystem *system, }static struct ftrace_event_field * -find_event_field (struct ftrace_event_call *call,char *name) +__find_event_field (struct list_head *head,char *name) {struct ftrace_event_field *field; -struct list_head *head; - head =trace_get_fields (call);list_for_each_entry (field, head, link) {if (!strcmp (field->name, name))return field;
@@ -511,6 +509,20 @@ find_event_field(struct ftrace_event_call *call, char *name)return NULL ; } +static struct ftrace_event_field * +find_event_field (struct ftrace_event_call *call,char *name) +{ +struct ftrace_event_field *field; +struct list_head *head; + + field =__find_event_field (&ftrace_common_fields, name); +if (field) +return field; + + head =trace_get_fields (call); +return __find_event_field (head, name); +} +static void filter_free_pred (struct filter_pred *pred) {if (!pred)
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 3/7 tracing: Convert some timer events to DEFINE_EVENT
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Use DECLARE_EVENT_CLASS, and save ~2.3K:
text data bss dec hex filename
7018823 2031888 7251132 16301843 f8bf13 vmlinux.o.orig
7016727 2031696 7251132 16299555 f8b623 vmlinux.o
5 events are converted:
timer_class: timer_init, timer_expire_exit, timer_cancel
hrtimer_class: hrtimer_init, hrtimer_cancel
No change in functionality.
LKML-Reference: <[email protected]>
--- include/trace/events/timer.h | 80 +++++++++++++++++------------------------- 1 files changed, 32 insertions(+), 48 deletions(-)
include/trace/events/timer.h +32 -48
@@ -8,11 +8,7 @@#include <linux/hrtimer.h> #include <linux/timer.h> -/** -* timer_init - called when the timer is initialized -* @timer: pointer to struct timer_list -*/ -TRACE_EVENT(timer_init, +DECLARE_EVENT_CLASS(timer_class, TP_PROTO(struct timer_list *timer),
@@ -30,6 +26,17 @@ TRACE_EVENT(timer_init, );/** +* timer_init - called when the timer is initialized +* @timer: pointer to struct timer_list +*/ +DEFINE_EVENT (timer_class, timer_init, + + TP_PROTO(struct timer_list *timer), + +TP_ARGS (timer) +); + +/** * timer_start - called when the timer is started * @timer: pointer to struct timer_list * @expires: the timers expiry time
@@ -94,42 +101,22 @@ TRACE_EVENT(timer_expire_entry,* NOTE: Do NOT derefernce timer in TP_fast_assign. The pointer might * be invalid. We solely track the pointer. */ -TRACE_EVENT (timer_expire_exit, +DEFINE_EVENT (timer_class, timer_expire_exit, TP_PROTO(struct timer_list *timer), -TP_ARGS (timer), - -TP_STRUCT__entry ( - __field(void *, timer ) - ), - -TP_fast_assign ( - __entry->timer = timer; - ), - -TP_printk ("timer=%p" , __entry->timer) +TP_ARGS (timer) );/** * timer_cancel - called when the timer is canceled * @timer: pointer to struct timer_list */ -TRACE_EVENT (timer_cancel, +DEFINE_EVENT (timer_class, timer_cancel, TP_PROTO(struct timer_list *timer), -TP_ARGS (timer), - -TP_STRUCT__entry ( - __field( void *, timer ) - ), - -TP_fast_assign ( - __entry->timer = timer; - ), - -TP_printk ("timer=%p" , __entry->timer) +TP_ARGS (timer) );/**
@@ -224,14 +211,7 @@ TRACE_EVENT(hrtimer_expire_entry, (unsigned long long)ktime_to_ns((ktime_t) { .tv64 = __entry->now })) ); -/** -* hrtimer_expire_exit - called immediately after the hrtimer callback returns -* @timer: pointer to struct hrtimer -* -* When used in combination with the hrtimer_expire_entry tracepoint we can -* determine the runtime of the callback function. -*/ -TRACE_EVENT(hrtimer_expire_exit, +DECLARE_EVENT_CLASS(hrtimer_class, TP_PROTO(struct hrtimer *hrtimer),
@@ -249,24 +229,28 @@ TRACE_EVENT(hrtimer_expire_exit, );/** -* hrtimer_cancel - called when the hrtimer is canceled -* @hrtimer: pointer to struct hrtimer +* hrtimer_expire_exit - called immediately after the hrtimer callback returns +* @timer: pointer to struct hrtimer +* +* When used in combination with the hrtimer_expire_entry tracepoint we can +* determine the runtime of the callback function. */ -TRACE_EVENT (hrtimer_cancel, +DEFINE_EVENT (hrtimer_class, hrtimer_expire_exit, TP_PROTO(struct hrtimer *hrtimer), -TP_ARGS (hrtimer), +TP_ARGS (hrtimer) +); -TP_STRUCT__entry ( - __field( void *, hrtimer ) - ), +/** +* hrtimer_cancel - called when the hrtimer is canceled +* @hrtimer: pointer to struct hrtimer +*/ +DEFINE_EVENT (hrtimer_class, hrtimer_cancel, -TP_fast_assign ( - __entry->hrtimer = hrtimer; - ), + TP_PROTO(struct hrtimer *hrtimer), -TP_printk ("hrtimer=%p" , __entry->hrtimer) +TP_ARGS (hrtimer) );/**
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 4/7 tracing: Conver more sched events to DEFINE_EVENT
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Convert sched_wait_task to DEFINE_EVENT, and save ~1K:
text data bss dec hex filename 104595 9424 4992 119011 1d0e3 kernel/sched.o.orig 103619 9344 4992 117955 1ccc3 kernel/sched.o
No change in functionality.
LKML-Reference: <[email protected]>
--- include/trace/events/sched.h | 32 +++++++------------------------- 1 files changed, 7 insertions(+), 25 deletions(-)
include/trace/events/sched.h +7 -25
@@ -50,31 +50,6 @@ TRACE_EVENT(sched_kthread_stop_ret, );/* -* Tracepoint for waiting on task to unschedule: -*/ -TRACE_EVENT (sched_wait_task, - - TP_PROTO(struct task_struct *p), - -TP_ARGS (p), - -TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) - __field( pid_t, pid ) -__field ( int, prio ) - ), - -TP_fast_assign ( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); - __entry->pid = p->pid; - __entry->prio = p->prio; - ), - -TP_printk ("comm=%s pid=%d prio=%d" , - __entry->comm, __entry->pid, __entry->prio) -); - -/* * Tracepoint for waking up a task: */ DECLARE_EVENT_CLASS(sched_wakeup_template,
@@ -223,6 +198,13 @@ DEFINE_EVENT(sched_process_template, sched_process_exit, TP_ARGS(p));/* +* Tracepoint for waiting on task to unschedule: +*/ +DEFINE_EVENT (sched_process_template, sched_wait_task, + TP_PROTO(struct task_struct *p), +TP_ARGS (p)); + +/* * Tracepoint for a waiting task: */ TRACE_EVENT(sched_process_wait,
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 5/7 tracing: Remove test of NULL define_fields callback
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Every event (or event class) has it's define_fields callback, so the test is redundant.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events.c | 28 +++++++++++++--------------- kernel/trace/trace_events_filter.c | 9 --------- 2 files changed, 13 insertions(+), 24 deletions(-)
kernel/trace/trace_events.c +13 -15
@@ -987,23 +987,21 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, id);#endif -if (call->class->define_fields) { -/* -* Other events may have the same class. Only update -* the fields if they are not already defined. -*/ - head =trace_get_fields (call); -if (list_empty (head)) { - ret = call->class->define_fields (call); -if (ret <0 ) { -pr_warning ("Could not initialize trace point" -" events/%s\n" , call->name); -return ret; - } +/* +* Other events may have the same class. Only update +* the fields if they are not already defined. +*/ + head =trace_get_fields (call); +if (list_empty (head)) { + ret = call->class->define_fields (call); +if (ret <0 ) { +pr_warning ("Could not initialize trace point" +" events/%s\n" , call->name); +return ret; } -trace_create_file ("filter" ,0644 , call->dir, call, - filter); } +trace_create_file ("filter" ,0644 , call->dir, call, + filter);trace_create_file ("format" ,0444 , call->dir, call, format);
kernel/trace/trace_events_filter.c +0 -9
@@ -639,9 +639,6 @@ static int init_subsystem_preds(struct event_subsystem *system)int err;list_for_each_entry (call, &ftrace_events, list) { -if (!call->class || !call->class->define_fields) -continue ; -if (strcmp (call->class->system, system->name) !=0 )continue ;
@@ -658,9 +655,6 @@ static void filter_free_subsystem_preds(struct event_subsystem *system)struct ftrace_event_call *call;list_for_each_entry (call, &ftrace_events, list) { -if (!call->class || !call->class->define_fields) -continue ; -if (strcmp (call->class->system, system->name) !=0 )continue ;
@@ -1263,9 +1257,6 @@ static int replace_system_preds(struct event_subsystem *system,list_for_each_entry (call, &ftrace_events, list) {struct event_filter *filter = call->filter; -if (!call->class || !call->class->define_fields) -continue ; -if (strcmp (call->class->system, system->name) !=0 )continue ;
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 6/7 tracing: Remove redundant raw_init callbacks
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
raw_init callback is optional.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_export.c | 8 +------- kernel/trace/trace_kprobe.c | 10 +--------- 2 files changed, 2 insertions(+), 16 deletions(-)
kernel/trace/trace_export.c +1 -7
@@ -125,12 +125,6 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \#include "trace_entries.h" -static int ftrace_raw_init_event (struct ftrace_event_call *call) -{ -INIT_LIST_HEAD (&call->class->fields); -return 0 ; -} -#undef __entry#define __entry REC
@@ -158,7 +152,7 @@ static int ftrace_raw_init_event(struct ftrace_event_call *call) struct ftrace_event_class event_class_ftrace_##call = { \ .system = __stringify(TRACE_SYSTEM), \ .define_fields = ftrace_define_fields_##call, \ - .raw_init = ftrace_raw_init_event, \ + .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\ }; \ \ struct ftrace_event_call __used \
kernel/trace/trace_kprobe.c +1 -9
@@ -1214,11 +1214,6 @@ static void probe_event_disable(struct ftrace_event_call *call) } } -static int probe_event_raw_init (struct ftrace_event_call *event_call) -{ -return 0 ; -} -#undef DEFINE_FIELD#define DEFINE_FIELD (type, item, name, is_signed) \ do { \
@@ -1486,15 +1481,12 @@ static int register_probe_event(struct trace_probe *tp)int ret;/* Initialize ftrace_event_call */ +INIT_LIST_HEAD (&call->class->fields);if (probe_is_return (tp)) { -INIT_LIST_HEAD (&call->class->fields); call->event.funcs = &kretprobe_funcs; - call->class->raw_init = probe_event_raw_init; call->class->define_fields = kretprobe_event_define_fields; }else { -INIT_LIST_HEAD (&call->class->fields); call->event.funcs = &kprobe_funcs; - call->class->raw_init = probe_event_raw_init; call->class->define_fields = kprobe_event_define_fields; }if (set_print_fmt (tp) <0 )
Signature · 1 line
1.7.0
Steven Rostedt
maintainerPATCH 7/7 tracing: Remove open-coded __trace_add_event_call()
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Let trace_module_add_events() and event_trace_init() call __trace_add_event_call().
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events.c | 70 +++++++++++------------------------------- 1 files changed, 19 insertions(+), 51 deletions(-)
kernel/trace/trace_events.c +19 -51
@@ -1009,11 +1009,17 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,return 0 ; } -static int __trace_add_event_call (struct ftrace_event_call *call) +static int +__trace_add_event_call (struct ftrace_event_call *call,struct module *mod, +const struct file_operations *id, +const struct file_operations *enable, +const struct file_operations *filter, +const struct file_operations *format) {struct dentry *d_events;int ret; +/* The linker may leave blanks */ if (!call->name)return -EINVAL ;
@@ -1021,8 +1027,8 @@ static int __trace_add_event_call(struct ftrace_event_call *call) ret = call->class->raw_init (call);if (ret <0 ) {if (ret != -ENOSYS ) -pr_warning ("Could not initialize trace " -"events/%s\n" , call->name); +pr_warning ("Could not initialize trace events/%s\n" , + call->name);return ret; } }
@@ -1031,11 +1037,10 @@ static int __trace_add_event_call(struct ftrace_event_call *call)if (!d_events)return -ENOENT ; - ret =event_create_dir (call, d_events, &ftrace_event_id_fops, - &ftrace_enable_fops, &ftrace_event_filter_fops, - &ftrace_event_format_fops); + ret =event_create_dir (call, d_events, id, enable, filter, format);if (!ret)list_add (&call->list, &ftrace_events); + call->mod = mod;return ret; }
@@ -1045,7 +1050,10 @@ int trace_add_event_call(struct ftrace_event_call *call) {int ret;mutex_lock (&event_mutex); - ret =__trace_add_event_call (call); + ret =__trace_add_event_call (call,NULL , &ftrace_event_id_fops, + &ftrace_enable_fops, + &ftrace_event_filter_fops, + &ftrace_event_format_fops);mutex_unlock (&event_mutex);return ret; }
@@ -1162,8 +1170,6 @@ static void trace_module_add_events(struct module *mod) {struct ftrace_module_file_ops *file_ops =NULL ;struct ftrace_event_call *call, *start, *end; -struct dentry *d_events; -int ret; start = mod->trace_events; end = mod->trace_events + mod->num_trace_events;
@@ -1171,38 +1177,14 @@ static void trace_module_add_events(struct module *mod)if (start == end)return ; - d_events =event_trace_events_dir (); -if (!d_events) + file_ops =trace_create_file_ops (mod); +if (!file_ops)return ;for_each_event (call, start, end) { -/* The linker may leave blanks */ -if (!call->name) -continue ; -if (call->class->raw_init) { - ret = call->class->raw_init (call); -if (ret <0 ) { -if (ret != -ENOSYS ) -pr_warning ("Could not initialize trace " -"point events/%s\n" , call->name); -continue ; - } - } -/* -* This module has events, create file ops for this module -* if not already done. -*/ -if (!file_ops) { - file_ops =trace_create_file_ops (mod); -if (!file_ops) -return ; - } - call->mod = mod; - ret =event_create_dir (call, d_events, +__trace_add_event_call (call, mod, &file_ops->id, &file_ops->enable, &file_ops->filter, &file_ops->format); -if (!ret) -list_add (&call->list, &ftrace_events); } }
@@ -1333,24 +1315,10 @@ static __init int event_trace_init(void)pr_warning ("tracing: Failed to allocate common fields" );for_each_event (call, __start_ftrace_events, __stop_ftrace_events) { -/* The linker may leave blanks */ -if (!call->name) -continue ; -if (call->class->raw_init) { - ret = call->class->raw_init (call); -if (ret <0 ) { -if (ret != -ENOSYS ) -pr_warning ("Could not initialize trace " -"point events/%s\n" , call->name); -continue ; - } - } - ret =event_create_dir (call, d_events, &ftrace_event_id_fops, +__trace_add_event_call (call,NULL , &ftrace_event_id_fops, &ftrace_enable_fops, &ftrace_event_filter_fops, &ftrace_event_format_fops); -if (!ret) -list_add (&call->list, &ftrace_events); }while (true) {
Signature · 1 line
1.7.0