Commit | Line | Data |
---|---|---|
77ef50a5 VN |
1 | #ifndef ASM_X86__TIMER_H |
2 | #define ASM_X86__TIMER_H | |
1da177e4 | 3 | #include <linux/init.h> |
c3c433e4 | 4 | #include <linux/pm.h> |
53d517cd | 5 | #include <linux/percpu.h> |
1da177e4 | 6 | |
1da177e4 | 7 | #define TICK_SIZE (tick_nsec / 1000) |
6cb9a835 | 8 | |
6cb9a835 | 9 | unsigned long long native_sched_clock(void); |
e93ef949 | 10 | unsigned long native_calibrate_tsc(void); |
6cb9a835 | 11 | |
cc038491 | 12 | #ifdef CONFIG_X86_32 |
1da177e4 | 13 | extern int timer_ack; |
c5d28fb2 | 14 | extern int recalibrate_cpu_khz(void); |
cc038491 JS |
15 | #endif /* CONFIG_X86_32 */ |
16 | ||
17 | extern int no_timer_check; | |
1da177e4 | 18 | |
6cb9a835 | 19 | #ifndef CONFIG_PARAVIRT |
e93ef949 | 20 | #define calibrate_tsc() native_calibrate_tsc() |
6cb9a835 ZA |
21 | #endif |
22 | ||
53d517cd | 23 | /* Accelerators for sched_clock() |
688340ea JF |
24 | * convert from cycles(64bits) => nanoseconds (64bits) |
25 | * basic equation: | |
26 | * ns = cycles / (freq / ns_per_sec) | |
27 | * ns = cycles * (ns_per_sec / freq) | |
28 | * ns = cycles * (10^9 / (cpu_khz * 10^3)) | |
29 | * ns = cycles * (10^6 / cpu_khz) | |
30 | * | |
31 | * Then we use scaling math (suggested by george@mvista.com) to get: | |
32 | * ns = cycles * (10^6 * SC / cpu_khz) / SC | |
33 | * ns = cycles * cyc2ns_scale / SC | |
34 | * | |
35 | * And since SC is a constant power of two, we can convert the div | |
36 | * into a shift. | |
37 | * | |
53d517cd | 38 | * We can use khz divisor instead of mhz to keep a better precision, since |
688340ea JF |
39 | * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits. |
40 | * (mathieu.desnoyers@polymtl.ca) | |
41 | * | |
42 | * -johnstul@us.ibm.com "math is hard, lets go shopping!" | |
43 | */ | |
53d517cd GC |
44 | |
45 | DECLARE_PER_CPU(unsigned long, cyc2ns); | |
688340ea JF |
46 | |
47 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | |
48 | ||
53d517cd | 49 | static inline unsigned long long __cycles_2_ns(unsigned long long cyc) |
688340ea | 50 | { |
53d517cd | 51 | return cyc * per_cpu(cyc2ns, smp_processor_id()) >> CYC2NS_SCALE_FACTOR; |
688340ea JF |
52 | } |
53 | ||
53d517cd GC |
54 | static inline unsigned long long cycles_2_ns(unsigned long long cyc) |
55 | { | |
56 | unsigned long long ns; | |
57 | unsigned long flags; | |
58 | ||
59 | local_irq_save(flags); | |
60 | ns = __cycles_2_ns(cyc); | |
61 | local_irq_restore(flags); | |
62 | ||
63 | return ns; | |
64 | } | |
688340ea | 65 | |
77ef50a5 | 66 | #endif /* ASM_X86__TIMER_H */ |