Solved Time lags behind on a running sever

There's a weird problem, even when the time is initially set by openntpd it keeps lagging by one second every few seconds:

Code:
$ sudo /usr/local/etc/rc.d/openntpd restart
Performing sanity check on openntpd configuration:
configuration OK
Stopping openntpd.
Waiting for PIDS: 85893.
Performing sanity check on openntpd configuration:
configuration OK
Starting openntpd.
$ ssh good-server date; date
Sun Jun 30 11:04:17 +04 2019
Sun Jun 30 11:04:17 +04 2019
$ ssh good-server date; date
Sun Jun 30 11:04:25 +04 2019
Sun Jun 30 11:04:24 +04 2019
$ ssh good-server date; date
Sun Jun 30 11:04:32 +04 2019
Sun Jun 30 11:04:31 +04 2019
$ ssh good-server date; date
Sun Jun 30 11:04:39 +04 2019
Sun Jun 30 11:04:37 +04 2019
$ ssh good-server date; date
Sun Jun 30 11:04:48 +04 2019
Sun Jun 30 11:04:45 +04 2019
On FreeBSD 11.4, but I'm not sure if this is an OS problem at all.
What could be causing this? Broken openntpd setup?
openntpd-6.2p3_3,2 Network Time Protocol (NTP) daemon

If it's a dead CMOS battery or whatever, shouldn't that only be relevant to when the PC is off (and this particular server never is)? The server itself is about half a year old.
 
Last edited by a moderator:
I removed /var/db/ntpd.leap-seconds.list and restarted openntpd, it didn't help.
Then I removed /var/db/ntpd.drift and restarted. didn't help either.
 
Trying the base ntpd from the OS hasn't helped either. Trying none of them at all and setting the time manually neither - the time keeps falling behind gradually. Maybe there's some drift value active that tells the OS to do that?
 
I think I got it, after checking /etc/crontab and looking up adjkerntz manual.

[rihad@sun ~]$ sysctl machdep.adjkerntz
machdep.adjkerntz: -14400
[rihad@sun ~]$ ssh another-good-server sysctl machdep.adjkerntz
machdep.adjkerntz: 0
[rihad@sun ~]$

Whoever set it to -14400? This is what causes the drift. Why is adjkerntz setting it 4 hours behind on this server, and not on others?
1,31 0-5 * * * root adjkerntz -a
 
I think the problem is because the current configuration tells the utilities that CMOS clock is in localtime, the file /etc/wall_cmos_clock exists. And it doesn't exist on other our servers.
 
So yeah, I probably answered wrong to the tzsetup dialog when configuring this server.
machdep.wall_cmos_clock: 1
machdep.adjkerntz: -1440

Oddly enough, setting both of them to 0 manually and running adjkerntz -a and restaring openntpd doesn't fix the jitter. Once set correctly, local time still keeps crawling back.
 
After some googling I've set this value:
kern.timecounter.hardware=HPET (from the default ACPI-low) without rebooting and it seems that it instantly fixed the time lagging.
And it also needs to be set in /etc/sysctl.conf to persist across reboots.
Hope this helps someone.
 
Sorry, 11.2 of course. I confused it with PostgreSQL 11.4, which is hosted on that box.
 
Back
Top