618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
-
+
-
+
|
/*
* 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;
}
/*
* If it appears to be more than 1.1 seconds since the last trip
* through the calibration loop, the performance counter may have
* jumped forward. (See MSDN Knowledge Base article Q274323 for a
* description of the hardware problem that makes this test
* necessary.) If the counter jumps, we don't want to use it directly.
* Instead, we must return system time. Eventually, the calibration
* loop should recover.
*/
if (curCounter.QuadPart - perfCounterLastCall <
11 * curCounterFreq * timeInfo.calibrationInterv / 10) {
/*
* Calibrated file-time is saved from posix in 100-ns ticks.
* Calibrated file-time is saved from Posix in 100-ns ticks.
*/
return NativeCalc100NsTicks(fileTimeLastCall,
perfCounterLastCall, curCounterFreq,
curCounter.QuadPart) / 10;
}
}
|
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
-
+
|
GetSystemTimeAsFileTime(&curFileTime);
QueryPerformanceCounter(&timeInfo.perfCounterLastCall);
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,
timeInfo.perfCounterLastCall.QuadPart,
timeInfo.curCounterFreq.QuadPart);
|
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
-
+
|
long long vt1; /* Tcl time one second from now. */
long long tdiff; /* Difference between system clock and Tcl
* time. */
long long driftFreq; /* Frequency needed to drift virtual time into
* step over 1 second. */
/*
* Sample performance counter and system time (from posix epoch).
* Sample performance counter and system time (from Posix epoch).
*/
GetSystemTimeAsFileTime(&curSysTime);
curFileTime.LowPart = curSysTime.dwLowDateTime;
curFileTime.HighPart = curSysTime.dwHighDateTime;
curFileTime.QuadPart -= timeInfo.posixEpoch.QuadPart;
|
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
|
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
|
-
+
|
return;
}
QueryPerformanceCounter(&curPerfCounter);
lastFileTime.QuadPart = curFileTime.QuadPart;
/*
* We devide by timeInfo.curCounterFreq.QuadPart in several places. That
* We divide by timeInfo.curCounterFreq.QuadPart in several places. That
* value should always be positive on a correctly functioning system. But
* it is good to be defensive about such matters. So if something goes
* wrong and the value does goes to zero, we clear the
* timeInfo.perfCounterAvailable in order to cause the calibration thread
* to shut itself down, then return without additional processing.
*/
|