Re: [PATCH] clocksource: shift helper
From: Atsushi Nemoto
Date: Wed May 07 2008 - 12:23:10 EST
On Tue, 06 May 2008 09:39:14 -0700, Daniel Walker <dwalker@xxxxxxxxxx> wrote:
> > > This is a little helper I pulled from the mips tree.
> > ...
> > > Signed-off-by: Daniel Walker <dwalker@xxxxxxxxxx>
> >
> > And who is the original author of this little helper in the MIPS tree?
>
> commit 16b7b2ac0148e839da86af8747b6fa4aad43a9b7
> Author: Atsushi Nemoto <anemo@xxxxxxxxxxxxx>
I think Ralf's version is better starting point.
commit 93c846f9047f392fc2335668a5234edfbddb7cdc
Author: Ralf Baechle <ralf@xxxxxxxxxxxxxx>
Date: Fri Oct 19 08:13:08 2007 +0100
[MIPS] time: Helpers to compute clocksource/event shift and mult values.
These helpers are live in arch/mips/kernel/time.c now.
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;
}
BTW, comparing this with clocksource_hz2mult(), inserting
temp += clock / 2;
to just before do_div() line might be better.
---
Atsushi Nemoto
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/