High performance counter

Started by
12 comments, last by johndunne 21 years, 6 months ago
Hope this is related to theme of this forum! I''ve recently started using the high-resolution performance counter the QueryPerformanceFrequency() funtion uses in MSVC++, but what is the speed of this counter dependent on? Is it the CPU or the motherboard, also, i''ve got an 800MHz Duron and my counter iterates 1,193,180 times per second. How does this compare with other processors?
I'm all dunne now
Advertisement
All comments appreciated!!
I'm all dunne now
well, help files say "The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock. "

and i get the same value as you(1193180) on my PIII 500, so its obviously nothing to do with cpu manufacturer/speed


Runicsoft -- home of my open source Function Parser and more
It depends on the type of system as well as the type of processor. The counter reports a frequency of 450990000 on my dual Pentium III 450 MHz system.

[edited by - spock on October 19, 2002 10:53:20 PM]
It''ll probably depend on the motherboard chip-set more than anything else (processor class as well).

For APi586 class processors, you can the assembly instruction rdtsc, which returns the current CPU ticks in eda:eax. This is highly dependany on the clock-rate. There are several ways to time the clock-rate, and you can use that as a divisor to calculate elapsed time very accurately & precisely.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Cheers for the replys guys. I see, but this rdtsc instruction returns a value with a high and low order part, anyone recommend a text on how to convert it to a ''standard'' long integer?
I'm all dunne now
quote:Original post by johndunne
how to convert it to a 'standard' long integer?


Well, you shouldn't do that because the full precision of the counter will overflow a 32-bit unsigned long very quickly. Use the full 64 bits instead. Many compilers have extended types for 64-bit integer arithmetic - in MSVC you can use __int64, for example.


[edited by - spock on October 20, 2002 7:16:27 AM]
quote:Original post by johndunne
...this rdtsc instruction returns a value with a high and low order part, anyone recommend a text on how to convert it to a ''standard'' long integer?


I would recommend reading this post . You simply multiply the value stored in edx by 2^32 and add it to the value stored in eax (although this is not possible on a 32-bit cpu). A 32-bit word like eax consists of 32 bits (!). Since the value that is returned is a 64-bit value the "most significant" bits are stored in edx while the "least significant" bits are stored in eax.

Let''s take an example:

If we have the number 13243546 and we want to write it on a small piece of paper but the pieces are very small it might mot be possible to write all eight digits on the same piece. Instead we could write 1324 on on piece and call these digits the most significant digits and write 3546 on another piece and call these digits the least significant digits. This is more or less what the cpu does when a MUL, DIV or rdtsc instruction is executed. The only difference is that the computer uses binary digits (=bits) and store the digits in so-called latches instead of writing it down on ridiculously small pieces of paper.
quote:
how to convert it to a ''standard'' long integer?


You can only do that if the value in edx:eax can fit into a long integer in which case you simply use the value in eax (and clear the sign bit if the long integer is signed) and discard the value in edx.
Back to the original question:
I''ve seen QPC use the PIT and the PCI clock (frequencies of 1.193 MHz and 3.580 MHz).

using rdtsc gives you awesome resolution, but it jitters a bit, and you get all sorts of problems on multiprocessor / mobile systems.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

This topic is closed to new replies.

Advertisement