Commit 37238abe authored by Steven Rostedt (VMware)'s avatar Steven Rostedt (VMware) Committed by Steven Rostedt (Google)
Browse files

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: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: default avatarMasami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent 2fbb5499
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -1027,11 +1027,15 @@ struct ftrace_graph_ret {
	unsigned long long rettime;
} __packed;

struct fgraph_ops;

/* Type of the callback handlers for tracing function graph*/
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
				       struct fgraph_ops *); /* return */
typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *,
				      struct fgraph_ops *); /* entry */

extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace);
extern int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);

#ifdef CONFIG_FUNCTION_GRAPH_TRACER

+9 −7
Original line number Diff line number Diff line
@@ -164,13 +164,13 @@ set_bitmap(struct task_struct *t, int offset, unsigned long bitmap)
}

/* ftrace_graph_entry set to this to tell some archs to run function graph */
static int entry_run(struct ftrace_graph_ent *trace)
static int entry_run(struct ftrace_graph_ent *trace, struct fgraph_ops *ops)
{
	return 0;
}

/* ftrace_graph_return set to this to tell some archs to run function graph */
static void return_run(struct ftrace_graph_ret *trace)
static void return_run(struct ftrace_graph_ret *trace, struct fgraph_ops *ops)
{
}

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

int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace,
			    struct fgraph_ops *gops)
{
	return 0;
}

static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace)
static void ftrace_graph_ret_stub(struct ftrace_graph_ret *trace,
				  struct fgraph_ops *gops)
{
}

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

		if (gops->entryfunc(&trace))
		if (gops->entryfunc(&trace, gops))
			bitmap |= BIT(i);
	}

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

		gops->retfunc(&trace);
		gops->retfunc(&trace, gops);
	}

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

/* The callbacks that hook a function */
trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph;
+4 −2
Original line number Diff line number Diff line
@@ -815,7 +815,8 @@ void ftrace_graph_graph_time_control(bool enable)
	fgraph_graph_time = enable;
}

static int profile_graph_entry(struct ftrace_graph_ent *trace)
static int profile_graph_entry(struct ftrace_graph_ent *trace,
			       struct fgraph_ops *gops)
{
	struct ftrace_ret_stack *ret_stack;

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

static void profile_graph_return(struct ftrace_graph_ret *trace)
static void profile_graph_return(struct ftrace_graph_ret *trace,
				 struct fgraph_ops *gops)
{
	struct ftrace_ret_stack *ret_stack;
	struct ftrace_profile_stat *stat;
+2 −2
Original line number Diff line number Diff line
@@ -679,8 +679,8 @@ void trace_latency_header(struct seq_file *m);
void trace_default_header(struct seq_file *m);
void print_trace_header(struct seq_file *m, struct trace_iterator *iter);

void trace_graph_return(struct ftrace_graph_ret *trace);
int trace_graph_entry(struct ftrace_graph_ent *trace);
void trace_graph_return(struct ftrace_graph_ret *trace, struct fgraph_ops *gops);
int trace_graph_entry(struct ftrace_graph_ent *trace, struct fgraph_ops *gops);
void set_graph_array(struct trace_array *tr);

void tracing_start_cmdline_record(void);
+7 −4
Original line number Diff line number Diff line
@@ -129,7 +129,8 @@ static inline int ftrace_graph_ignore_irqs(void)
	return in_hardirq();
}

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

void trace_graph_return(struct ftrace_graph_ret *trace)
void trace_graph_return(struct ftrace_graph_ret *trace,
			struct fgraph_ops *gops)
{
	struct trace_array *tr = graph_array;
	struct trace_array_cpu *data;
@@ -275,7 +277,8 @@ void set_graph_array(struct trace_array *tr)
	smp_mb();
}

static void trace_graph_thresh_return(struct ftrace_graph_ret *trace)
static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
				      struct fgraph_ops *gops)
{
	ftrace_graph_addr_finish(trace);

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

static struct fgraph_ops funcgraph_thresh_ops = {
Loading