From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Michael Petlan <mpetlan@redhat.com>,
linux-perf-users@vger.kernel.org, acme@redhat.com
Subject: Re: [PATCH v2] perf trace: Fix potential u64 underflow in duration calculation
Date: Thu, 2 Apr 2026 18:40:36 -0700 [thread overview]
Message-ID: <ac8alE0Nm-DL20a2@google.com> (raw)
In-Reply-To: <CAP-5=fUo6GVurv8qQnMfpgN-hYa1ukNLhF_5n2VfEv=X6APBTQ@mail.gmail.com>
On Thu, Apr 02, 2026 at 08:09:12AM -0700, Ian Rogers wrote:
> On Thu, Apr 2, 2026 at 7:51 AM Michael Petlan <mpetlan@redhat.com> wrote:
> >
> > Although it happens very rarely, in case of out-of-order events (i.e.
> > due to CPU migration when a syscall is executed), the calculation of
> > event duration might underflow and thus a bogus value is printed:
> >
> > 2.804 ( 0.001 ms): :49553/49553 rt_sigaction(sig: QUIT, act: 0x7fff403ed6e0, oact: 0x7fff403ed780, sigsetsize: 8) = 0
> > 2.807 ( 0.001 ms): :49553/49553 rt_sigaction(sig: CHLD, act: 0x7fff403ed6e0, oact: 0x7fff403ed780, sigsetsize: 8) = 0
> > 2.815 (18446744073709.438 ms): :49553/49553 execve(filename: 0xbb173a30, argv: 0x55aabb171930, envp: 0x55aabb171120) = 0
> > 2.815 ( 0.534 ms): pwd/49553 ... [continued]: execve()) = 0
> >
> > Check for possible underflow first and in case of a bogus value, do
> > not print it.
I guess this means to leave the duration empty and print the rest. For
clear communication, I think it's better to put examples before and
after for user-visible changes.
> >
> > v2: Use greater-or-equal to handle "zero" duration calls correctly.
>
> Nit: This normally comes after the signed-off-by past a "---" to
> indicate it should not be included in the commit log.
+1. I can handle that this time but please do later.
>
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
>
> Reviewed-by: Ian Rogers <irogers@google.com>
Thanks,
Namhyung
>
> > ---
> > tools/perf/builtin-trace.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> > index f487fbaa0ad6..9c59969de2af 100644
> > --- a/tools/perf/builtin-trace.c
> > +++ b/tools/perf/builtin-trace.c
> > @@ -2956,7 +2956,7 @@ static int trace__sys_exit(struct trace *trace, struct evsel *evsel,
> > ++trace->stats.vfs_getname;
> > }
> >
> > - if (ttrace->entry_time) {
> > + if (ttrace->entry_time && sample->time >= ttrace->entry_time) {
> > duration = sample->time - ttrace->entry_time;
> > if (trace__filter_duration(trace, duration))
> > goto out;
> > --
> > 2.47.3
> >
next prev parent reply other threads:[~2026-04-03 1:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 10:10 [PATCH] perf trace: Fix potential u64 underflow in duration calculation Michael Petlan
2026-03-31 17:15 ` Ian Rogers
2026-04-02 14:31 ` Michael Petlan
2026-04-02 14:51 ` [PATCH v2] " Michael Petlan
2026-04-02 15:09 ` Ian Rogers
2026-04-03 1:40 ` Namhyung Kim [this message]
2026-04-04 0:15 ` Namhyung Kim
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=ac8alE0Nm-DL20a2@google.com \
--to=namhyung@kernel.org \
--cc=acme@redhat.com \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=mpetlan@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.