tracing: Fix and trace event space savings
Steven Rostedt
maintainerIngo,
Please pull the latest tip/tracing/core tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/core
Javier Martinez Canillas (1):
tracing: Fix strstrip usage in set_ftrace_pid
Steven Rostedt (3):
tracing: Create new TRACE_EVENT_TEMPLATE
tracing: Create new DEFINE_EVENT_PRINT
tracing: Convert some sched trace events to DEFINE_EVENT and _PRINT
----
include/linux/tracepoint.h | 6 + include/trace/define_trace.h | 8 ++ include/trace/events/sched.h | 170 ++++++++------------------- include/trace/ftrace.h | 266 +++++++++++++++++++++++++++++++++++------- kernel/trace/ftrace.c | 7 +- 5 files changed, 293 insertions(+), 164 deletions(-)
Steven Rostedt
maintainerPATCH 1/4 tracing: Fix strstrip usage in set_ftrace_pid
From: Javier Martinez Canillas <[email protected]>
The code in writing to set_ftrace_pid crops off whitespace before and after the passed in string. But the usage of strstrip is incorrect, and does not do the intended job.
# echo ' 3431 ' > /debug/tracing/set_ftrace_pid -bash: echo: write error: Invalid argument
With this fix, the above line now succeeds.
LKML-Reference: <1256965563.4278.7.camel@laptop>
--- kernel/trace/ftrace.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-)
kernel/trace/ftrace.c +4 -3
@@ -2987,6 +2987,7 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf, {char buf[64 ];long val; +char *bufstr;int ret;if (cnt >=sizeof (buf))
@@ -3001,11 +3002,11 @@ ftrace_pid_write(struct file *filp, const char __user *ubuf,* Allow "echo > set_ftrace_pid" or "echo -n '' > set_ftrace_pid" * to clean the filter quietly. */ -strstrip (buf); -if (strlen (buf) ==0 ) + bufstr =strstrip (buf); +if (strlen (bufstr) ==0 )return 1 ; - ret =strict_strtol (buf,10 , &val); + ret =strict_strtol (bufstr,10 , &val);if (ret <0 )return ret;
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 2/4 tracing: Create new TRACE_EVENT_TEMPLATE
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
There are some places in the kernel that define several tracepoints and they are all identical besides the name. The code to enable, disable and record is created for every trace point even if most of the code is identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create a template TRACE_EVENT and create trace points with DEFINE_EVENT, which is based off of a given template. Each trace point used by this will share most of the code, and bring down the size of the kernel when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template is the name of the TRACE_EVENT_TEMPLATE to use. The name is the name of the trace point. The parameters proto and args must be the same as the proto and args of the template. If they are not the same, then a compile error will result. I tried hard removing this duplication but the C preprocessor is not powerful enough (or my CPP magic experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of the trace points are identical except for the name. The following shows the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.tracexfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
--- include/linux/tracepoint.h | 4 + include/trace/define_trace.h | 4 + include/trace/ftrace.h | 149 ++++++++++++++++++++++++++++++------------ 3 files changed, 115 insertions(+), 42 deletions(-)
include/linux/tracepoint.h +4 -0
@@ -280,6 +280,10 @@ static inline void tracepoint_synchronize_unregister(void)* TRACE_EVENT_FN to perform any (un)registration work. */ +#define TRACE_EVENT_TEMPLATE (name, proto, args, tstruct, assign, print) +#define DEFINE_EVENT (template, name, proto, args) \ + DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) +#define TRACE_EVENT (name, proto, args, struct, assign, print) \ DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) #define TRACE_EVENT_FN(name, proto, args, struct, \
include/trace/define_trace.h +4 -0
@@ -31,6 +31,10 @@ assign, print, reg, unreg) \ DEFINE_TRACE_FN(name, reg, unreg) +#undef DEFINE_EVENT +#define DEFINE_EVENT (template, name, proto, args) \ + DEFINE_TRACE(name) +#undef DECLARE_TRACE#define DECLARE_TRACE (name, proto, args) \ DEFINE_TRACE(name)
include/trace/ftrace.h +107 -42
286 lines not on this page · raw message
Signature · 1 line
1.6.5
Re: [PATCH 2/4] [PATCH 2/4] tracing: Create new TRACE_EVENT_TEMPLATE
Quoted 7 lines · Steven Rostedt
From: Steven Rostedt <[email protected]>
There are some places in the kernel that define several tracepoints and they are all identical besides the name. The code to enable, disable and record is created for every trace point even if most of the code is identical.
Quoted 6 lines
This patch adds
TRACE_EVENT_TEMPLATEthat lets the developer create a templateTRACE_EVENTand create trace points withDEFINE_EVENT, which is based off of a given template. Each trace point used by this will share most of the code, and bring down the size of the kernel when there are several duplicate events.
Great!
There are quite many places that this template can be used.
If you haven't planed to convert other TRACE_EVENTs, I'll take it.
More over, I'll cook another patch to annotate some functions as __init, so shrink the kernel size further.
Steven Rostedt
maintainerPATCH 3/4 tracing: Create new DEFINE_EVENT_PRINT
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
After creating the TRACE_EVENT_TEMPLATE I started to look at other trace points to see what duplication was made. I noticed that there are several trace points where they are almost identical except for the name and the output format. Since TRACE_EVENT_TEMPLATE was successful in bringing down the size of trace events, I added a DEFINE_EVENT_PRINT.
DEFINE_EVENT_PRINT is used just like DEFINE_EVENT is. That is, the DEFINE_EVENT_PRINT also uses a TRACE_EVENT_TEMPLATE, but it allows the developer to overwrite the print format. If there are two or more TRACE_EVENTS that are identical except for the name and print, then they can be converted to use a TRACE_EVENT_TEMPLATE. Since the TRACE_EVENT_TEMPLATE already does the print output, the first trace event would have its print format held in the TRACE_EVENT_TEMPLATE and be defined with a DEFINE_EVENT. The rest will use the DEFINE_EVENT_PRINT and override the print format.
Converting the sched trace points to both DEFINE_EVENT and DEFINE_EVENT_PRINT. Five were converted to DEFINE_EVENT and two were converted to DEFINE_EVENT_PRINT.
I was able to get the following:
$ size kernel/sched.o-* text data bss dec hex filename 79299 6776 2520 88595 15a13 kernel/sched.o-notrace 101941 11896 2584 116421 1c6c5 kernel/sched.o-templ 104779 11896 2584 119259 1d1db kernel/sched.o-trace
sched.o-notrace is the scheduler compiled with no trace points. sched.o-templ is with the use of DEFINE_EVENT and DEFINE_EVENT_PRINT sched.o-trace is the current trace events.
--- include/linux/tracepoint.h | 2 + include/trace/define_trace.h | 4 ++ include/trace/ftrace.h | 123 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 125 insertions(+), 4 deletions(-)
include/linux/tracepoint.h +2 -0
@@ -283,6 +283,8 @@ static inline void tracepoint_synchronize_unregister(void)#define TRACE_EVENT_TEMPLATE (name, proto, args, tstruct, assign, print)#define DEFINE_EVENT (template, name, proto, args) \ DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) +#define DEFINE_EVENT_PRINT (template, name, proto, args, print) \ + DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))#define TRACE_EVENT (name, proto, args, struct, assign, print) \ DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
include/trace/define_trace.h +4 -0
@@ -35,6 +35,10 @@#define DEFINE_EVENT (template, name, proto, args) \ DEFINE_TRACE(name) +#undef DEFINE_EVENT_PRINT +#define DEFINE_EVENT_PRINT (template, name, proto, args, print) \ + DEFINE_TRACE(name) +#undef DECLARE_TRACE#define DECLARE_TRACE (name, proto, args) \ DEFINE_TRACE(name)
include/trace/ftrace.h +119 -4
195 lines not on this page · raw message
Signature · 1 line
1.6.5
Steven Rostedt
maintainerPATCH 4/4 tracing: Convert some sched trace events to DEFINE_EVENT and _PRINT
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Converting some of the scheduler trace events to use the TRACE_EVENT_TEMPLATE, DEFINE_EVENT and DEFINE_EVENT_PRINT helped to save some space:
$ size kernel/sched.o-* text data bss dec hex filename 79299 6776 2520 88595 15a13 kernel/sched.o-notrace 101941 11896 2584 116421 1c6c5 kernel/sched.o-templ 104779 11896 2584 119259 1d1db kernel/sched.o-trace
sched.o-notrace is without any tracepoints compiled sched.o-templ is with this patch sched.o-trace is the tracepoints before this patch
The trace events converted to DEFINE_EVENT:
sched_wakeup, sched_wakeup_new, sched_process_free, sched_process_exit, and sched_stat_wait.
The trace events converted to DEFINE_EVENT_PRINT:
sched_stat_sleep and sched_stat_iowait.
Note, since the TRACE_EVENT_TEMPLATE always uses a print, the sched_stat_wait print format is defined in the template and this template is used by sched_stat_sleep and sched_stat_iowait. But the later two override the print format.
--- include/trace/events/sched.h | 170 +++++++++++++----------------------------- 1 files changed, 52 insertions(+), 118 deletions(-)
include/trace/events/sched.h +52 -118
@@ -83,7 +83,7 @@ TRACE_EVENT(sched_wait_task,* (NOTE: the 'rq' argument is not used by generic trace events, * but used by the latency tracer plugin. ) */ -TRACE_EVENT(sched_wakeup, +TRACE_EVENT_TEMPLATE(sched_wakeup_template, TP_PROTO(struct rq *rq, struct task_struct *p, int success),
@@ -110,38 +110,19 @@ TRACE_EVENT(sched_wakeup, __entry->success, __entry->cpu) ); +DEFINE_EVENT (sched_wakeup_template, sched_wakeup, + TP_PROTO(struct rq *rq, struct task_struct *p, int success), +TP_ARGS (rq, p, success)); +/* * Tracepoint for waking up a new task: * * (NOTE: the 'rq' argument is not used by generic trace events, * but used by the latency tracer plugin. ) */ -TRACE_EVENT (sched_wakeup_new, - - TP_PROTO(struct rq *rq, struct task_struct *p, int success), - -TP_ARGS (rq, p, success), - -TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) - __field( pid_t, pid ) - __field( int, prio ) - __field( int, success ) -__field ( int, cpu ) - ), - -TP_fast_assign ( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); - __entry->pid = p->pid; - __entry->prio = p->prio; - __entry->success = success; - __entry->cpu = task_cpu(p); - ), - -TP_printk ("task %s:%d [%d] success=%d [%03d]" , - __entry->comm, __entry->pid, __entry->prio, - __entry->success, __entry->cpu) -); +DEFINE_EVENT (sched_wakeup_template, sched_wakeup_new, + TP_PROTO(struct rq *rq, struct task_struct *p, int success), +TP_ARGS (rq, p, success));/* * Tracepoint for task switches, performed by the scheduler:
@@ -216,10 +197,7 @@ TRACE_EVENT(sched_migrate_task, __entry->orig_cpu, __entry->dest_cpu) ); -/* -* Tracepoint for freeing a task: -*/ -TRACE_EVENT(sched_process_free, +TRACE_EVENT_TEMPLATE(sched_process_template, TP_PROTO(struct task_struct *p),
@@ -242,29 +220,19 @@ TRACE_EVENT(sched_process_free, );/* -* Tracepoint for a task exiting: +* Tracepoint for freeing a task: */ -TRACE_EVENT (sched_process_exit, - - TP_PROTO(struct task_struct *p), +DEFINE_EVENT (sched_process_template, sched_process_free, + TP_PROTO(struct task_struct *p), +TP_ARGS (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 ("task %s:%d [%d]" , - __entry->comm, __entry->pid, __entry->prio) -); +/* +* Tracepoint for a task exiting: +*/ +DEFINE_EVENT (sched_process_template, sched_process_exit, + TP_PROTO(struct task_struct *p), +TP_ARGS (p));/* * Tracepoint for a waiting task:
@@ -348,12 +316,7 @@ TRACE_EVENT(sched_signal_send,* XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE * adding sched_stat support to SCHED_FIFO/RR would be welcome. */ - -/* -* Tracepoint for accounting wait time (time the task is runnable -* but not actually running due to scheduler contention). -*/ -TRACE_EVENT(sched_stat_wait, +TRACE_EVENT_TEMPLATE(sched_stat_template, TP_PROTO(struct task_struct *tsk, u64 delay),
@@ -379,6 +342,37 @@ TRACE_EVENT(sched_stat_wait, (unsigned long long)__entry->delay) ); + +/* +* Tracepoint for accounting wait time (time the task is runnable +* but not actually running due to scheduler contention). +*/ +DEFINE_EVENT (sched_stat_template, sched_stat_wait, + TP_PROTO(struct task_struct *tsk, u64 delay), +TP_ARGS (tsk, delay)); + +/* +* Tracepoint for accounting sleep time (time the task is not runnable, +* including iowait, see below). +*/ +DEFINE_EVENT_PRINT (sched_stat_template, sched_stat_sleep, + TP_PROTO(struct task_struct *tsk, u64 delay), +TP_ARGS (tsk, delay), +TP_printk ("task: %s:%d sleep: %Lu [ns]" , + __entry->comm, __entry->pid, + (unsigned long long )__entry->delay)); + +/* +* Tracepoint for accounting iowait time (time the task is not runnable +* due to waiting on IO to complete). +*/ +DEFINE_EVENT_PRINT (sched_stat_template, sched_stat_iowait, + TP_PROTO(struct task_struct *tsk, u64 delay), +TP_ARGS (tsk, delay), +TP_printk ("task: %s:%d iowait: %Lu [ns]" , + __entry->comm, __entry->pid, + (unsigned long long )__entry->delay)); +/* * Tracepoint for accounting runtime (time the task is executing * on a CPU).
@@ -412,66 +406,6 @@ TRACE_EVENT(sched_stat_runtime, (unsigned long long)__entry->vruntime) ); -/* -* Tracepoint for accounting sleep time (time the task is not runnable, -* including iowait, see below). -*/ -TRACE_EVENT (sched_stat_sleep, - - TP_PROTO(struct task_struct *tsk, u64 delay), - -TP_ARGS (tsk, delay), - -TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) - __field( pid_t, pid ) -__field ( u64, delay ) - ), - - TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); - __entry->pid = tsk->pid; - __entry->delay = delay; - ) -TP_perf_assign ( - __perf_count(delay); - ), - -TP_printk ("task: %s:%d sleep: %Lu [ns]" , - __entry->comm, __entry->pid, - (unsigned long long )__entry->delay) -); - -/* -* Tracepoint for accounting iowait time (time the task is not runnable -* due to waiting on IO to complete). -*/ -TRACE_EVENT (sched_stat_iowait, - - TP_PROTO(struct task_struct *tsk, u64 delay), - -TP_ARGS (tsk, delay), - -TP_STRUCT__entry ( - __array( char, comm, TASK_COMM_LEN ) - __field( pid_t, pid ) -__field ( u64, delay ) - ), - - TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); - __entry->pid = tsk->pid; - __entry->delay = delay; - ) -TP_perf_assign ( - __perf_count(delay); - ), - -TP_printk ("task: %s:%d iowait: %Lu [ns]" , - __entry->comm, __entry->pid, - (unsigned long long )__entry->delay) -); -#endif /* _TRACE_SCHED_H */ /* This part must be outside protection */
Signature · 1 line
1.6.5