[PATCH 2/3] powerpc/mpic: add global timer support

Wang Dongsheng-B40534 B40534 at freescale.com
Tue Mar 19 18:55:58 EST 2013


> > +static void convert_ticks_to_time(struct timer_group_priv *priv,
> > +		const u64 ticks, struct timeval *time) {
> > +	u64 tmp_sec;
> > +	u32 rem_us;
> > +	u32 div;
> > +
> > +	if (!(priv->flags & FSL_GLOBAL_TIMER)) {
> > +		time->tv_sec = (__kernel_time_t)
> > +			div_u64_rem(ticks, priv->timerfreq, &rem_us);
> > +		tmp_sec = (u64)time->tv_sec * (u64)priv->timerfreq;
> > +		time->tv_usec = (__kernel_suseconds_t)
> > +			div_u64((ticks - tmp_sec) * 1000000,
> > priv->timerfreq);
> > +
> > +		return;
> > +	}
> > +
> > +	div = (1 << (MPIC_TIMER_TCR_CLKDIV_64 >> 8)) * 8;
> > +
> > +	time->tv_sec = (__kernel_time_t)div_u64(ticks, priv->timerfreq
> > / div);
> > +	tmp_sec = div_u64((u64)time->tv_sec * (u64)priv->timerfreq,
> > div);
> > +
> > +	time->tv_usec = (__kernel_suseconds_t)
> > +		div_u64((ticks - tmp_sec) * 1000000, priv->timerfreq /
> > div);
> > +
> > +	return;
> 
> Why don't you just adjust the clock frequency up front for CLKDIV_64,
> rather than introduce alternate (and untested!) code paths throughout the
> driver?
> 
No, It cannot be integrated. The div cannot be removed.
Because if do priv->timerfreq /= div, that will affect the accuracy.

Like:
3 * 5 / 2 = 7;
3 / 2 * 5 = 5;

BTW
if (!(priv->flags & FSL_GLOBAL_TIMER)) {
	time->tv_sec = (__kernel_time_t)
		div_u64_rem(ticks, priv->timerfreq, &rem_us);
	tmp_sec = (u64)time->tv_sec * (u64)priv->timerfreq;
	time->tv_usec = (__kernel_suseconds_t)
		div_u64((ticks - tmp_sec) * 1000000, priv->timerfreq);

	return;
}
This branch I has been tested.

Test methods:
1. Get timerfreq and set timerfreq.
   timerfreq /= 64;(Clock ratio is divide by 64)

2. Clear FSL_GLOBAL_TIMER flag.

Test Log:
[root at p5020 root]# echo 20 > /sys/devices/system/mpic/timer_wakeup
[root at p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec = 18, ticks = 118295518.., timerfreq = 6249999..
19
[root at p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec = 17, ticks = 110095766.., timerfreq = 6249999..
18
[root at p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec = 16, ticks = 105095737.., timerfreq = 6249999..
17
[root at p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec = 15, ticks = 99495711.., timerfreq = 6249999..
16



More information about the Linuxppc-dev mailing list