From: Wu Zhangjin <wuzhangjin@gmail.com>
To: David Daney <ddaney@caviumnetworks.com>
Cc: "Ralf Baechle" <ralf@linux-mips.org>,
linux-mips@linux-mips.org, "Ralf Rösch" <roesch.ralf@web.de>
Subject: Re: [PATCH v2 1/3] MIPS: add a common mips_cyc2ns()
Date: Sat, 10 Apr 2010 13:46:29 +0800 [thread overview]
Message-ID: <1270878389.17333.39.camel@falcon> (raw)
In-Reply-To: <1270719171.5709.37.camel@falcon>
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
next prev parent reply other threads:[~2010-04-10 5:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-07 16:05 [PATCH v2 0/3] add high resolution sched_clock() for MIPS Wu Zhangin
[not found] ` <cover.1270655886.git.wuzhangjin@gmail.com>
2010-04-07 16:05 ` [PATCH v2 1/3] MIPS: add a common mips_cyc2ns() Wu Zhangin
2010-04-07 16:48 ` David Daney
2010-04-08 9:36 ` Wu Zhangjin
2010-04-07 16:50 ` David Daney
2010-04-08 9:32 ` Wu Zhangjin
2010-04-10 5:46 ` Wu Zhangjin [this message]
2010-04-07 16:05 ` [PATCH v2 2/3] MIPS: cavium-octeon: rewrite the sched_clock() based on mips_cyc2ns() Wu Zhangin
2010-07-29 1:24 ` wu zhangjin
2010-07-29 1:24 ` wu zhangjin
2010-04-07 16:05 ` [PATCH v2 3/3] MIPS: r4k: Add a high resolution sched_clock() Wu Zhangin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1270878389.17333.39.camel@falcon \
--to=wuzhangjin@gmail.com \
--cc=ddaney@caviumnetworks.com \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=roesch.ralf@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox