From owner-freebsd-arch@freebsd.org Thu Dec 3 22:03:37 2020 Return-Path: Delivered-To: freebsd-arch@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 09FA74B0D91 for ; Thu, 3 Dec 2020 22:03:37 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from smtp-out-so.shaw.ca (smtp-out-so.shaw.ca [64.59.136.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cn8x45Kz5z4ppP; Thu, 3 Dec 2020 22:03:36 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from spqr.komquats.com ([70.67.229.168]) by shaw.ca with ESMTPA id kwhIkuSBFktFkkwhJk5g6y; Thu, 03 Dec 2020 15:03:35 -0700 X-Authority-Analysis: v=2.4 cv=NYRYa0P4 c=1 sm=1 tr=0 ts=5fc960b7 a=7AlCcx2GqMg+lh9P3BclKA==:117 a=7AlCcx2GqMg+lh9P3BclKA==:17 a=xqWC_Br6kY4A:10 a=kj9zAlcOel0A:10 a=zTNgK-yGK50A:10 a=6I5d2MoRAAAA:8 a=YxBL1-UpAAAA:8 a=EkcXrb_YAAAA:8 a=RwVsqvfjfJKKwxMFqc0A:9 a=CjuIK1q_8ugA:10 a=IjZwj45LgO3ly-622nXo:22 a=Ia-lj3WSrqcvXOmTRaiG:22 a=LK5xJRSDVpKd5WXXoEvA:22 Received: from slippy.cwsent.com (slippy [IPv6:fc00:1:1:1::5b]) by spqr.komquats.com (Postfix) with ESMTPS id 27512232; Thu, 3 Dec 2020 14:03:31 -0800 (PST) Received: from slippy (localhost [127.0.0.1]) by slippy.cwsent.com (8.16.1/8.16.1) with ESMTP id 0B3M3VJx004269; Thu, 3 Dec 2020 14:03:31 -0800 (PST) (envelope-from Cy.Schubert@cschubert.com) Message-Id: <202012032203.0B3M3VJx004269@slippy.cwsent.com> X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.7.1 Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: "Poul-Henning Kamp" cc: Ian Lepore , Cy Schubert , freebsd-arch@freebsd.org Subject: Re: struct timex and Linux adjtimex() In-reply-to: <25487.1607029223@critter.freebsd.dk> References: <202012030523.0B35NsG7003810@slippy.cwsent.com> <4086.1606982335@critter.freebsd.dk> <5e0db735b29f1ece02521871b2cd392c3467101d.camel@freebsd.org> <25487.1607029223@critter.freebsd.dk> Comments: In-reply-to "Poul-Henning Kamp" message dated "Thu, 03 Dec 2020 21:00:23 +0000." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 03 Dec 2020 14:03:31 -0800 X-CMAE-Envelope: MS4xfPXuuuGqNJMQ6WZRRaLcokb66RW1elWmlUm1520t7Pw3yp3/rP+TUL3F5DOMzMVIVK90x2/rXpCqDrrEwQUO9AQ1yyhFF+mMzqPSN12DCpxXdbLS0lM3 5WGW68qzyJmUOQpvcfhKuSKYaSGil0hgmDsCIMvbMoJVWIxeks/QPUqA7fNrxdT74LpHY+s71MdWEQnikhAdPiaQX6p+/5JS8TpX5NLUFRGUXcyrrwvZPxgk ARpj3tKkLsnR3pFj7LK1F9beDWcksqgM1YGP2d8Xapc= X-Rspamd-Queue-Id: 4Cn8x45Kz5z4ppP X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2020 22:03:37 -0000 In message <25487.1607029223@critter.freebsd.dk>, "Poul-Henning Kamp" writes: > -------- > Ian Lepore writes: > > On Thu, 2020-12-03 at 07:58 +0000, Poul-Henning Kamp wrote: > > > We run freebsd on hardware whose timecounter clock is fed from a gps- > > disciplined oscillator and the hardware in the SOC implementing that > > clock can capture the counter on an edge of an incoming PPS (which is > > generated from the same disciplined oscillator), so we can get fairly > > accurate phase measurements. > > > > But I can't set the time with anything like the same accuracy. > > Wrong. > > You can set time with nanosecond precision, even pretty quickly, > but you cannot *step* it with nano-second precision. > > (This last is an universal truth: The code to do the load+add+store > takes instructions on the order of several nanoseconds, and try as > you might, you cannot calibrate that offset to sub-nanosecond > uncertainty on contemporary hardware. This is why there is no > escaping fiddling with minute frequency adjustments and measurements > over a period of time, if you want your clock to be precise at the > ~sub-20 nanosecond level.) > > MOD_OFFSET will precisly slew the clock a given offset over a period > of time, in an exponential-decay manner, taking pains to ensure > time never stops og goes backwards. > > The "no-step-no-stop" policy was a very deliberate design decision > by Dave Mills, and not one he was ever willing to compromise on. > > His argument was that while forward steps are generally not too > troublesome, time should never *ever* go backwards, *and* that > postive and negative offsets should be handled identically. > > On a purely philosophical basis, that argument is unassailable, > but we have all tried CMOS RTC's giving us bogus time. > > Both the "initial step" code in ntpd(8) and the ntpdate(8) program > exists as workarounds around Daves veto, to cope with bad CMOS > time. > > Fortunately time-steps are a lot less poisonous these days, because > people have discovered CLOCK_MONOTONIC, but "no-step-no-stop" is > fundamentally still the right way to go. > > Anyway, the "ADJ_SETOFFSET" is a hackish bolt-on, starting with the > fact that the "ADJ_" prefix is totally out of family for , > and any interaction with the rest of the PLL is unspecified. Yes. The initial proposal was for a uniquely new syscall that simply added and subtracted. But that quickly became a discussion about adjtimex(). Looking at the Linux code a few days ago it became apparent that adjtimex() was a hack. ADJ_TICK is another hack similar to MOD_FREQUENCY, which is called ADJ_FREQUENCY in adjtimex. ADJ_TICK is handled by ADJ_FREQUENCY (which is synonymous to MOD_FREQUENCY). ADJ_TICK looks broken. The Linux sys/timex.h equates the ADJ_* to MOD_* except for ADJ_SETOFFSET and ADJ_TICK, which aren't supported by ntp_adjtime(). > > That is why I'm not too entusiastic about adopting it. Neither am I, which is why I raised the issue here. They felt the need for it. Having discussion here gives me more gravitas to speak for the Project. Having said that, I'd roll up my sleeves to implement what we decided here. > > A more correct integration in the kernel-pll would be to have a > modifier flag for MOD_OFFSET which indicates that a step is desired, > and document that it zeros the PLL as part of the operation. > > But as mentioned above, no matter what, the precision is probably > limited to around 25 nanoseconds, possibly more depending on locking, > and while that may be good enough for your specific case, it is > a blemish on the otherwise very stringent about precision PLL code. > > > > I notice a struct timeval was mentioned, but hopefully that's in a > > context where MOD_NANO/STA_NANO apply and tv_usec will actually convey > > nanos? > > Yes, when the _NANO flag is set, the timeval is a timespec > > -- > Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 > phk@FreeBSD.ORG | TCP/IP since RFC 956 > FreeBSD committer | BSD since 4.3-tahoe > Never attribute to malice what can adequately be explained by incompetence. The take away from this discussion is that we are not interested in implementing the Linux adjtimex() here. Which I agree with. I will go back with my initial proposal of a timespec add/subtract syscall takes a timespec as input increments or decrements the clock by the timespec and returns a timespec with the time. That enables the ntp developers to add or subtract time and compare it with what ntp thinks it should be. Their idea is to have a loop feeding deltas to the syscall and comparing the output with their expectation. This is certainly less disruptive and IMO more maintainable than their desired solution. I have had code for the other more simpler separate new syscall option in my git repo for about a week. This was rejected because the desire was for FreeBSD to implement adjtimex(). I could submit the simpler separate unrelated to ntp_adjtime() syscall as a phabricator review or post it here if people prefer that instead. The code hasn't been tested. IMO the important consideration isn't Linux compatibility but being atomic (reduction of syscalls from two to one). Once through the review process I can take it back to the nwtime folks. I'm sure they'd be happier with this over nothing. Thoughts? -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org The need of the many outweighs the greed of the few.