Skip to content

Commit a9a5776

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing: Allow events to share their print functions
Multiple events may use the same method to print their data. Instead of having all events have a pointer to their print funtions, the trace_event structure now points to a trace_event_functions structure that will hold the way to print ouf the event. The event itself is now passed to the print function to let the print function know what kind of event it should print. This opens the door to consolidating the way several events print their output. 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 This change slightly increases the size but is needed for the next change. v3: Fix the branch tracer events to handle this change. v2: Fix the new function graph tracer event calls to handle this change. Acked-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: Masami Hiramatsu <mhiramat@redhat.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 0405ab8 commit a9a5776

13 files changed

Lines changed: 192 additions & 92 deletions

‎include/linux/ftrace_event.h‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,25 @@ struct trace_iterator {
7070
};
7171

7272

73+
struct trace_event;
74+
7375
typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
74-
int flags);
75-
struct trace_event {
76-
struct hlist_node node;
77-
struct list_head list;
78-
int type;
76+
int flags, struct trace_event *event);
77+
78+
struct trace_event_functions {
7979
trace_print_func trace;
8080
trace_print_func raw;
8181
trace_print_func hex;
8282
trace_print_func binary;
8383
};
8484

85+
struct trace_event {
86+
struct hlist_node node;
87+
struct list_head list;
88+
int type;
89+
struct trace_event_functions *funcs;
90+
};
91+
8592
extern int register_ftrace_event(struct trace_event *event);
8693
extern int unregister_ftrace_event(struct trace_event *event);
8794

‎include/linux/syscalls.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,12 @@ extern struct ftrace_event_class event_class_syscall_exit;
125125
static struct syscall_metadata __syscall_meta_##sname; \
126126
static struct ftrace_event_call \
127127
__attribute__((__aligned__(4))) event_enter_##sname; \
128-
static struct trace_event enter_syscall_print_##sname = { \
128+
static struct trace_event_functions enter_syscall_print_funcs_##sname = { \
129129
.trace = print_syscall_enter, \
130130
}; \
131+
static struct trace_event enter_syscall_print_##sname = { \
132+
.funcs = &enter_syscall_print_funcs_##sname, \
133+
}; \
131134
static struct ftrace_event_call __used \
132135
__attribute__((__aligned__(4))) \
133136
__attribute__((section("_ftrace_events"))) \
@@ -142,9 +145,12 @@ extern struct ftrace_event_class event_class_syscall_exit;
142145
static struct syscall_metadata __syscall_meta_##sname; \
143146
static struct ftrace_event_call \
144147
__attribute__((__aligned__(4))) event_exit_##sname; \
145-
static struct trace_event exit_syscall_print_##sname = { \
148+
static struct trace_event_functions exit_syscall_print_funcs_##sname = { \
146149
.trace = print_syscall_exit, \
147150
}; \
151+
static struct trace_event exit_syscall_print_##sname = { \
152+
.funcs = &exit_syscall_print_funcs_##sname, \
153+
}; \
148154
static struct ftrace_event_call __used \
149155
__attribute__((__aligned__(4))) \
150156
__attribute__((section("_ftrace_events"))) \

