aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-01-27 09:15:30 -0500
committerSteven Rostedt <rostedt@goodmis.org>2011-02-02 21:37:13 -0500
commite4a9ea5ee7c8812a7bf0c3fb725ceeaa3d4c2fcc (patch)
tree1b25668508fa302a6ada053c895cd55727f798f1
parent9ffdc6c37df131f89d52001e0ef03091b158826f (diff)
tracing: Replace trace_event struct array with pointer array
Currently the trace_event structures are placed in the _ftrace_events section, and at link time, the linker makes one large array of all the trace_event structures. On boot up, this array is read (much like the initcall sections) and the events are processed. The problem is that there is no guarantee that gcc will place complex structures nicely together in an array format. Two structures in the same file may be placed awkwardly, because gcc has no clue that they are suppose to be in an array. A hack was used previous to force the alignment to 4, to pack the structures together. But this caused alignment issues with other architectures (sparc). Instead of packing the structures into an array, the structures' addresses are now put into the _ftrace_event section. As pointers are always the natural alignment, gcc should always pack them tightly together (otherwise initcall, extable, etc would also fail). By having the pointers to the structures in the section, we can still iterate the trace_events without causing unnecessary alignment problems with other architectures, or depending on the current behaviour of gcc that will likely change in the future just to tick us kernel developers off a little more. The _ftrace_event section is also moved into the .init.data section as it is now only needed at boot up. Suggested-by: David Miller <davem@davemloft.net> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--include/asm-generic/vmlinux.lds.h7
-rw-r--r--include/linux/module.h2
-rw-r--r--include/linux/syscalls.h10
-rw-r--r--include/trace/ftrace.h24
-rw-r--r--kernel/trace/trace_events.c12
-rw-r--r--kernel/trace/trace_export.c6
6 files changed, 32 insertions, 29 deletions
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 6ebb81030d2d..f53708be95eb 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -124,7 +124,8 @@
124#endif 124#endif
125 125
126#ifdef CONFIG_EVENT_TRACING 126#ifdef CONFIG_EVENT_TRACING
127#define FTRACE_EVENTS() VMLINUX_SYMBOL(__start_ftrace_events) = .; \ 127#define FTRACE_EVENTS() . = ALIGN(8); \
128 VMLINUX_SYMBOL(__start_ftrace_events) = .; \
128 *(_ftrace_events) \ 129 *(_ftrace_events) \
129 VMLINUX_SYMBOL(__stop_ftrace_events) = .; 130 VMLINUX_SYMBOL(__stop_ftrace_events) = .;
130#else 131#else
@@ -179,9 +180,6 @@
179 TRACE_PRINTKS() \ 180 TRACE_PRINTKS() \
180 \ 181 \
181 STRUCT_ALIGN(); \ 182 STRUCT_ALIGN(); \
182 FTRACE_EVENTS() \
183 \
184 STRUCT_ALIGN(); \
185 TRACE_SYSCALLS() 183 TRACE_SYSCALLS()
186 184
187/* 185/*
@@ -482,6 +480,7 @@
482 KERNEL_CTORS() \ 480 KERNEL_CTORS() \
483 *(.init.rodata) \ 481 *(.init.rodata) \
484 MCOUNT_REC() \ 482 MCOUNT_REC() \
483 FTRACE_EVENTS() \
485 DEV_DISCARD(init.rodata) \ 484 DEV_DISCARD(init.rodata) \
486 CPU_DISCARD(init.rodata) \ 485 CPU_DISCARD(init.rodata) \
487 MEM_DISCARD(init.rodata) \ 486 MEM_DISCARD(init.rodata) \
diff --git a/include/linux/module.h b/include/linux/module.h
index e7c6385c6683..7695a303bb55 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -389,7 +389,7 @@ struct module
389 unsigned int num_trace_bprintk_fmt; 389 unsigned int num_trace_bprintk_fmt;
390#endif 390#endif
391#ifdef CONFIG_EVENT_TRACING 391#ifdef CONFIG_EVENT_TRACING
392 struct ftrace_event_call *trace_events; 392 struct ftrace_event_call **trace_events;
393 unsigned int num_trace_events; 393 unsigned int num_trace_events;
394#endif 394#endif
395#ifdef CONFIG_FTRACE_MCOUNT_RECORD 395#ifdef CONFIG_FTRACE_MCOUNT_RECORD
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 18cd0684fc4e..45508fec366d 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -128,28 +128,30 @@ extern struct trace_event_functions exit_syscall_print_funcs;
128 static struct syscall_metadata \ 128 static struct syscall_metadata \
129 __attribute__((__aligned__(4))) __syscall_meta_##sname; \ 129 __attribute__((__aligned__(4))) __syscall_meta_##sname; \
130 static struct ftrace_event_call __used \ 130 static struct ftrace_event_call __used \
131 __attribute__((__aligned__(4))) \
132 __attribute__((section("_ftrace_events"))) \
133 event_enter_##sname = { \ 131 event_enter_##sname = { \
134 .name = "sys_enter"#sname, \ 132 .name = "sys_enter"#sname, \
135 .class = &event_class_syscall_enter, \ 133 .class = &event_class_syscall_enter, \
136 .event.funcs = &enter_syscall_print_funcs, \ 134 .event.funcs = &enter_syscall_print_funcs, \
137 .data = (void *)&__syscall_meta_##sname,\ 135 .data = (void *)&__syscall_meta_##sname,\
138 }; \ 136 }; \
137 static struct ftrace_event_call __used \
138 __attribute__((section("_ftrace_events"))) \
139 *__event_enter_##sname = &event_enter_##sname; \
139 __TRACE_EVENT_FLAGS(enter_##sname, TRACE_EVENT_FL_CAP_ANY) 140 __TRACE_EVENT_FLAGS(enter_##sname, TRACE_EVENT_FL_CAP_ANY)
140 141
141#define SYSCALL_TRACE_EXIT_EVENT(sname) \ 142#define SYSCALL_TRACE_EXIT_EVENT(sname) \
142 static struct syscall_metadata \ 143 static struct syscall_metadata \
143 __attribute__((__aligned__(4))) __syscall_meta_##sname; \ 144 __attribute__((__aligned__(4))) __syscall_meta_##sname; \
144 static struct ftrace_event_call __used \ 145 static struct ftrace_event_call __used \
145 __attribute__((__aligned__(4))) \
146 __attribute__((section("_ftrace_events"))) \
147 event_exit_##sname = { \ 146 event_exit_##sname = { \
148 .name = "sys_exit"#sname, \ 147 .name = "sys_exit"#sname, \
149 .class = &event_class_syscall_exit, \ 148 .class = &event_class_syscall_exit, \
150 .event.funcs = &exit_syscall_print_funcs, \ 149 .event.funcs = &exit_syscall_print_funcs, \
151 .data = (void *)&__syscall_meta_##sname,\ 150 .data = (void *)&__syscall_meta_##sname,\
152 }; \ 151 }; \
152 static struct ftrace_event_call __used \
153 __attribute__((section("_ftrace_events"))) \
154 *__event_exit_##sname = &event_exit_##sname; \
153 __TRACE_EVENT_FLAGS(exit_##sname, TRACE_EVENT_FL_CAP_ANY) 155 __TRACE_EVENT_FLAGS(exit_##sname, TRACE_EVENT_FL_CAP_ANY)
154 156
155#define SYSCALL_METADATA(sname, nb) \ 157#define SYSCALL_METADATA(sname, nb) \
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index e16610c208c9..3e68366d485a 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -446,14 +446,16 @@ static inline notrace int ftrace_get_offsets_##call( \
446 * .reg = ftrace_event_reg, 446 * .reg = ftrace_event_reg,
447 * }; 447 * };
448 * 448 *
449 * static struct ftrace_event_call __used 449 * static struct ftrace_event_call event_<call> = {
450 * __attribute__((__aligned__(4)))
451 * __attribute__((section("_ftrace_events"))) event_<call> = {
452 * .name = "<call>", 450 * .name = "<call>",
453 * .class = event_class_<template>, 451 * .class = event_class_<template>,
454 * .event = &ftrace_event_type_<call>, 452 * .event = &ftrace_event_type_<call>,
455 * .print_fmt = print_fmt_<call>, 453 * .print_fmt = print_fmt_<call>,
456 * }; 454 * };
455 * // its only safe to use pointers when doing linker tricks to
456 * // create an array.
457 * static struct ftrace_event_call __used
458 * __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
457 * 459 *
458 */ 460 */
459 461
@@ -579,28 +581,28 @@ static struct ftrace_event_class __used event_class_##call = { \
579#undef DEFINE_EVENT 581#undef DEFINE_EVENT
580#define DEFINE_EVENT(template, call, proto, args) \ 582#define DEFINE_EVENT(template, call, proto, args) \
581 \ 583 \
582static struct ftrace_event_call __used \ 584static struct ftrace_event_call __used event_##call = { \
583__attribute__((__aligned__(4))) \
584__attribute__((section("_ftrace_events"))) event_##call = { \
585 .name = #call, \ 585 .name = #call, \
586 .class = &event_class_##template, \ 586 .class = &event_class_##template, \
587 .event.funcs = &ftrace_event_type_funcs_##template, \ 587 .event.funcs = &ftrace_event_type_funcs_##template, \
588 .print_fmt = print_fmt_##template, \ 588 .print_fmt = print_fmt_##template, \
589}; 589}; \
590static struct ftrace_event_call __used \
591__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
590 592
591#undef DEFINE_EVENT_PRINT 593#undef DEFINE_EVENT_PRINT
592#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ 594#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
593 \ 595 \
594static const char print_fmt_##call[] = print; \ 596static const char print_fmt_##call[] = print; \
595 \ 597 \
596static struct ftrace_event_call __used \ 598static struct ftrace_event_call __used event_##call = { \
597__attribute__((__aligned__(4))) \
598__attribute__((section("_ftrace_events"))) event_##call = { \
599 .name = #call, \ 599 .name = #call, \
600 .class = &event_class_##template, \ 600 .class = &event_class_##template, \
601 .event.funcs = &ftrace_event_type_funcs_##call, \ 601 .event.funcs = &ftrace_event_type_funcs_##call, \
602 .print_fmt = print_fmt_##call, \ 602 .print_fmt = print_fmt_##call, \
603} 603}; \
604static struct ftrace_event_call __used \
605__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
604 606
605#include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 607#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
606 608
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 35fde09b81de..5f499e0438a4 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1284,7 +1284,7 @@ trace_create_file_ops(struct module *mod)
1284static void trace_module_add_events(struct module *mod) 1284static void trace_module_add_events(struct module *mod)
1285{ 1285{
1286 struct ftrace_module_file_ops *file_ops = NULL; 1286 struct ftrace_module_file_ops *file_ops = NULL;
1287 struct ftrace_event_call *call, *start, *end; 1287 struct ftrace_event_call **call, **start, **end;
1288 1288
1289 start = mod->trace_events; 1289 start = mod->trace_events;
1290 end = mod->trace_events + mod->num_trace_events; 1290 end = mod->trace_events + mod->num_trace_events;
@@ -1297,7 +1297,7 @@ static void trace_module_add_events(struct module *mod)
1297 return; 1297 return;
1298 1298
1299 for_each_event(call, start, end) { 1299 for_each_event(call, start, end) {
1300 __trace_add_event_call(call, mod, 1300 __trace_add_event_call(*call, mod,
1301 &file_ops->id, &file_ops->enable, 1301 &file_ops->id, &file_ops->enable,
1302 &file_ops->filter, &file_ops->format); 1302 &file_ops->filter, &file_ops->format);
1303 } 1303 }
@@ -1367,8 +1367,8 @@ static struct notifier_block trace_module_nb = {
1367 .priority = 0, 1367 .priority = 0,
1368}; 1368};
1369 1369
1370extern struct ftrace_event_call __start_ftrace_events[]; 1370extern struct ftrace_event_call *__start_ftrace_events[];
1371extern struct ftrace_event_call __stop_ftrace_events[]; 1371extern struct ftrace_event_call *__stop_ftrace_events[];
1372 1372
1373static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; 1373static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1374 1374
@@ -1384,7 +1384,7 @@ __setup("trace_event=", setup_trace_event);
1384 1384
1385static __init int event_trace_init(void) 1385static __init int event_trace_init(void)
1386{ 1386{
1387 struct ftrace_event_call *call; 1387 struct ftrace_event_call **call;
1388 struct dentry *d_tracer; 1388 struct dentry *d_tracer;
1389 struct dentry *entry; 1389 struct dentry *entry;
1390 struct dentry *d_events; 1390 struct dentry *d_events;
@@ -1430,7 +1430,7 @@ static __init int event_trace_init(void)
1430 pr_warning("tracing: Failed to allocate common fields"); 1430 pr_warning("tracing: Failed to allocate common fields");
1431 1431
1432 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) { 1432 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
1433 __trace_add_event_call(call, NULL, &ftrace_event_id_fops, 1433 __trace_add_event_call(*call, NULL, &ftrace_event_id_fops,
1434 &ftrace_enable_fops, 1434 &ftrace_enable_fops,
1435 &ftrace_event_filter_fops, 1435 &ftrace_event_filter_fops,
1436 &ftrace_event_format_fops); 1436 &ftrace_event_format_fops);
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
index 4b74d71705c0..bbeec31e0ae3 100644
--- a/kernel/trace/trace_export.c
+++ b/kernel/trace/trace_export.c
@@ -161,13 +161,13 @@ struct ftrace_event_class event_class_ftrace_##call = { \
161 .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\ 161 .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
162}; \ 162}; \
163 \ 163 \
164struct ftrace_event_call __used \ 164struct ftrace_event_call __used event_##call = { \
165__attribute__((__aligned__(4))) \
166__attribute__((section("_ftrace_events"))) event_##call = { \
167 .name = #call, \ 165 .name = #call, \
168 .event.type = etype, \ 166 .event.type = etype, \
169 .class = &event_class_ftrace_##call, \ 167 .class = &event_class_ftrace_##call, \
170 .print_fmt = print, \ 168 .print_fmt = print, \
171}; \ 169}; \
170struct ftrace_event_call __used \
171__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
172 172
173#include "trace_entries.h" 173#include "trace_entries.h"