Skip to content

Commit 37238ab

Browse files
committed
ftrace/function_graph: Pass fgraph_ops to function graph callbacks
Pass the fgraph_ops structure to the function graph callbacks. This will allow callbacks to add a descriptor to a fgraph_ops private field that wil be added in the future and use it for the callbacks. This will be useful when more than one callback can be registered to the function graph tracer. Co-developed with Masami Hiramatsu: Link: https://lore.kernel.org/linux-trace-kernel/171509098588.162236.4787930115997357578.stgit@devnote2 Link: https://lore.kernel.org/linux-trace-kernel/20240603190822.035147698@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 2fbb549 commit 37238ab

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

include/linux/ftrace.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,15 @@ struct ftrace_graph_ret {
10271027
unsigned long long rettime;
10281028
} __packed;
10291029

1030+
struct fgraph_ops;
1031+
10301032
/* Type of the callback handlers for tracing function graph*/
1031-
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
1032-
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
1033+
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
1034+
struct fgraph_ops *); /* return */
1035+
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *,
1036+
struct fgraph_ops *); /* entry */
10331037

1034-
extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
1038+
extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
10351039

10361040
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
10371041

kernel/trace/fgraph.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ set_bitmap(struct task_struct *t, int offset, unsigned long bitmap)
164164
}
165165

166166
/* ftrace_graph_entry set to this to tell some archs to run function graph */
167-
static int entry_run(struct ftrace_graph_ent *trace)
167+
static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops)
168168
{
169169
return 0;
170170
}
171171

172172
/* ftrace_graph_return set to this to tell some archs to run function graph */
173-
static void return_run(struct ftrace_graph_ret *trace)
173+
static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops)
174174
{
175175
}
176176

@@ -234,12 +234,14 @@ int __weak ftrace_disable_ftrace_graph_caller(void)
234234
}
235235
#endif
236236

237-
int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
237+
int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
238+
struct fgraph_ops *gops)
238239
{
239240
return 0;
240241
}
241242

242-
static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace)
243+
static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace,
244+
struct fgraph_ops *gops)
243245
{
244246
}
245247

@@ -379,7 +381,7 @@ int function_graph_enter(unsigned long ret, unsigned long func,
379381
if (gops == &fgraph_stub)
380382
continue;
381383

382-
if (gops->entryfunc(&trace))
384+
if (gops->entryfunc(&trace, gops))
383385
bitmap |= BIT(i);
384386
}
385387

@@ -527,7 +529,7 @@ static unsigned long __ftrace_return_to_handler(struct fgraph_ret_regs *ret_regs
527529
if (gops == &fgraph_stub)
528530
continue;
529531

530-
gops->retfunc(&trace);
532+
gops->retfunc(&trace, gops);
531533
}
532534

533535
/*
@@ -681,7 +683,7 @@ void ftrace_graph_sleep_time_control(bool enable)
681683
* Simply points to ftrace_stub, but with the proper protocol.
682684
* Defined by the linker script in linux/vmlinux.lds.h
683685
*/
684-
extern void ftrace_stub_graph(struct ftrace_graph_ret *);
686+
void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
685687

686688
/* The callbacks that hook a function */
687689
trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph;

kernel/trace/ftrace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,8 @@ void ftrace_graph_graph_time_control(bool enable)
815815
fgraph_graph_time = enable;
816816
}
817817

818-
static int profile_graph_entry(struct ftrace_graph_ent *trace)
818+
static int profile_graph_entry(struct ftrace_graph_ent *trace,
819+
struct fgraph_ops *gops)
819820
{
820821
struct ftrace_ret_stack *ret_stack;
821822

@@ -832,7 +833,8 @@ static int profile_graph_entry(struct ftrace_graph_ent *trace)
832833
return 1;
833834
}
834835

835-
static void profile_graph_return(struct ftrace_graph_ret *trace)
836+
static void profile_graph_return(struct ftrace_graph_ret *trace,
837+
struct fgraph_ops *gops)
836838
{
837839
struct ftrace_ret_stack *ret_stack;
838840
struct ftrace_profile_stat *stat;

kernel/trace/trace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ void trace_latency_header(struct seq_file *m);
679679
void trace_default_header(struct seq_file *m);
680680
void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
681681

682-
void trace_graph_return(struct ftrace_graph_ret *trace);
683-
int trace_graph_entry(struct ftrace_graph_ent *trace);
682+
void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
683+
int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
684684
void set_graph_array(struct trace_array *tr);
685685

686686
void tracing_start_cmdline_record(void);

kernel/trace/trace_functions_graph.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ static inline int ftrace_graph_ignore_irqs(void)
129129
return in_hardirq();
130130
}
131131

