[time-nuts] refclock -> NTP server settings/tuning?

Hal Murray hmurray at megapathdsl.net
Sun Sep 29 18:17:47 EDT 2013


anders.e.e.wallin at gmail.com said:
> The refclock driver is a userspace C-program (daemon) that essentially does:
> while(1) {
>     gettimeofday(&tv,NULL) // system time, for NTP  receiveTimeStamp
>     get_wr_time(&wr_tv); // WR time, for NTP clockTimeStamp
>     // write tv and wr_tv to shared memory where NTP expects to see them
>     sleep(8);
>  } 

Where did you get the 8 from?

Each ntpd refclock has a 64 slot FIFO.  Every polling interval, ntpd 
processes the data in the buffer and turns it into a sample feed to the main 
algorithm.  That processing discards 1/3 of the samples as (potential) 
outliers and averages the rest.

You had min/max poll set to 4 (16 seconds) so you are only giving ntpd 2 
samples to work with.

So the first thing I would do is change the 8 to 1.  Then I'd fiddle with 
min/max poll to see what worked best.

The next source of noise that I see is that time it takes to execute the 
time-reads may vary due to cache faults and may get interrupted.  Plan one 
would be:
    gettimeofday(&tv0,NULL)
    get_wr_time(&wr_tv);
    gettimeofday(&tv1,NULL)
    if (tv1-tv0 > xxx) try again
You can get xxx from a calibration run.

Plan two would be
    gettimeofday(&tv,NULL)
    get_wr_time(&wr_tv);
    gettimeofday(&tv,NULL)
    get_wr_time(&wr_tv);
The first two will warm up the cache.  You will still get occasional 
interrupts, but ntp should filter them out.


> If the driver was written as a kernel module, would that run with higher
> priority and less variable delay? 

Depends upon how it's written.

> I use the same piece of code to log how well system time tracks WR-time.
> Here I sometimes see sudden spikes of 100s of microseconds. Could this be
> caused by the OS context switching in the middle of my program between the
> two timestamp-reading functions?

My guess is that an interrupt is more likely than a user level context switch.

--------

Go back to the big picture.  What are you trying to do?  What sort of 
accuracy do you need?

Is this a one-off project or do you need to run code on many systems using 
different hardware?

Can you modify the code that needs accurate time to call get_wr_time rather 
than gettimeofday?  (Or patch the library so gettimeofday uses WR rather than 
calling the system?)


-- 
These are my opinions.  I hate spam.





More information about the time-nuts mailing list