Skip to contentSkip to conversation

ftrace: support early boot function tracing

PATCH Superseded Abderrahmane Benbachir 1 participant 1 message Jan 13, 2019

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ftrace: support early boot function tracing

Hi Steven, just noticed that the last patch had issue with the formatting, this patch is the good one.
Thanks.

Previous changes:
PATCH v1: Initial patch
PATCH v2:
Removed arch specific code and use the default clock.
Add more code re-usability
Add HAVE_EARLY_BOOT_FTRACE config option, which will be disabled by default
PATCH v3:
Write early boot temporary buffer to a sub-buffer instead of the global one. Improve Kconfig help text.

PATCH v4 :
Some code refactoring.

PATCH v5 :
fixing the build failers on arch i386.

Patch starts here:
----------------------------------------------------------------------

The early boot tracing will start from the beginning of start_kernel() and will stop at ftrace_init()

start_kernel()
{
ftrace_early_init() <--- start early boot function tracing
...
(calls)
...
ftrace_init() <--- stop early boot function tracing
early_trace_init();
...
}

The events are placed in a temporary buffer, which will be copied to the trace buffer after memory setup.

Dynamic tracing is not implemented with live patching, we use ftrace_filter and ftrace_notrace to find which functions to be filtered (traced / not traced), then during the callback from mcount hook, we do binary search lookup to decide which function to save and which one to discard.

Cc Steven Rostedt <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Mathieu Desnoyers <[email protected]>
---
 arch/x86/Kconfig            |   1 +
 arch/x86/kernel/ftrace_32.S |  45 ++++--
 arch/x86/kernel/ftrace_64.S |  14 ++
 include/linux/ftrace.h      |  18 ++-
 init/main.c                 |   1 +
 kernel/trace/Kconfig        |  51 +++++++
 kernel/trace/ftrace.c       | 294 +++++++++++++++++++++++++++++++++++-
 kernel/trace/trace.c        |  41 +++++
 8 files changed, 453 insertions(+), 12 deletions(-)
arch/x86/Kconfig +1 -0
index 8689e794a43c..f4f754d4aa7a 100644
@@ -152,6 +152,7 @@ config X86
 	select HAVE_FTRACE_MCOUNT_RECORD
 	select HAVE_FUNCTION_GRAPH_TRACER
 	select HAVE_FUNCTION_TRACER
+	select HAVE_EARLY_BOOT_FTRACE
 	select HAVE_GCC_PLUGINS
 	select HAVE_HW_BREAKPOINT
 	select HAVE_IDE
arch/x86/kernel/ftrace_32.S +36 -9

65 lines not on this page · raw message

arch/x86/kernel/ftrace_64.S +14 -0
index 91b2cff4b79a..81736c6e2f9b 100644
@@ -151,7 +151,21 @@ EXPORT_SYMBOL(mcount)
 #ifdef CONFIG_DYNAMIC_FTRACE
 
 ENTRY(function_hook)
+# ifdef CONFIG_EARLY_BOOT_FUNCTION_TRACER
+	cmpq $ftrace_stub, ftrace_early_boot_trace_function
+	jnz early_boot_trace
+
+early_boot_stub:
 	retq
+
+early_boot_trace:
+	save_mcount_regs
+	call *ftrace_early_boot_trace_function
+	restore_mcount_regs
+	jmp early_boot_stub
+# else
+	retq
+# endif
 ENDPROC(function_hook)
 
 ENTRY(ftrace_caller)
include/linux/ftrace.h +17 -1
index dd16e8218db3..b48382de1fd4 100644
@@ -239,6 +239,18 @@ static inline void ftrace_free_init_mem(void) { }
 static inline void ftrace_free_mem(struct module *mod, void *start, void *end) { }
 #endif /* CONFIG_FUNCTION_TRACER */
 
+#ifdef CONFIG_EARLY_BOOT_FUNCTION_TRACER
+extern void __init ftrace_early_boot_init(char *command_line);
+extern void __init ftrace_early_boot_shutdown(void);
+extern void __init ftrace_early_boot_fill_ringbuffer(void *data);
+extern inline bool __init is_ftrace_early_boot_activated(void);
+#else
+static inline void __init ftrace_early_boot_init(char *command_line) { }
+static inline void __init ftrace_early_boot_shutdown(void) { }
+static inline void __init ftrace_early_boot_fill_ringbuffer(void *data) { }
+static inline bool __init is_ftrace_early_boot_activated(void) { return false; }
+#endif
+
 #ifdef CONFIG_STACK_TRACER
 
 #define STACK_TRACE_ENTRIES 500
@@ -443,6 +455,10 @@ unsigned long ftrace_get_addr_curr(struct dyn_ftrace *rec);
 
 extern ftrace_func_t ftrace_trace_function;
 
+#if defined(CONFIG_EARLY_BOOT_FUNCTION_TRACER) && defined(CONFIG_DYNAMIC_FTRACE)
+extern ftrace_func_t ftrace_early_boot_trace_function;
+#endif
+
 int ftrace_regex_open(struct ftrace_ops *ops, int flag,
 		  struct inode *inode, struct file *file);
 ssize_t ftrace_filter_write(struct file *file, const char __user *ubuf,
@@ -716,7 +732,7 @@ static inline unsigned long get_lock_parent_ip(void)
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
 extern void ftrace_init(void);
 #else
-static inline void ftrace_init(void) { }
+static inline void ftrace_init(void) { ftrace_early_boot_shutdown(); }
 #endif
 
 /*
init/main.c +1 -0
index ee147103ba1b..07b83997b6a7 100644
@@ -539,6 +539,7 @@ asmlinkage __visible void __init start_kernel(void)
 	char *command_line;
 	char *after_dashes;
 
+	ftrace_early_boot_init(boot_command_line);
 	set_task_stack_end_magic(&init_task);
 	smp_setup_processor_id();
 	debug_objects_early_init();
kernel/trace/Kconfig +51 -0

63 lines not on this page · raw message

kernel/trace/ftrace.c +292 -2

312 lines not on this page · raw message

kernel/trace/trace.c +41 -0

44 lines not on this page · raw message

Signature · 1 line
2.17.1