Commit 615cd033 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/tsc: Fix sched_clock() sync

While looking through the code I noticed that we initialize the cyc2ns
fields with a different cycle value for each CPU, resulting in a
slightly different 0 point for each CPU.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 59eaef78
...@@ -137,9 +137,9 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc) ...@@ -137,9 +137,9 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc)
return ns; return ns;
} }
static void set_cyc2ns_scale(unsigned long khz, int cpu) static void __set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_now)
{ {
unsigned long long tsc_now, ns_now; unsigned long long ns_now;
struct cyc2ns_data data; struct cyc2ns_data data;
struct cyc2ns *c2n; struct cyc2ns *c2n;
unsigned long flags; unsigned long flags;
...@@ -150,7 +150,6 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu) ...@@ -150,7 +150,6 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu)
if (!khz) if (!khz)
goto done; goto done;
tsc_now = rdtsc();
ns_now = cycles_2_ns(tsc_now); ns_now = cycles_2_ns(tsc_now);
/* /*
...@@ -186,6 +185,12 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu) ...@@ -186,6 +185,12 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu)
sched_clock_idle_wakeup_event(0); sched_clock_idle_wakeup_event(0);
local_irq_restore(flags); local_irq_restore(flags);
} }
static void set_cyc2ns_scale(unsigned long khz, int cpu)
{
__set_cyc2ns_scale(khz, cpu, rdtsc());
}
/* /*
* Scheduler clock - returns current time in nanosec units. * Scheduler clock - returns current time in nanosec units.
*/ */
...@@ -1251,7 +1256,7 @@ device_initcall(init_tsc_clocksource); ...@@ -1251,7 +1256,7 @@ device_initcall(init_tsc_clocksource);
void __init tsc_init(void) void __init tsc_init(void)
{ {
u64 lpj; u64 lpj, cyc;
int cpu; int cpu;
if (!boot_cpu_has(X86_FEATURE_TSC)) { if (!boot_cpu_has(X86_FEATURE_TSC)) {
...@@ -1291,9 +1296,10 @@ void __init tsc_init(void) ...@@ -1291,9 +1296,10 @@ void __init tsc_init(void)
* speed as the bootup CPU. (cpufreq notifiers will fix this * speed as the bootup CPU. (cpufreq notifiers will fix this
* up if their speed diverges) * up if their speed diverges)
*/ */
cyc = rdtsc();
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
cyc2ns_init(cpu); cyc2ns_init(cpu);
set_cyc2ns_scale(tsc_khz, cpu); __set_cyc2ns_scale(tsc_khz, cpu, cyc);
} }
if (tsc_disabled > 0) if (tsc_disabled > 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment