diff mbox series

function_graph: Simplify the initialization of fgraph LRU data

Message ID 20240912111550.1752115-1-liaochang1@huawei.com (mailing list archive)
State New
Headers show
Series function_graph: Simplify the initialization of fgraph LRU data | expand

Commit Message

Liao, Chang Sept. 12, 2024, 11:15 a.m. UTC
This patch uses [first ... last] = value to initialize fgraph_array[].
And it declares all the callbacks in fgraph_stub as static, as they are
not called from external code.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 include/linux/ftrace.h |  1 -
 kernel/trace/fgraph.c  | 54 +++++++++++++++++++++---------------------
 2 files changed, 27 insertions(+), 28 deletions(-)

Comments

kernel test robot Sept. 13, 2024, 8:10 p.m. UTC | #1
Hi Liao,

kernel test robot noticed the following build errors:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.11-rc7 next-20240913]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Liao-Chang/function_graph-Simplify-the-initialization-of-fgraph-LRU-data/20240912-193159
base:   linus/master
patch link:    https://lore.kernel.org/r/20240912111550.1752115-1-liaochang1%40huawei.com
patch subject: [PATCH] function_graph: Simplify the initialization of fgraph LRU data
config: arm-randconfig-004-20240913 (https://download.01.org/0day-ci/archive/20240914/202409140325.G1zsZ0jL-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project bf684034844c660b778f0eba103582f582b710c9)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240914/202409140325.G1zsZ0jL-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409140325.G1zsZ0jL-lkp@intel.com/

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined symbol: ftrace_graph_entry_stub
   >>> referenced by arch/arm/kernel/entry-ftrace.o:(.text+0xB8) in archive vmlinux.a
diff mbox series

Patch

diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h
index fd5e84d0ec47..76bfc5560b57 100644
--- a/include/linux/ftrace.h
+++ b/include/linux/ftrace.h
@@ -1039,7 +1039,6 @@  typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *,
 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, struct fgraph_ops *gops);
 bool ftrace_pids_enabled(struct ftrace_ops *ops);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c
index d7d4fb403f6f..41d14b455185 100644
--- a/kernel/trace/fgraph.c
+++ b/kernel/trace/fgraph.c
@@ -172,20 +172,41 @@  enum {
 DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph);
 int ftrace_graph_active;
 
-static struct fgraph_ops *fgraph_array[FGRAPH_ARRAY_SIZE];
+static 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,
+				  struct fgraph_ops *gops)
+{
+}
+
+static struct fgraph_ops fgraph_stub = {
+	.entryfunc = ftrace_graph_entry_stub,
+	.retfunc = ftrace_graph_ret_stub,
+};
+
+static struct fgraph_ops *fgraph_array[FGRAPH_ARRAY_SIZE] = {
+	[0 ... FGRAPH_ARRAY_SIZE - 1] = &fgraph_stub,
+};
 static unsigned long fgraph_array_bitmask;
 
 /* LRU index table for fgraph_array */
 static int fgraph_lru_table[FGRAPH_ARRAY_SIZE];
-static int fgraph_lru_next;
-static int fgraph_lru_last;
+static int fgraph_lru_next = -1;
+static int fgraph_lru_last = -1;
 
 /* Initialize fgraph_lru_table with unused index */
 static void fgraph_lru_init(void)
 {
-	int i;
+	if ((fgraph_lru_next >= 0) && (fgraph_lru_last >= 0))
+		return;
 
-	for (i = 0; i < FGRAPH_ARRAY_SIZE; i++)
+	fgraph_lru_next = fgraph_lru_last = 0;
+
+	for (int i = 0; i < FGRAPH_ARRAY_SIZE; i++)
 		fgraph_lru_table[i] = i;
 }
 
@@ -483,22 +504,6 @@  int __weak ftrace_disable_ftrace_graph_caller(void)
 }
 #endif
 
-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,
-				  struct fgraph_ops *gops)
-{
-}
-
-static struct fgraph_ops fgraph_stub = {
-	.entryfunc = ftrace_graph_entry_stub,
-	.retfunc = ftrace_graph_ret_stub,
-};
-
 static struct fgraph_ops *fgraph_direct_gops = &fgraph_stub;
 DEFINE_STATIC_CALL(fgraph_func, ftrace_graph_entry_stub);
 DEFINE_STATIC_CALL(fgraph_retfunc, ftrace_graph_ret_stub);
@@ -1250,12 +1255,7 @@  int register_ftrace_graph(struct fgraph_ops *gops)
 
 	mutex_lock(&ftrace_lock);
 
-	if (!fgraph_array[0]) {
-		/* The array must always have real data on it */
-		for (i = 0; i < FGRAPH_ARRAY_SIZE; i++)
-			fgraph_array[i] = &fgraph_stub;
-		fgraph_lru_init();
-	}
+	fgraph_lru_init();
 
 	i = fgraph_lru_alloc_index();
 	if (i < 0 || WARN_ON_ONCE(fgraph_array[i] != &fgraph_stub)) {