diff options
Diffstat (limited to 'arch/i386/kernel/timers/timer_tsc.c')
-rw-r--r-- | arch/i386/kernel/timers/timer_tsc.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/arch/i386/kernel/timers/timer_tsc.c b/arch/i386/kernel/timers/timer_tsc.c index 6dd470cc9f72..d395e3b42485 100644 --- a/arch/i386/kernel/timers/timer_tsc.c +++ b/arch/i386/kernel/timers/timer_tsc.c | |||
@@ -49,23 +49,28 @@ static seqlock_t monotonic_lock = SEQLOCK_UNLOCKED; | |||
49 | * basic equation: | 49 | * basic equation: |
50 | * ns = cycles / (freq / ns_per_sec) | 50 | * ns = cycles / (freq / ns_per_sec) |
51 | * ns = cycles * (ns_per_sec / freq) | 51 | * ns = cycles * (ns_per_sec / freq) |
52 | * ns = cycles * (10^9 / (cpu_mhz * 10^6)) | 52 | * ns = cycles * (10^9 / (cpu_khz * 10^3)) |
53 | * ns = cycles * (10^3 / cpu_mhz) | 53 | * ns = cycles * (10^6 / cpu_khz) |
54 | * | 54 | * |
55 | * Then we use scaling math (suggested by george@mvista.com) to get: | 55 | * Then we use scaling math (suggested by george@mvista.com) to get: |
56 | * ns = cycles * (10^3 * SC / cpu_mhz) / SC | 56 | * ns = cycles * (10^6 * SC / cpu_khz) / SC |
57 | * ns = cycles * cyc2ns_scale / SC | 57 | * ns = cycles * cyc2ns_scale / SC |
58 | * | 58 | * |
59 | * And since SC is a constant power of two, we can convert the div | 59 | * And since SC is a constant power of two, we can convert the div |
60 | * into a shift. | 60 | * into a shift. |
61 | * | ||
62 | * We can use khz divisor instead of mhz to keep a better percision, since | ||
63 | * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits. | ||
64 | * (mathieu.desnoyers@polymtl.ca) | ||
65 | * | ||
61 | * -johnstul@us.ibm.com "math is hard, lets go shopping!" | 66 | * -johnstul@us.ibm.com "math is hard, lets go shopping!" |
62 | */ | 67 | */ |
63 | static unsigned long cyc2ns_scale; | 68 | static unsigned long cyc2ns_scale; |
64 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | 69 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ |
65 | 70 | ||
66 | static inline void set_cyc2ns_scale(unsigned long cpu_mhz) | 71 | static inline void set_cyc2ns_scale(unsigned long cpu_khz) |
67 | { | 72 | { |
68 | cyc2ns_scale = (1000 << CYC2NS_SCALE_FACTOR)/cpu_mhz; | 73 | cyc2ns_scale = (1000000 << CYC2NS_SCALE_FACTOR)/cpu_khz; |
69 | } | 74 | } |
70 | 75 | ||
71 | static inline unsigned long long cycles_2_ns(unsigned long long cyc) | 76 | static inline unsigned long long cycles_2_ns(unsigned long long cyc) |
@@ -286,7 +291,7 @@ time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | |||
286 | if (use_tsc) { | 291 | if (use_tsc) { |
287 | if (!(freq->flags & CPUFREQ_CONST_LOOPS)) { | 292 | if (!(freq->flags & CPUFREQ_CONST_LOOPS)) { |
288 | fast_gettimeoffset_quotient = cpufreq_scale(fast_gettimeoffset_ref, freq->new, ref_freq); | 293 | fast_gettimeoffset_quotient = cpufreq_scale(fast_gettimeoffset_ref, freq->new, ref_freq); |
289 | set_cyc2ns_scale(cpu_khz/1000); | 294 | set_cyc2ns_scale(cpu_khz); |
290 | } | 295 | } |
291 | } | 296 | } |
292 | #endif | 297 | #endif |
@@ -536,7 +541,7 @@ static int __init init_tsc(char* override) | |||
536 | printk("Detected %u.%03u MHz processor.\n", | 541 | printk("Detected %u.%03u MHz processor.\n", |
537 | cpu_khz / 1000, cpu_khz % 1000); | 542 | cpu_khz / 1000, cpu_khz % 1000); |
538 | } | 543 | } |
539 | set_cyc2ns_scale(cpu_khz/1000); | 544 | set_cyc2ns_scale(cpu_khz); |
540 | return 0; | 545 | return 0; |
541 | } | 546 | } |
542 | } | 547 | } |