On Thu, 2010-04-08 at 17:32 +0800, Wu Zhangjin wrote: > On Wed, 2010-04-07 at 09:50 -0700, David Daney wrote: > [...] > > > +static inline unsigned long long mips_cyc2ns(u64 cyc, u64 mult, u64 shift) > > > +{ > > > +#ifdef CONFIG_32BIT > > > + /* > > > + * To balance the overhead of 128bit-arithematic and the precision > > > + * lost, we choose a smaller shift to avoid the quick overflow as the > > > + * X86& ARM does. please refer to arch/x86/kernel/tsc.c and > > > + * arch/arm/plat-orion/time.c > > > + */ > > > + return (cyc * mult)>> shift; > > > > Have you tested that on a 32-bit kernel? I think it may overflow for > > many cases. > > > > Yes, I have done some basic testing ;) > > Since a c0 count with 400MHz clock frequency will overflow after about > more than 1 hour with the scaling factor 10, Exactly, with 10, it will overflow after counting 2^51, which means it will overflow at 3127 hours(about 130 days), which is enough. > I think it is enough for > the generic debugging, such as Ftrace, If it is not enough, perhaps we > can choose a smaller scaling factor, such as 8. With 8, it will overflow after 12510 hours(about 521 days). So, I will choose 8 in the next revision. PS: ... #include <stdio.h> #define NSEC_PER_SEC 1000000000 /* 10^9 */ #define CLOCK_FREQ 400000000 /* 400 M*/ #define CYC2NS_SHIFT 8 int main(void) { unsigned long long mult, v; unsigned long long ullint_max = ~0; unsigned long long tmp = 2ULL<<53; double t_ns; int t_h, t_d; v = NSEC_PER_SEC; v <<= CYC2NS_SHIFT; v += CLOCK_FREQ/2; v = v / CLOCK_FREQ; mult = v; printf("sizeof(unsigned long long): %d\n", sizeof(unsigned long long)); printf("%lld (max of cycles)\n", ullint_max/mult); printf("%lld (2^53)\n", tmp); t_h = (double)tmp / CLOCK_FREQ / 3600; t_d = t_h / 24; printf("%d hours, %d days\n", t_h, t_d); return 0; } $ gcc -o clock clock.c $ $ ./clock sizeof(unsigned long long): 8 28823037615171174 (max of cycles) 18014398509481984 (2^53) 12509 hours, 521 days Regards, Wu Zhangjin