From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202408 header.b=HEcpUtSJ; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id BEB7A5A004E for ; Fri, 06 Sep 2024 12:56:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725620206; bh=mSuoqrMRp3FB61Gr70B6wrH0oIicwB4pSUbOvjxEPMw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HEcpUtSJPJxI6Xptn01uiQz0NhHEg+JAEDoviHY5t8HEm9cEvpUWILZJ4RB11cUHz 0VSal3gQxm69FUamdZn4e52M+Y/dadssAp9Fy+zPvKEu/v4q0zM1MLARD/ZFbju/XW 27DNOccElTCL+NlenlMal+c4Af3+SWKjQBK37PwsDvNsBN+c4E2Tf++gRJSslKExSq W4ieOfSIprPM3sOdY6DengZKVovgm5d55owGw/qxrDO279s0jVr/1N2AZrZu7CPS9U /1GdYnkTJ9A86Z49PRZOTWZmYuVeWB8dQVtSBFf2xB7g39L+pakyY7MNPhCaD9K29d Nuic3yv+rYrEQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X0Y7x743Kz4wnw; Fri, 6 Sep 2024 20:56:45 +1000 (AEST) Date: Fri, 6 Sep 2024 20:56:40 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] util: Fix missing carry of one second, as nanoseconds, in timespec_diff_us() Message-ID: References: <20240906104939.475928-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="YI2Ow/kFSqL0N+wF" Content-Disposition: inline In-Reply-To: Message-ID-Hash: M4KHPTTCC33JQZ4AMRFC7SID4VEPYNAJ X-Message-ID-Hash: M4KHPTTCC33JQZ4AMRFC7SID4VEPYNAJ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --YI2Ow/kFSqL0N+wF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 06, 2024 at 08:56:06PM +1000, David Gibson 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. > >=20 > > 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. >=20 > Perhaps more to the point, the subtraction was the wrong way around > before. I think we're too used to math mod 2^n, where reversing the > order of the arguments would be equivalent to adding an extra 2^n. Oops, and also Reviewed-by: David Gibson >=20 > > Signed-off-by: Stefano Brivio > > --- > > util.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > diff --git a/util.c b/util.c > > index 6e64279..eede4e5 100644 > > --- a/util.c > > +++ b/util.c > > @@ -249,7 +249,7 @@ void sock_probe_mem(struct ctx *c) > > int64_t timespec_diff_us(const struct timespec *a, const struct timesp= ec *b) > > { > > if (a->tv_nsec < b->tv_nsec) { > > - return (b->tv_nsec - a->tv_nsec) / 1000 + > > + return (a->tv_nsec + 1000000000 - b->tv_nsec) / 1000 + > > (a->tv_sec - b->tv_sec - 1) * 1000000; > > } > > =20 >=20 --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --YI2Ow/kFSqL0N+wF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmba3+cACgkQzQJF27ox 2GdoPQ//WJ0XPbvSGeQR6WRaOR/traBqTYzsmf9GGSVDc2cMWW/lr+vJ2mQKLmWr rtOv1DgP+Ve/ok61QHEszC9mVpL/QTilXW1s9cjf3P6082LpbPHF9T8Bw6UbGF4t h7vbe0gVO/YXmoGioYvQX/wpME0WsuxCw4vwtLLV9o0v+rflG2ebwMCxDElUO/sJ k933BJm2PjE8lvNklK4knErtQBeOHZ9y/o310QLmjHPZathNVJCqLxGKJEjOZgUY 50In3vV7xcRR2fikT/mDcLCHWl24ZHIkgSyG+ZdV2aspyufLIsab0PzOJIymqXry LZXD8tSEZ5qbbjGEOQVmbpnZu6ajxGhc14lSdHRgABX+jSBIFIWjgdB18G56dDTj hvIJS2M/+0s9XXV3uY3Wja2KntZ3YUfYChCLz8JnLHRJVf4bkGfu6cIL3KC7KKgQ ESUMGu0MnrcA8xgVviMOZ0p8JpKYJJlJzkUnzsD7qHV/Y/ET3Olk/tnTTmTqLO3i U2jTYm1PkSZd/d1knyOFqnkhdw4TLqM+bIdyU8S+/i744qiWpUPZSmuXzteI9TXq TkxKnE3lDQNJJe9bQr+sRZSUAICu1K34svcUJua2p1mH6weQYZNXOy/VFx08dkVO fdte97txH4EFJYrweP0CRv7X8AIw3UOz5ZTX/hbhjkaNGQu0LL4= =TofY -----END PGP SIGNATURE----- --YI2Ow/kFSqL0N+wF--