Project

General

Profile

NTP time sync

Added by Martin Bednar over 5 years ago

I recently discovered that DVB signals could be used as a time source, and decided to try adding it as a time source to my local NTP server.
Note that this does not work with openntpd, as it requires the SHMem ntp driver.

In tvheadend go to Configuration -> General -> Base, and check "Enable NTP driver.

Chrony configuration:
add the following to /etc/chrony/chrony.conf

refclock SHM 0:perm=0600 poll 0 refid TVH0
refclock SHM 2:perm=0666 poll 0 refid TVH2

TVH0 is for when tvheadend is run as root.
TVH2 is for when tvheadend is run as non-root.
The permission settings are inferred from code in tvhtime.c (https://github.com/tvheadend/tvheadend/blob/66d6161c563181e5a572337ab3509a835c5a57e2/src/tvhtime.c)
The poll parameter is necessary to disable chrony's median filter (see update 2)

I checked this using ipcs -m. Tvheadend creates the shared memory segment, and starting chrony increments the nattach by one (was 0 at beginning).

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x4e545032 36         tvheadend  666        96         1

Note that the owner is the uid of the owning process, and that if chrony is started before tvheadend tries updating the time, chrony will be the owner.

And now the real question: Does it actually work?
As of now, I honestly have no idea, I came up with these theoretical checks, but don't know how to practically check...
If anyone familiar with chrony could give me a hint about how to check, I'd be grateful.

update:I was wrong, the nattach number should be 2 (chronyd + tvheadend). Which it just became. So the SHM config works! I still don't know if chrony takes any data from it though...

update 2: chrony receives the data. So it works.

chronyc> sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#? TVH2                          0   0     0   473  +2803ms[+2803ms] +/-   49n

Note the LastRx value. :)
Unfortunately the TOT/TDT tables come in so rarely, that it isn't deemed by default a good source. Updated the config to make chrony use it.


Replies (1)

RE: NTP time sync - Added by thermionic valve about 5 years ago

I'm an ntpsec user rather thana chrony user, but in ntpsec there is ntpviz https://docs.ntpsec.org/latest/ntpviz.html for graphing ntp stats.

Of course when trying to check accuracy, one needs something that is more accurate, but as long as the clock on the device you are using is "reasonable", using other ntp servers (I would suggest that unless you have a local GPS/PPS connected
ntpd that you used the ntp pool project) should give you at least an estimation as to the "quality" of the recovered time.

    (1-1/1)