‎include/trace/ftrace.h‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ ftrace_raw_output_id_##call(int event_id, const char *name, \
239239
#undef DEFINE_EVENT
240240
#define DEFINE_EVENT(template, name, proto, args) \
241241
static notrace enum print_line_t \
242-
ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
242+
ftrace_raw_output_##name(struct trace_iterator *iter, int flags, \
243+
struct trace_event *event) \
243244
{ \
244245
return ftrace_raw_output_id_##template(event_##name.id, \
245246
#name, iter, flags); \
@@ -248,7 +249,8 @@ ftrace_raw_output_##name(struct trace_iterator *iter, int flags) \
248249
#undef DEFINE_EVENT_PRINT
249250
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
250251
static notrace enum print_line_t \
251-
ftrace_raw_output_##call(struct trace_iterator *iter, int flags) \
252+
ftrace_raw_output_##call(struct trace_iterator *iter, int flags, \
253+
struct trace_event *event) \
252254
{ \
253255
struct trace_seq *s = &iter->seq; \
254256
struct ftrace_raw_##template *field; \
@@ -531,11 +533,12 @@ ftrace_raw_event_##call(void *__data, proto) \
531533

532534
#undef DEFINE_EVENT
533535
#define DEFINE_EVENT(template, call, proto, args) \
534-
\
535-
static struct trace_event ftrace_event_type_##call = { \
536+
static struct trace_event_functions ftrace_event_type_funcs_##call = { \
536537
.trace = ftrace_raw_output_##call, \
537538
}; \
538-
\
539+
static struct trace_event ftrace_event_type_##call = { \
540+
.funcs = &ftrace_event_type_funcs_##call, \
541+
}; \
539542
static inline void ftrace_test_probe_##call(void) \
540543
{ \
541544
check_trace_callback_type_##call(ftrace_raw_event_##template); \

‎include/trace/syscall.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ extern int reg_event_syscall_exit(struct ftrace_event_call *call);
4242
extern void unreg_event_syscall_exit(struct ftrace_event_call *call);
4343
extern int
4444
ftrace_format_syscall(struct ftrace_event_call *call, struct trace_seq *s);
45-
enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags);
46-
enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags);
45+
enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags,
46+
struct trace_event *event);
47+
enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags,
48+
struct trace_event *event);
4749
#endif
4850

4951
#ifdef CONFIG_PERF_EVENTS

‎kernel/trace/blktrace.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ static enum print_line_t print_one_line(struct trace_iterator *iter,
13361336
}
13371337

13381338
static enum print_line_t blk_trace_event_print(struct trace_iterator *iter,
1339-
int flags)
1339+
int flags, struct trace_event *event)
13401340
{
13411341
return print_one_line(iter, false);
13421342
}
@@ -1358,7 +1358,8 @@ static int blk_trace_synthesize_old_trace(struct trace_iterator *iter)
13581358
}
13591359

13601360
static enum print_line_t
1361-
blk_trace_event_print_binary(struct trace_iterator *iter, int flags)
1361+
blk_trace_event_print_binary(struct trace_iterator *iter, int flags,
1362+
struct trace_event *event)
13621363
{
13631364
return blk_trace_synthesize_old_trace(iter) ?
13641365
TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
@@ -1396,12 +1397,16 @@ static struct tracer blk_tracer __read_mostly = {
13961397
.set_flag = blk_tracer_set_flag,
13971398
};
13981399

1399-
static struct trace_event trace_blk_event = {
1400-
.type = TRACE_BLK,
1400+
static struct trace_event_functions trace_blk_event_funcs = {
14011401
.trace = blk_trace_event_print,
14021402
.binary = blk_trace_event_print_binary,
14031403
};
14041404

1405+
static struct trace_event trace_blk_event = {
1406+
.type = TRACE_BLK,
1407+
.funcs = &trace_blk_event_funcs,
1408+
};
1409+
14051410
static int __init init_blk_tracer(void)
14061411
{
14071412
if (!register_ftrace_event(&trace_blk_event)) {

‎kernel/trace/kmemtrace.c‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ struct kmemtrace_user_event_alloc {
243243
};
244244

245245
static enum print_line_t
246-
kmemtrace_print_alloc(struct trace_iterator *iter, int flags)
246+
kmemtrace_print_alloc(struct trace_iterator *iter, int flags,
247+
struct trace_event *event)
247248
{
248249
struct trace_seq *s = &iter->seq;
249250
struct kmemtrace_alloc_entry *entry;
@@ -263,7 +264,8 @@ kmemtrace_print_alloc(struct trace_iterator *iter, int flags)
263264
}
264265

265266
static enum print_line_t
266-
kmemtrace_print_free(struct trace_iterator *iter, int flags)
267+
kmemtrace_print_free(struct trace_iterator *iter, int flags,
268+
struct trace_event *event)
267269
{
268270
struct trace_seq *s = &iter->seq;
269271
struct kmemtrace_free_entry *entry;
@@ -281,7 +283,8 @@ kmemtrace_print_free(struct trace_iterator *iter, int flags)
281283
}
282284

283285
static enum print_line_t
284-
kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags)
286+
kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags,
287+
struct trace_event *event)
285288
{
286289
struct trace_seq *s = &iter->seq;
287290
struct kmemtrace_alloc_entry *entry;
@@ -315,7 +318,8 @@ kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags)
315318
}
316319

317320
static enum print_line_t
318-
kmemtrace_print_free_user(struct trace_iterator *iter, int flags)
321+
kmemtrace_print_free_user(struct trace_iterator *iter, int flags,
322+
struct trace_event *event)
319323
{
320324
struct trace_seq *s = &iter->seq;
321325
struct kmemtrace_free_entry *entry;
@@ -469,18 +473,26 @@ static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
469473
}
470474
}
471475

