NTP and clocks under QNX

I have been playing around with an early version of NTP that was ported
to QNX4. I’ve been adding functions like ClockAdjust() and ClockCycles()
to the program. Its working fairly well but it brings up some questions
about
how QNXRTP 6.1 handles the clock.

ClockAdjust() appears to be an offset that is applied to any request for an
absolute time. It appears to be stored in
SYSPAGE_ENTRY(qtime)->nsec_tod_adjust.
It also implies that the hardware clock is not being adjusted and that it is
not
resolution limited to hardware clock steps. Does this mean that if I set up
a
periodic timer using relative times it would become out of sync with the
absolute
time that is being corrected using ClockAdjust() ? Thus requiring one to use
a
series of absolute times.

NTP is limited in resolution to about +/- 1/2 the OS tick on most systems
and it
appears to be about what I am getting. But the ClockCycles() feature on the
newer
CPUs opens up the possibility of doing much better. Presently I am
attempting to
sync to the tick using delay(1) and reading the time using gettimeofday()
followed by
a call to ClockCycles(). This seems to work in that I don’t get 1 ms steps
in my
time comparisons. But I am getting some drifts of about +/- 1 ms over a half
hour.
This is maybe/(probably) a problem with the code that I don’t have quite
right yet.
It would make it a lot easier though if QNX stored the ClockCycles() reading
during
the ISR for the timer tick. Then one could read the absolute time at any
point to
a resolution of sub-microseconds ! :slight_smile: Of course my application doesn’t
require this
resolution. I just wanted to sync the clocks to within tens of ms and RTP
doesn’t
ship with a version of NTP. Plus this looked like a good application to test
out
QNX. BTW, is delay(1) a good/(recommended) way to sync an application to the
tick ?

I was inspecting other variables in the syspage space in hope of finding
ClockCycles()
stored in there. I understand most of the values but
SYSPAGE_ENTRY(qtime)->nsec.
It seems to be always changing. I assumed it would be the absolute system
time
without the ClockAdjust() correction applied. But this value should only be
incremented
every tick. What is it ?

TIA,

Dave Eisert