From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Cfm4dLm8; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id B52515A004E for ; Fri, 06 Sep 2024 13:06:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725620817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2SPICS7dt8ooCDjQ1A1iuC9SvKUNhGuep+dUv5R8vsI=; b=Cfm4dLm8c6PmTjpGW8i/af7ha574DkEdO3P0iFt8em2KNvG6NSrYFiUaM1DkCh6js+/TCR PebM0YQblzzY6Q2F5vV1U6kdy0SBfX2HHlVu4WcfsyfrtDuUfTl6UTX8eIUH/eoSGFK+jZ nWN73ThOJC/HAaBPeQ4sif2jUdKGB3g= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-674-Kx06zxfvP9evFSgEe87OYA-1; Fri, 06 Sep 2024 07:06:55 -0400 X-MC-Unique: Kx06zxfvP9evFSgEe87OYA-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-7174c6cbdbaso2688110b3a.2 for ; Fri, 06 Sep 2024 04:06:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725620812; x=1726225612; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=2SPICS7dt8ooCDjQ1A1iuC9SvKUNhGuep+dUv5R8vsI=; b=s8PniqxKZeeGg8SGPREJJ+ibjwVR4xQWvSjWPLNpBYWjszkOKQ8dF5vUq58GT8CmRK 2C/44aiQgYOXqrMHnPr1hI65K0AqH/YG0ocdaMKbIGLPGfySMYdEzFvbI51rwtx3b9Et ul6/21auagw3xj7UBD5Q0UkmT3pa/chHsUbIWSNG38ybAFU9u9eJ6KaKODGr5rekfhrA rPWRAEVI2PhNcQhIF1z8+9qYgYqcqYuY7Ql8riRgS3ThlaV5GbvW8lunV8av2cL2pjlp ks5Sb1qLUushKpDtmLatblXscvzpQfueO3mLX5msMLIbLvFVlnefa6F5Ne+l8jrI72DK iZ/g== X-Gm-Message-State: AOJu0Yw1BDRhuxRwrfL7aP7ho/mxJRLMitWADG+y2MTNlAwk0PNjkgpA 3khC86kHcrkVc3XnzE0Oq0IC6WEpves4Kv1CjuV4YoIQqJ9MM74hEZtgGIJKuiS+UT2PYeeGhSp WgmPMbPrSbnFcm35KqPlO7NHC0Fzj6sMGDp6Z1INHQepBw8UOJQySySWUsg== X-Received: by 2002:a05:6a20:9c9b:b0:1cd:f065:4eec with SMTP id adf61e73a8af0-1cdf06555a8mr25597910637.41.1725620811693; Fri, 06 Sep 2024 04:06:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnlRv3tW7FJIiGCVCWsLDrT2pXE4ny5+oDllqVlOEGcnkoq4dv0eKuBtBxjp5SN3YmYJ0TSg== X-Received: by 2002:a05:6a20:9c9b:b0:1cd:f065:4eec with SMTP id adf61e73a8af0-1cdf06555a8mr25597881637.41.1725620811183; Fri, 06 Sep 2024 04:06:51 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-718dbc504d5sm664641b3a.187.2024.09.06.04.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Sep 2024 04:06:49 -0700 (PDT) Date: Fri, 6 Sep 2024 13:06:45 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH] util: Fix missing carry of one second, as nanoseconds, in timespec_diff_us() Message-ID: <20240906130645.55f6c1ce@elisabeth> In-Reply-To: References: <20240906104939.475928-1-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: OAPSBEKXA4AY6EF3JTAMP73MVENWJ4ZM X-Message-ID-Hash: OAPSBEKXA4AY6EF3JTAMP73MVENWJ4ZM X-MailFrom: sbrivio@redhat.com 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: On Fri, 6 Sep 2024 20:56:06 +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. > > > > 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