x86, msr: Add rd/wrmsr interfaces with preset registers
[safe/jmp/linux-2.6] / arch / x86 / lib / atomic64_32.c
index 5fc1e2c..824fa0b 100644 (file)
@@ -1,10 +1,12 @@
 #include <linux/compiler.h>
+#include <linux/module.h>
 #include <linux/types.h>
+
 #include <asm/processor.h>
 #include <asm/cmpxchg.h>
 #include <asm/atomic.h>
 
-static inline u64 cmpxchg8b(u64 *ptr, u64 old, u64 new)
+static noinline u64 cmpxchg8b(u64 *ptr, u64 old, u64 new)
 {
        u32 low = new;
        u32 high = new >> 32;
@@ -21,6 +23,7 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
 {
        return cmpxchg8b(&ptr->counter, old_val, new_val);
 }
+EXPORT_SYMBOL(atomic64_cmpxchg);
 
 /**
  * atomic64_xchg - xchg atomic64 variable
@@ -30,17 +33,27 @@ u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
  * Atomically xchgs the value of @ptr to @new_val and returns
  * the old value.
  */
-
 u64 atomic64_xchg(atomic64_t *ptr, u64 new_val)
 {
-       u64 old_val;
+       /*
+        * Try first with a (possibly incorrect) assumption about
+        * what we have there. We'll do two loops most likely,
+        * but we'll get an ownership MESI transaction straight away
+        * instead of a read transaction followed by a
+        * flush-for-ownership transaction:
+        */
+       u64 old_val, real_val = 0;
 
        do {
-               old_val = atomic_read(ptr);
-       } while (atomic64_cmpxchg(ptr, old_val, new_val) != old_val);
+               old_val = real_val;
+
+               real_val = atomic64_cmpxchg(ptr, old_val, new_val);
+
+       } while (real_val != old_val);
 
        return old_val;
 }
+EXPORT_SYMBOL(atomic64_xchg);
 
 /**
  * atomic64_set - set atomic64 variable
@@ -53,54 +66,56 @@ void atomic64_set(atomic64_t *ptr, u64 new_val)
 {
        atomic64_xchg(ptr, new_val);
 }
+EXPORT_SYMBOL(atomic64_set);
 
 /**
- * atomic64_read - read atomic64 variable
- * @ptr:      pointer to type atomic64_t
- *
- * Atomically reads the value of @ptr and returns it.
- */
-u64 atomic64_read(atomic64_t *ptr)
-{
-       u64 old = 1LL << 32;
-
-       return cmpxchg8b(&ptr->counter, old, old);
-}
-
-/**
+EXPORT_SYMBOL(atomic64_read);
  * atomic64_add_return - add and return
  * @delta: integer value to add
  * @ptr:   pointer to type atomic64_t
  *
  * Atomically adds @delta to @ptr and returns @delta + *@ptr
  */
-u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
+noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
 {
-       u64 old_val, new_val;
+       /*
+        * Try first with a (possibly incorrect) assumption about
+        * what we have there. We'll do two loops most likely,
+        * but we'll get an ownership MESI transaction straight away
+        * instead of a read transaction followed by a
+        * flush-for-ownership transaction:
+        */
+       u64 old_val, new_val, real_val = 0;
 
        do {
-               old_val = atomic_read(ptr);
+               old_val = real_val;
                new_val = old_val + delta;
 
-       } while (atomic64_cmpxchg(ptr, old_val, new_val) != old_val);
+               real_val = atomic64_cmpxchg(ptr, old_val, new_val);
+
+       } while (real_val != old_val);
 
        return new_val;
 }
+EXPORT_SYMBOL(atomic64_add_return);
 
 u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
 {
        return atomic64_add_return(-delta, ptr);
 }
+EXPORT_SYMBOL(atomic64_sub_return);
 
 u64 atomic64_inc_return(atomic64_t *ptr)
 {
        return atomic64_add_return(1, ptr);
 }
+EXPORT_SYMBOL(atomic64_inc_return);
 
 u64 atomic64_dec_return(atomic64_t *ptr)
 {
        return atomic64_sub_return(1, ptr);
 }
+EXPORT_SYMBOL(atomic64_dec_return);
 
 /**
  * atomic64_add - add integer to atomic64 variable
@@ -113,6 +128,7 @@ void atomic64_add(u64 delta, atomic64_t *ptr)
 {
        atomic64_add_return(delta, ptr);
 }
+EXPORT_SYMBOL(atomic64_add);
 
 /**
  * atomic64_sub - subtract the atomic64 variable
@@ -125,6 +141,7 @@ void atomic64_sub(u64 delta, atomic64_t *ptr)
 {
        atomic64_add(-delta, ptr);
 }
+EXPORT_SYMBOL(atomic64_sub);
 
 /**
  * atomic64_sub_and_test - subtract value from variable and test result
@@ -137,10 +154,11 @@ void atomic64_sub(u64 delta, atomic64_t *ptr)
  */
 int atomic64_sub_and_test(u64 delta, atomic64_t *ptr)
 {
-       u64 old_val = atomic64_sub_return(delta, ptr);
+       u64 new_val = atomic64_sub_return(delta, ptr);
 
-       return old_val == 0;
+       return new_val == 0;
 }
+EXPORT_SYMBOL(atomic64_sub_and_test);
 
 /**
  * atomic64_inc - increment atomic64 variable
@@ -152,6 +170,7 @@ void atomic64_inc(atomic64_t *ptr)
 {
        atomic64_add(1, ptr);
 }
+EXPORT_SYMBOL(atomic64_inc);
 
 /**
  * atomic64_dec - decrement atomic64 variable
@@ -163,6 +182,7 @@ void atomic64_dec(atomic64_t *ptr)
 {
        atomic64_sub(1, ptr);
 }
+EXPORT_SYMBOL(atomic64_dec);
 
 /**
  * atomic64_dec_and_test - decrement and test
@@ -176,6 +196,7 @@ int atomic64_dec_and_test(atomic64_t *ptr)
 {
        return atomic64_sub_and_test(1, ptr);
 }
+EXPORT_SYMBOL(atomic64_dec_and_test);
 
 /**
  * atomic64_inc_and_test - increment and test
@@ -189,6 +210,7 @@ int atomic64_inc_and_test(atomic64_t *ptr)
 {
        return atomic64_sub_and_test(-1, ptr);
 }
+EXPORT_SYMBOL(atomic64_inc_and_test);
 
 /**
  * atomic64_add_negative - add and test if negative
@@ -201,7 +223,8 @@ int atomic64_inc_and_test(atomic64_t *ptr)
  */
 int atomic64_add_negative(u64 delta, atomic64_t *ptr)
 {
-       long long old_val = atomic64_add_return(delta, ptr);
+       s64 new_val = atomic64_add_return(delta, ptr);
 
-       return old_val < 0;
+       return new_val < 0;
 }
+EXPORT_SYMBOL(atomic64_add_negative);