[Ntp] Wtrlt: Issues with clock_getres() and clock_gettime() on fast machines
Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de> Tue, 03 November 2020 13:24 UTC
Return-Path: <Ulrich.Windl@rz.uni-regensburg.de>
X-Original-To: ntp@ietfa.amsl.com
Delivered-To: ntp@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id AF4A03A0A6E for <ntp@ietfa.amsl.com>; Tue, 3 Nov 2020 05:24:44 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.899
X-Spam-Level:
X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1ivxq1E-J8qB for <ntp@ietfa.amsl.com>; Tue, 3 Nov 2020 05:24:43 -0800 (PST)
Received: from mx2.uni-regensburg.de (mx2.uni-regensburg.de [194.94.157.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id A9FB43A0A6F for <ntp@ietf.org>; Tue, 3 Nov 2020 05:24:41 -0800 (PST)
Received: from mx2.uni-regensburg.de (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id A5D63600005D for <ntp@ietf.org>; Tue, 3 Nov 2020 14:24:38 +0100 (CET)
Received: from gwsmtp.uni-regensburg.de (gwsmtp1.uni-regensburg.de [132.199.5.51]) by mx2.uni-regensburg.de (Postfix) with ESMTP id 8143D6000059 for <ntp@ietf.org>; Tue, 3 Nov 2020 14:24:36 +0100 (CET)
Received: from uni-regensburg-smtp1-MTA by gwsmtp.uni-regensburg.de with Novell_GroupWise; Tue, 03 Nov 2020 14:24:36 +0100
Message-Id: <5FA15A13020000A10003C75D@gwsmtp.uni-regensburg.de>
X-Mailer: Novell GroupWise Internet Agent 18.2.1
Date: Tue, 03 Nov 2020 14:24:35 +0100
From: Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
To: "ntp@ietf.org" <ntp@ietf.org>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="=__PartCFF13C03.0__="
Archived-At: <https://mailarchive.ietf.org/arch/msg/ntp/tAMmBuvIyI4VpQUA4sIVpYf9F24>
Subject: [Ntp] Wtrlt: Issues with clock_getres() and clock_gettime() on fast machines
X-BeenThere: ntp@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <ntp.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ntp>, <mailto:ntp-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/ntp/>
List-Post: <mailto:ntp@ietf.org>
List-Help: <mailto:ntp-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ntp>, <mailto:ntp-request@ietf.org?subject=subscribe>
X-List-Received-Date: Tue, 03 Nov 2020 13:24:45 -0000
(Originally sent to the old list; sorry) >>> "Ulrich Windl" <Ulrich.Windl@rz.uni-regensburg.de> schrieb am 03.11.2020 um 10:40 in Nachricht <5FA1259E020000A10003C735@gwsmtp.uni-regensburg.de>: > Hi! > > I ran into a problem with an application doing timing: > clock_getres() returns 1 nanosecond as resolution, even though the actual > clock may have less resolution. > Trying to avoid outputting fractional digits that are more or less nonsense, > I tried to find out the maximum resolution by doing a few fast clock samples, > building and sorting differences. > That worked, but then I suddenly got a clock resolution of zero (less than > one nanosecond)! > I debugged it, and actually I saw up to three subsequent calls to > clock_gettime() (CLOCK_MONOTONIC in my case) returning exactly the same > timestamp, while the time between the calls should be around 2 microseconds > or so. > > I think in the past (possibly excluding plain old time()) the clock > resolution always had been faster than the shortest possible clock polling > interval, but recent machines seem to turn that around: If your polling > interval is less or equal to clock resolution, the same timestamp will be > returned. > I also think that in the past there was a work‑around ensuring that the time > will at least advance by one nanosecond between calls, but that's obviously > not common any more. > The other problem is with NTP corrections: Assume your clock resolution > actually is 1 nanosecond or better, and the minimum polling delay is also > about one nanosecond, and the system clock is too fast, going to be corrected > to be slower. Wouldn't then a number of clock_gettime() retrun identical > timestamps, or maybe, even worse show a clock running backwards? > Dividing by a zero or negative time difference will not result in good rate > numbers, not to talk about application crashes (as it was in my case, so I > got alerted initially)... > > I think these issues should be addressed by some informational document, > helping implementers to "do things right". Opinions? > > Regards, > Ulrich
- [Ntp] Wtrlt: Issues with clock_getres() and clock… Ulrich Windl
- Re: [Ntp] Wtrlt: Issues with clock_getres() and c… Miroslav Lichvar
- [Ntp] Antw: [EXT] Re: Wtrlt: Issues with clock_ge… Ulrich Windl
- Re: [Ntp] Antw: [EXT] Re: Wtrlt: Issues with cloc… Miroslav Lichvar
- Re: [Ntp] Antw: [EXT] Re: Wtrlt: Issues with cloc… Hal Murray