From ebc7d2496417baca372d599affdaffc3754ff268 Mon Sep 17 00:00:00 2001 From: Dave Hart Date: Tue, 20 Mar 2012 06:03:15 +0000 Subject: [PATCH] Treat zero counter as indication of precise system time in Windows PPSAPI helper function pps_ntp_timestamp_from_counter(), enabling PPSAPI providers to use the Windows 8 precise clock directly. bk: 4f681da3R3sXoD6JALttpSHBWAFGTw --- ChangeLog | 3 +++ ports/winnt/include/clockstuff.h | 9 ------- ports/winnt/ntpd/nt_clockstuff.c | 43 +++++--------------------------- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 07b60973a..119737052 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* Treat zero counter as indication of precise system time in Windows + PPSAPI helper function pps_ntp_timestamp_from_counter(), enabling + PPSAPI providers to use the Windows 8 precise clock directly. (4.2.7p264) 2012/03/14 Released by Harlan Stenn * [Bug 2160] Note if leapseconds file is past its prime. * Use GetSystemTimePreciseAsFileTime() on Windows 8. diff --git a/ports/winnt/include/clockstuff.h b/ports/winnt/include/clockstuff.h index 3c1100b49..df8569935 100644 --- a/ports/winnt/include/clockstuff.h +++ b/ports/winnt/include/clockstuff.h @@ -41,13 +41,4 @@ extern PGSTAFT pGetSystemTimePreciseAsFileTime; void lock_thread_to_processor(HANDLE); -#ifdef HAVE_PPSAPI -/* - * ntp_timestamp_from_counter provides an interface for - * serialpps.sys counterstamps to be converted to - * interpolated timestamps. - */ -extern void ntp_timestamp_from_counter(l_fp *, ULONGLONG, ULONGLONG); -#endif - #endif diff --git a/ports/winnt/ntpd/nt_clockstuff.c b/ports/winnt/ntpd/nt_clockstuff.c index fd6f6c35e..53c5415ae 100644 --- a/ports/winnt/ntpd/nt_clockstuff.c +++ b/ports/winnt/ntpd/nt_clockstuff.c @@ -1183,6 +1183,9 @@ lock_thread_to_processor(HANDLE thread) #ifdef HAVE_PPSAPI +static inline void ntp_timestamp_from_counter(l_fp *, ULONGLONG, + ULONGLONG); + /* * helper routine for serial PPS which returns QueryPerformanceCounter * timestamp and needs to interpolate it to an NTP timestamp. @@ -1204,6 +1207,7 @@ pps_ntp_timestamp_from_counter( } +static inline void ntp_timestamp_from_counter( l_fp *result, @@ -1225,27 +1229,9 @@ ntp_timestamp_from_counter( } InterpTimestamp = interp_time(Counterstamp + QPC_offset, FALSE); - -#ifdef DEBUG - /* sanity check timestamp is within 1 minute of now */ - GetSystemTimeAsFileTime(&Now.ft); - Now.ull -= InterpTimestamp; - if (debug && - Now.ll > 60 * HECTONANOSECONDS || - Now.ll < -60 * HECTONANOSECONDS) { - DPRINTF(1, ("ntp_timestamp_from_counter interpolated time %.6fs from current\n", - Now.ll / (double)HECTONANOSECONDS)); - DPRINTF(1, ("interpol time %llx from %llx + %llx\n", - InterpTimestamp, Counterstamp, - QPC_offset)); - msyslog(LOG_ERR, - "ntp_timestamp_from_counter interpolated time %.6fs from current\n", - Now.ll / (double)HECTONANOSECONDS); - exit(-1); - } -#endif } else { /* ! winnt_use_interpolation */ - if (NULL != pGetSystemTimePreciseAsFileTime) { + if (NULL != pGetSystemTimePreciseAsFileTime && + 0 != Counterstamp) { QueryPerformanceCounter(&Ctr.li); (*pGetSystemTimePreciseAsFileTime)(&Now.ft); CtrDelta = Ctr.ull - Counterstamp; @@ -1257,23 +1243,6 @@ ntp_timestamp_from_counter( InterpTimestamp = Timestamp; GetSystemTimeAsFileTime(&Now.ft); } -#ifdef DEBUG - /* sanity check timestamp is within 1 minute of now */ - Now.ull -= InterpTimestamp; - if (debug && - Now.ll > 60 * HECTONANOSECONDS || - Now.ll < -60 * HECTONANOSECONDS) { - DPRINTF(1, ("ntp_timestamp_from_counter serial driver %s time %.6fs from current\n", - (NULL == pGetSystemTimePreciseAsFileTime) - ? "system" - : "counter", - Now.ll / (double)HECTONANOSECONDS)); - msyslog(LOG_ERR, - "ntp_timestamp_from_counter serial driver system time %.6fs from current\n", - Now.ll / (double)HECTONANOSECONDS); - exit(-1); - } -#endif } /* convert from 100ns units to NTP fixed point format */ -- 2.47.3