From: Andrew Morton Marin Mitov points out that delay_tsc() can misbehave if it is preempted and rescheduled on a different CPU which has a skewed TSC. Fix it by disabling preemption. (I assume that the worst-case behaviour here is a stall of 2^32 cycles) Cc: Andi Kleen Cc: Marin Mitov Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Signed-off-by: Andrew Morton --- arch/x86/lib/delay_32.c | 3 +++ arch/x86/lib/delay_64.c | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff -puN arch/x86/lib/delay_32.c~x86-disable-preemption-in-delay_tsc arch/x86/lib/delay_32.c --- a/arch/x86/lib/delay_32.c~x86-disable-preemption-in-delay_tsc +++ a/arch/x86/lib/delay_32.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -42,11 +43,13 @@ static void delay_tsc(unsigned long loop { unsigned long bclock, now; + preempt_disable(); /* TSC's are per-cpu */ rdtscl(bclock); do { rep_nop(); rdtscl(now); } while ((now-bclock) < loops); + preempt_enable(); } /* diff -puN arch/x86/lib/delay_64.c~x86-disable-preemption-in-delay_tsc arch/x86/lib/delay_64.c --- a/arch/x86/lib/delay_64.c~x86-disable-preemption-in-delay_tsc +++ a/arch/x86/lib/delay_64.c @@ -10,7 +10,9 @@ #include #include +#include #include + #include #include @@ -27,14 +29,15 @@ int read_current_timer(unsigned long *ti void __delay(unsigned long loops) { unsigned bclock, now; - + + preempt_disable(); /* TSC's are pre-cpu */ rdtscl(bclock); - do - { + do { rep_nop(); rdtscl(now); } - while((now-bclock) < loops); + while ((now-bclock) < loops); + preempt_enable(); } EXPORT_SYMBOL(__delay); _