[RFC/RFT 1/3] iop: clocksource support

Mikael Pettersson mikpe at it.uu.se
Tue Sep 1 16:16:13 EDT 2009


Linus Walleij writes:
 > > +/*
 > > + * IOP clocksource (free-running timer 1).
 > > + */
 > > +static cycle_t iop_clocksource_read(struct clocksource *unused)
 > > +{
 > > +       return 0xffffffffu - read_tcr1();
 > 
 > So tcr1 counts downwards and wraps around?

Yes. The timers are decrementers that when reaching zero either
halt or reload from another register and continue decrementing,
depending on settings in a mode register.

 > > +static struct clocksource iop_clocksource = {
 > > +       .name           = "iop_timer1",
 > > +       .rating         = 300,
 > > +       .read           = iop_clocksource_read,
 > > +       .mask           = CLOCKSOURCE_MASK(32),
 > > +       .shift          = 20,   /* ??? crude guesstimate */
 > 
 > Calculate this using the algorithm in arch/mips/kernel/time.c
 > they have a dynamically changing clocksource...

Thanks, I've implemented that now. On my n2100 with its 198MHz
timer it computes shift = 29 and mult = 0xa19dbcc4.

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?

/Mikael



More information about the linux-arm-kernel mailing list