linux/kernel/time
john stultz b5776c4a6d Fix rounding in clocks_calc_mult_shift()
Russell King reports:
| On the ARM dev boards, we have a 32-bit counter running at 24MHz.  Calling
| clocks_calc_mult_shift(&mult, &shift, 24MHz, NSEC_PER_SEC, 60) gives
| us a multiplier of 2796202666 and a shift of 26.
|
| Over a large counter delta, this produces an error - lets take a count
| from 362976315 to 4280663372:
|
| (4280663372-362976315) * 2796202666 / 2^26 - (4280663372-362976315) * (1000/24)
|  => -38.91872422891230269990
|
| Can we do better?
|
| (4280663372-362976315) * 2796202667 / 2^26 - (4280663372-362976315) * (1000/24)
| 19.45936211449532822051
|
| which is about twice as good as the 2796202666 multiplier.
|
| Looking at the equivalent divisions obtained, 2796202666 / 2^26 gives
| 41.66666665673255920410ns per tick, whereas 2796202667 / 2^26 gives
| 41.66666667163372039794ns.  The actual value wanted is 1000/24 =
| 41.66666666666666666666ns.

Fix this by ensuring we round to nearest when calculating the
multiplier.

Signed-off-by: John Stultz <john.stultz@linaro.org>
Tested-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Tested-by: Will Deacon <will.deacon@arm.com>
Tested-by: Mikael Pettersson <mikpe@it.uu.se>
Tested-by: Eric Miao <eric.y.miao@gmail.com>
Tested-by: Olof Johansson <olof@lixom.net>
Tested-by: Jamie Iles <jamie@jamieiles.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2010-12-22 22:44:43 +00:00
..
Kconfig time: Kill off CONFIG_GENERIC_TIME 2010-07-27 12:40:54 +02:00
Makefile time: add function to convert between calendar time and broken-down time for universal use 2009-09-24 07:20:56 -07:00
clockevents.c clockevent: Don't remove broadcast device when cpu is dead 2010-01-18 14:44:50 +01:00
clocksource.c Fix rounding in clocks_calc_mult_shift() 2010-12-22 22:44:43 +00:00
jiffies.c clocksource: Cleanup clocksource selection 2009-08-15 10:55:46 +02:00
ntp.c ntp: Clamp PLL update interval 2010-09-09 20:48:37 +02:00
tick-broadcast.c fix comment/printk typos concerning "already" 2010-07-11 21:45:40 +02:00
tick-common.c clockevents: Convert to raw_spinlock 2009-12-14 23:55:34 +01:00
tick-internal.h clockevents: Make tick_device_lock static 2009-12-14 23:55:34 +01:00
tick-oneshot.c clockevents: Sanitize min_delta_ns adjustment and prevent overflows 2010-03-12 19:10:29 +01:00
tick-sched.c Merge branch 'timers-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip 2010-08-06 13:12:36 -07:00
timecompare.c include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h 2010-03-30 22:02:32 +09:00
timeconv.c time: add function to convert between calendar time and broken-down time for universal use 2009-09-24 07:20:56 -07:00
timekeeping.c time: Workaround gcc loop optimization that causes 64bit div errors 2010-08-13 12:03:24 -07:00
timer_list.c sched: Intoduce get_cpu_iowait_time_us() 2010-05-09 19:35:27 +02:00
timer_stats.c hrtimers: Convert to raw_spinlocks 2009-12-14 23:55:34 +01:00