tracing: Showing symbols for TRACE_EVENT
Subsystems (2)
Steven Rostedt
maintainerv2 cover tracing: Showing symbols for TRACE_EVENT
Frederic,
Is this what you were thinking about?
Peter,
This now tightly couples the enum with the trace export. It also allows you to couple it with the current __print_symbolic()
Careful, I may start getting CPP happy again.
-- Steve
Steven Rostedt
maintainerPATCH v2 1/2 tracing: Add EXTRACT_TRACE_SYMBOL() macro
The trace events that are created with the TRACE_EVENT family macros can be read by binary readers, such as perf and trace-cmd. In order to translate the binary data, the events also have a format file associated with them. This format file explains the offset, size and signedness of elements in the raw binary data of an event.
At the end of the format file, there is a description on how to print this data. A helper function is used to map numbers into strings called __print_symbolic(). A problem arises when these numbers are defined as enums in the kernel. The macros that export this data into the format file does not translate the enums into numbers. Thus we have in the irq.h file:
#define softirq_name(sirq) { sirq##_SOFTIRQ, #sirq }
#define show_softirq_name(val) \
__print_symbolic(val, \
softirq_name(HI), \
softirq_name(TIMER), \
softirq_name(NET_TX), \
softirq_name(NET_RX), \
softirq_name(BLOCK), \
softirq_name(BLOCK_IOPOLL), \
softirq_name(TASKLET), \
softirq_name(SCHED), \
softirq_name(HRTIMER), \
softirq_name(RCU))
TP_printk("vec=%d [action=%s]", __entry->vec,
show_softirq_name(__entry->vec))Which shows up in the event format file as:
print fmt: "vec=%d [action=%s]", REC->vec, __print_symbolic(REC->vec, { HI_SOFTIRQ, "HI" }, { TIMER_SOFTIRQ, "TIMER" }, { NET_TX_SOFTIRQ, "NET_TX" }, { NET_RX_SOFTIRQ, "NET_RX" }, { BLOCK_SOFTIRQ, "BLOCK" }, { BLOCK_IOPOLL_SOFTIRQ, "BLOCK_IOPOLL" }, { TASKLET_SOFTIRQ, "TASKLET" }, { SCHED_SOFTIRQ, "SCHED" }, { HRTIMER_SOFTIRQ, "HRTIMER" }, { RCU_SOFTIRQ, "RCU" })
The parser has no idea of how to translate "HI_SOFTIRQ" into a number.
This patch adds an EXTRACT_TRACE_SYMBOLS() macro that lets a trace header define symbols that it uses, and will be converted into numbers. These symbols will be shown in an "event_symbols" file in the event directory.
Enums that use this also need to be converted into the following format:
#define ENUMS \ C(ENUM1) \ C(ENUM2) \ C(ENUM3)
#define C(name) name
enum { ENUMS };
#undef C
Then the trace header can do the following:
#define C(name) TRACE_SYMBOL_PARSE(#name, name, sizeof(name)) EXTRACT_TRACE_SYMBOLS(mysyms, ENUMS)
For example, for the softirq names we can now have:
#define C(sirq) \
TRACE_SYMBOL_PARSE(#sirq, sirq##_SOFTIRQ, sizeof(sirq##_SOFTIRQ))
EXTRACT_TRACE_SYMBOLS(softirqs, SOFTIRQ_NAMES)
where the SOFTIRQ_NAMES are defined as:
#define SOFTIRQ_NAMES \ C(HI), \ C(TIMER), \ C(NET_TX), \ [...] C(RCU)
#define C(name) name##_SOFTIRQ
enum { SOFTIRQ_NAMES, NR_SOFTIRQS };
This produces:
[tracing/]$ cat events/event_symbols
# Symbol:Size:Value
# =================
HI_SOFTIRQ:4:0
TIMER_SOFTIRQ:4:1
NET_TX_SOFTIRQ:4:2
NET_RX_SOFTIRQ:4:3
BLOCK_SOFTIRQ:4:4
BLOCK_IOPOLL_SOFTIRQ:4:5
TASKLET_SOFTIRQ:4:6
SCHED_SOFTIRQ:4:7
HRTIMER_SOFTIRQ:4:8
RCU_SOFTIRQ:4:9
Now a parser can read this file and replace symbols it encounters in the format files with an actual number.
Changes since v1:
- Added separate header to store struct trace_syms
- Document fields of struct trace_syms (both suggested by Andrew Morton)
- Coupled the enums with the exports with one macro (suggested by Frederic Weisbecker)
--- include/asm-generic/vmlinux.lds.h | 4 + include/linux/tracepoint.h | 2 include/trace/define_trace.h | 18 ++++++++ include/trace/trace_syms.h | 14 ++++++ kernel/trace/trace_events.c | 84 +++++++++++++++++++++++++++++++++++++- 5 files changed, 121 insertions(+), 1 deletion(-)
include/asm-generic/vmlinux.lds.h +4 -0
@@ -163,6 +163,10 @@ VMLINUX_SYMBOL(__start___verbose) = .; \ *(__verbose ) \ VMLINUX_SYMBOL(__stop___verbose) = .; \ + . = ALIGN(32); \ + VMLINUX_SYMBOL(__start_trace_syms) = .; \ + *(_trace_symbols ) \ + VMLINUX_SYMBOL(__stop_trace_syms) = .; \ LIKELY_PROFILE() \ BRANCH_PROFILE() \TRACE_PRINTKS () \
include/linux/tracepoint.h +2 -0
@@ -292,4 +292,6 @@ static inline void tracepoint_synchroniz assign, print, reg, unreg) \ DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) +#define EXTRACT_TRACE_SYMBOLS (name, symbols) +#endif /* ifdef TRACE_EVENT (see note above) */
include/trace/define_trace.h +18 -0
@@ -20,6 +20,7 @@/* Prevent recursion */ #undef CREATE_TRACE_POINTS +#include <trace/trace_syms.h> #include <linux/stringify.h> #undef TRACE_EVENT
@@ -43,6 +44,20 @@#define DECLARE_TRACE (name, proto, args) \ DEFINE_TRACE(name) +#undef EXTRACT_TRACE_SYMBOLS +#define EXTRACT_TRACE_SYMBOLS (name, symbols) \ + struct trace_syms ___trace_sym_##name[] \ + __attribute__((section("_trace_symbols"), aligned(4))) = { \ + symbols \ + } + +#define TRACE_SYMBOL_PARSE (symbol, value, sym_size) \ + { \ + .name = symbol, \ + .val = (u64)(value), \ + .size = sym_size \ + } +#undef TRACE_INCLUDE#undef __TRACE_INCLUDE
@@ -65,6 +80,9 @@#include TRACE_INCLUDE (TRACE_INCLUDE_FILE ) +#undef EXTRACT_TRACE_SYMBOLS +#define EXTRACT_TRACE_SYMBOLS (name, symbols) +#ifdef CONFIG_EVENT_TRACING #include <trace/ftrace.h> #endif
kernel/trace/trace_events.c +83 -1
114 lines not on this page · raw message
include/trace/trace_syms.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _TRACE_SYMS_H +#define _TRACE_SYMS_H + +/* +* This is used by trace/define_trace.h and needs to be in its +* own header to prevent inclusion hell. +*/ +struct trace_syms { +u64 val;/* value of the symbol */ +const char *name;/* name of symbol to export */ +int size;/* size of the value */ +}; + +#endif /* _TRACE_SYMS_H */
Re: [PATCH 1/2 v2] tracing: Add EXTRACT_TRACE_SYMBOL() macro
Quoted 81 lines · Steven Rostedt
The trace events that are created with the
TRACE_EVENTfamily macros can be read by binary readers, such as perf and trace-cmd. In order to translate the binary data, the events also have a format file associated with them. This format file explains the offset, size and signedness of elements in the raw binary data of an event.At the end of the format file, there is a description on how to print this data. A helper function is used to map numbers into strings called
__print_symbolic(). A problem arises when these numbers are defined as enums in the kernel. The macros that export this data into the format file does not translate the enums into numbers. Thus we have in theirq.hfile:#define
softirq_name(sirq){ sirq##_SOFTIRQ, #sirq }#define show_softirq_name(val) \ __print_symbolic(val, \ softirq_name(HI), \ softirq_name(TIMER), \ softirq_name(NET_TX), \ softirq_name(NET_RX), \ softirq_name(BLOCK), \ softirq_name(BLOCK_IOPOLL), \ softirq_name(TASKLET), \ softirq_name(SCHED), \ softirq_name(HRTIMER), \ softirq_name(RCU)) TP_printk("vec=%d [action=%s]", __entry->vec, show_softirq_name(__entry->vec))Which shows up in the event format file as:
print fmt: "vec=%d [action=%s]",
REC->vec, __print_symbolic(REC->vec, {HI_SOFTIRQ, "HI" }, {TIMER_SOFTIRQ, "TIMER" }, {NET_TX_SOFTIRQ, "NET_TX" }, {NET_RX_SOFTIRQ, "NET_RX" }, {BLOCK_SOFTIRQ, "BLOCK" }, {BLOCK_IOPOLL_SOFTIRQ, "BLOCK_IOPOLL" }, {TASKLET_SOFTIRQ, "TASKLET" }, {SCHED_SOFTIRQ, "SCHED" }, {HRTIMER_SOFTIRQ, "HRTIMER" }, {RCU_SOFTIRQ, "RCU" })The parser has no idea of how to translate "
HI_SOFTIRQ" into a number.This patch adds an
EXTRACT_TRACE_SYMBOLS()macro that lets a trace header define symbols that it uses, and will be converted into numbers. These symbols will be shown in an "event_symbols" file in the event directory.Enums that use this also need to be converted into the following format:
#define ENUMS \ C(ENUM1) \ C(ENUM2) \ C(ENUM3)#define C(name) name
enum { ENUMS };
#undef CThen the trace header can do the following:
#define C(name) TRACE_SYMBOL_PARSE(#name, name, sizeof(name)) EXTRACT_TRACE_SYMBOLS(mysyms, ENUMS)For example, for the softirq names we can now have:
#define C(sirq) \
TRACE_SYMBOL_PARSE(#sirq, sirq##_SOFTIRQ, sizeof(sirq##_SOFTIRQ))
EXTRACT_TRACE_SYMBOLS(softirqs, SOFTIRQ_NAMES)where the
SOFTIRQ_NAMESare defined as:#define SOFTIRQ_NAMES \ C(HI), \ C(TIMER), \ C(NET_TX), \ [...] C(RCU)#define C(name) name##_SOFTIRQ
enum {SOFTIRQ_NAMES,NR_SOFTIRQS};This produces:
Quoted 13 lines
[tracing/]$ cat events/event_symbols # Symbol:Size:Value # ================= HI_SOFTIRQ:4:0 TIMER_SOFTIRQ:4:1 NET_TX_SOFTIRQ:4:2 NET_RX_SOFTIRQ:4:3 BLOCK_SOFTIRQ:4:4 BLOCK_IOPOLL_SOFTIRQ:4:5 TASKLET_SOFTIRQ:4:6 SCHED_SOFTIRQ:4:7 HRTIMER_SOFTIRQ:4:8 RCU_SOFTIRQ:4:9
There is a risk of having a big mess in this file if we have various types of enums inside. I mean, it doesn't make the things easy for the tools as they will have to iterate through the whole list and sort it out using the suffixes (*_SOFTIRQ).
We could perhaps have this per event subsystem?
cat events/irq/event_symbols
include/linux/tracepoint.h static inline void tracepoint_synchroniz · line 295
Quoted 10 lines
TRACE_PRINTKS()\
Index:linux-trace.git/include/linux/tracepoint.h
===================================================================include/linux/tracepoint.h +1
-0@@ -292,4 +292,6 @@ static inline void tracepoint_synchroniz assign, print, reg, unreg) \ DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) +#define EXTRACT_TRACE_SYMBOLS (name, symbols)
So this could also take the name of the subsystem.
Quoted 20 lines
include/linux/tracepoint.h +1
-0+#endif /* ifdef TRACE_EVENT (see note above) */ Index:
linux-trace.git/include/trace/define_trace.h
===================================================================include/trace/define_trace.h +3
-0@@ -20,6 +20,7 @@/* Prevent recursion */ #undef CREATE_TRACE_POINTS +#include <trace/trace_syms.h> #include <linux/stringify.h> #undef TRACE_EVENT@@ -43,6 +44,20 @@#define DECLARE_TRACE (name, proto, args) \ DEFINE_TRACE(name) +#undef EXTRACT_TRACE_SYMBOLS +#define EXTRACT_TRACE_SYMBOLS (name, symbols) \
include/trace/define_trace.h line 58
Quoted 10 lines
include/trace/define_trace.h +10
-0+ struct trace_syms ___trace_sym_##name[] \ + __attribute__((section("_trace_symbols"), aligned(4))) = { \ + symbols \ + } + +#define TRACE_SYMBOL_PARSE (symbol, value, sym_size) \ + { \ + .name = symbol, \ + .val = (u64)(value), \ + .size = sym_size \
...which could be appended there.
What do you think?
Steven Rostedt
maintainerPATCH v2 2/2 tracing: Add extract out softirq names used by irq trace events
In reply to Steven RostedtThe irq trace events that map the softirq vectors to strings shows up in the format files as names. To allow binary parsers to be able to convert these names to their actual numbers, this patch extracts those enums.
In doing this, we also change the way the softirq names are defined. This gives us a tight coupling between the names and what is exported as well as used by the __print_symbolic() macro.
--- include/linux/interrupt.h | 29 ++++++++++++++++++----------- include/trace/events/irq.h | 22 ++++++++++------------ 2 files changed, 28 insertions(+), 23 deletions(-)
include/trace/events/irq.h +10 -12
@@ -7,19 +7,15 @@#include <linux/tracepoint.h> #include <linux/interrupt.h> -#define softirq_name (sirq) { sirq##_SOFTIRQ, #sirq } +#define C (sirq) \ + TRACE_SYMBOL_PARSE(#sirq, sirq##_SOFTIRQ, sizeof(sirq##_SOFTIRQ)) + +EXTRACT_TRACE_SYMBOLS (softirqs,SOFTIRQ_NAMES ); + +#undef C +#define C (sirq) { sirq##_SOFTIRQ, #sirq }#define show_softirq_name (val) \ - __print_symbolic(val, \ - softirq_name(HI), \ - softirq_name(TIMER), \ - softirq_name(NET_TX), \ - softirq_name(NET_RX), \ - softirq_name(BLOCK), \ - softirq_name(BLOCK_IOPOLL), \ - softirq_name(TASKLET), \ - softirq_name(SCHED), \ - softirq_name(HRTIMER), \ - softirq_name(RCU)) + __print_symbolic(val, SOFTIRQ_NAMES)/** * irq_handler_entry - called immediately before the irq action handler
@@ -136,6 +132,8 @@ DEFINE_EVENT(softirq, softirq_exit,TP_ARGS (h, vec) ); +#undef C +#endif /* _TRACE_IRQ_H */ /* This part must be outside protection */
include/linux/interrupt.h +18 -11
@@ -338,21 +338,28 @@ static inline int disable_irq_wake(unsigal. should be converted to tasklets, not to softirqs. */ +#define SOFTIRQ_NAMES \ + C(HI), \ + C(TIMER), \ + C(NET_TX), \ + C(NET_RX), \ + C(BLOCK), \ + C(BLOCK_IOPOLL), \ + C(TASKLET), \ + C(SCHED), \ + C(HRTIMER), \ +/* Preferable RCU should always be the last softirq */ \ + C(RCU) + +#undef C +#define C (name) name##_SOFTIRQ +enum { -HI_SOFTIRQ =0 , -TIMER_SOFTIRQ , -NET_TX_SOFTIRQ , -NET_RX_SOFTIRQ , -BLOCK_SOFTIRQ , -BLOCK_IOPOLL_SOFTIRQ , -TASKLET_SOFTIRQ , -SCHED_SOFTIRQ , -HRTIMER_SOFTIRQ , -RCU_SOFTIRQ ,/* Preferable RCU should always be the last softirq */ - +SOFTIRQ_NAMES ,NR_SOFTIRQS }; +#undef C/* map softirq index to softirq name. update 'softirq_to_name' in * kernel/softirq.c when adding a new softirq.