Skip to content

Commit 2fbb549

Browse files
committed
function_graph: Remove logic around ftrace_graph_entry and return
The function pointers ftrace_graph_entry and ftrace_graph_return are no longer called via the function_graph tracer. Instead, an array structure is now used that will allow for multiple users of the function_graph infrastructure. The variables are still used by the architecture code for non dynamic ftrace configs, where a test is made against them to see if they point to the default stub function or not. This is how the static function tracing knows to call into the function graph tracer infrastructure or not. Two new stub functions are made. entry_run() and return_run(). The ftrace_graph_entry and ftrace_graph_return are set to them respectively when the function graph tracer is enabled, and this will trigger the architecture specific function graph code to be executed. This also requires checking the global_ops hash for all calls into the function_graph tracer. Co-developed with Masami Hiramatsu: Link: https://lore.kernel.org/linux-trace-kernel/171509097408.162236.17387844142114638932.stgit@devnote2 Link: https://lore.kernel.org/linux-trace-kernel/20240603190821.872127216@goodmis.org Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com> Cc: Florent Revest <revest@chromium.org> Cc: Martin KaFai Lau <martin.lau@linux.dev> Cc: bpf <bpf@vger.kernel.org> Cc: Sven Schnelle <svens@linux.ibm.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Alan Maguire <alan.maguire@oracle.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Guo Ren <guoren@kernel.org> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 375bb57 commit 2fbb549

File tree

3 files changed

+15
-56
lines changed

3 files changed

+15
-56
lines changed

kernel/trace/fgraph.c

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,17 @@ set_bitmap(struct task_struct *t, int offset, unsigned long bitmap)
163163
(FGRAPH_TYPE_BITMAP << FGRAPH_TYPE_SHIFT) | FGRAPH_FRAME_OFFSET;
164164
}
165165

166+
/* ftrace_graph_entry set to this to tell some archs to run function graph */
167+
static int entry_run(struct ftrace_graph_ent *trace)
168+
{
169+
return 0;
170+
}
171+
172+
/* ftrace_graph_return set to this to tell some archs to run function graph */
173+
static void return_run(struct ftrace_graph_ret *trace)
174+
{
175+
}
176+
166177
/*
167178
* @offset: The offset into @t->ret_stack to find the ret_stack entry
168179
* @frame_offset: Where to place the offset into @t->ret_stack of that entry
@@ -675,7 +686,6 @@ extern void ftrace_stub_graph(struct ftrace_graph_ret *);
675686
/* The callbacks that hook a function */
676687
trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph;
677688
trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub;
678-
static trace_func_graph_ent_t __ftrace_graph_entry = ftrace_graph_entry_stub;
679689

680690
/* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */
681691
static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
@@ -758,46 +768,6 @@ ftrace_graph_probe_sched_switch(void *ignore, bool preempt,
758768
}
759769
}
760770

761-
static int ftrace_graph_entry_test(struct ftrace_graph_ent *trace)
762-
{
763-
if (!ftrace_ops_test(&global_ops, trace->func, NULL))
764-
return 0;
765-
return __ftrace_graph_entry(trace);
766-
}
767-
768-
/*
769-
* The function graph tracer should only trace the functions defined
770-
* by set_ftrace_filter and set_ftrace_notrace. If another function
771-
* tracer ops is registered, the graph tracer requires testing the
772-
* function against the global ops, and not just trace any function
773-
* that any ftrace_ops registered.
774-
*/
775-
void update_function_graph_func(void)
776-
{
777-
struct ftrace_ops *op;
778-
bool do_test = false;
779-
780-
/*
781-
* The graph and global ops share the same set of functions
782-
* to test. If any other ops is on the list, then
783-
* the graph tracing needs to test if its the function
784-
* it should call.
785-
*/
786-
do_for_each_ftrace_op(op, ftrace_ops_list) {
787-
if (op != &global_ops && op != &graph_ops &&
788-
op != &ftrace_list_end) {
789-
do_test = true;
790-
/* in double loop, break out with goto */
791-
goto out;
792-
}
793-
} while_for_each_ftrace_op(op);
794-
out:
795-
if (do_test)
796-
ftrace_graph_entry = ftrace_graph_entry_test;
797-
else
798-
ftrace_graph_entry = __ftrace_graph_entry;
799-
}
800-
801771
static DEFINE_PER_CPU(unsigned long *, idle_ret_stack);
802772

803773
static void
@@ -939,18 +909,12 @@ int register_ftrace_graph(struct fgraph_ops *gops)
939909
ftrace_graph_active--;
940910
goto out;
941911
}
942-
943-
ftrace_graph_return = gops->retfunc;
944-
945912
/*
946-
* Update the indirect function to the entryfunc, and the
947-
* function that gets called to the entry_test first. Then
948-
* call the update fgraph entry function to determine if
949-
* the entryfunc should be called directly or not.
913+
* Some archs just test to see if these are not
914+
* the default function
950915
*/
951-
__ftrace_graph_entry = gops->entryfunc;
952-
ftrace_graph_entry = ftrace_graph_entry_test;
953-
update_function_graph_func();
916+
ftrace_graph_return = return_run;
917+
ftrace_graph_entry = entry_run;
954918

955919
ret = ftrace_startup(&graph_ops, FTRACE_START_FUNC_RET);
956920
}
@@ -986,7 +950,6 @@ void unregister_ftrace_graph(struct fgraph_ops *gops)
986950
if (!ftrace_graph_active) {
987951
ftrace_graph_return = ftrace_stub_graph;
988952
ftrace_graph_entry = ftrace_graph_entry_stub;
989-
__ftrace_graph_entry = ftrace_graph_entry_stub;
990953
ftrace_shutdown(&graph_ops, FTRACE_STOP_FUNC_RET);
991954
unregister_pm_notifier(&ftrace_suspend_notifier);
992955
unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);

kernel/trace/ftrace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ static void update_ftrace_function(void)
235235
func = ftrace_ops_list_func;
236236
}
237237

238-
update_function_graph_func();
239-
240238
/* If there's no change, then do nothing more here */
241239
if (ftrace_trace_function == func)
242240
return;

kernel/trace/ftrace_internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs)
4242

4343
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
4444
extern int ftrace_graph_active;
45-
void update_function_graph_func(void);
4645
#else /* !CONFIG_FUNCTION_GRAPH_TRACER */
4746
# define ftrace_graph_active 0
48-
static inline void update_function_graph_func(void) { }
4947
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
5048

5149
#else /* !CONFIG_FUNCTION_TRACER */

0 commit comments

Comments
 (0)