aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernd Faust <berndfaust@gmail.com>2012-12-05 09:16:49 -0500
committerJohn Stultz <john.stultz@linaro.org>2013-01-15 21:16:07 -0500
commit2353b47bffe4e6ab39042f470c55d41bb3ff3846 (patch)
tree75d4c5bd873f97c029530349f875153f0d68119a
parent023f333a99cee9b5cd3268ff87298eb01a31f78e (diff)
Round the calculated scale factor in set_cyc2ns_scale()
During some experiments with an external clock (in a FPGA), we saw that the TSC clock drifted approx. 2.5ms per second. This drift was caused by the current way of calculating the scale. In our case cpu_khz had a value of 3292725. This resulted in a scale value of 310. But when doing the calculation by hand it shows that the actual value is 310.9886188491, so a value of 311 would be more precise. With this change the value is rounded. Signed-off-by: Bernd Faust <berndfaust@gmail.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--arch/x86/kernel/tsc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index cfa5d4f7ca56..8ed085733773 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -617,7 +617,8 @@ static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu)
617 ns_now = __cycles_2_ns(tsc_now); 617 ns_now = __cycles_2_ns(tsc_now);
618 618
619 if (cpu_khz) { 619 if (cpu_khz) {
620 *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz; 620 *scale = ((NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR) +
621 cpu_khz / 2) / cpu_khz;
621 *offset = ns_now - mult_frac(tsc_now, *scale, 622 *offset = ns_now - mult_frac(tsc_now, *scale,
622 (1UL << CYC2NS_SCALE_FACTOR)); 623 (1UL << CYC2NS_SCALE_FACTOR));
623 } 624 }