ref: e16f6004ab0807ecce5aa9d894a854a136947349
parent: fdb503349c9e8007902b26211170cdc8dfa745af
author: Aidan Wiggins <akw@oneiri.one>
date: Sun Oct 26 11:38:12 EDT 2025
timesync: use last sample as reference timestamp Previously in ntpserver(), we would only populate ntp->refts if we were using a utc (-U) time source. This will instead use the last source sample appended to the list of Samples, this requires we add RFMEM to the rfork() in background(), in order to share lastrefts to ntpserver().
--- a/sys/src/cmd/aux/timesync.c
+++ b/sys/src/cmd/aux/timesync.c
@@ -40,7 +40,7 @@
vlong mydisp, rootdisp;
vlong mydelay, rootdelay;
vlong avgdelay;
-vlong lastutc;
+vlong lastrefts;
uchar rootid[4];
char *sysid;
int myprec;
@@ -490,6 +490,7 @@
/* add current sample to list. */
*l = s;
l = &s->next;
+ lastrefts = s->stime;
if(logging)
syslog(0, logfile, "δ %lld avgδ %lld hz %lld",
@@ -1093,8 +1094,7 @@
gettime(&s, nil, nil);
s -= atoll(v[1]);
}
- lastutc = atoll(v[0]) + s;
- return lastutc;
+ return atoll(v[0]) + s;
}
/*
@@ -1173,7 +1173,7 @@
ntp->precision = myprec;
hnputfp(ntp->rootdelay, rootdelay + mydelay);
hnputfp(ntp->rootdisp, rootdisp + mydisp);
- hnputts(ntp->refts, lastutc);
+ hnputts(ntp->refts, lastrefts);
memmove(ntp->origts, ntp->xmitts, sizeof(ntp->origts));
hnputts(ntp->recvts, recvts);
memmove(ntp->rootid, rootid, sizeof(ntp->rootid));
@@ -1361,7 +1361,7 @@
return;
if(!debug)
- switch(rfork(RFPROC|RFFDG|RFNAMEG|RFNOTEG|RFNOWAIT)){+ switch(rfork(RFPROC|RFMEM|RFFDG|RFNAMEG|RFNOTEG|RFNOWAIT)){case -1:
sysfatal("forking: %r");break;
--
⑨