From: pengdonglin <dolinux.peng@gmail.com>
To: rostedt@goodmis.org
Cc: mhiramat@kernel.org, dolinux.peng@gmai.com,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
pengdonglin <dolinux.peng@gmail.com>
Subject: [PATCH 2/2] ftrace: Fix preemption acounting for stacktrace filter command
Date: Mon, 12 May 2025 17:42:46 +0800 [thread overview]
Message-ID: <20250512094246.1167956-2-dolinux.peng@gmail.com> (raw)
In-Reply-To: <20250512094246.1167956-1-dolinux.peng@gmail.com>
From: pengdonglin <pengdonglin@xiaomi.com>
While using the stacktrace filter command to trace ksys_read, I noticed
that the preemption count was consistently reported as 1, which seemed
incorrect:
$ echo ksys_read:stacktrace > set_ftrace_filter
<...>-453 [004] ...1. 38.308956: <stack trace>
=> ksys_read
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe
The root cause is that the trace framework disables preemption when
invoking the filter command callback in function_trace_probe_call:
preempt_disable_notrace();
probe_ops->func(ip, parent_ip, probe_opsbe->tr, probe_ops, probe->data);
preempt_enable_notrace();
This patch uses tracing_gen_ctx_dec() to obtain the correct preemption
count within the callback, resulting in accurate reporting:
$ echo ksys_read:stacktrace > set_ftrace_filter
<...>-410 [006] ..... 31.420396: <stack trace>
=> ksys_read
=> do_syscall_64
=> entry_SYSCALL_64_after_hwframe
Signed-off-by: pengdonglin <dolinux.peng@gmail.com>
---
kernel/trace/trace_functions.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 98ccf3f00c51..4e37a0f6aaa3 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -633,11 +633,7 @@ ftrace_traceoff(unsigned long ip, unsigned long parent_ip,
static __always_inline void trace_stack(struct trace_array *tr)
{
- unsigned int trace_ctx;
-
- trace_ctx = tracing_gen_ctx();
-
- __trace_stack(tr, trace_ctx, FTRACE_STACK_SKIP);
+ __trace_stack(tr, tracing_gen_ctx_dec(), FTRACE_STACK_SKIP);
}
static void
--
2.25.1
next prev parent reply other threads:[~2025-05-12 9:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-12 9:42 [PATCH 1/2] ftrace: Fix preemption acounting for stacktrace trigger command pengdonglin
2025-05-12 9:42 ` pengdonglin [this message]
2025-05-12 14:16 ` Steven Rostedt
2025-05-12 14:31 ` Donglin Peng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250512094246.1167956-2-dolinux.peng@gmail.com \
--to=dolinux.peng@gmail.com \
--cc=dolinux.peng@gmai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®