472-
static struct trace_event kmem_trace_alloc = {
473-
.type = TRACE_KMEM_ALLOC,
476+
static struct trace_event_functions kmem_trace_alloc_funcs = {
474477
.trace = kmemtrace_print_alloc,
475478
.binary = kmemtrace_print_alloc_user,
476479
};
477480

478-
static struct trace_event kmem_trace_free = {
479-
.type = TRACE_KMEM_FREE,
481+
static struct trace_event kmem_trace_alloc = {
482+
.type = TRACE_KMEM_ALLOC,
483+
.funcs = &kmem_trace_alloc_funcs,
484+
};
485+
486+
static struct trace_event_functions kmem_trace_free_funcs = {
480487
.trace = kmemtrace_print_free,
481488
.binary = kmemtrace_print_free_user,
482489
};
483490

491+
static struct trace_event kmem_trace_free = {
492+
.type = TRACE_KMEM_FREE,
493+
.funcs = &kmem_trace_free_funcs,
494+
};
495+
484496
static struct tracer kmem_tracer __read_mostly = {
485497
.name = "kmemtrace",
486498
.init = kmem_trace_init,

‎kernel/trace/trace.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
19361936
}
19371937

19381938
if (event)
1939-
return event->trace(iter, sym_flags);
1939+
return event->funcs->trace(iter, sym_flags, event);
19401940

19411941
if (!trace_seq_printf(s, "Unknown type %d\n", entry->type))
19421942
goto partial;
@@ -1962,7 +1962,7 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
19621962

19631963
event = ftrace_find_event(entry->type);
19641964
if (event)
1965-
return event->raw(iter, 0);
1965+
return event->funcs->raw(iter, 0, event);
19661966

19671967
if (!trace_seq_printf(s, "%d ?\n", entry->type))
19681968
goto partial;
@@ -1989,7 +1989,7 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
19891989

19901990
event = ftrace_find_event(entry->type);
19911991
if (event) {
1992-
enum print_line_t ret = event->hex(iter, 0);
1992+
enum print_line_t ret = event->funcs->hex(iter, 0, event);
19931993
if (ret != TRACE_TYPE_HANDLED)
19941994
return ret;
19951995
}
@@ -2014,7 +2014,8 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
20142014
}
20152015

20162016
event = ftrace_find_event(entry->type);
2017-
return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED;
2017+
return event ? event->funcs->binary(iter, 0, event) :
2018+
TRACE_TYPE_HANDLED;
20182019
}
20192020

20202021
int trace_empty(struct trace_iterator *iter)

‎kernel/trace/trace_branch.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void branch_trace_reset(struct trace_array *tr)
143143
}
144144

145145
static enum print_line_t trace_branch_print(struct trace_iterator *iter,
146-
int flags)
146+
int flags, struct trace_event *event)
147147
{
148148
struct trace_branch *field;
149149

@@ -167,9 +167,13 @@ static void branch_print_header(struct seq_file *s)
167167
" |\n");
168168
}
169169

170+
static struct trace_event_functions trace_branch_funcs = {
171+
.trace = trace_branch_print,
172+
};
173+
170174
static struct trace_event trace_branch_event = {
171175
.type = TRACE_BRANCH,
172-
.trace = trace_branch_print,
176+
.funcs = &trace_branch_funcs,
173177
};
174178

175179
static struct tracer branch_trace __read_mostly =

‎kernel/trace/trace_functions_graph.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
10251025
if (!event)
10261026
return TRACE_TYPE_UNHANDLED;
10271027

1028-
ret = event->trace(iter, sym_flags);
1028+
ret = event->funcs->trace(iter, sym_flags, event);
10291029
if (ret != TRACE_TYPE_HANDLED)
10301030
return ret;
10311031
}
@@ -1112,7 +1112,8 @@ print_graph_function(struct trace_iterator *iter)
11121112
}
11131113

