From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: <hu.shengming@zte.com.cn>
Cc: <rostedt@goodmis.org>, <mhiramat@kernel.org>,
<mathieu.desnoyers@efficios.com>, <linux-kernel@vger.kernel.org>,
<linux-trace-kernel@vger.kernel.org>, <zhang.run@zte.com.cn>,
<yang.tao172@zte.com.cn>, <yang.yang29@zte.com.cn>
Subject: Re: [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust
Date: Tue, 24 Feb 2026 17:36:58 +0900 [thread overview]
Message-ID: <20260224173658.f4882de0db9b290ced3ae1f4@kernel.org> (raw)
In-Reply-To: <20260221113314048jE4VRwIyZEALiYByGK0My@zte.com.cn>
On Sat, 21 Feb 2026 11:33:14 +0800 (CST)
<hu.shengming@zte.com.cn> wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
>
> trace_graph_thresh_return() called handle_nosleeptime() and then
> delegated to trace_graph_return(), which calls
> handle_nosleeptime() again. When sleep-time accounting is
> disabled this double-adjusts calltime and can produce bogus
> durations (including underflow).
>
> Fix this by computing rettime once, applying
> handle_nosleeptime() only once, using the adjusted calltime
> for threshold comparison, and writing the return event
> directly via __trace_graph_return() when the threshold is met.
>
Looks good to me.
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Thanks!
> Fixes: 3c9880f3ab52b ("ftrace: Use a running sleeptime instead of
> saving on shadow stack")
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> ---
> kernel/trace/trace_functions_graph.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
> index cbe43680c..b9c81fbd9 100644
> --- a/kernel/trace/trace_functions_graph.c
> +++ b/kernel/trace/trace_functions_graph.c
> @@ -403,8 +403,12 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
> unsigned long *task_var = fgraph_get_task_var(gops);
> struct fgraph_times *ftimes;
> struct trace_array *tr;
> + unsigned int trace_ctx;
> + u64 calltime, rettime;
> int size;
>
> + rettime = trace_clock_local();
> +
> ftrace_graph_addr_finish(gops, trace);
>
> if (*task_var & TRACE_GRAPH_NOTRACE) {
> @@ -419,11 +423,13 @@ static void trace_graph_thresh_return(struct ftrace_graph_ret *trace,
> tr = gops->private;
> handle_nosleeptime(tr, trace, ftimes, size);
>
> - if (tracing_thresh &&
> - (trace_clock_local() - ftimes->calltime < tracing_thresh))
> + calltime = ftimes->calltime;
> +
> + if (tracing_thresh && (rettime - calltime < tracing_thresh))
> return;
> - else
> - trace_graph_return(trace, gops, fregs);
> +
> + trace_ctx = tracing_gen_ctx();
> + __trace_graph_return(tr, trace, trace_ctx, calltime, rettime);
> }
>
> static struct fgraph_ops funcgraph_ops = {
> --
> 2.25.1
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
prev parent reply other threads:[~2026-02-24 8:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-21 3:16 [PATCH 0/2] fgraph: fixes for thresh_return return handler hu.shengming
2026-02-21 3:30 ` [PATCH 1/2] fgraph: fix thresh_return clear per-task notrace hu.shengming
2026-02-24 8:33 ` Masami Hiramatsu
2026-02-21 3:33 ` [PATCH 2/2] fgraph: fix thresh_return nosleeptime double-adjust hu.shengming
2026-02-24 8:36 ` Masami Hiramatsu [this message]
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=20260224173658.f4882de0db9b290ced3ae1f4@kernel.org \
--to=mhiramat@kernel.org \
--cc=hu.shengming@zte.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=rostedt@goodmis.org \
--cc=yang.tao172@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
--cc=zhang.run@zte.com.cn \
/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