From: Michael Petlan <mpetlan@redhat.com>
To: Ian Rogers <irogers@google.com>
Cc: Michael Petlan <mpetlan@redhat.com>,
linux-perf-users@vger.kernel.org, acme@redhat.com,
namhyung@kernel.org
Subject: Re: [PATCH] perf trace: Fix potential u64 underflow in duration calculation
Date: Thu, 2 Apr 2026 16:31:02 +0200 (CEST) [thread overview]
Message-ID: <dfec5c3e-3fc9-fa99-e859-29f38412027@redhat.com> (raw)
In-Reply-To: <CAP-5=fX51zhteqMNsHb=oiB1L7QcXuZm71-_-RB_+TrfvS8_RQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2171 bytes --]
On Tue, 31 Mar 2026, Ian Rogers wrote:
> On Tue, Mar 31, 2026 at 3:10 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.
> >
> > Signed-off-by: Michael Petlan <mpetlan@redhat.com>
>
> Reviewed-by: Ian Rogers <irogers@google.com>
>
> Sashiko notes [1] that maybe this should be >= so that 0ns system
> calls still have a duration. I'm not sure how sensible that is.
>
OK, although there is nothing of zero duration, coarse clock resolution
is a reasonable case. Sending v2.
Thanks.
Michael
> Thanks,
> Ian
>
> [1] https://sashiko.dev/#/patchset/20260331101020.1270363-1-mpetlan%40redhat.com
>
>
> > ---
> > 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..c9de6bb9b0ea 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-02 14:31 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 [this message]
2026-04-02 14:51 ` [PATCH v2] " Michael Petlan
2026-04-02 15:09 ` Ian Rogers
2026-04-03 1:40 ` Namhyung Kim
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=dfec5c3e-3fc9-fa99-e859-29f38412027@redhat.com \
--to=mpetlan@redhat.com \
--cc=acme@redhat.com \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.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