aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/include/asm/timer.h')
-rw-r--r--arch/x86/include/asm/timer.h59
1 files changed, 0 insertions, 59 deletions
diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h
index 10a78c037910..b4c667693a21 100644
--- a/arch/x86/include/asm/timer.h
+++ b/arch/x86/include/asm/timer.h
@@ -13,66 +13,7 @@ extern int recalibrate_cpu_khz(void);
13 13
14extern int no_timer_check; 14extern int no_timer_check;
15 15
16/* Accelerators for sched_clock()
17 * convert from cycles(64bits) => nanoseconds (64bits)
18 * basic equation:
19 * ns = cycles / (freq / ns_per_sec)
20 * ns = cycles * (ns_per_sec / freq)
21 * ns = cycles * (10^9 / (cpu_khz * 10^3))
22 * ns = cycles * (10^6 / cpu_khz)
23 *
24 * Then we use scaling math (suggested by george@mvista.com) to get:
25 * ns = cycles * (10^6 * SC / cpu_khz) / SC
26 * ns = cycles * cyc2ns_scale / SC
27 *
28 * And since SC is a constant power of two, we can convert the div
29 * into a shift.
30 *
31 * We can use khz divisor instead of mhz to keep a better precision, since
32 * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
33 * (mathieu.desnoyers@polymtl.ca)
34 *
35 * -johnstul@us.ibm.com "math is hard, lets go shopping!"
36 *
37 * In:
38 *
39 * ns = cycles * cyc2ns_scale / SC
40 *
41 * Although we may still have enough bits to store the value of ns,
42 * in some cases, we may not have enough bits to store cycles * cyc2ns_scale,
43 * leading to an incorrect result.
44 *
45 * To avoid this, we can decompose 'cycles' into quotient and remainder
46 * of division by SC. Then,
47 *
48 * ns = (quot * SC + rem) * cyc2ns_scale / SC
49 * = quot * cyc2ns_scale + (rem * cyc2ns_scale) / SC
50 *
51 * - sqazi@google.com
52 */
53
54DECLARE_PER_CPU(unsigned long, cyc2ns); 16DECLARE_PER_CPU(unsigned long, cyc2ns);
55DECLARE_PER_CPU(unsigned long long, cyc2ns_offset); 17DECLARE_PER_CPU(unsigned long long, cyc2ns_offset);
56 18
57#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
58
59static inline unsigned long long __cycles_2_ns(unsigned long long cyc)
60{
61 unsigned long long ns = this_cpu_read(cyc2ns_offset);
62 ns += mul_u64_u32_shr(cyc, this_cpu_read(cyc2ns), CYC2NS_SCALE_FACTOR);
63 return ns;
64}
65
66static inline unsigned long long cycles_2_ns(unsigned long long cyc)
67{
68 unsigned long long ns;
69 unsigned long flags;
70
71 local_irq_save(flags);
72 ns = __cycles_2_ns(cyc);
73 local_irq_restore(flags);
74
75 return ns;
76}
77
78#endif /* _ASM_X86_TIMER_H */ 19#endif /* _ASM_X86_TIMER_H */