x86, suspend, acpi: correct and add comments about Big Real Mode
[pandora-kernel.git] / arch / x86 / lib / delay_64.c
index 0ebbfb9..4c441be 100644 (file)
 
 #include <linux/module.h>
 #include <linux/sched.h>
+#include <linux/timex.h>
+#include <linux/preempt.h>
 #include <linux/delay.h>
+#include <linux/init.h>
+
 #include <asm/delay.h>
 #include <asm/msr.h>
 
@@ -18,7 +22,7 @@
 #include <asm/smp.h>
 #endif
 
-int read_current_timer(unsigned long *timer_value)
+int __devinit read_current_timer(unsigned long *timer_value)
 {
        rdtscll(*timer_value);
        return 0;
@@ -27,14 +31,37 @@ int read_current_timer(unsigned long *timer_value)
 void __delay(unsigned long loops)
 {
        unsigned bclock, now;
-       
+       int cpu;
+
+       preempt_disable();
+       cpu = smp_processor_id();
        rdtscl(bclock);
-       do
-       {
-               rep_nop(); 
+       for (;;) {
                rdtscl(now);
+               if ((now - bclock) >= loops)
+                       break;
+
+               /* Allow RT tasks to run */
+               preempt_enable();
+               rep_nop();
+               preempt_disable();
+
+               /*
+                * It is possible that we moved to another CPU, and
+                * since TSC's are per-cpu we need to calculate
+                * that. The delay must guarantee that we wait "at
+                * least" the amount of time. Being moved to another
+                * CPU could make the wait longer but we just need to
+                * make sure we waited long enough. Rebalance the
+                * counter for this CPU.
+                */
+               if (unlikely(cpu != smp_processor_id())) {
+                       loops -= (now - bclock);
+                       cpu = smp_processor_id();
+                       rdtscl(bclock);
+               }
        }
-       while((now-bclock) < loops);
+       preempt_enable();
 }
 EXPORT_SYMBOL(__delay);