Re: [discuss] Re: [Perfctr-devel] Re: Enabling RDPMC in user space by default

Andi Kleen
2005-11-29T23:46:21Z

> I happen to have an old program which uses RDTSC frequently for timing
> purposes. That seemed like a good idea at the time, but I guess it
> should be updated. The question is, what replacement is there? I don't
> want to have to use a syscall every 50 instructions or so. Feel free to
> laugh, but suggesting a workable replacement might be more helpful.

Well, you're asking me to write all the points from the documentation
in advance. Not tonight (or look up the full thread in the l-k archives,
I think I covered most)

But right now gettimeofday or clock_gettime(CLOCK_MONOTONIC) is
probably your best option. It tries to be reasonable fast depending
on hardware capabilities (and when you measure on P4
even basic RDTSC is quite slow). At least on x86-64 gettimeofday
isn't a real system call, but actually often stays in ring 3.

If you want to measure instructions in cycles in the future you can probably
use RDPMC 0, but that's not implemented yet. It won't be a replacement
for a timer for other purposes.

-Andi