ftrace: Reduce size of function graph entries
Subsystems (3)
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 some archs can have efficient unaligned accesses, reducing the alignment can save ~10% of data size:
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. Tested on x86_64 only.
--- include/linux/ftrace.h | 16 ++++++++++++---- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_entries.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-)
include/linux/ftrace.h +12 -4
@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif +#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif + +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT))) +/* * Structure that defines an entry function trace. */ struct ftrace_graph_ent {unsigned long func;/* Current function */ int depth; -}; +}FTRACE_ALIGN_DATA ;/* * Structure that defines a return function trace. */ struct ftrace_graph_ret {unsigned long func;/* Current function */ -unsigned long long calltime; -unsigned long long rettime;/* Number of functions that overran the depth limit for current task */ unsigned long overrun; +unsigned long long calltime; +unsigned long long rettime;int depth; -}; +}FTRACE_ALIGN_DATA ;/* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t )(struct ftrace_graph_ret *);/* return */
kernel/trace/trace.h +11 -0
@@ -80,6 +80,12 @@ enum trace_type {FTRACE_ENTRY (name, struct_name, id,PARAMS (tstruct),PARAMS (print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (name, struct_name, id, tstruct, print, \ + filter) \ + FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) FTRACE_ALIGN_DATA +#include "trace_entries.h" /*
@@ -1600,6 +1606,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print, filter) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (call, struct_name, id, tstruct, print, filter) \ + FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) +#include "trace_entries.h" #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_FUNCTION_TRACER )
kernel/trace/trace_entries.h +2 -2
@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry, );/* Function call entry */ -FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, +FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, TRACE_GRAPH_ENT,
@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, );/* Function return entry */ -FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry, +FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, TRACE_GRAPH_RET,
Signature · 1 line
2.8.0
Hi Steve,
Could you please take a look at this?
Thanks,
Namhyung
Quoted 115 lines · Namhyung Kim
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 some archs can have efficient unaligned accesses, reducing the alignment can save ~10% of data size:
ftrace_graph_ent_entry: 24 -> 20
ftrace_graph_ret_entry: 48 -> 44Also I moved the 'overrun' field in struct
ftrace_graph_retto minimize the padding. Tested onx86_64only.Signed-off-by Namhyung Kim <[email protected]>--- include/linux/ftrace.h | 16 ++++++++++++---- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_entries.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-)include/linux/ftrace.h +12
-4@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif +#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif + +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT))) +/* * Structure that defines an entry function trace. */ struct ftrace_graph_ent {unsigned long func;/* Current function */ int depth; -}; +}FTRACE_ALIGN_DATA ;/* * Structure that defines a return function trace. */ struct ftrace_graph_ret {unsigned long func;/* Current function */ -unsigned long long calltime; -unsigned long long rettime;/* Number of functions that overran the depth limit for current task */ unsigned long overrun; +unsigned long long calltime; +unsigned long long rettime;int depth; -}; +}FTRACE_ALIGN_DATA ;/* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t )(struct ftrace_graph_ret *);/* return */ kernel/trace/trace.h +11
-0@@ -80,6 +80,12 @@ enum trace_type {FTRACE_ENTRY (name, struct_name, id,PARAMS (tstruct),PARAMS (print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (name, struct_name, id, tstruct, print, \ + filter) \ + FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) FTRACE_ALIGN_DATA +#include "trace_entries.h" /* @@ -1600,6 +1606,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print, filter) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (call, struct_name, id, tstruct, print, filter) \ + FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) +#include "trace_entries.h" #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_FUNCTION_TRACER )kernel/trace/trace_entries.h +2
-3@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry, );/* Function call entry */ -FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, +FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, TRACE_GRAPH_ENT,@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, );/* Function return entry */ -FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry, +FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, TRACE_GRAPH_RET, --2.8.0
Signature · 2 lines
Thanks, Namhyung
Ping!
Quoted 130 lines · Namhyung Kim
Hi Steve,
Could you please take a look at this?
Thanks,
NamhyungQuoted 113 lines · Namhyung Kim
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 some archs can have efficient unaligned accesses, reducing the alignment can save ~10% of data size:
ftrace_graph_ent_entry: 24 -> 20
ftrace_graph_ret_entry: 48 -> 44Also I moved the 'overrun' field in struct
ftrace_graph_retto minimize the padding. Tested onx86_64only.Signed-off-by Namhyung Kim <[email protected]>--- include/linux/ftrace.h | 16 ++++++++++++---- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_entries.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-)include/linux/ftrace.h +12
-4@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif +#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif + +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT))) +/* * Structure that defines an entry function trace. */ struct ftrace_graph_ent {unsigned long func;/* Current function */ int depth; -}; +}FTRACE_ALIGN_DATA ;/* * Structure that defines a return function trace. */ struct ftrace_graph_ret {unsigned long func;/* Current function */ -unsigned long long calltime; -unsigned long long rettime;/* Number of functions that overran the depth limit for current task */ unsigned long overrun; +unsigned long long calltime; +unsigned long long rettime;int depth; -}; +}FTRACE_ALIGN_DATA ;/* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t )(struct ftrace_graph_ret *);/* return */ kernel/trace/trace.h +11
-0@@ -80,6 +80,12 @@ enum trace_type {FTRACE_ENTRY (name, struct_name, id,PARAMS (tstruct),PARAMS (print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (name, struct_name, id, tstruct, print, \ + filter) \ + FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) FTRACE_ALIGN_DATA +#include "trace_entries.h" /* @@ -1600,6 +1606,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print, filter) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (call, struct_name, id, tstruct, print, filter) \ + FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) +#include "trace_entries.h" #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_FUNCTION_TRACER )kernel/trace/trace_entries.h +2
-3@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry, );/* Function call entry */ -FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, +FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, TRACE_GRAPH_ENT,@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, );/* Function return entry */ -FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry, +FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, TRACE_GRAPH_RET, --Quoted 2 lines
2.8.0
--
Thanks,
Namhyung
Steven Rostedt
maintainerQuoted 2 lines · On Wed, 22 Jun 2016 22:58:43 +0900 Namhyung Kim <[email protected]> wrote:
Ping!
Ug, this got missed twice (still marked unread in my inbox).
I'll take a look at this today. Thanks!
-- Steve
Steven Rostedt
maintainerQuoted 11 lines · On Mon, 23 May 2016 00:26:15 +0900 Namhyung Kim <[email protected]> wrote:
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 some archs can have efficient unaligned accesses, reducing the alignment can save ~10% of data size:
ftrace_graph_ent_entry: 24 -> 20
ftrace_graph_ret_entry: 48 -> 44Also I moved the 'overrun' field in struct
ftrace_graph_retto minimize the padding. Tested onx86_64only.
I'd like to see this tested on other archs too.
[ Added linux-arch so maybe other arch maintainers may know about this ]
Quoted 13 lines
Signed-off-by Namhyung Kim <[email protected]>--- include/linux/ftrace.h | 16 ++++++++++++---- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_entries.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-)include/linux/ftrace.h +0
-0
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 8 lines
include/linux/ftrace.h +5
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif +#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif
Swap the above. Having the #ifndef is more confusing to understand than to have a #ifdef.
include/linux/ftrace.h extern void ftrace_init(void); · line 760
Quoted 2 lines
include/linux/ftrace.h +2
-0+ +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT)))
Do we really need to pack it? I mean, just get rid of the hole (like you did with the movement of the overrun) and shouldn't the array be aligned normally without holes, if the arch can support it? Doesn't gcc take care of that?
-- Steve
Quoted 78 lines
include/linux/ftrace.h +5
-4+/* * Structure that defines an entry function trace. */ struct ftrace_graph_ent {unsigned long func;/* Current function */ int depth; -}; +}FTRACE_ALIGN_DATA ;/* * Structure that defines a return function trace. */ struct ftrace_graph_ret {unsigned long func;/* Current function */ -unsigned long long calltime; -unsigned long long rettime;/* Number of functions that overran the depth limit for current task */ unsigned long overrun; +unsigned long long calltime; +unsigned long long rettime;int depth; -}; +}FTRACE_ALIGN_DATA ;/* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t )(struct ftrace_graph_ret *);/* return */ kernel/trace/trace.h +11
-0@@ -80,6 +80,12 @@ enum trace_type {FTRACE_ENTRY (name, struct_name, id,PARAMS (tstruct),PARAMS (print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (name, struct_name, id, tstruct, print, \ + filter) \ + FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) FTRACE_ALIGN_DATA +#include "trace_entries.h" /* @@ -1600,6 +1606,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print, filter) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (call, struct_name, id, tstruct, print, filter) \ + FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) +#include "trace_entries.h" #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_FUNCTION_TRACER )kernel/trace/trace_entries.h +2
-2@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry, );/* Function call entry */ -FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, +FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, TRACE_GRAPH_ENT,@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, );/* Function return entry */ -FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry, +FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, TRACE_GRAPH_RET,
Hi Steve,
Quoted 12 lines · Steven Rostedt
Quoted 9 lines · On Mon, 23 May 2016 00:26:15 +0900 Namhyung Kim <[email protected]> wrote:
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 some archs can have efficient unaligned accesses, reducing the alignment can save ~10% of data size:
ftrace_graph_ent_entry: 24 -> 20
ftrace_graph_ret_entry: 48 -> 44
Quoted 6 lines
Quoted 2 lines
Also I moved the 'overrun' field in struct
ftrace_graph_retto minimize the padding. Tested onx86_64only.I'd like to see this tested on other archs too.
[ Added linux-arch so maybe other arch maintainers may know about this ]
Thanks, it'd be great if anyone could try this.
I think it doesn't affect most of (64-bit) archs since only x86_64, arm64 and powerpc define CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS (and it turns off CONFIG_HAVE_64BIT_ALIGNED_ACCESS). So other archs still have (same) 8-byte alignment requirement.
Do 32-bit archs really require 64-bit alignment for unsigned long long? IOW is it an alignment violation putting it in 32-bit boundary?
Quoted 17 lines
Quoted 17 lines
Signed-off-by Namhyung Kim <[email protected]>--- include/linux/ftrace.h | 16 ++++++++++++---- kernel/trace/trace.h | 11 +++++++++++ kernel/trace/trace_entries.h | 4 ++-- 3 files changed, 25 insertions(+), 6 deletions(-)include/linux/ftrace.h +0
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif
Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 5 lines
include/linux/ftrace.h +5
-0+#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif Swap the above. Having the #ifndef is more confusing to understand than to have a #ifdef.
Will do.
Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 760
Quoted 3 lines
include/linux/ftrace.h +2
-0+ +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT)))Do we really need to pack it? I mean, just get rid of the hole (like you did with the movement of the overrun) and shouldn't the array be aligned normally without holes, if the arch can support it? Doesn't gcc take care of that?
I'm not sure I understood you correctly. AFAIK the size of struct is a multiple of alignment unit and gcc manual says the aligment attribute only can be increased unless the 'packed' is used as well..
Thanks,
Namhyung
Quoted 82 lines
-- Steve
Quoted 78 lines
include/linux/ftrace.h +5
-4+/* * Structure that defines an entry function trace. */ struct ftrace_graph_ent {unsigned long func;/* Current function */ int depth; -}; +}FTRACE_ALIGN_DATA ;/* * Structure that defines a return function trace. */ struct ftrace_graph_ret {unsigned long func;/* Current function */ -unsigned long long calltime; -unsigned long long rettime;/* Number of functions that overran the depth limit for current task */ unsigned long overrun; +unsigned long long calltime; +unsigned long long rettime;int depth; -}; +}FTRACE_ALIGN_DATA ;/* Type of the callback handlers for tracing function graph*/ typedef void (*trace_func_graph_ret_t )(struct ftrace_graph_ret *);/* return */ kernel/trace/trace.h +11
-0@@ -80,6 +80,12 @@ enum trace_type {FTRACE_ENTRY (name, struct_name, id,PARAMS (tstruct),PARAMS (print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (name, struct_name, id, tstruct, print, \ + filter) \ + FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) FTRACE_ALIGN_DATA +#include "trace_entries.h" /* @@ -1600,6 +1606,11 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);#define FTRACE_ENTRY_DUP (call, struct_name, id, tstruct, print, filter) \ FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ filter) +#undef FTRACE_ENTRY_PACKED +#define FTRACE_ENTRY_PACKED (call, struct_name, id, tstruct, print, filter) \ + FTRACE_ENTRY(call, struct_name, id, PARAMS(tstruct), PARAMS(print), \ + filter) +#include "trace_entries.h" #if defined(CONFIG_PERF_EVENTS ) && defined(CONFIG_FUNCTION_TRACER )kernel/trace/trace_entries.h +2
-2@@ -72,7 +72,7 @@ FTRACE_ENTRY_REG(function, ftrace_entry, );/* Function call entry */ -FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, +FTRACE_ENTRY_PACKED(funcgraph_entry, ftrace_graph_ent_entry, TRACE_GRAPH_ENT,@@ -88,7 +88,7 @@ FTRACE_ENTRY(funcgraph_entry, ftrace_graph_ent_entry, );/* Function return entry */ -FTRACE_ENTRY(funcgraph_exit, ftrace_graph_ret_entry, +FTRACE_ENTRY_PACKED(funcgraph_exit, ftrace_graph_ret_entry, TRACE_GRAPH_RET,
Steven Rostedt
maintainerQuoted 28 lines · On Fri, 24 Jun 2016 15:35:44 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
include/linux/ftrace.h +0
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 5 lines
include/linux/ftrace.h +5
-0+#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif Swap the above. Having the #ifndef is more confusing to understand than to have a #ifdef.
Will do.
Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 760
Quoted 3 lines
include/linux/ftrace.h +2
-0+ +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT)))Do we really need to pack it? I mean, just get rid of the hole (like you did with the movement of the overrun) and shouldn't the array be aligned normally without holes, if the arch can support it? Doesn't gcc take care of that?
Quoted 3 lines
I'm not sure I understood you correctly. AFAIK the size of struct is a multiple of alignment unit and gcc manual says the aligment attribute only can be increased unless the 'packed' is used as well..
Ah, I see you are trying to get the recorded size in the array down to a 4 byte alignment (due to the "int depth"), instead of adding the 4 bytes to the buffer.
Hmm, I wondering if we need the ifdef above, as the ring buffer itself will force the 8 byte alignment of structures added to the buffer.
-- Steve
Quoted 36 lines · Steven Rostedt
Quoted 28 lines · On Fri, 24 Jun 2016 15:35:44 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
include/linux/ftrace.h +0
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 5 lines
include/linux/ftrace.h +5
-0+#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif Swap the above. Having the #ifndef is more confusing to understand than to have a #ifdef.
Will do.
Quoted 8 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 760
Quoted 3 lines
include/linux/ftrace.h +2
-0+ +#define FTRACE_ALIGN_DATA __attribute__((packed, aligned(FTRACE_ALIGNMENT)))Do we really need to pack it? I mean, just get rid of the hole (like you did with the movement of the overrun) and shouldn't the array be aligned normally without holes, if the arch can support it? Doesn't gcc take care of that?
Quoted 3 lines
I'm not sure I understood you correctly. AFAIK the size of struct is a multiple of alignment unit and gcc manual says the aligment attribute only can be increased unless the 'packed' is used as well..
Quoted 6 lines
Ah, I see you are trying to get the recorded size in the array down to a 4 byte alignment (due to the "int depth"), instead of adding the 4 bytes to the buffer.
Hmm, I wondering if we need the ifdef above, as the ring buffer itself will force the 8 byte alignment of structures added to the buffer.
As far as I can see, the ring buffer has following code in ring_buffer.c:
#define RB_ALIGNMENT 4U #define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) #define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ #ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS # define RB_FORCE_8BYTE_ALIGNMENT 0 # define RB_ARCH_ALIGNMENT RB_ALIGNMENT #else # define RB_FORCE_8BYTE_ALIGNMENT 1 # define RB_ARCH_ALIGNMENT 8U #endif #define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT)
Thanks,
Namhyung
Steven Rostedt
maintainerQuoted 22 lines · On Sat, 25 Jun 2016 01:15:34 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Fri, 24 Jun 2016 15:35:44 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
include/linux/ftrace.h +0
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 5 lines
include/linux/ftrace.h +5
-0+#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif As far as I can see, the ring buffer has following code in
ring_buffer.c:
Quoted 14 lines
#define RB_ALIGNMENT 4U #define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) #define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ #ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS # define RB_FORCE_8BYTE_ALIGNMENT 0 # define RB_ARCH_ALIGNMENT RB_ALIGNMENT #else # define RB_FORCE_8BYTE_ALIGNMENT 1 # define RB_ARCH_ALIGNMENT 8U #endif #define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT)
Right, what I meant was that we should just define FTRACE_ALIGNMENT unconditionally to 4. If CONFIG_HAVE_64BIT_ALIGNED_ACCESS is not set, it will add the buffered space regardless.
You already moved "overrun", I don't see anything that would be out of alignment if the structure itself is aligned.
-- Steve
Quoted 40 lines · Steven Rostedt
Quoted 22 lines · On Sat, 25 Jun 2016 01:15:34 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 12 lines · Steven Rostedt
Quoted 8 lines · On Fri, 24 Jun 2016 15:35:44 +0900 Namhyung Kim <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
include/linux/ftrace.h +0
-0@@ -751,25 +751,33 @@ extern void ftrace_init(void);static inline void ftrace_init (void ) { }#endif Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
include/linux/ftrace.h extern void ftrace_init(void); · line 758
Quoted 5 lines
include/linux/ftrace.h +5
-0+#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS +# define FTRACE_ALIGNMENT 4 +#else +# define FTRACE_ALIGNMENT 8 +#endif As far as I can see, the ring buffer has following code in
ring_buffer.c:Quoted 14 lines
#define RB_ALIGNMENT 4U #define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX) #define RB_EVNT_MIN_SIZE 8U /* two 32bit words */ #ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS # define RB_FORCE_8BYTE_ALIGNMENT 0 # define RB_ARCH_ALIGNMENT RB_ALIGNMENT #else # define RB_FORCE_8BYTE_ALIGNMENT 1 # define RB_ARCH_ALIGNMENT 8U #endif #define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT)
Quoted 6 lines
Right, what I meant was that we should just define
FTRACE_ALIGNMENTunconditionally to 4. IfCONFIG_HAVE_64BIT_ALIGNED_ACCESSis not set, it will add the buffered space regardless.You already moved "overrun", I don't see anything that would be out of alignment if the structure itself is aligned.
In that case if CONFIG_HAVE_64BIT_ALIGNED_ACCESS is set, the ring buffer is 8-byte aligned but the struct is 4-byte aligned, right? Note that the function graph tracer saves the data in a local variable (of the struct) first and copies to the ring buffer later. Wouldn't it be a problem?
Thanks,
Namhyung