Skip to content

Commit 18bfee3

Browse files
chleroyrostedt
authored andcommitted
ftrace: Make ftrace_graph_is_dead() a static branch
ftrace_graph_is_dead() is used on hot paths, it just reads a variable in memory and is not worth suffering function call constraints. For instance, at entry of prepare_ftrace_return(), inlining it avoids saving prepare_ftrace_return() parameters to stack and restoring them after calling ftrace_graph_is_dead(). While at it using a static branch is even more performant and is rather well adapted considering that the returned value will almost never change. Inline ftrace_graph_is_dead() and replace 'kill_ftrace_graph' bool by a static branch. The performance improvement is noticeable. Link: https://lkml.kernel.org/r/e0411a6a0ed3eafff0ad2bc9cd4b0e202b4617df.1648623570.git.christophe.leroy@csgroup.eu Signed-off-by: Christophe Leroy <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent fcbf591 commit 18bfee3

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

include/linux/ftrace.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/trace_recursion.h>
1111
#include <linux/trace_clock.h>
12+
#include <linux/jump_label.h>
1213
#include <linux/kallsyms.h>
1314
#include <linux/linkage.h>
1415
#include <linux/bitops.h>
@@ -1015,7 +1016,20 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
10151016
extern int register_ftrace_graph(struct fgraph_ops *ops);
10161017
extern void unregister_ftrace_graph(struct fgraph_ops *ops);
10171018

1018-
extern bool ftrace_graph_is_dead(void);
1019+
/**
1020+
* ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
1021+
*
1022+
* ftrace_graph_stop() is called when a severe error is detected in
1023+
* the function graph tracing. This function is called by the critical
1024+
* paths of function graph to keep those paths from doing any more harm.
1025+
*/
1026+
DECLARE_STATIC_KEY_FALSE(kill_ftrace_graph);
1027+
1028+
static inline bool ftrace_graph_is_dead(void)
1029+
{
1030+
return static_branch_unlikely(&kill_ftrace_graph);
1031+
}
1032+
10191033
extern void ftrace_graph_stop(void);
10201034

10211035
/* The current handlers in use */

kernel/trace/fgraph.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Highly modified by Steven Rostedt (VMware).
99
*/
10+
#include <linux/jump_label.h>
1011
#include <linux/suspend.h>
1112
#include <linux/ftrace.h>
1213
#include <linux/slab.h>
@@ -23,24 +24,12 @@
2324
#define ASSIGN_OPS_HASH(opsname, val)
2425
#endif
2526

26-
static bool kill_ftrace_graph;
27+
DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph);
2728
int ftrace_graph_active;
2829

2930
/* Both enabled by default (can be cleared by function_graph tracer flags */
3031
static bool fgraph_sleep_time = true;
3132

32-
/**
33-
* ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
34-
*
35-
* ftrace_graph_stop() is called when a severe error is detected in
36-
* the function graph tracing. This function is called by the critical
37-
* paths of function graph to keep those paths from doing any more harm.
38-
*/
39-
bool ftrace_graph_is_dead(void)
40-
{
41-
return kill_ftrace_graph;
42-
}
43-
4433
/**
4534
* ftrace_graph_stop - set to permanently disable function graph tracing
4635
*
@@ -51,7 +40,7 @@ bool ftrace_graph_is_dead(void)
5140
*/
5241
void ftrace_graph_stop(void)
5342
{
54-
kill_ftrace_graph = true;
43+
static_branch_enable(&kill_ftrace_graph);
5544
}
5645

5746
/* Add a function return address to the trace stack on thread info.*/

0 commit comments

Comments
 (0)