summaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/timer.h
diff options
context:
space:
mode:
authorSalman Qazi <sqazi@google.com>2012-03-09 16:41:01 -0800
committerIngo Molnar <mingo@elte.hu>2012-03-13 16:27:51 +0100
commit9993bc635d01a6ee7f6b833b4ee65ce7c06350b1 (patch)
tree9e40c69ef513fc0a57c03a05a68afc6711418ed8 /arch/x86/include/asm/timer.h
parent47258cf3c4aa5d56e678bafe0dd0d03ddd980b88 (diff)
downloadlinux-9993bc635d01a6ee7f6b833b4ee65ce7c06350b1.tar.gz
linux-9993bc635d01a6ee7f6b833b4ee65ce7c06350b1.tar.bz2
linux-9993bc635d01a6ee7f6b833b4ee65ce7c06350b1.zip
sched/x86: Fix overflow in cyc2ns_offset
When a machine boots up, the TSC generally gets reset. However, when kexec is used to boot into a kernel, the TSC value would be carried over from the previous kernel. The computation of cycns_offset in set_cyc2ns_scale is prone to an overflow, if the machine has been up more than 208 days prior to the kexec. The overflow happens when we multiply *scale, even though there is enough room to store the final answer. We fix this issue by decomposing tsc_now into the quotient and remainder of division by CYC2NS_SCALE_FACTOR and then performing the multiplication separately on the two components. Refactor code to share the calculation with the previous fix in __cycles_2_ns(). Signed-off-by: Salman Qazi <sqazi@google.com> Acked-by: John Stultz <john.stultz@linaro.org> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Turner <pjt@google.com> Cc: john stultz <johnstul@us.ibm.com> Link: http://lkml.kernel.org/r/20120310004027.19291.88460.stgit@dungbeetle.mtv.corp.google.com Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/include/asm/timer.h')
-rw-r--r--arch/x86/include/asm/timer.h8
1 files changed, 2 insertions, 6 deletions
diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h
index 431793e5d484..34baa0eb5d0c 100644
--- a/arch/x86/include/asm/timer.h
+++ b/arch/x86/include/asm/timer.h
@@ -57,14 +57,10 @@ DECLARE_PER_CPU(unsigned long long, cyc2ns_offset);
static inline unsigned long long __cycles_2_ns(unsigned long long cyc)
{
- unsigned long long quot;
- unsigned long long rem;
int cpu = smp_processor_id();
unsigned long long ns = per_cpu(cyc2ns_offset, cpu);
- quot = (cyc >> CYC2NS_SCALE_FACTOR);
- rem = cyc & ((1ULL << CYC2NS_SCALE_FACTOR) - 1);
- ns += quot * per_cpu(cyc2ns, cpu) +
- ((rem * per_cpu(cyc2ns, cpu)) >> CYC2NS_SCALE_FACTOR);
+ ns += mult_frac(cyc, per_cpu(cyc2ns, cpu),
+ (1UL << CYC2NS_SCALE_FACTOR));
return ns;
}