summaryrefslogtreecommitdiffstats
path: root/win/tclWinTime.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2021-04-03 13:53:56 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2021-04-03 13:53:56 (GMT)
commit8b11f08b3cb7e5e92dd7812df02e8419e49be96d (patch)
tree87a42b23f924af5846a8c2999de5fd98db252a25 /win/tclWinTime.c
parent02855d5980f78e6e42b3a35274a26c978f9af694 (diff)
parent743881d3ce722dbba89ec98a6f5a9618e683bbf1 (diff)
downloadtcl-8b11f08b3cb7e5e92dd7812df02e8419e49be96d.zip
tcl-8b11f08b3cb7e5e92dd7812df02e8419e49be96d.tar.gz
tcl-8b11f08b3cb7e5e92dd7812df02e8419e49be96d.tar.bz2
Clean up the notifier code to not spread the hooks quite so widely
Diffstat (limited to 'win/tclWinTime.c')
-rw-r--r--win/tclWinTime.c419
1 files changed, 264 insertions, 155 deletions
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index 0bd5b7e..6de8944 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -28,7 +28,8 @@ typedef struct {
* initialized. */
int perfCounterAvailable; /* Flag == 1 if the hardware has a performance
* counter. */
- DWORD calibrationInterv; /* Calibration interval in seconds (start 1 sec) */
+ DWORD calibrationInterv; /* Calibration interval in seconds (start 1
+ * sec) */
HANDLE calibrationThread; /* Handle to the thread that keeps the virtual
* clock calibrated. */
HANDLE readyEvent; /* System event used to trigger the requesting
@@ -97,7 +98,8 @@ static TimeInfo timeInfo = {
*/
static struct {
int initialized; /* 1 if initialized, 0 otherwise */
- int perfCounter; /* 1 if performance counter usable for wide clicks */
+ int perfCounter; /* 1 if performance counter usable for wide
+ * clicks */
double microsecsScale; /* Denominator scale between clock / microsecs */
} wideClick = {0, 0, 0.0};
@@ -128,6 +130,23 @@ Tcl_ScaleTimeProc *tclScaleTimeProcPtr = NativeScaleTime;
ClientData tclTimeClientData = NULL;
/*
+ * Inlined version of Tcl_GetTime.
+ */
+
+static inline void
+GetTime(
+ Tcl_Time *timePtr)
+{
+ tclGetTimeProcPtr(timePtr, tclTimeClientData);
+}
+
+static inline int
+IsTimeNative(void)
+{
+ return tclGetTimeProcPtr == NativeGetTime;
+}
+
+/*
*----------------------------------------------------------------------
*
* TclpGetSeconds --
@@ -149,16 +168,17 @@ TclpGetSeconds(void)
{
long long usecSincePosixEpoch;
- /* Try to use high resolution timer */
- if ( tclGetTimeProcPtr == NativeGetTime
- && (usecSincePosixEpoch = NativeGetMicroseconds())
- ) {
+ /*
+ * Try to use high resolution timer
+ */
+
+ if (IsTimeNative() && (usecSincePosixEpoch = NativeGetMicroseconds())) {
return usecSincePosixEpoch / 1000000;
} else {
Tcl_Time t;
- tclGetTimeProcPtr(&t, tclTimeClientData); /* Tcl_GetTime inlined. */
- return (unsigned long long)(unsigned long)t.sec;
+ GetTime(&t);
+ return (unsigned long long)(unsigned long) t.sec;
}
}
@@ -186,11 +206,12 @@ TclpGetClicks(void)
{
long long usecSincePosixEpoch;
- /* Try to use high resolution timer */
- if ( tclGetTimeProcPtr == NativeGetTime
- && (usecSincePosixEpoch = NativeGetMicroseconds())
- ) {
- return (Tcl_WideUInt)usecSincePosixEpoch;
+ /*
+ * Try to use high resolution timer.
+ */
+
+ if (IsTimeNative() && (usecSincePosixEpoch = NativeGetMicroseconds())) {
+ return (Tcl_WideUInt) usecSincePosixEpoch;
} else {
/*
* Use the Tcl_GetTime abstraction to get the time in microseconds, as
@@ -199,8 +220,9 @@ TclpGetClicks(void)
Tcl_Time now; /* Current Tcl time */
- tclGetTimeProcPtr(&now, tclTimeClientData); /* Tcl_GetTime inlined */
- return ((unsigned long long)(unsigned long)now.sec * 1000000ULL) + now.usec;
+ GetTime(&now);
+ return ((unsigned long long)(unsigned long) now.sec * 1000000ULL) +
+ now.usec;
}
}
@@ -236,6 +258,7 @@ TclpGetWideClicks(void)
* is consistent across all processors. Therefore, the frequency need
* only be queried upon application initialization.
*/
+
if (QueryPerformanceFrequency(&perfCounterFreq)) {
wideClick.perfCounter = 1;
wideClick.microsecsScale = 1000000.0 / perfCounterFreq.QuadPart;
@@ -282,7 +305,7 @@ double
TclpWideClickInMicrosec(void)
{
if (!wideClick.initialized) {
- (void)TclpGetWideClicks(); /* initialize */
+ (void) TclpGetWideClicks(); /* initialize */
}
return wideClick.microsecsScale;
}
@@ -309,21 +332,22 @@ TclpGetMicroseconds(void)
{
long long usecSincePosixEpoch;
- /* Try to use high resolution timer */
- if ( tclGetTimeProcPtr == NativeGetTime
- && (usecSincePosixEpoch = NativeGetMicroseconds())
- ) {
+ /*
+ * Try to use high resolution timer.
+ */
+
+ if (IsTimeNative() && (usecSincePosixEpoch = NativeGetMicroseconds())) {
return usecSincePosixEpoch;
} else {
/*
- * Use the Tcl_GetTime abstraction to get the time in microseconds, as
- * nearly as we can, and return it.
- */
+ * Use the Tcl_GetTime abstraction to get the time in microseconds, as
+ * nearly as we can, and return it.
+ */
Tcl_Time now;
- tclGetTimeProcPtr(&now, tclTimeClientData); /* Tcl_GetTime inlined */
- return (((long long)now.sec) * 1000000) + now.usec;
+ GetTime(&now);
+ return (((long long) now.sec) * 1000000) + now.usec;
}
}
@@ -355,14 +379,15 @@ Tcl_GetTime(
{
long long usecSincePosixEpoch;
- /* Try to use high resolution timer */
- if ( tclGetTimeProcPtr == NativeGetTime
- && (usecSincePosixEpoch = NativeGetMicroseconds())
- ) {
+ /*
+ * Try to use high resolution timer.
+ */
+
+ if (IsTimeNative() && (usecSincePosixEpoch = NativeGetMicroseconds())) {
timePtr->sec = (long) (usecSincePosixEpoch / 1000000);
timePtr->usec = (unsigned long) (usecSincePosixEpoch % 1000000);
} else {
- tclGetTimeProcPtr(timePtr, tclTimeClientData);
+ GetTime(timePtr);
}
}
@@ -396,6 +421,96 @@ NativeScaleTime(
/*
*----------------------------------------------------------------------
*
+ * IsPerfCounterAvailable --
+ *
+ * Tests whether the performance counter is available, which is a gnarly
+ * problem on 32-bit systems. Also retrieves the nominal frequency of the
+ * performance counter.
+ *
+ * Results:
+ * 1 if the counter is available, 0 if not.
+ *
+ * Side effects:
+ * Updates fields of the timeInfo global. Make sure you hold the lock
+ * before calling this.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static inline int
+IsPerfCounterAvailable(void)
+{
+ timeInfo.perfCounterAvailable =
+ QueryPerformanceFrequency(&timeInfo.nominalFreq);
+
+ /*
+ * Some hardware abstraction layers use the CPU clock in place of the
+ * real-time clock as a performance counter reference. This results in:
+ * - inconsistent results among the processors on multi-processor
+ * systems.
+ * - unpredictable changes in performance counter frequency on
+ * "gearshift" processors such as Transmeta and SpeedStep.
+ *
+ * There seems to be no way to test whether the performance counter is
+ * reliable, but a useful heuristic is that if its frequency is 1.193182
+ * MHz or 3.579545 MHz, it's derived from a colorburst crystal and is
+ * therefore the RTC rather than the TSC.
+ *
+ * A sloppier but serviceable heuristic is that the RTC crystal is
+ * normally less than 15 MHz while the TSC crystal is virtually assured to
+ * be greater than 100 MHz. Since Win98SE appears to fiddle with the
+ * definition of the perf counter frequency (perhaps in an attempt to
+ * calibrate the clock?), we use the latter rule rather than an exact
+ * match.
+ *
+ * We also assume (perhaps questionably) that the vendors have gotten
+ * their act together on Win64, so bypass all this rubbish on that
+ * platform.
+ */
+
+#if !defined(_WIN64)
+ if (timeInfo.perfCounterAvailable &&
+ /*
+ * The following lines would do an exact match on crystal
+ * frequency:
+ *
+ * timeInfo.nominalFreq.QuadPart != (long long) 1193182 &&
+ * timeInfo.nominalFreq.QuadPart != (long long) 3579545 &&
+ */
+ timeInfo.nominalFreq.QuadPart > (long long) 15000000) {
+ /*
+ * As an exception, if every logical processor on the system is on the
+ * same chip, we use the performance counter anyway, presuming that
+ * everyone's TSC is locked to the same oscillator.
+ */
+
+ SYSTEM_INFO systemInfo;
+ int regs[4];
+
+ GetSystemInfo(&systemInfo);
+ if (TclWinCPUID(0, regs) == TCL_OK
+ && regs[1] == 0x756E6547 /* "Genu" */
+ && regs[3] == 0x49656E69 /* "ineI" */
+ && regs[2] == 0x6C65746E /* "ntel" */
+ && TclWinCPUID(1, regs) == TCL_OK
+ && ((regs[0]&0x00000F00) == 0x00000F00 /* Pentium 4 */
+ || ((regs[0] & 0x00F00000) /* Extended family */
+ && (regs[3] & 0x10000000))) /* Hyperthread */
+ && (((regs[1]&0x00FF0000) >> 16)/* CPU count */
+ == (int)sy stemInfo.dwNumberOfProcessors)) {
+ timeInfo.perfCounterAvailable = TRUE;
+ } else {
+ timeInfo.perfCounterAvailable = FALSE;
+ }
+ }
+#endif /* above code is Win32 only */
+
+ return timeInfo.perfCounterAvailable;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* NativeGetMicroseconds --
*
* Gets the current system time in microseconds since the beginning
@@ -421,10 +536,10 @@ NativeCalc100NsTicks(
ULONGLONG fileTimeLastCall,
LONGLONG perfCounterLastCall,
LONGLONG curCounterFreq,
- LONGLONG curCounter
-) {
+ LONGLONG curCounter)
+{
return fileTimeLastCall +
- ((curCounter - perfCounterLastCall) * 10000000 / curCounterFreq);
+ ((curCounter - perfCounterLastCall) * 10000000 / curCounterFreq);
}
static long long
@@ -440,83 +555,15 @@ NativeGetMicroseconds(void)
if (!timeInfo.initialized) {
TclpInitLock();
if (!timeInfo.initialized) {
-
timeInfo.posixEpoch.LowPart = 0xD53E8000;
timeInfo.posixEpoch.HighPart = 0x019DB1DE;
- timeInfo.perfCounterAvailable =
- QueryPerformanceFrequency(&timeInfo.nominalFreq);
-
- /*
- * Some hardware abstraction layers use the CPU clock in place of
- * the real-time clock as a performance counter reference. This
- * results in:
- * - inconsistent results among the processors on
- * multi-processor systems.
- * - unpredictable changes in performance counter frequency on
- * "gearshift" processors such as Transmeta and SpeedStep.
- *
- * There seems to be no way to test whether the performance
- * counter is reliable, but a useful heuristic is that if its
- * frequency is 1.193182 MHz or 3.579545 MHz, it's derived from a
- * colorburst crystal and is therefore the RTC rather than the
- * TSC.
- *
- * A sloppier but serviceable heuristic is that the RTC crystal is
- * normally less than 15 MHz while the TSC crystal is virtually
- * assured to be greater than 100 MHz. Since Win98SE appears to
- * fiddle with the definition of the perf counter frequency
- * (perhaps in an attempt to calibrate the clock?), we use the
- * latter rule rather than an exact match.
- *
- * We also assume (perhaps questionably) that the vendors have
- * gotten their act together on Win64, so bypass all this rubbish
- * on that platform.
- */
-
-#if !defined(_WIN64)
- if (timeInfo.perfCounterAvailable
- /*
- * The following lines would do an exact match on crystal
- * frequency:
- * && timeInfo.nominalFreq.QuadPart != (long long)1193182
- * && timeInfo.nominalFreq.QuadPart != (long long)3579545
- */
- && timeInfo.nominalFreq.QuadPart > (long long) 15000000){
- /*
- * As an exception, if every logical processor on the system
- * is on the same chip, we use the performance counter anyway,
- * presuming that everyone's TSC is locked to the same
- * oscillator.
- */
-
- SYSTEM_INFO systemInfo;
- int regs[4];
-
- GetSystemInfo(&systemInfo);
- if (TclWinCPUID(0, regs) == TCL_OK
- && regs[1] == 0x756E6547 /* "Genu" */
- && regs[3] == 0x49656E69 /* "ineI" */
- && regs[2] == 0x6C65746E /* "ntel" */
- && TclWinCPUID(1, regs) == TCL_OK
- && ((regs[0]&0x00000F00) == 0x00000F00 /* Pentium 4 */
- || ((regs[0] & 0x00F00000) /* Extended family */
- && (regs[3] & 0x10000000))) /* Hyperthread */
- && (((regs[1]&0x00FF0000) >> 16)/* CPU count */
- == (int)systemInfo.dwNumberOfProcessors)) {
- timeInfo.perfCounterAvailable = TRUE;
- } else {
- timeInfo.perfCounterAvailable = FALSE;
- }
- }
-#endif /* above code is Win32 only */
-
/*
* If the performance counter is available, start a thread to
* calibrate it.
*/
- if (timeInfo.perfCounterAvailable) {
+ if (IsPerfCounterAvailable()) {
DWORD id;
InitializeCriticalSection(&timeInfo.cs);
@@ -550,8 +597,8 @@ NativeGetMicroseconds(void)
ULONGLONG fileTimeLastCall;
LONGLONG perfCounterLastCall, curCounterFreq;
- /* Copy with current data of calibration cycle */
-
+ /* Copy with current data of calibration
+ * cycle. */
LARGE_INTEGER curCounter;
/* Current performance counter. */
@@ -560,6 +607,7 @@ NativeGetMicroseconds(void)
/*
* Hold time section locked as short as possible
*/
+
EnterCriticalSection(&timeInfo.cs);
fileTimeLastCall = timeInfo.fileTimeLastCall.QuadPart;
@@ -571,8 +619,12 @@ NativeGetMicroseconds(void)
/*
* If calibration cycle occurred after we get curCounter
*/
+
if (curCounter.QuadPart <= perfCounterLastCall) {
- /* Calibrated file-time is saved from posix in 100-ns ticks */
+ /*
+ * Calibrated file-time is saved from posix in 100-ns ticks
+ */
+
return fileTimeLastCall / 10;
}
@@ -587,17 +639,21 @@ NativeGetMicroseconds(void)
*/
if (curCounter.QuadPart - perfCounterLastCall <
- 11 * curCounterFreq * timeInfo.calibrationInterv / 10
- ) {
- /* Calibrated file-time is saved from posix in 100-ns ticks */
+ 11 * curCounterFreq * timeInfo.calibrationInterv / 10) {
+ /*
+ * Calibrated file-time is saved from posix in 100-ns ticks.
+ */
+
return NativeCalc100NsTicks(fileTimeLastCall,
- perfCounterLastCall, curCounterFreq, curCounter.QuadPart) / 10;
+ perfCounterLastCall, curCounterFreq,
+ curCounter.QuadPart) / 10;
}
}
/*
* High resolution timer is not available.
*/
+
return 0;
}
@@ -628,18 +684,20 @@ NativeGetTime(
/*
* Try to use high resolution timer.
*/
- if ( (usecSincePosixEpoch = NativeGetMicroseconds()) ) {
+
+ usecSincePosixEpoch = NativeGetMicroseconds();
+ if (usecSincePosixEpoch) {
timePtr->sec = (long) (usecSincePosixEpoch / 1000000);
timePtr->usec = (unsigned long) (usecSincePosixEpoch % 1000000);
} else {
/*
- * High resolution timer is not available. Just use ftime.
- */
+ * High resolution timer is not available. Just use ftime.
+ */
struct _timeb t;
_ftime(&t);
- timePtr->sec = (long)t.time;
+ timePtr->sec = (long) t.time;
timePtr->usec = t.millitm * 1000;
}
}
@@ -722,7 +780,11 @@ CalibrationThread(
QueryPerformanceFrequency(&timeInfo.curCounterFreq);
timeInfo.fileTimeLastCall.LowPart = curFileTime.dwLowDateTime;
timeInfo.fileTimeLastCall.HighPart = curFileTime.dwHighDateTime;
- /* Calibrated file-time will be saved from posix in 100-ns ticks */
+
+ /*
+ * Calibrated file-time will be saved from posix in 100-ns ticks.
+ */
+
timeInfo.fileTimeLastCall.QuadPart -= timeInfo.posixEpoch.QuadPart;
ResetCounterSamples(timeInfo.fileTimeLastCall.QuadPart,
@@ -782,10 +844,11 @@ UpdateTimeEachSecond(void)
/* Current value returned from
* QueryPerformanceCounter. */
FILETIME curSysTime; /* Current system time. */
- static LARGE_INTEGER lastFileTime; /* File time of the previous calibration */
+ static LARGE_INTEGER lastFileTime;
+ /* File time of the previous calibration */
LARGE_INTEGER curFileTime; /* File time at the time this callback was
* scheduled. */
- long long estFreq; /* Estimated perf counter frequency. */
+ long long estFreq; /* Estimated perf counter frequency. */
long long vt0; /* Tcl time right now. */
long long vt1; /* Tcl time one second from now. */
long long tdiff; /* Difference between system clock and Tcl
@@ -801,12 +864,17 @@ UpdateTimeEachSecond(void)
curFileTime.LowPart = curSysTime.dwLowDateTime;
curFileTime.HighPart = curSysTime.dwHighDateTime;
curFileTime.QuadPart -= timeInfo.posixEpoch.QuadPart;
- /* If calibration still not needed (check for possible time switch) */
- if ( curFileTime.QuadPart > lastFileTime.QuadPart
- && curFileTime.QuadPart < lastFileTime.QuadPart +
- (timeInfo.calibrationInterv * 10000000)
- ) {
- /* again in next one second */
+
+ /*
+ * If calibration still not needed (check for possible time switch)
+ */
+
+ if (curFileTime.QuadPart > lastFileTime.QuadPart && curFileTime.QuadPart <
+ lastFileTime.QuadPart + (timeInfo.calibrationInterv * 10000000)) {
+ /*
+ * Look again in next one second.
+ */
+
return;
}
QueryPerformanceCounter(&curPerfCounter);
@@ -862,8 +930,9 @@ UpdateTimeEachSecond(void)
*/
vt0 = NativeCalc100NsTicks(timeInfo.fileTimeLastCall.QuadPart,
- timeInfo.perfCounterLastCall.QuadPart, timeInfo.curCounterFreq.QuadPart,
- curPerfCounter.QuadPart);
+ timeInfo.perfCounterLastCall.QuadPart,
+ timeInfo.curCounterFreq.QuadPart, curPerfCounter.QuadPart);
+
/*
* If we've gotten more than a second away from system time, then drifting
* the clock is going to be pretty hopeless. Just let it jump. Otherwise,
@@ -872,17 +941,25 @@ UpdateTimeEachSecond(void)
tdiff = vt0 - curFileTime.QuadPart;
if (tdiff > 10000000 || tdiff < -10000000) {
- /* jump to current system time, use curent estimated frequency */
+ /*
+ * Jump to current system time, use curent estimated frequency.
+ */
+
vt0 = curFileTime.QuadPart;
} else {
- /* calculate new frequency and estimate drift to the next second */
+ /*
+ * Calculate new frequency and estimate drift to the next second.
+ */
+
vt1 = 20000000 + curFileTime.QuadPart;
driftFreq = (estFreq * 20000000 / (vt1 - vt0));
+
/*
- * Avoid too large drifts (only half of the current difference),
- * that allows also be more accurate (aspire to the smallest tdiff),
- * so then we can prolong calibration interval by tdiff < 100000
+ * Avoid too large drifts (only half of the current difference), that
+ * allows also be more accurate (aspire to the smallest tdiff), so
+ * then we can prolong calibration interval by tdiff < 100000
*/
+
driftFreq = timeInfo.curCounterFreq.QuadPart +
(driftFreq - timeInfo.curCounterFreq.QuadPart) / 2;
@@ -890,50 +967,79 @@ UpdateTimeEachSecond(void)
* Average between estimated, 2 current and 5 drifted frequencies,
* (do the soft drifting as possible)
*/
- estFreq = (estFreq + 2 * timeInfo.curCounterFreq.QuadPart + 5 * driftFreq) / 8;
+
+ estFreq = (estFreq + 2 * timeInfo.curCounterFreq.QuadPart +
+ 5 * driftFreq) / 8;
}
- /* Avoid too large discrepancy from nominal frequency */
- if (estFreq > 1003*timeInfo.nominalFreq.QuadPart/1000) {
- estFreq = 1003*timeInfo.nominalFreq.QuadPart/1000;
+ /*
+ * Avoid too large discrepancy from nominal frequency.
+ */
+
+ if (estFreq > 1003 * timeInfo.nominalFreq.QuadPart / 1000) {
+ estFreq = 1003 * timeInfo.nominalFreq.QuadPart / 1000;
vt0 = curFileTime.QuadPart;
- } else if (estFreq < 997*timeInfo.nominalFreq.QuadPart/1000) {
- estFreq = 997*timeInfo.nominalFreq.QuadPart/1000;
+ } else if (estFreq < 997 * timeInfo.nominalFreq.QuadPart / 1000) {
+ estFreq = 997 * timeInfo.nominalFreq.QuadPart / 1000;
vt0 = curFileTime.QuadPart;
} else if (vt0 != curFileTime.QuadPart) {
/*
- * Be sure the clock ticks never backwards (avoid it by negative drifting)
- * just compare native time (in 100-ns) before and hereafter using
- * new calibrated values) and do a small adjustment (short time freeze)
+ * Be sure the clock ticks never backwards (avoid it by negative
+ * drifting). Just compare native time (in 100-ns) before and
+ * hereafter using new calibrated values) and do a small adjustment
+ * (short time freeze).
*/
+
LARGE_INTEGER newPerfCounter;
long long nt0, nt1;
QueryPerformanceCounter(&newPerfCounter);
nt0 = NativeCalc100NsTicks(timeInfo.fileTimeLastCall.QuadPart,
- timeInfo.perfCounterLastCall.QuadPart, timeInfo.curCounterFreq.QuadPart,
- newPerfCounter.QuadPart);
+ timeInfo.perfCounterLastCall.QuadPart,
+ timeInfo.curCounterFreq.QuadPart, newPerfCounter.QuadPart);
nt1 = NativeCalc100NsTicks(vt0,
- curPerfCounter.QuadPart, estFreq,
- newPerfCounter.QuadPart);
- if (nt0 > nt1) { /* drifted backwards, try to compensate with new base */
- /* first adjust with a micro jump (short frozen time is acceptable) */
+ curPerfCounter.QuadPart, estFreq, newPerfCounter.QuadPart);
+ if (nt0 > nt1) {
+ /*
+ * Drifted backwards, try to compensate with new base.
+ *
+ * First adjust with a micro jump (short frozen time is
+ * acceptable).
+ */
+
vt0 += nt0 - nt1;
- /* if drift unavoidable (e. g. we had a time switch), then reset it */
+
+ /*
+ * If drift unavoidable (e. g. we had a time switch), then reset
+ * it.
+ */
+
vt1 = vt0 - curFileTime.QuadPart;
if (vt1 > 10000000 || vt1 < -10000000) {
- /* larger jump resp. shift relative new file-time */
+ /*
+ * Larger jump resp. shift relative new file-time.
+ */
+
vt0 = curFileTime.QuadPart;
}
}
}
- /* In lock commit new values to timeInfo (hold lock as short as possible) */
+ /*
+ * In lock commit new values to timeInfo (hold lock as short as possible)
+ */
+
EnterCriticalSection(&timeInfo.cs);
- /* grow calibration interval up to 10 seconds (if still precise enough) */
+ /*
+ * Grow calibration interval up to 10 seconds (if still precise enough)
+ */
+
if (tdiff < -100000 || tdiff > 100000) {
- /* too long drift - reset calibration interval to 1000 second */
+ /*
+ * Too long drift. Reset calibration interval to 1000 second.
+ */
+
timeInfo.calibrationInterv = 1;
} else if (timeInfo.calibrationInterv < 10) {
timeInfo.calibrationInterv++;
@@ -967,12 +1073,13 @@ UpdateTimeEachSecond(void)
static void
ResetCounterSamples(
- unsigned long long fileTime, /* Current file time */
+ unsigned long long fileTime,/* Current file time */
long long perfCounter, /* Current performance counter */
- long long perfFreq) /* Target performance frequency */
+ long long perfFreq) /* Target performance frequency */
{
int i;
- for (i=SAMPLES-1 ; i>=0 ; --i) {
+
+ for (i = SAMPLES - 1 ; i >= 0 ; --i) {
timeInfo.perfCounterSample[i] = perfCounter;
timeInfo.fileTimeSample[i] = fileTime;
perfCounter -= perfFreq;
@@ -1012,15 +1119,17 @@ AccumulateSample(
long long perfCounter,
unsigned long long fileTime)
{
- unsigned long long workFTSample; /* File time sample being removed from or
+ unsigned long long workFTSample;
+ /* File time sample being removed from or
* added to the circular buffer. */
long long workPCSample; /* Performance counter sample being removed
* from or added to the circular buffer. */
- unsigned long long lastFTSample; /* Last file time sample recorded */
+ unsigned long long lastFTSample;
+ /* Last file time sample recorded */
long long lastPCSample; /* Last performance counter sample recorded */
long long FTdiff; /* Difference between last FT and current */
long long PCdiff; /* Difference between last PC and current */
- long long estFreq; /* Estimated performance counter frequency */
+ long long estFreq; /* Estimated performance counter frequency */
/*
* Test for jumps and reset the samples if we have one.