Skip to content

Commit a4a551b

Browse files
namhyungrostedt
authored andcommitted
ftrace: Reduce size of function graph entries
Currently ftrace_graph_ent{,_entry} and ftrace_graph_ret{,_entry} struct can have padding bytes at the end due to alignment in 64-bit data type. As these data are recorded so frequently, those paddings waste non-negligible space. As the ring buffer maintains alignment properly for each architecture, just to remove the extra padding using 'packed' attribute. ftrace_graph_ent_entry: 24 -> 20 ftrace_graph_ret_entry: 48 -> 44 Also I moved the 'overrun' field in struct ftrace_graph_ret to minimize the padding in the middle. Tested on x86_64 only. Link: http://lkml.kernel.org/r/1467197808-13578-1-git-send-email-namhyung@kernel.org Cc: Ingo Molnar <mingo@kernel.org> Cc: linux-arch@vger.kernel.org Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 7ad8fb6 commit a4a551b

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎include/linux/ftrace.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,23 +754,27 @@ static inline void ftrace_init(void) { }
754754

755755
/*
756756
* Structure that defines an entry function trace.
757+
* It's already packed but the attribute "packed" is needed
758+
* to remove extra padding at the end.
757759
*/
758760
struct ftrace_graph_ent {
759761
unsigned long func; /* Current function */
760762
int depth;
761-
};
763+
} __packed;
762764

763765
/*
764766
* Structure that defines a return function trace.
767+
* It's already packed but the attribute "packed" is needed
768+
* to remove extra padding at the end.
765769
*/
766770
struct ftrace_graph_ret {
767771
unsigned long func; /* Current function */
768-
unsigned long long calltime;
769-
unsigned long long rettime;
770772
/* Number of functions that overran the depth limit for current task */
771773
unsigned long overrun;
774+
unsigned long long calltime;
775+
unsigned long long rettime;
772776
int depth;
773-
};
777+
} __packed;
774778

775779
/* Type of the callback handlers for tracing function graph*/
776780
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */

‎kernel/trace/trace.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ enum trace_type {
8080
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
8181
filter)
8282

83+
#undef FTRACE_ENTRY_PACKED
84+
#define FTRACE_ENTRY_PACKED(name, struct_name, id, tstruct, print, \
85+
filter) \
86+
FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
87+
filter) __packed
88+
8389
#include "trace_entries.h"
8490

8591
/*
@@ -1625,6 +1631,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
16251631
#define FTRACE_ENTRY_DUP(call, struct_name, id, tstruct, print, filter) \
16261632
FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
16271633
filter)
1634+
#undef FTRACE_ENTRY_PACKED
1635+
#define FTRACE_ENTRY_PACKED(call, struct_name, id, tstruct, print, filter) \
1636+
FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \
1637+
filter)
1638+
16281639
#include "trace_entries.h"
16291640

16301641
#if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_FUNCTION_TRACER)

‎kernel/trace/trace_entries.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry,
7272
);
7373

7474
/* Function call entry */
75-
FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry,
75+
FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry,
7676

7777
TRACE_GRAPH_ENT,
7878

@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry,
8888
);
8989

9090
/* Function return entry */
91-
FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry,
91+
FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry,
9292

9393
TRACE_GRAPH_RET,
9494

0 commit comments

Comments
 (0)