From: ralf@linux-mips.org (Ralf Baechle)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC/RFT 1/3] iop: clocksource support
Date: Wed, 2 Sep 2009 16:15:37 +0100 [thread overview]
Message-ID: <20090902151537.GA12951@linux-mips.org> (raw)
In-Reply-To: <63386a3d0909011448k6f221118k81cc7d993c65ac20@mail.gmail.com>
On Tue, Sep 01, 2009 at 11:48:57PM +0200, Linus Walleij wrote:
> > ?> Calculate this using the algorithm in arch/mips/kernel/time.c
> > ?> they have a dynamically changing clocksource...
> >
> > The algorithm always computes the largest shift/mult pair that
> > solves the equation:
> >
> > ? ? ? ?// 0 <= shift && shift <= 32
> > ? ? ? ?u64 mult = ((u64)1E9 << shift) / hz;
> > ? ? ? ?(mult >> 32) == 0
> >
> > Can I assume that this is to minimize precision loss?
>
> So I think, I asked the question of how to calculate div but noone
> answered IIRC, then I found the MIPS code and it contained this
> clue. Ralf Baechle from the MIPS camp wrote this code so lets
> ask him.
The code you're talking about is in arch/mips/kernel/time.c:
[...]
void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
{
u64 temp;
u32 shift;
/* Find a shift value */
for (shift = 32; shift > 0; shift--) {
temp = (u64) NSEC_PER_SEC << shift;
do_div(temp, clock);
if ((temp >> 32) == 0)
break;
}
cs->shift = shift;
cs->mult = (u32) temp;
}
void __cpuinit clockevent_set_clock(struct clock_event_device *cd,
unsigned int clock)
{
u64 temp;
u32 shift;
/* Find a shift value */
for (shift = 32; shift > 0; shift--) {
temp = (u64) clock << shift;
do_div(temp, NSEC_PER_SEC);
if ((temp >> 32) == 0)
break;
}
cd->shift = shift;
cd->mult = (u32) temp;
}
[...]
The algorithm tries to minimize the loss of precision. Like two years ago
I had already agreed with Thomas Gleixner to move this function into
generic code but somehow that never happened.
Ralf
prev parent reply other threads:[~2009-09-02 15:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-22 12:04 [RFC/RFT 1/3] iop: clocksource support Mikael Pettersson
2009-08-24 23:07 ` Linus Walleij
2009-09-01 20:16 ` Mikael Pettersson
2009-09-01 21:48 ` Linus Walleij
2009-09-02 15:15 ` Ralf Baechle [this message]
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=20090902151537.GA12951@linux-mips.org \
--to=ralf@linux-mips.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).