[ntp:questions] how to write a reference clock driver

Juergen Perlinger juergen.perlinger at t-online.de
Sat Dec 27 19:33:39 UTC 2008


Harlan Stenn wrote:

>>>> In article <4944eab4$0$12693$9b622d9e at news.freenet.de>, Juergen Kosel
>>>> <juergen.kosel at freenet.de> writes:
> 
> Juergen> Hello, Greg Dowd schrieb:
>>> I'm not quite sure what you mean.  A reference clock doesn't compute an
>>> offset, it acquires, formats and returns a time value from an external
>>> source.  NTP takes care of the rest.
> 
> Juergen> ntpd reads the time of a reference clock with a reference clock
> Juergen> driver.  My problem was, that I didn't know from the manual what
> Juergen> need to be done with the time from the reference clock.
> Especially Juergen> when it is in a differnet format than of the other
> reference Juergen> clocks.
> 
> Juergen> But finally I succeeded by calculating the difference between
> Juergen> refence clock time - system clock time and using the SAMPLE()
> macro Juergen> to insert this value into the the right data structure
> entry of Juergen> ntpd.
> 
> 
> Juergen,
> 
> Most refclock drives do not do it the way you describe.
> 
> They take the time from the reflock along with the system timestamp (with
> the intent to get the system timestamp as close as possible to the moment
> the refclock timestamp is obtained), build the contents of the struct
> refclockproc, and call refclock_process().
> 

Hi Harlan, Hi Juergen,

The difference is bit more subtle. 'refclock_process()' *will*
call 'refclock_process_offset()', but *only* if the clock conversion
in 'clocktime()' was successful. That means that the difference between
local time and clock time is less than 4 hours! That's why initial
synchronization with clocks only can/will fail if the system has no
battery-backup clock. (That's probably true for most, not all clock
drivers.)

Calling refclock_process_offset()' directly will save that hassle, and it
might provide initial synchronization even if the system clock is way off
from the real time, for a given value of real 8-)
-- 
juergen 'pearly' perlinger
"It's hard to make new errors!"




More information about the questions mailing list