On Fri, 6 Sep 2024 20:56:06 +1000 David Gibson <david(a)gibson.dropbear.id.au> wrote:On Fri, Sep 06, 2024 at 12:49:39PM +0200, Stefano Brivio wrote: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. -- StefanoIf 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.