QueryPerformanceCounter -- Timming code


  • Hello --

    I am calling the win/sdk function QueryPerformanceCounter to do timing -- how is
    it in some cases that over 2 calls over time that the call in the future has a
    lesser value than the one in the past so

    start = QueryPerformanceCounter

    :::  wait some time

    finish = QueryPerformanceCounter

    then the value of

    finish - start

    is less than zero -- is this possible?

    Wednesday, January 09, 2013 7:31 AM

All replies

  • What kind is the machine? How much is the difference?

    Assuming it is not a "normal" time rollover, you have a buggy platform, where QPC is not monotonic. Avoid these platforms or find a fix (BIOS update, etc) if you can.

    -- pa

    Wednesday, January 09, 2013 9:48 PM
  • Hello --  Thanks for the reply. It's win/xp -- there are no more BIOS updates from the vendor MSI -- Its an old  MOBO  -- from 2006  -- I guess I could set affinity and just run on 1 cpu  -- are there any other work-a-rounds? 

    Wednesday, January 09, 2013 10:19 PM
  • You are probably hitting a bug on older AMD machines where the RDTSC value is not sync'd between cores.

    See Gaming Timing and Multicore Processors

    Wednesday, January 09, 2013 11:12 PM
  • yes -- thank for the info ... If its a hardware /  bios issue there is noting I can do about it at this time

    I guess its its critical, I could force the process to run on 1 cpu 

    thanks again 

    Friday, January 11, 2013 8:45 PM
  • If I remember correctly, this behavior can be seen even on one-CPU machines (I've seen it on a Geode UP system).

    -- pa

    Saturday, January 12, 2013 1:44 PM
  • If the RDTSC count isn't monotonically increasing on a single-CPU machine, then that's a pretty nasty hardware bug. Of course, you still have to cope with 32-bit rollover on x86 CPUs.
    Monday, January 14, 2013 8:37 PM