get_cyles()
Jerry Van Baren
gerald.vanbaren at smiths-aerospace.com
Fri Jun 3 06:08:09 EST 2005
Shirley Ma wrote:
>
> Doesn't ppc64 supports get_cycles() correctly?
> I used below function to get_cycles(), it seems not right.
>
> t1 = get_cycles();
> t2 = get_cycles();
>
> t2-t1 is huge.
>
> static inline cycles_t get_cycles(void)
> {
> cycles_t ret;
>
> __asm__ __volatile__("mftb %0" : "=r" (ret) : );
> return ret;
> }
>
> Shirley Ma
> IBM Linux Technology Center
> 15300 SW Koll Parkway
> Beaverton, OR 97006-6063
> Phone(Fax): (503) 578-7638
Is (t2-t1) (a) _always_ huge or (b) only sometimes huge?
If (a), are you sure t1 and t2 are executing in the written order? The
compiler may be re-ordering the instructions on you. Use objdump -S to
disassemble the object file (or executable).
If (b), you are getting burned by carry out of the time base lower
register. Every 2^32 counts, the timebase (lower) register will wrap
around from 0xFFFFFFFF to 0x00000000. If the wrap occurs between
reading t1 and t2, you will get a very large jump.
Another possiblility for (b) is that you are getting an interrupt
between reading t1 and t2, so your delta will include the interrupt
handling time and potentially more... if your task is pre-empted due to
the interrupt, the time delta will be (relatively speaking) very large.
This is actually the most likely scenario in my mind.
gvb
More information about the Linuxppc64-dev
mailing list