11141114
static enum print_line_t
1115-
print_graph_function_event(struct trace_iterator *iter, int flags)
1115+
print_graph_function_event(struct trace_iterator *iter, int flags,
1116+
struct trace_event *event)
11161117
{
11171118
return print_graph_function(iter);
11181119
}
@@ -1225,14 +1226,18 @@ void graph_trace_close(struct trace_iterator *iter)
12251226
}
12261227
}
12271228

1229+
static struct trace_event_functions graph_functions = {
1230+
.trace = print_graph_function_event,
1231+
};
1232+
12281233
static struct trace_event graph_trace_entry_event = {
12291234
.type = TRACE_GRAPH_ENT,
1230-
.trace = print_graph_function_event,
1235+
.funcs = &graph_functions,
12311236
};
12321237

12331238
static struct trace_event graph_trace_ret_event = {
12341239
.type = TRACE_GRAPH_RET,
1235-
.trace = print_graph_function_event,
1240+
.funcs = &graph_functions
12361241
};
12371242

12381243
static struct tracer graph_trace __read_mostly = {

‎kernel/trace/trace_kprobe.c‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,16 +1011,15 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
10111011

10121012
/* Event entry printers */
10131013
enum print_line_t
1014-
print_kprobe_event(struct trace_iterator *iter, int flags)
1014+
print_kprobe_event(struct trace_iterator *iter, int flags,
1015+
struct trace_event *event)
10151016
{
10161017
struct kprobe_trace_entry *field;
10171018
struct trace_seq *s = &iter->seq;
1018-
struct trace_event *event;
10191019
struct trace_probe *tp;
10201020
int i;
10211021

10221022
field = (struct kprobe_trace_entry *)iter->ent;
1023-
event = ftrace_find_event(field->ent.type);
10241023
tp = container_of(event, struct trace_probe, event);
10251024

10261025
if (!trace_seq_printf(s, "%s: (", tp->call.name))
@@ -1046,16 +1045,15 @@ print_kprobe_event(struct trace_iterator *iter, int flags)
10461045
}
10471046

10481047
enum print_line_t
1049-
print_kretprobe_event(struct trace_iterator *iter, int flags)
1048+
print_kretprobe_event(struct trace_iterator *iter, int flags,
1049+
struct trace_event *event)
10501050
{
10511051
struct kretprobe_trace_entry *field;
10521052
struct trace_seq *s = &iter->seq;
1053-
struct trace_event *event;
10541053
struct trace_probe *tp;
10551054
int i;
10561055

10571056
field = (struct kretprobe_trace_entry *)iter->ent;
1058-
event = ftrace_find_event(field->ent.type);
10591057
tp = container_of(event, struct trace_probe, event);
10601058

10611059
if (!trace_seq_printf(s, "%s: (", tp->call.name))
@@ -1351,20 +1349,28 @@ int kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)
13511349
return 0; /* We don't tweek kernel, so just return 0 */
13521350
}
13531351

1352+
static struct trace_event_functions kretprobe_funcs = {
1353+
.trace = print_kretprobe_event
1354+
};
1355+
1356+
static struct trace_event_functions kprobe_funcs = {
1357+
.trace = print_kprobe_event
1358+
};
1359+
13541360
static int register_probe_event(struct trace_probe *tp)
13551361
{
13561362
struct ftrace_event_call *call = &tp->call;
13571363
int ret;
13581364

13591365
/* Initialize ftrace_event_call */
13601366
if (probe_is_return(tp)) {
1361-
tp->event.trace = print_kretprobe_event;
1367+
tp->event.funcs = &kretprobe_funcs;
13621368
INIT_LIST_HEAD(&call->class->fields);
13631369
call->class->raw_init = probe_event_raw_init;
13641370
call->class->define_fields = kretprobe_event_define_fields;
13651371
} else {
13661372
INIT_LIST_HEAD(&call->class->fields);
1367-
tp->event.trace = print_kprobe_event;
1373+
tp->event.funcs = &kprobe_funcs;
13681374
call->class->raw_init = probe_event_raw_init;
13691375
call->class->define_fields = kprobe_event_define_fields;
13701376
}

0 commit comments

Comments
 (0)