[ntp:questions] implementing a simple ntp server: offset jumps

Brian Inglis Brian.Inglis at SystematicSw.ab.ca
Sun Nov 27 01:32:58 UTC 2016


On 2016-11-26 16:26, folkert wrote:
> For fun I'm implementing a simple ntp-server which gets its time from
> a gps with pps.
> Now this works somewhat: most of the time the offset is pretty low
> compared to a system with a real ntp implementation but sometimes
> the offset is almost a second, as if something wraps.
> I've been staring for hours at the code and can't find the bug.
> Maybe you guys want to look?

Only thing that comes to mind is that by the time you receive the GPS
message and process it, time is nearly at the next second, and your
timestamps make that obvious.
All you're showing us are the symptoms and results of the timing error,
not the data which causes it.

What you think is happening probably isn't what's happening, or when,
and you may need timing info around your function calls to see where
that is occurring e.g. if you have WiFi or USB or combined, something
sometimes may take hundreds of ms instead of ms away from your thread
e.g. a syscall which sometimes blocks, rescheduling your thread.

Change your process(es) based on the NTP *V4* reference implementation:
	https://tools.ietf.org/html/rfc5905
and dump out your real local system hardware time stamp, showing all
the incoming packet NTP time stamps with the changes in the state
variables and the results of the calculations on them, the same with
the outgoing packet, GPS PPS, and GPS messages.

Preferably these should be queued to an output thread, and the source
of the timing error should become obvious.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada


More information about the questions mailing list