[ntp:hackers] timespec vs timeval

Frank Kardel kardel at ntp.org
Tue Jul 17 09:06:03 UTC 2007


Hi Dave !

> This might go to Frank, Danny and Harlan. Others might be interested.
>
> I was looking in ntp_io.c for something or other and tripped over the
fetch_timestamp() routine. It uses a timeval structure where I would
think a timespec structure more appropriate. Is there a reason why the
get_systimer() is not used?

fetch_timestamp() extracts the time stamp taken by the *kernel* upon
receipt of a UDP paket for sockets that have the SO_TIMESTAMP option. If
no kernel time stamp is provided the time stamp from paket reception will
be used (read via get_systimer()).
SO_TIMESTAMP is enabled for systems that provide that interface.

Unfortunately SO_TIMESTAMP only provides usec resolution an I currently
don't know of any widespread SO_TIMESTAMP like implementation with a
better resolution.

Anyhow, measurements have shown (DEBUG_TIMING IIR) that the kernel taken
time stamps preceedes user level time stamps by several usecs (range
10-700) on an AMD Athlon X2 4400+ running NetBSD 4/-current.
I'd rather take a usec time stamp on soft intr level than a sub usec time
stamp delayed by several microseconds.

Maybe we should propose another SO_TIMESTAMP option to make use of struct
timespec to the OS communities.

>
> I checked elsewhere for timvals and found a few, mostly in some
> refclocks. The input buffer timestamp is the most important, as the time
to read the clock is now in the order of half a microsecond.

Yes, but get_systime() is too late - it's running at user
level and fetch_timestamp fetches the kernel time stamp.
To improve the resolution of SO_TIMESTAMP beyond struct timeval that we
need to change the kernel interface.

Frank





More information about the hackers mailing list