From nobody Fri May 10 05:37:50 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VbHj41J5dz5KtFQ for ; Fri, 10 May 2024 05:38:00 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4VbHj35wM7z4nKB for ; Fri, 10 May 2024 05:37:59 +0000 (UTC) (envelope-from phk@critter.freebsd.dk) Authentication-Results: mx1.freebsd.org; none Received: from critter.freebsd.dk (unknown [192.168.55.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by phk.freebsd.dk (Postfix) with ESMTPS id 2417389287; Fri, 10 May 2024 05:37:52 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.18.1/8.16.1) with ESMTPS id 44A5bps5076724 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 10 May 2024 05:37:51 GMT (envelope-from phk@critter.freebsd.dk) Received: (from phk@localhost) by critter.freebsd.dk (8.18.1/8.16.1/Submit) id 44A5boZA076723; Fri, 10 May 2024 05:37:50 GMT (envelope-from phk) Message-Id: <202405100537.44A5boZA076723@critter.freebsd.dk> To: "Josef 'Jeff' Sipek" cc: freebsd-hackers@freebsd.org Subject: Re: Precision Hardware Clocks In-reply-to: From: "Poul-Henning Kamp" References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <76721.1715319470.1@critter.freebsd.dk> Date: Fri, 10 May 2024 05:37:50 +0000 X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:1835, ipnet:130.225.0.0/16, country:EU] X-Rspamd-Queue-Id: 4VbHj35wM7z4nKB Josef 'Jeff' Sipek writes: > To summarize, the goals/non-goals for this work are: > > Goals: > * read-only interface to various precision hardware clocks (PHCs) > * support for both absolute time and counter-only PHCs > * ability to use software like chrony to stabilize system clocks I should and will be the last to discourage anybody from having fun with timekeeping. But I do feel a responsibility to point out, that you are trying to solve already solved problems, in a way that does not work nearly as well as those solutions. Chesterton's fence: Before you throw it out or bypass it, you should find out why the current timekeeping infrastructure is built like it is. Back in the mists of time, before even I got involved in it, NTPD did more or less exactly what you propose, because there were no kernel support for timekeeping, only for adding device drivers, and it did not work then, and it wont work much better today, for fundamental and inescapable reasons. For starters, exposing the hardware count though a char-dev is going to be very jittery (= time-noise). The "userland->kernel->userland" context switches are very unpredictable timewise, because it is anyones guess how many memory operations it will take, even in the best case. Worse, there is a high risk that you loose the CPU to another (kernel)thread which is going to /really/ introduce jitter. That is why the PPS-API, timecounters and kernel_pll exists: To keep the "real-time" aspect of the timekeeping firmly inside the kernel and undisturbed by userland and lower priority kernel activities. Unless you can expose the hardware directly to userland, via mmap(2), timekeeping in userland is simply not going to perform. With that said, a lot of our timekeeping is stuff I wrote 25 years old, and it is absolutely due for both a rethink and a refresh, but if you decide to throw it all out and start from fresh, you will not get to the interesting parts for years. So before you continue, at the very least, read this: https://papers.freebsd.org/2002/phk-timecounters/ And you should think a LOT about page 91 in this one too: https://www.am1.us/wp-content/uploads/Documents/U11625_VIG-TUTORIAL.pdf (The other 307 pages are also interesting :-) Poul-Henning FreeBSD TimeLord (retired) -- 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.