x86/time: Adjust init-time handling of pit0_ticks
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 7 Dec 2016 13:52:02 +0000 (13:52 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 8 Feb 2017 17:45:50 +0000 (17:45 +0000)
There is no need for the volatile cast in the timer interrupt; the compiler
may not elide the update.  This reduces the generated assembly from a read,
local modify, write to a single add instruction.

Drop the memory barriers from timer_irq_works(), as they are not needed.
pit0_ticks is only modified by timer_interrupt() running on the same CPU, so
all that is required is a volatile reference to prevent the compiler from
eliding the second read.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/io_apic.c
xen/arch/x86/time.c
xen/include/xen/lib.h

index 33e5927c71c52ac339278f243ac723f65db79a0a..f98997870cc30ed592db01858714f3a57cba1e8e 100644 (file)
@@ -1485,8 +1485,7 @@ static int __init timer_irq_works(void)
 {
     unsigned long t1, flags;
 
-    t1 = pit0_ticks;
-    mb();
+    t1 = ACCESS_ONCE(pit0_ticks);
 
     local_save_flags(flags);
     local_irq_enable();
@@ -1501,8 +1500,7 @@ static int __init timer_irq_works(void)
      * might have cached one ExtINT interrupt.  Finally, at
      * least one tick may be lost due to delays.
      */
-    mb();
-    if (pit0_ticks - t1 > 4)
+    if ( (ACCESS_ONCE(pit0_ticks) - t1) > 4 )
         return 1;
 
     return 0;
index d3b0c696e34799764a54c3e54de0ee4e7166e3c1..699dfb6604eaf112b0e8a8338b82455d69f57b35 100644 (file)
@@ -197,7 +197,7 @@ static void timer_interrupt(int irq, void *dev_id, struct cpu_user_regs *regs)
         return;
 
     /* Only for start-of-day interruopt tests in io_apic.c. */
-    (*(volatile unsigned long *)&pit0_ticks)++;
+    pit0_ticks++;
 
     /* Rough hack to allow accurate timers to sort-of-work with no APIC. */
     if ( !cpu_has_apic )
index d1171b774b13003837cdcd1647ec619f489569c6..1976e4be8dcbe6547643b64d33c7c53e3257123b 100644 (file)
@@ -56,6 +56,8 @@
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + __must_be_array(x))
 
+#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
+
 #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
 #define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))