For Programmers: Free Programming Magazines  


Home > Archive > VC Language > April 2006 > Using QueryPerformanceCounter for timing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using QueryPerformanceCounter for timing
Murrgon

2006-04-25, 7:22 pm

Hello,
I am using QueryPerformanceCounter() and
QueryPerformanceFrequency() for doing timing in my application.
This worked fine before, but I have recently run it on a dual
processor Xeon (each being a dual-core processor) and the timing
is all messed up. My app basically runs as fast as it can now,
instead of waiting for the proper intervals.

Is there something you need to do to get these functions to work
properly on multi-processor machines?

Thank you
Phil Frisbie, Jr.

2006-04-25, 7:22 pm

Murrgon wrote:

> Hello,
> I am using QueryPerformanceCounter() and
> QueryPerformanceFrequency() for doing timing in my application.
> This worked fine before, but I have recently run it on a dual
> processor Xeon (each being a dual-core processor) and the timing
> is all messed up. My app basically runs as fast as it can now,
> instead of waiting for the proper intervals.
>
> Is there something you need to do to get these functions to work
> properly on multi-processor machines?


These functions are designed for multi-CPU usage, so you most likely have a bug
in your BIOS. Read this article to find out more and a work around:
http://msdn.microsoft.com/library/d..._Processors.asp

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
Tim Roberts

2006-04-27, 4:07 am

Murrgon <murrgon@hotmail.com> wrote:
>
> I am using QueryPerformanceCounter() and
>QueryPerformanceFrequency() for doing timing in my application.
>This worked fine before, but I have recently run it on a dual
>processor Xeon (each being a dual-core processor) and the timing
>is all messed up. My app basically runs as fast as it can now,
>instead of waiting for the proper intervals.
>
>Is there something you need to do to get these functions to work
>properly on multi-processor machines?


With a multiprocessor HAL, QueryPerformanceCounter uses the CPU cycle
counter. That means it counts very, very quickly; on a 3GHz machine, it
will overflow the low-order 32-bits in less than 1.5 seconds. Is it
possibly your arithmetic is overflowing?

On my Athlon64 X2, the cycle counters on the two processors are about 2
million cycles apart. That means that calls to QueryPerformanceCounter are
not necessarily monotonic. For that problem, you can use SetThreadAffinity
to force the thread into a single processor.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com