function_graph: Enable funcgraph-args and funcgraph-retaddr to work simultaneously
PATCH v3 1/1 function_graph: Enable funcgraph-args and funcgraph-retaddr to work simultaneously
From: Donglin Peng <[email protected]>
From: Donglin Peng <[email protected]>
Currently, the funcgraph-args and funcgraph-retaddr features are mutually exclusive. This patch resolves this limitation by modifying funcgraph-retaddr to adopt the same implementation approach as funcgraph-args, specifically by storing the return address in the first entry of the args array.
As a result, both features now coexist seamlessly and function as intended.
To verify the change, use perf to trace vfs_write with both options enabled:
Before:
# perf ftrace -G vfs_write --graph-opts args,retaddr
......
0) | down_read() { /* <-n_tty_write+0xa3/0x540 */
0) 0.075 us | __cond_resched(); /* <-down_read+0x12/0x160 */
0) 0.079 us | preempt_count_add(); /* <-down_read+0x3b/0x160 */
0) 0.077 us | preempt_count_sub(); /* <-down_read+0x8b/0x160 */
0) 0.754 us | }After:
# perf ftrace -G vfs_write --graph-opts args,retaddr
......
0) | down_read(sem=0xffff8880100bea78) { /* <-n_tty_write+0xa3/0x540 */
0) 0.075 us | __cond_resched(); /* <-down_read+0x12/0x160 */
0) 0.079 us | preempt_count_add(val=1); /* <-down_read+0x3b/0x160 */
0) 0.077 us | preempt_count_sub(val=1); /* <-down_read+0x8b/0x160 */
0) 0.754 us | }---
v3:
- Replace min() with min_t() to improve type safety and maintainability
- Keep only one Signed-off-by for cleaner attribution
- Code refactoring for improved readability
v2:
- Preserve retaddr event functionality (suggested by Steven)
- Store the retaddr in args[0] (suggested by Steven)
- Refactor implementation logic and commit message clarity
--- include/linux/ftrace.h | 11 -- kernel/trace/trace.h | 4 - kernel/trace/trace_entries.h | 6 +- kernel/trace/trace_functions_graph.c | 145 ++++++++++++--------------- 4 files changed, 69 insertions(+), 97 deletions(-)
include/linux/ftrace.h +0 -11
@@ -1129,17 +1129,6 @@ struct ftrace_graph_ent {int depth; } __packed; -/* -* Structure that defines an entry function trace with retaddr. -* It's already packed but the attribute "packed" is needed -* to remove extra padding at the end. -*/ -struct fgraph_retaddr_ent { -unsigned long func;/* Current function */ -int depth; -unsigned long retaddr;/* Return address */ -} __packed; -/* * Structure that defines a return function trace. * It's already packed but the attribute "packed" is needed
kernel/trace/trace.h +0 -4
@@ -955,10 +955,6 @@ extern void graph_trace_close(struct trace_iterator *iter);extern int __trace_graph_entry (struct trace_array *tr,struct ftrace_graph_ent *trace,unsigned int trace_ctx); -extern int __trace_graph_retaddr_entry (struct trace_array *tr, -struct ftrace_graph_ent *trace, -unsigned int trace_ctx, -unsigned long retaddr); extern void __trace_graph_return(struct trace_array *tr, struct ftrace_graph_ret *trace, unsigned int trace_ctx,
kernel/trace/trace_entries.h +3 -3
@@ -95,14 +95,14 @@ FTRACE_ENTRY_PACKED(fgraph_retaddr_entry, fgraph_retaddr_ent_entry,TRACE_GRAPH_RETADDR_ENT ,F_STRUCT ( - __field_struct( struct fgraph_retaddr_ent, graph_ent ) + __field_struct( struct ftrace_graph_ent, graph_ent ) __field_packed( unsigned long, graph_ent, func ) __field_packed( unsigned int, graph_ent, depth ) - __field_packed( unsigned long, graph_ent, retaddr ) + __dynamic_array(unsigned long, args ) ),F_printk ("--> %ps (%u) <- %ps" , (void *)__entry->func, __entry->depth, - (void *)__entry->retaddr) + (void *)__entry->args[0 ]) );#else
kernel/trace/trace_functions_graph.c +66 -79
275 lines not on this page · raw message
Signature · 1 line
2.34.1