views:

1235

answers:

3

I would like to use the High Performance Event Timer (HPET) for an profiling tool to take very high precision measurements, quickly. timeGetTime does not provide sufficient resolution at 1ms, and QueryPerformanceCounter is much slower per read than I'd like. I came across the HPET while researching the problem, but I can't see any samples of how to actually get at it.

So can I use it directly (assembly is fine), or do I have to rely on the multimedia/high performance timing tools already built into the Win32 API?

A: 

I found this info while digging around, and it seems it can be the most cost effective way. I will try it out when I get the guts to dig into assembly. :)

UPDATE

I tested this with my profiler. although a bit faster, it seems I still have tonnes of other overhead :( (I did not bother with timing as I it did not seem to be enough benefit)

leppie
No! Don't use RDTSC, it will do strange things on multicore machines. Each core having it's own counter can give effects like functions taking negative time ect. The Timestamp counters aren't always in sync!Been there, done that.
Nils Pipenbrinck
And say you keep track of the thread? How can that affect the difference?
leppie
Keeping track of the thread will just tell you that there *might* be a problem, not if there *is* a problem or how to fix it. To use RDTSC safely you *must* pin the thread to a specific core. There is no way to safely compute the RDTSC difference across cores from userspace.
Mihai Limbășan
A: 

Here is how to do it in Linux. http://blog.fpmurphy.com/2009/07/linux-hpet-support.html

A: 

I am also interested in using the HPET, but as a timer. The way I understand it, QueryPerformanceCounter and QueryPerformanceFrequency are actually accessing the counter and clock for the HPET, and this works under Windows XP (see, for example, http://www.geisswerks.com/ryan/FAQS/timing.html).

So as far as timing code, I think by using QueryPerformanceCounter you are in fact getting access to the counter that form the base of HPET, and this is all present in the chipset (rather than the processor).

pelesl