132-
int trace_graph_entry(struct ftrace_graph_ent *trace)
132+
int trace_graph_entry(struct ftrace_graph_ent *trace,
133+
struct fgraph_ops *gops)
133134
{
134135
struct trace_array *tr = graph_array;
135136
struct trace_array_cpu *data;
@@ -238,7 +239,8 @@ void __trace_graph_return(struct trace_array *tr,
238239
trace_buffer_unlock_commit_nostack(buffer, event);
239240
}
240241

241-
void trace_graph_return(struct ftrace_graph_ret *trace)
242+
void trace_graph_return(struct ftrace_graph_ret *trace,
243+
struct fgraph_ops *gops)
242244
{
243245
struct trace_array *tr = graph_array;
244246
struct trace_array_cpu *data;
@@ -275,7 +277,8 @@ void set_graph_array(struct trace_array *tr)
275277
smp_mb();
276278
}
277279

278-
static void trace_graph_thresh_return(struct ftrace_graph_ret *trace)
280+
static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
281+
struct fgraph_ops *gops)
279282
{
280283
ftrace_graph_addr_finish(trace);
281284

@@ -288,7 +291,7 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace)
288291
(trace->rettime - trace->calltime < tracing_thresh))
289292
return;
290293
else
291-
trace_graph_return(trace);
294+
trace_graph_return(trace, gops);
292295
}
293296

294297
static struct fgraph_ops funcgraph_thresh_ops = {

kernel/trace/trace_irqsoff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ static int irqsoff_display_graph(struct trace_array *tr, int set)
175175
return start_irqsoff_tracer(irqsoff_trace, set);
176176
}
177177

178-
static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
178+
static int irqsoff_graph_entry(struct ftrace_graph_ent *trace,
179+
struct fgraph_ops *gops)
179180
{
180181
struct trace_array *tr = irqsoff_trace;
181182
struct trace_array_cpu *data;
@@ -205,7 +206,8 @@ static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
205206
return ret;
206207
}
207208

208-
static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
209+
static void irqsoff_graph_return(struct ftrace_graph_ret *trace,
210+
struct fgraph_ops *gops)
209211
{
210212
struct trace_array *tr = irqsoff_trace;
211213
struct trace_array_cpu *data;

kernel/trace/trace_sched_wakeup.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ static int wakeup_display_graph(struct trace_array *tr, int set)
112112
return start_func_tracer(tr, set);
113113
}
114114

115-
static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
115+
static int wakeup_graph_entry(struct ftrace_graph_ent *trace,
116+
struct fgraph_ops *gops)
116117
{
117118
struct trace_array *tr = wakeup_trace;
118119
struct trace_array_cpu *data;
@@ -141,7 +142,8 @@ static int wakeup_graph_entry(struct ftrace_graph_ent *trace)
141142
return ret;
142143
}
143144

144-
static void wakeup_graph_return(struct ftrace_graph_ret *trace)
145+
static void wakeup_graph_return(struct ftrace_graph_ret *trace,
146+
struct fgraph_ops *gops)
145147
{
146148
struct trace_array *tr = wakeup_trace;
147149
struct trace_array_cpu *data;

kernel/trace/trace_selftest.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
762762
static unsigned int graph_hang_thresh;
763763

764764
/* Wrap the real function entry probe to avoid possible hanging */
765-
static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
765+
static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace,
766+
struct fgraph_ops *gops)
766767
{
767768
/* This is harmlessly racy, we want to approximately detect a hang */
768769
if (unlikely(++graph_hang_thresh > GRAPH_MAX_FUNC_TEST)) {
@@ -776,7 +777,7 @@ static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
776777
return 0;
777778
}
778779

779-
return trace_graph_entry(trace);
780+
return trace_graph_entry(trace, gops);
780781
}
781782

782783
static struct fgraph_ops fgraph_ops __initdata = {

0 commit comments

Comments
 (0)