[ntp:hackers] Windows 8 has a microsecond-precision system clock

Dave Hart hart at ntp.org
Thu Mar 1 20:58:43 UTC 2012


Windows 8 will finally include an interpolated system clock:

http://msdn.microsoft.com/en-us/library/windows/desktop/Hh706895(v=vs.85).aspx

This is a new API, GetSystemTimePreciseAsFileTime().  Existing
applications and C runtimes built for earlier Windows will continue to
see a lower-precision clock -- applications have to opt-in to using
the likely much slower new API.  The existing
GetSystemTimeAsFileTime() API is particularly fast as it does not
involve any calculation or any kernel mode transition overhead -- it
simply reads 64 bits from shared memory mapped into every process
which contains the time as of the last system clock tick (between 64
and 2000 Hz).  The new API likely involves a kernel transition to read
the performance counter (which is always provided by the HAL and
requires the kernel transition), plus a scaling operation to convert
the counter value to the wall-clock timeline using the low-precision
64-bit shared memory clock and a new stored counter value taken at the
time of the last system clock tick.

This is great news for ntpd on Windows 8, where the availability of
the new API will allow a future ntpd to achieve better performance
than the current interpolation hack allows, and it will work on all
Windows 8 systems, not only those whose system clock ticks at 100 Hz
or slower, as is the case for the interpolation hack.

This was brought to my attention thanks to my brother Lee, who works
on Windows developer documentation at Microsoft, and a program manager
there interested in low-latency computing.  I took the opportunity to
respond to them laying out other wishlist items to make Windows
competitive with FreeBSD for ntpd:

1.  SO_RECEIVE using the new precise clock to timestamp received NTP
packets in the kernel earlier than ntpd can after the socket recv()
operation completes.
2.  PPS timestamping in the stock serial.sys driver, rather than
requiring my patched serialpps.sys and the complications of using an
unsigned driver on 64-bit editions of Windows.
3.  Better understanding of what changes the precision of the system
clock on Vista, Win7, and Windows Server 2008 from the boot-time value
of 15.6 msec between ticks to 0.5 or 1.0 msec ticks, which change can
occur after ntpd starts and has decided to use its interpolation hack,
which then falls over into a mass of noise on the order of 15 msec.

Cheers,
Dave Hart


More information about the hackers mailing list