tracing: memory savings and minor fixes
Steven Rostedt
maintainerPATCH 1/6 tracing: Add a helper function for event print functions
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
Move duplicate code in event print functions to a helper function.
This shrinks the size of the kernel by ~13K.
text data bss dec hex filename
6596137 1743966 10138672 18478775 119f6b7 vmlinux.o.old 6583002 1743849 10138672 18465523 119c2f3 vmlinux.o.new
--- include/linux/ftrace_event.h | 8 ++++++-- include/trace/ftrace.h | 23 ++++++----------------- kernel/trace/trace_output.c | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 19 deletions(-)
include/linux/ftrace_event.h +6 -2
@@ -38,6 +38,12 @@ const char *ftrace_print_symbols_seq_u64(struct trace_seq *p,const char *ftrace_print_hex_seq (struct trace_seq *p,const unsigned char *buf,int len); +struct trace_iterator ; +struct trace_event ; + +int ftrace_raw_output_prep (struct trace_iterator *iter, +struct trace_event *event); +/* * The trace entry - the most basic unit of tracing. This is what * is printed in the end as a single line in the trace output, such as:
@@ -95,8 +101,6 @@ enum trace_iter_flags { }; -struct trace_event ; -typedef enum print_line_t (*trace_print_func )(struct trace_iterator *iter,int flags,struct trace_event *event);
include/trace/ftrace.h +6 -17
@@ -227,29 +227,18 @@ static notrace enum print_line_t \ ftrace_raw_output_##call(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 __maybe_unused *p = &iter->tmp_seq; \ struct ftrace_raw_##call *field; \ - struct trace_entry *entry; \ - struct trace_seq *p = &iter->tmp_seq; \ int ret; \ \ - event = container_of(trace_event, struct ftrace_event_call, \ - event); \ - \ - entry = iter->ent; \ + field = (typeof(field))iter->ent; \ \ - if (entry->type != event->event.type) { \ - WARN_ON_ONCE(1); \ - return TRACE_TYPE_UNHANDLED; \ - } \ - \ - field = (typeof(field))entry; \ - \ - trace_seq_init(p); \ - ret = trace_seq_printf(s, "%s: ", event->name); \ + ret = ftrace_raw_output_prep(iter, trace_event); \ if (ret) \ - ret = trace_seq_printf(s, print); \ + return ret; \ + \ + ret = trace_seq_printf(s, print); \ if (!ret) \ return TRACE_TYPE_PARTIAL_LINE; \ \
kernel/trace/trace_output.c +26 -0
@@ -397,6 +397,32 @@ ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len) }EXPORT_SYMBOL (ftrace_print_hex_seq); +int ftrace_raw_output_prep (struct trace_iterator *iter, +struct trace_event *trace_event) +{ +struct ftrace_event_call *event; +struct trace_seq *s = &iter->seq; +struct trace_seq *p = &iter->tmp_seq; +struct trace_entry *entry; +int ret; + + event = container_of(trace_event, struct ftrace_event_call, event); + entry = iter->ent; + +if (entry->type != event->event.type) { +WARN_ON_ONCE (1 ); +return TRACE_TYPE_UNHANDLED ; + } + +trace_seq_init (p); + ret =trace_seq_printf (s,"%s: " , event->name); +if (!ret) +return TRACE_TYPE_PARTIAL_LINE ; + +return 0 ; +} +EXPORT_SYMBOL (ftrace_raw_output_prep); +#ifdef CONFIG_KRETPROBES static inline const char *kretprobed (const char *name) {
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 3/6 tracing/syscalls: Annotate field-defining functions with __init
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
These two functions are called during kernel boot only.
--- kernel/trace/trace_syscalls.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_syscalls.c +2 -2
@@ -261,7 +261,7 @@ static void free_syscall_print_fmt(struct ftrace_event_call *call)kfree (call->print_fmt); } -static int syscall_enter_define_fields (struct ftrace_event_call *call) +static int __init syscall_enter_define_fields (struct ftrace_event_call *call) {struct syscall_trace_enter trace;struct syscall_metadata *meta = call->data;
@@ -284,7 +284,7 @@ static int syscall_enter_define_fields(struct ftrace_event_call *call)return ret; } -static int syscall_exit_define_fields (struct ftrace_event_call *call) +static int __init syscall_exit_define_fields (struct ftrace_event_call *call) {struct syscall_trace_exit trace;int ret;
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainercover tracing: memory savings and minor fixes
Some more updates to the linux-next queue for 3.10. Li Zefan did a few updates to save a bit of kernel memory.
I did a few minor fixes to the previous patchset I sent out.
-- Steve
Li Zefan (4):
tracing: Add a helper function for event print functions
tracing: Annotate event field-defining functions with __init tracing/syscalls: Annotate field-defining functions with __init
tracing: Fix some section mismatch warninings
Steven Rostedt (Red Hat) (2):
tracing: Add __per_cpu annotation to trace array percpu data pointer
tracing: Fix trace events build without modules
----
include/linux/ftrace_event.h | 8 ++++-- include/trace/ftrace.h | 27 ++++++-------------- kernel/trace/trace.h | 2 +- kernel/trace/trace_events.c | 55 +++++++++++++++++++++++++++-------------- kernel/trace/trace_export.c | 4 +-- kernel/trace/trace_output.c | 26 +++++++++++++++++++ kernel/trace/trace_syscalls.c | 8 +++--- 7 files changed, 83 insertions(+), 47 deletions(-)
Steven Rostedt
maintainerPATCH 2/6 tracing: Annotate event field-defining functions with __init
From: Li Zefan <[email protected]>
Those functions are called either during kernel boot or module init.
Before:
$ dmesg | grep 'Freeing unused kernel memory' Freeing unused kernel memory: 1208k freed Freeing unused kernel memory: 1360k freed Freeing unused kernel memory: 1960k freed
After:
$ dmesg | grep 'Freeing unused kernel memory' Freeing unused kernel memory: 1236k freed Freeing unused kernel memory: 1388k freed Freeing unused kernel memory: 1960k freed
--- include/trace/ftrace.h | 2 +- kernel/trace/trace_export.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/trace/ftrace.h +1 -1
@@ -324,7 +324,7 @@ static struct trace_event_functions ftrace_event_type_funcs_##call = { \#undef DECLARE_EVENT_CLASS#define DECLARE_EVENT_CLASS (call, proto, args, tstruct, func, print) \ -static int notrace \ +static int notrace __init \ ftrace_define_fields_##call(struct ftrace_event_call *event_call) \ { \ struct ftrace_raw_##call field; \
kernel/trace/trace_export.c +1 -1
@@ -129,7 +129,7 @@ static void __always_unused ____ftrace_check_##name(void) \#undef FTRACE_ENTRY#define FTRACE_ENTRY (name, struct_name, id, tstruct, print, filter) \ -int \ +static int __init \ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \ { \ struct struct_name field; \
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 6/6 tracing: Fix some section mismatch warnings
In reply to Steven RostedtFrom: Li Zefan <[email protected]>
As we've added __init annotation to field-defining functions, we should add __refdata annotation to event_call variables, which reference those functions.
--- include/trace/ftrace.h | 2 +- kernel/trace/trace_export.c | 2 +- kernel/trace/trace_syscalls.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
include/trace/ftrace.h +1 -1
@@ -572,7 +572,7 @@ static inline void ftrace_test_probe_##call(void) \#define DECLARE_EVENT_CLASS (call, proto, args, tstruct, assign, print) \ _TRACE_PERF_PROTO(call, PARAMS(proto)); \ static const char print_fmt_##call[] = print; \ -static struct ftrace_event_class __used event_class_##call = { \ +static struct ftrace_event_class __used __refdata event_class_##call = { \ .system = __stringify(TRACE_SYSTEM), \ .define_fields = ftrace_define_fields_##call, \ .fields = LIST_HEAD_INIT(event_class_##call.fields),\
kernel/trace/trace_export.c +1 -1
@@ -168,7 +168,7 @@ ftrace_define_fields_##name(struct ftrace_event_call *event_call) \#define FTRACE_ENTRY_REG (call, struct_name, etype, tstruct, print, filter,\ regfn) \ \ -struct ftrace_event_class event_class_ftrace_##call = { \ +struct ftrace_event_class __refdata event_class_ftrace_##call = { \ .system = __stringify(TRACE_SYSTEM), \ .define_fields = ftrace_define_fields_##call, \ .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
kernel/trace/trace_syscalls.c +2 -2
@@ -479,7 +479,7 @@ struct trace_event_functions exit_syscall_print_funcs = { .trace = print_syscall_exit, }; -struct ftrace_event_class event_class_syscall_enter = { +struct ftrace_event_class __refdata event_class_syscall_enter = { .system ="syscalls" , .reg = syscall_enter_register, .define_fields = syscall_enter_define_fields,
@@ -487,7 +487,7 @@ struct ftrace_event_class event_class_syscall_enter = { .raw_init = init_syscall_trace, }; -struct ftrace_event_class event_class_syscall_exit = { +struct ftrace_event_class __refdata event_class_syscall_exit = { .system ="syscalls" , .reg = syscall_exit_register, .define_fields = syscall_exit_define_fields,
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 5/6 tracing: Fix trace events build without modules
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
The new multi-buffers added a descriptor that kept track of module events, and the directories they use, with struct ftace_module_file_ops. This is used to add a ref count to keep modules from unloading while their files are being accessed.
As the descriptor is only needed when CONFIG_MODULES is enabled, it is only declared when the config is enabled. But that struct is dereferenced in a few areas outside the #ifdef CONFIG_MODULES.
By adding some helper routines and moving code around a little, events can be compiled again without modules.
--- kernel/trace/trace_events.c | 55 ++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-)
kernel/trace/trace_events.c +36 -19
@@ -1546,9 +1546,18 @@ struct ftrace_module_file_ops {struct file_operations filter; }; -static struct ftrace_module_file_ops *find_ftrace_file_ops (struct module *mod) +static struct ftrace_module_file_ops * +find_ftrace_file_ops (struct ftrace_module_file_ops *file_ops,struct module *mod) { -struct ftrace_module_file_ops *file_ops; +/* +* As event_calls are added in groups by module, +* when we find one file_ops, we don't need to search for +* each call in that module, as the rest should be the +* same. Only search for a new one if the last one did +* not match. +*/ +if (file_ops && mod == file_ops->mod) +return file_ops;list_for_each_entry (file_ops, &ftrace_module_file_list, list) {if (file_ops->mod == mod)
@@ -1664,16 +1673,35 @@ static int trace_module_notify(struct notifier_block *self,return 0 ; } + +static int +__trace_add_new_mod_event (struct ftrace_event_call *call, +struct trace_array *tr, +struct ftrace_module_file_ops *file_ops) +{ +return __trace_add_new_event (call, tr, + &file_ops->id, &file_ops->enable, + &file_ops->filter, &file_ops->format); +} +#else -static struct ftrace_module_file_ops *find_ftrace_file_ops (struct module *mod) +static inline struct ftrace_module_file_ops * +find_ftrace_file_ops (struct ftrace_module_file_ops *file_ops,struct module *mod) {return NULL ; } -static int trace_module_notify (struct notifier_block *self, -unsigned long val,void *data) +static inline int trace_module_notify (struct notifier_block *self, +unsigned long val,void *data) {return 0 ; } +static inline int +__trace_add_new_mod_event (struct ftrace_event_call *call, +struct trace_array *tr, +struct ftrace_module_file_ops *file_ops) +{ +return -ENODEV ; +}#endif /* CONFIG_MODULES */ /* Create a new event directory structure for a trace directory. */
@@ -1692,20 +1720,11 @@ __trace_add_event_dirs(struct trace_array *tr)* want the module to disappear when reading one * of these files). The file_ops keep account of * the module ref count. -* -* As event_calls are added in groups by module, -* when we find one file_ops, we don't need to search for -* each call in that module, as the rest should be the -* same. Only search for a new one if the last one did -* not match. */ -if (!file_ops || call->mod != file_ops->mod) - file_ops =find_ftrace_file_ops (call->mod); + file_ops =find_ftrace_file_ops (file_ops, call->mod);if (!file_ops)continue ;/* Warn? */ - ret =__trace_add_new_event (call, tr, - &file_ops->id, &file_ops->enable, - &file_ops->filter, &file_ops->format); + ret =__trace_add_new_mod_event (call, tr, file_ops);if (ret <0 )pr_warning ("Could not create directory for event %s\n" , call->name);
@@ -1794,9 +1813,7 @@ __add_event_to_tracers(struct ftrace_event_call *call,list_for_each_entry (tr, &ftrace_trace_arrays, list) {if (file_ops) -__trace_add_new_event (call, tr, - &file_ops->id, &file_ops->enable, - &file_ops->filter, &file_ops->format); +__trace_add_new_mod_event (call, tr, file_ops);else __trace_add_new_event(call, tr, &ftrace_event_id_fops,
Signature · 1 line
1.7.10.4
Steven Rostedt
maintainerPATCH 4/6 tracing: Add __per_cpu annotation to trace array percpu data pointer
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
With the conversion of the data array to per cpu, sparse now complains about the use of per_cpu_ptr() on the variable. But The variable is allocated with alloc_percpu() and is fine to use. But since the structure that contains the data variable does not annotate it as such, sparse gives out a lot of false warnings.
--- kernel/trace/trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.h +1 -1
@@ -198,7 +198,7 @@ struct trace_array {struct list_head systems;struct list_head events;struct task_struct *waiter; -struct trace_array_cpu *data; +struct trace_array_cpu __percpu *data; };enum {
Signature · 1 line
1.7.10.4