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=gCA/0jK+; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 711BA5A0262 for ; Fri, 06 Sep 2024 12:56:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202408; t=1725620205; bh=naIV4sk5UsSQtQvnKIHffjDgRsBUdNi9uzEweG081Oo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gCA/0jK+GO3hngXz0FoFwVzRiRt+0I2lmnW1AM+mq447TOrPL7RodqpWhgXU0l9+V GLGTEwnYsmdxZMXVqYyZMeFjErbB+CQkHzZ6Zd8G92R+XnOdF1MgDIp5CpHVKoD9ae j/oIW2tNqyw8c90uO17J9SvGUuFrVxwGmbVm7UFdPO9pqM9H0gDKJmnQ7uKO2FLSnJ Fn5HKP4572pvAWgKJMM4trWgSVuCXYomZx8107Wo250A/OvW3vNlHW9b3xNN+wXiOd xZgFTsegZaHaGbSusRFNLFvt8QaeFFqGGHeHGCxXe8nP8uS1k5VMAN6LOzzbs4fJWh sqzibXQTFN1Tg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4X0Y7x70LWz4wy9; Fri, 6 Sep 2024 20:56:45 +1000 (AEST) Date: Fri, 6 Sep 2024 20:56:06 +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="sbcEmVNGW1GOgVCr" Content-Disposition: inline In-Reply-To: <20240906104939.475928-1-sbrivio@redhat.com> Message-ID-Hash: TS7BOPCIIQJ6D2QUKYZNCYRSWCDU4KVJ X-Message-ID-Hash: TS7BOPCIIQJ6D2QUKYZNCYRSWCDU4KVJ 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: --sbcEmVNGW1GOgVCr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. 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. > 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 timespec= *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 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 --sbcEmVNGW1GOgVCr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmba37QACgkQzQJF27ox 2GfnKA//dkM4Tiu82UKzhFueIbnHIqEJ6gqPE0Jm1plKVeOcFYKEeytn4MVX4Aed +hDWRR/7gliZDOd4oZg+Gd7cGITvBjm+NJkNcv+hB61qRosj1nUYz90kp0jsJCLc BIViMmrpTzXagNeGHraD/TcQsLc6Q1/aAUQk3vy+9DKKuLq3V3JkmLXnGkYRhptc XtR0Z2aXTTBcBbPV9Ea4vTptxAn+tK/zjNqM5wyl1V8lzMAx4DNcDyvqktlrcBnw FEggPSIk+R/qN1Jowi8y2Z0ZXla2Q5qbUqxozMe5Ms3023cggYfsgtogc1q4O2Xz vlAqFGSrMTJ01gIKoEy9gKYzM9lVBuOL78cn59ewLp1D7qa3UhlGd0AkHdFSLnUD Ee8tOe/7XQq19T28o/XSjNFD5oqabQ+U5djIW1DE4+d8ymmHPitMniY+PZXftkP6 S2ULtmB4sKhUcy5MWjytK+hF6x7t6YaDqOFDb6TRD9kdwkljYAGMQyDeLpSx1XPo RPIjGlamC3js4amvvIlCLAe+NUSsHIAb7i/B5gEnuDDEVX6bT77daBg4D/WQOMOp HAhpvyEGge9ReTP4m8r4pMPq6s95BakiKBSWayKaGtnLIvpIuy7ATyh0zUQ6/Jjh czSz5KjjLALXM5cQ6xfKLW+DkTcrORhU0oqZ0kXmXAD8KZBbjBY= =w0f+ -----END PGP SIGNATURE----- --sbcEmVNGW1GOgVCr--