public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: passt-dev@passt.top
Subject: Re: [PATCH] util: Fix missing carry of one second, as nanoseconds, in timespec_diff_us()
Date: Fri, 6 Sep 2024 13:06:45 +0200	[thread overview]
Message-ID: <20240906130645.55f6c1ce@elisabeth> (raw)
In-Reply-To: <Ztrfxtu-NpGlYNpd@zatzit.fritz.box>

On Fri, 6 Sep 2024 20:56:06 +1000
David Gibson <david@gibson.dropbear.id.au> wrote:

> On Fri, Sep 06, 2024 at 12:49:39PM +0200, Stefano Brivio wrote:
> > If the nanoseconds of the minuend timestamp are less than the
> > nanoseconds of the subtrahend timestamp, we need to carry one second
> > in the subtraction.
> > 
> > I subtracted this second from the minuend, but didn't actually carry
> > it in the subtraction of nanoseconds, and logged timestamps would jump
> > back whenever we switched to the first branch of timespec_diff_us()
> > from the second one.  
> 
> Perhaps more to the point, the subtraction was the wrong way around
> before.

Ah, right, I just slightly tweaked the commit message:

--
util: Fix order of operands and carry of one second in timespec_diff_us()

If the nanoseconds of the minuend timestamp are less than the
nanoseconds of the subtrahend timestamp, we need to carry one second
in the subtraction.

I subtracted this second from the minuend, but didn't actually carry
it in the subtraction of nanoseconds, and logged timestamps would jump
back whenever we switched to the first branch of timespec_diff_us()
from the second one.

Most likely, the reason why I didn't carry the second is that I
instinctively thought that swapping the operands would have the same
effect. But it doesn't, in general: that only happens with arithmetic
in modulo powers of two. Undo the swap as well.
--

I kept your Reviewed-by.

-- 
Stefano


      parent reply	other threads:[~2024-09-06 11:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06 10:49 [PATCH] util: Fix missing carry of one second, as nanoseconds, in timespec_diff_us() Stefano Brivio
2024-09-06 10:56 ` David Gibson
2024-09-06 10:56   ` David Gibson
2024-09-06 11:06   ` Stefano Brivio [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=20240906130645.55f6c1ce@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).