[Devel] [PATCH] trace: fix frame skip when saving event stacktrace

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Tue Aug 31 14:27:05 MSK 2021


When saving stacktraces, some frames are skipped because they correspond
to calls of internal functions of the tracing subsystem.

The number of frames to skip went out of sync with the current codebase,
leading to skipping some caller's frames. Fix that.

https://jira.sw.ru/browse/PSBM-92088
Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 kernel/trace/trace.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 94f2825f838f..4828f7cf4de6 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1588,6 +1588,15 @@ __buffer_unlock_commit(struct ring_buffer *buffer, struct ring_buffer_event *eve
 	ring_buffer_unlock_commit(buffer, event);
 }
 
+/*
+ * Skip 3:
+ *
+ *   __ftrace_trace_stack()
+ *   trace_buffer_unlock_commit()
+ *   ftrace_raw_event_xxx()
+ */
+#define STACK_SKIP 3
+
 static inline void
 __trace_buffer_unlock_commit(struct ring_buffer *buffer,
 			     struct ring_buffer_event *event,
@@ -1595,7 +1604,7 @@ __trace_buffer_unlock_commit(struct ring_buffer *buffer,
 {
 	__buffer_unlock_commit(buffer, event);
 
-	ftrace_trace_stack(buffer, flags, 6, pc);
+	ftrace_trace_stack(buffer, flags, STACK_SKIP, pc);
 	ftrace_trace_userstack(buffer, flags, pc);
 }
 
-- 
2.20.1



More information about the Devel mailing list