Original Post
I recently upgraded my machine up to an Athlon64 X2 processor, and discovered to my much annoyance, that QueryPerformanceCounter no longer works properly at all. Apparently, I'm not the only one who's discovered this: http://devforums.amd.com/index.php?showtopic=416 Perhaps the easiest way to show what's happening, is to post this snippet from my log. Each frame I wrote out what the frame time was. Frequency: 2002580000 Timer: 0.00871690768908109 NewTickCount: 36147969222589 LastTickCount: 36147951766284 Timer: 0.00872693725094628 NewTickCount: 36147986698979 LastTickCount: 36147969222589 Timer: 0.0375251740255071 NewTickCount: 36148061846142 LastTickCount: 36147986698979 Timer: -0.0197190838817925 NewTickCount: 36148022357099 LastTickCount: 36148061846142 Timer: 0.00889879405566819 NewTickCount: 36148040177646 LastTickCount: 36148022357099 Now, if you'll observe, immediately before the time becomes negative for that frame (yikes!), the frame time jumps up about 4x to what it normally is. This of course, totally screws up the smoothness of my animations and physics, making them leap forwards and then backwards. The typical cycle for this happening is about every 15 frames or so. Also interestingly enough, if you add together that larger time and the negative time and divide by 2, you get 0.0089030450718573, which is within 0.00002 seconds of the other times or so. Additionally, in another test, I called QueryPerformanceFrequency every frame as well, and it always returned the same number. So that's at least constant. I've verified that my timer is only being updated once per frame by also inserting in lines into my log whenever I begin rendering a new frame. I've also tried setting the affinity of my game's thread to a single core, and that didn't help any. This same effect happens, if I strip out my timer and put it into a tiny program that just displays the times returned by looping a bunch of times. So it isn't anything in the rest of my game causing this. My code works flawlessly on my old Athlon 2200+, and works on a hyperthreaded P4. Reading through the Game Timing and Multicore Processors article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Game_Timing_and_Multicore_Processors.asp didn't provide any insights either into what the problem is. It states, "This article suggests a more accurate, reliable solution using the Windows QueryPerformanceCounter and QueryPerformanceFrequency APIs.", which is exactly what I am using. I haven't tried the shim to force my game to run on a single-processor yet, as one of the main reasons that I bought this processor was to multi-thread my game engine. The other timers like Environment.TickCount and GetTickCount simply don't provide me with a fine enough timing resolution, being limited to updating every 15ms or so. And that RDTSC instruction sounds far too unreliable and outdated (plus I'm not even sure if there's any sort of nice direct way to use assembly in .net, other than compiling up a c++ dll and using it, though that seems massively overkill for a single assembly instruction). So, have any of you encountered this problem? Or can any of you recommend a different high performance counter that'll work on my processor? At the very least, this is a heads up for any of you also considering getting yourself one of those processors. I'll have to content myself in the mean time by doing some sort of averaging trick with the times when I see one jumping upwards suddenly (though sadly that can be normal game behavior)