diff options
| -rw-r--r-- | arch/x86/include/asm/timer.h | 6 | ||||
| -rw-r--r-- | arch/x86/kernel/tsc.c | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h index bd37ed444a21..20ca9c4d4686 100644 --- a/arch/x86/include/asm/timer.h +++ b/arch/x86/include/asm/timer.h | |||
| @@ -45,12 +45,16 @@ extern int no_timer_check; | |||
| 45 | */ | 45 | */ |
| 46 | 46 | ||
| 47 | DECLARE_PER_CPU(unsigned long, cyc2ns); | 47 | DECLARE_PER_CPU(unsigned long, cyc2ns); |
| 48 | DECLARE_PER_CPU(unsigned long long, cyc2ns_offset); | ||
| 48 | 49 | ||
| 49 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ | 50 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ |
| 50 | 51 | ||
| 51 | static inline unsigned long long __cycles_2_ns(unsigned long long cyc) | 52 | static inline unsigned long long __cycles_2_ns(unsigned long long cyc) |
| 52 | { | 53 | { |
| 53 | return cyc * per_cpu(cyc2ns, smp_processor_id()) >> CYC2NS_SCALE_FACTOR; | 54 | int cpu = smp_processor_id(); |
| 55 | unsigned long long ns = per_cpu(cyc2ns_offset, cpu); | ||
| 56 | ns += cyc * per_cpu(cyc2ns, cpu) >> CYC2NS_SCALE_FACTOR; | ||
| 57 | return ns; | ||
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | static inline unsigned long long cycles_2_ns(unsigned long long cyc) | 60 | static inline unsigned long long cycles_2_ns(unsigned long long cyc) |
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 3e1c057e98fe..ef4dac50143f 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c | |||
| @@ -589,22 +589,26 @@ EXPORT_SYMBOL(recalibrate_cpu_khz); | |||
| 589 | */ | 589 | */ |
| 590 | 590 | ||
| 591 | DEFINE_PER_CPU(unsigned long, cyc2ns); | 591 | DEFINE_PER_CPU(unsigned long, cyc2ns); |
| 592 | DEFINE_PER_CPU(unsigned long long, cyc2ns_offset); | ||
| 592 | 593 | ||
| 593 | static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu) | 594 | static void set_cyc2ns_scale(unsigned long cpu_khz, int cpu) |
| 594 | { | 595 | { |
| 595 | unsigned long long tsc_now, ns_now; | 596 | unsigned long long tsc_now, ns_now, *offset; |
| 596 | unsigned long flags, *scale; | 597 | unsigned long flags, *scale; |
| 597 | 598 | ||
| 598 | local_irq_save(flags); | 599 | local_irq_save(flags); |
| 599 | sched_clock_idle_sleep_event(); | 600 | sched_clock_idle_sleep_event(); |
| 600 | 601 | ||
| 601 | scale = &per_cpu(cyc2ns, cpu); | 602 | scale = &per_cpu(cyc2ns, cpu); |
| 603 | offset = &per_cpu(cyc2ns_offset, cpu); | ||
| 602 | 604 | ||
| 603 | rdtscll(tsc_now); | 605 | rdtscll(tsc_now); |
| 604 | ns_now = __cycles_2_ns(tsc_now); | 606 | ns_now = __cycles_2_ns(tsc_now); |
| 605 | 607 | ||
| 606 | if (cpu_khz) | 608 | if (cpu_khz) { |
| 607 | *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz; | 609 | *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz; |
| 610 | *offset = ns_now - (tsc_now * *scale >> CYC2NS_SCALE_FACTOR); | ||
| 611 | } | ||
| 608 | 612 | ||
| 609 | sched_clock_idle_wakeup_event(0); | 613 | sched_clock_idle_wakeup_event(0); |
| 610 | local_irq_restore(flags); | 614 | local_irq_restore(flags); |
