http://sources.redhat.com/ml/systemtap/2006-q3/msg00250.html

using get_cycles() to get the real elapsed time

  • From: Li Guanglei <guanglei at cn dot ibm dot com>
  • To: "systemtap at sourceware dot org" <systemtap at sourceware dot org>
  • Date: Sat, 05 Aug 2006 23:35:20 +0800
  • Subject: using get_cycles() to get the real elapsed time
  • Organization: IBM CSTL

Hi,
I took a look at the runtime/time.c and found it uses get_cycles()/freq to get the elapsed time:


   ...
   delta = get_cycles() - last;
   do_div(delta, freq);
   ...
   return (USEC_PER_SEC * (int64_t)base.tv_sec) + base.tv_usec + delta;

But AFAIK, some architectures will increase Time Base register(i.e TSC) with a fixed ratio of cpu freq. On x86, this = cpu freq. and on Power5, Time Base driven at 1/8 the processor clock frequency. I even remembered that on some old PowerPC(4xx, 7xx) the Time Base is driven by the bus clock(33Mhz)

So we need deal with different Arches to get the elapsed time by using get_cycles()

BTW, get_cycles() will return 32-bit value for some architectures e.g ppc32, although the major architectures such as ppc64, x86, x86_64 will all return a 64-bit value. Should we care about those architectures whose get_cycles() returns 32-bit value?

Thanks.



Reply via email to