Jump to content
  • Advertisement
Sign in to follow this  
simon10k

rdtsc help

This topic is 4421 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was just wondering if this is the correct way to use the rdtsc
unsigned __int64 get_cpu_tick() 
{	
	DWORD dwLow, dwHigh;

	__asm 
	{
		rdtsc
		mov dwLow, eax
		mov dwHigh, edx
	}

	return ((unsigned __int64) dwHigh << 32 | dwLow); 
}

or am I missing something? Thanks. ~edit~ I found another function, unsigned __int64 __rdtsc(void); Which does what I need, another question, does QueryPerformanceFrequency() return the frequency of the processsor?

Share this post


Link to post
Share on other sites
Advertisement

>Which does what I need, another question, does QueryPerformanceFrequency()
>return the frequency of the processsor?
It returns the number of counts / second which the high-frequency timer has.

Beware that using rdtsc on multi-core cpu's _will_ give you problems
(actually qpc/qpf will also, if you don't install a special win-xp patch).

Share this post


Link to post
Share on other sites
Quote:
Original post by Kitt3n
Beware that using rdtsc on multi-core cpu's _will_ give you problems
(actually qpc/qpf will also, if you don't install a special win-xp patch).


Maybe you can try RDTSCP, which will also return another value in ecx to identify the process (at least if your processor supports it, mine does not).

If you want to time very short functions (i.e. to get the cycle count), you may also want to put a serializing instruction in front of RDTSC, i.e. CPUID is one.

To time your code using RDTSC, you can set the thread affinity to keep it on a single cpu.

Share this post


Link to post
Share on other sites
Be forewarned: From experimentation RDTSC doesn't appear to work right on AMD64s or dual-core machines. I haven't bothered to research a solution yet.

Share this post


Link to post
Share on other sites
Quote:
Original post by simon10k
Another thing, can I convert the rdtsc into ms?


If you measured a reference value for your ticks, you can divide the number of ticks by the tick frequency.

Share this post


Link to post
Share on other sites
>rdtsc also suffers from cpu's which throttle down (Pentium M?) to save energy
Same thing goes for qpc/qpf

>Maybe you can try RDTSCP, which will also return another value in ecx to
>identify the process (at least if your processor supports it, mine does not).
www.intel.com mentions a way to determine on which cpu code was just executed (look for APIC).

>To time your code using RDTSC, you can set the thread affinity to keep it
>on a single cpu.
Easiest way, yes - but using the APIC, you can actually make rdtsc multicore
safe. It involves running a thread on all cpu's in realtime priority and
letting them simultaneously get an initial/reference-timestamp.

From then on each time you get a timestamp, check which cpu it ran on
and subtract the initial timestamp.

This still will give problems with throttle-down though...


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!