Re: what exactly does CPU_TIME measure?



In article <2tydnZXVes5fdq3bnZ2dnUVZ_oytnZ2d@xxxxxxxxxxx>, glen herrmannsfeldt wrote:
mecej4 wrote:

(snip)
Some recent processors incorporate frequency changing as part of their
power saving strategy, which makes it harder to use a hardware register
to keep track of time.

If, in fact, RDTSC gives the quantity \int_0^T \f dt, one has to
differentiate the RDTSC readings and then evaluate \int_0^T dt!

Yes, but if you consider the goal of minimizing the number of
clock cycles then rdtsc makes more sense. Or, to put it
another way, not all CPU seconds are equal (on a variable
speed CPU) but clock cycles are.

On the other hand, rdtsc measure wall time, not CPU time.

No, it measures the cpu tick count (which is why the CPU changing
frequency is a problem for timing). Secondly each CPU has its own TSC,
which is not synchronized with the TSC:s of other CPU:s, so if your
app happens to switch to another CPU on a multiprocessor -> oops.

For these reasons, RDTSC is pretty useless these days. Which is a bit
of a shame, since as such it's the most accurate and lowest overhead
timer available.

See e.g.

http://www.ussg.iu.edu/hypermail/linux/kernel/0505.1/1463.html

http://en.wikipedia.org/wiki/RDTSC

If you time small enough sections of code you will rarely be
interrupted. Small sections are difficult to time with a coarse
resolution clock.

Fancier profilers these days seem to use hw counters and sampling
(e.g. oprofile), so you can get accurate timing even for small
sections, provided the loop count is high enough.


--
Janne Blomqvist
.



Relevant Pages

  • Re: Is timeGetTime monotonic and uniform?
    ... that returns the CPU ticks since boot time in EDX:EAX. ... Some time ago I read that when you get the RDTSC overhead (ie the time ... of checking whether the above recommendation is really necessary, ... forcing all other instructions out of the internal CPU ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: Whats the purpose of get_cycles_sync()
    ... Vojtech had one test that tested time monotonicity over CPUs ... I suspect the reason was because the CPU reordered the RDTSCs so that ... fit more than one iteration into the CPU's reordering window. ... What could have been happening then was that the RDTSC instruction might ...
    (Linux-Kernel)
  • Re: assembly in future C standard
    ... should the compiler author implement method 1 ... Some compilers will give an option to which set of cpu instruction ... complience with standard XX run on a cpu predated XX. ... Again ill use an example of RDTSC: ...
    (comp.lang.c)
  • Re: what exactly does CPU_TIME measure?
    ... differentiate the RDTSC readings and then evaluate \int_0^T dt! ... clock cycles then rdtsc makes more sense. ... speed CPU) but clock cycles are. ...
    (comp.lang.fortran)
  • Re: rdtsc and the sleep fcn (Was problem with rdtsc instruction on Pentium M)
    ... > function goes into the idle loop, causing the tsc to stop counting. ... the CPU is slowed down which stuffs ... The solution is not to use RDTSC. ...
    (comp.lang.asm.x86)