Hi all.
A customer of mine reported a strange issue, and I tracked the issue down to
wrong values returned by KeQueryPerformanceCounter (or the user counterpart
QueryPerformanceCounter/Frequency).
The MSDN docs clearly state that
KeQueryPerformanceCounter always returns a 64-bit integer that represents
the current value of a monotonically nondecreasing counter. The resolution
of the timer used to accumulate the current count can be obtained by
specifying a pointer value for PerformanceFrequency. The value that is
returned is the number of ticks per second. The count starts accumulating
when the computer is started up.
What I get on some specific customer machine is something that is not “ticks
per second”. Either the frequency is bogus, or the counter itself.
I wrote a small user app to test it:
int _tmain(int argc, _TCHAR* argv)
{
int i;
LARGE_INTEGER freq, counter;
SYSTEMTIME systemTime;
for (i = 0; i < 10; i++)
{
GetSystemTime(&systemTime);
if (QueryPerformanceCounter(&counter) == FALSE ||
QueryPerformanceFrequency(&freq) == FALSE)
{
printf(“Error getting performance counters\n”);
}
printf(“Counter = %I64d Freq = %I64d”, counter.QuadPart, freq.QuadPart);
printf(" system: %02d:%02d:%02d\n",
systemTime.wHour,
systemTime.wMinute,
systemTime.wSecond);
Sleep(1000);
}
return 0;
}
And this is the output on the failing machine:
Counter = 56497408135970 Freq = 3158750000 system: 01:18:57
Counter = 56497818110218 Freq = 3158750000 system: 01:18:58
Counter = 56498206404250 Freq = 3158750000 system: 01:18:59
Counter = 56498715528269 Freq = 3158750000 system: 01:19:00
Counter = 56499113984213 Freq = 3158750000 system: 01:19:01
Counter = 56499489120527 Freq = 3158750000 system: 01:19:02
Counter = 56499867623469 Freq = 3158750000 system: 01:19:03
Counter = 56500252073478 Freq = 3158750000 system: 01:19:04
Counter = 56500713252945 Freq = 3158750000 system: 01:19:05
Counter = 56501096560332 Freq = 3158750000 system: 01:19:06
If you make some computations, the counter seems to say that every iteration
is about 0.12 seconds apart from the previous one, while it should be more
or less 1 second.
The failing machine is running XP SP3 (hal.dll 5.1.2600.5687, ntoskrnl.exe
5.1.2600.5938) on an Intel Core 2 Duo E8500.
Has anyone ever seen this?
Have a nice day
GV