Thread (32 messages) 32 messages, 5 authors, 2013-03-29

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

From: Wang Dongsheng-B40534 <hidden>
Date: 2013-03-19 07:56:09

quoted
+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 =3D (__kernel_time_t)
+			div_u64_rem(ticks, priv->timerfreq, &rem_us);
+		tmp_sec =3D (u64)time->tv_sec * (u64)priv->timerfreq;
+		time->tv_usec =3D (__kernel_suseconds_t)
+			div_u64((ticks - tmp_sec) * 1000000,
priv->timerfreq);
+
+		return;
+	}
+
+	div =3D (1 << (MPIC_TIMER_TCR_CLKDIV_64 >> 8)) * 8;
+
+	time->tv_sec =3D (__kernel_time_t)div_u64(ticks, priv->timerfreq
/ div);
+	tmp_sec =3D div_u64((u64)time->tv_sec * (u64)priv->timerfreq,
div);
+
+	time->tv_usec =3D (__kernel_suseconds_t)
+		div_u64((ticks - tmp_sec) * 1000000, priv->timerfreq /
div);
+
+	return;
=20
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?
=20
No, It cannot be integrated. The div cannot be removed.
Because if do priv->timerfreq /=3D div, that will affect the accuracy.

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

BTW
if (!(priv->flags & FSL_GLOBAL_TIMER)) {
	time->tv_sec =3D (__kernel_time_t)
		div_u64_rem(ticks, priv->timerfreq, &rem_us);
	tmp_sec =3D (u64)time->tv_sec * (u64)priv->timerfreq;
	time->tv_usec =3D (__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 /=3D 64;(Clock ratio is divide by 64)

2. Clear FSL_GLOBAL_TIMER flag.

Test Log:
[root@p5020 root]# echo 20 > /sys/devices/system/mpic/timer_wakeup
[root@p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec =3D 18, ticks =3D 118295518.., timerfreq =3D 6249999..
19
[root@p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec =3D 17, ticks =3D 110095766.., timerfreq =3D 6249999..
18
[root@p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec =3D 16, ticks =3D 105095737.., timerfreq =3D 6249999..
17
[root@p5020 root]# cat /sys/devices/system/mpic/timer_wakeup
sec =3D 15, ticks =3D 99495711.., timerfreq =3D 6249999..
16
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help