| [chrony-dev] [PATCH] refclock: add SENSORS driver for OpenBSD timedelta sensors |
[ Thread Index |
Date Index
| More chrony.tuxfamily.org/chrony-dev Archives
]
- To: chrony-dev@xxxxxxxxxxxxxxxxxxxx
- Subject: [chrony-dev] [PATCH] refclock: add SENSORS driver for OpenBSD timedelta sensors
- From: Atanas Vladimirov <vlado@xxxxxxxxx>
- Date: Tue, 14 Jul 2026 00:12:45 +0300
- Cc: tom@xxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdbg.net; s=dkim; t=1783977165; 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; bh=u8Gh/Nj1qR6zQWT6KWjqmHEnsVGt1E/M1Mcps5LXpEQ=; b=LHz17AhjEOSnKGoW+H2LdgXfML0xfis6gW9pv9QaNNGeMF84kRwU/j1Ye/E1y2ETnOi0yS niTjedOhVEq0xwGI91AWSRfl9e9oMFDiqWBIPg+CbcIsJh5nFYM/kIvalfcQ3oYG8f4VxN eBHSC4Ib2tnKOkc1jaACV9eUtImbj+LQpIPxEjH7yAQOXppIZ4un4W7wVXnMuawbcRzt/r XA6I0nBqR5h/zwephzjay76t/WwMKIo0JTL94C/VYvrPkWUjAubsIq5fpR2N2Um+/K8XT2 /JCjZzfqJNaY6h2KPbXivKFN6J+0dJxk4wqyd5Klw4v7EaBX+UylGtztBvBU+A==
Hello,
First of all I was very happy to find that OpenBSD support was added recently. (thanks Thomas!)
I've been running a Stratum 1 ntp server with Garmin GPS 18x LVC (1PPS wired to DCD) with OpenNTPd for many years
and always had a big offset drifts and bad accuracy as a whole. So, when I found that the crony support is available I
was very excited to try/test it.
This patch adds a new refclock driver for OpenBSD, which reads timedelta sensors from the hw.sensors sysctl framework.
OpenBSD does not implement the RFC 2783 PPS API, so the PPS driver cannot be used there, and gpsd's PPS support does not work either (it relies on TIOCMIWAIT, which OpenBSD does not have). What OpenBSD has instead is kernel-level support for serial time sources: a line discipline attached with ldattach(8), e.g. nmea(4), parses the incoming sentences in the kernel and can timestamp a PPS signal wired to a modem control line (ldattach -t dcd) at interrupt time. The result is exposed as a timedelta sensor (offset of the system clock from the reference, in nanoseconds, timestamped with the system time of the pulse). This is the same mechanism OpenBSD's ntpd uses for its "sensor" time sources, and it is accurate to a few microseconds.
Until now (last few months since I test it) the only way to use these sensors with chronyd was an external bridge program feeding the SOCK refclock.
A native driver removes that extra daemon and process boundary.
The driver parameter is the sensor device name (e.g. nmea0). The device index is not stable across hotplug (the kernel reuses indices of detached devices), so the driver verifies the xname and presence of a timedelta sensor on every read and rediscovers the device on mismatch, same as OpenBSD's ntpd does.
Samples are skipped while the kernel marks the sensor invalid or its status is not OK (receiver lost fix, missing PPS signal), and duplicate measurements are filtered by the sensor timestamp.
No pledge() changes are needed; hw.sensors sysctl reads are always allowed on OpenBSD.
configure probes for sys/sensors.h, so the driver builds on OpenBSD only and compiles to the usual "not compiled in" stub elsewhere.
Tested on OpenBSD -current/amd64 with a Garmin GPS 18x LVC (NMEA at 4800 baud on com0, 1PPS wired to DCD, ldattach -t dcd nmea) and
```
refclock SENSORS nmea0 refid GPS precision 1e-7 prefer
```
in /etc/chrony.conf
The full config is as follows:
```
refclock SENSORS nmea0 refid GPS precision 1e-7 prefer
pool 2.europe.pool.ntp.org iburst maxpoll 6
pool 3.europe.pool.ntp.org iburst maxpoll 6
allow all
opencommands activity rtcdata smoothing sourcename sources sourcestats tracking serverstats
driftfile /var/db/chrony/drift
makestep 1.0 3
logdir /var/log/chrony
log measurements statistics tracking
```
and here is the `chronyc sources`
```
$ chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
#* GPS 0 4 377 18 -83us[ -92us] +/- 22us
^- ns2.netflash.com.cy 2 6 377 23 -913us[ -922us] +/- 44ms
^- ntp2.glypnod.com 2 6 377 22 -5143us[-5151us] +/- 28ms
^- mail.xfde.dev 2 6 377 25 -3712us[-3721us] +/- 23ms
^- 2a00:6d41:200:2::13 2 6 377 26 -3636us[-3645us] +/- 60ms
^- yggno.de 2 6 377 27 +1710us[+1701us] +/- 35ms
^- 85.209.96.20 3 6 377 24 -206us[ -215us] +/- 73ms
^- ntp.wide-net.pl 2 6 377 25 +3904us[+3895us] +/- 51ms
^- 77-173-106-70.fixed.kpn.> 3 6 371 23 +217us[ +208us] +/- 35ms
```
and `systat se` form the server
```
.....
nmea0.indicator0 On OK Signal
nmea0.timedelta0 22.000 us OK GPS differential
nmea0.angle0 XY.6853 degrees OK Latitude
nmea0.angle1 ZW.2932 degrees OK Longitude
nmea0.distance0 606.900 m OK Altitude
nmea0.velocity0 0.000 m/s OK Ground speed
```
I'm happy to make any changes you'd find appropriate.