Original Post
So we've been wrestling with a problem that seems to be with QueryPerformanceCounter. Consider the following test code.
#include <iostream>
#include <Windows.h>
int main(const char **_args, int _argn)
{
LARGE_INTEGER frequency, lastTime, currentTime;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&lastTime);
std::cout << "Freq: " << frequency.QuadPart << " : counter " << lastTime.QuadPart << std::endl;
while(1)
{
QueryPerformanceCounter(¤tTime);
LARGE_INTEGER difference;
difference.QuadPart = currentTime.QuadPart - lastTime.QuadPart;
double dDeltaTime = (double)difference.QuadPart / (double)frequency.QuadPart;
if((currentTime.QuadPart < lastTime.QuadPart) || (difference.QuadPart < 0))
{
std::cout << "Bad Timer Values: Last Time " << lastTime.QuadPart <<
" current Time " << currentTime.QuadPart << std::endl <<
" difference " << currentTime.QuadPart - lastTime.QuadPart << std::endl;
}
lastTime = currentTime;
}
return 0;
}
Running this on various single cpu machines around the office outputs no errors, however we have a collection of duel core AMD machines that continuously spam out bad values(negative difference). Anyone know anything about this type of thing? We've noticed a post online where apparently this problem can be 'fixed' by setting the processor affinity or something to a specific processor, but I'm concerned that doing this could adversly effect the performance of the application. I just wanted to get some more input. Could anyone out there with a duel core cpu or multi-processor machine run the above code and tell me if you get any output with a negative counter difference. I'm wondering if this is a bug with duel core/multi-proc machines in general, or if its a possible chipset bug. Thanks J