All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/8] <asm/atomic.h> adjustments
@ 2016-07-14  9:09 Corneliu ZUZU
  2016-07-14  9:09 ` [PATCH v3 1/8] asm-arm/atomic.h: fix arm32|arm64 macros duplication Corneliu ZUZU
                   ` (7 more replies)
  0 siblings, 8 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:09 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Jan Beulich

Corneliu ZUZU (8):
  1/8: asm-arm/atomic.h: fix arm32|arm64 macros duplication
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Changed:
        * also moved mistakenly omitted atomic_xchg()
        * arm empty line fixes moved here

  2/8: asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement
    Changed:
        * arm empty line fixes moved from here (to 1/8)

  3/8: asm-arm/atomic.h: reorder macros to match x86-side
    Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
    Changed: <nothing>

  4/8: asm/atomic.h: common prototyping (add xen/atomic.h)
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Changed:
        * sample code for atomic_cmpxchg() (doc-comment in <xen/atomic.h>)
          updated to use atomic_read() instead of directly accessing v.counter

  5/8: fix: make atomic_read() param const
    Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
    Changed: <nothing>

  New in this version:
      6/8: asm-arm/atomic.h: atomic_{inc,dec}_return: macros to inline functions
      7/8: arm/atomic.h: remove '__' prefix for __atomic_add_unless()
      8/8: asm-x86/atomic.h: implement missing, add common prototypes

 xen/include/asm-arm/arm32/atomic.h |  17 +--
 xen/include/asm-arm/arm64/atomic.h |  17 +--
 xen/include/asm-arm/atomic.h       |  55 ++++++++--
 xen/include/asm-x86/atomic.h       | 151 +++++++--------------------
 xen/include/xen/atomic.h           | 207 +++++++++++++++++++++++++++++++++++++
 5 files changed, 296 insertions(+), 151 deletions(-)
 create mode 100644 xen/include/xen/atomic.h

-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH v3 1/8] asm-arm/atomic.h: fix arm32|arm64 macros duplication
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
@ 2016-07-14  9:09 ` Corneliu ZUZU
  2016-07-14  9:10 ` [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement Corneliu ZUZU
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:09 UTC (permalink / raw)
  To: xen-devel; +Cc: Julien Grall, Stefano Stabellini

Move duplicate macros between asm-arm/arm32/atomic.h and asm-arm/arm64/atomic.h
to asm-arm/atomic.h.
Also empty line fixes.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changed since v2:
  * also moved mistakenly omitted atomic_xchg()
  * arm empty line fixes moved here
---
 xen/include/asm-arm/arm32/atomic.h | 15 ++-------------
 xen/include/asm-arm/arm64/atomic.h | 15 ++-------------
 xen/include/asm-arm/atomic.h       | 14 ++++++++++++++
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/xen/include/asm-arm/arm32/atomic.h b/xen/include/asm-arm/arm32/atomic.h
index 7ec712f..78de60f 100644
--- a/xen/include/asm-arm/arm32/atomic.h
+++ b/xen/include/asm-arm/arm32/atomic.h
@@ -8,6 +8,7 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+
 #ifndef __ARCH_ARM_ARM32_ATOMIC__
 #define __ARCH_ARM_ARM32_ATOMIC__
 
@@ -147,20 +148,8 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
 	return oldval;
 }
 
-#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
-
-#define atomic_inc(v)		atomic_add(1, v)
-#define atomic_dec(v)		atomic_sub(1, v)
-
-#define atomic_inc_and_test(v)	(atomic_add_return(1, v) == 0)
-#define atomic_dec_and_test(v)	(atomic_sub_return(1, v) == 0)
-#define atomic_inc_return(v)    (atomic_add_return(1, v))
-#define atomic_dec_return(v)    (atomic_sub_return(1, v))
-#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
-
-#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
-
 #endif /* __ARCH_ARM_ARM32_ATOMIC__ */
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/arm64/atomic.h b/xen/include/asm-arm/arm64/atomic.h
index b49219e..d640bef 100644
--- a/xen/include/asm-arm/arm64/atomic.h
+++ b/xen/include/asm-arm/arm64/atomic.h
@@ -19,6 +19,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+
 #ifndef __ARCH_ARM_ARM64_ATOMIC
 #define __ARCH_ARM_ARM64_ATOMIC
 
@@ -113,8 +114,6 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
 	return oldval;
 }
 
-#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
-
 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
 {
 	int c, old;
@@ -125,18 +124,8 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
 	return c;
 }
 
-#define atomic_inc(v)		atomic_add(1, v)
-#define atomic_dec(v)		atomic_sub(1, v)
-
-#define atomic_inc_and_test(v)	(atomic_add_return(1, v) == 0)
-#define atomic_dec_and_test(v)	(atomic_sub_return(1, v) == 0)
-#define atomic_inc_return(v)    (atomic_add_return(1, v))
-#define atomic_dec_return(v)    (atomic_sub_return(1, v))
-#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
-
-#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
-
 #endif
+
 /*
  * Local variables:
  * mode: C
diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index 29ab265..32771e9 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -138,7 +138,21 @@ static inline void _atomic_set(atomic_t *v, int i)
 # error "unknown ARM variant"
 #endif
 
+#define atomic_inc(v)       atomic_add(1, v)
+#define atomic_dec(v)       atomic_sub(1, v)
+
+#define atomic_inc_and_test(v)  (atomic_add_return(1, v) == 0)
+#define atomic_dec_and_test(v)  (atomic_sub_return(1, v) == 0)
+#define atomic_inc_return(v)    (atomic_add_return(1, v))
+#define atomic_dec_return(v)    (atomic_sub_return(1, v))
+#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
+
+#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
+
+#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
+
 #endif /* __ARCH_ARM_ATOMIC__ */
+
 /*
  * Local variables:
  * mode: C
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
  2016-07-14  9:09 ` [PATCH v3 1/8] asm-arm/atomic.h: fix arm32|arm64 macros duplication Corneliu ZUZU
@ 2016-07-14  9:10 ` Corneliu ZUZU
  2016-07-14  9:27   ` Andrew Cooper
  2016-07-14  9:11 ` [PATCH v3 3/8] asm-arm/atomic.h: reorder macros to match x86-side Corneliu ZUZU
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:10 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Jan Beulich

Place atomic_inc_and_test() implementation after atomic_inc().
Also empty line fix.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
Changed since v2: arm empty line fixes moved from here
---
 xen/include/asm-x86/atomic.h | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)

diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index d246b70..5f9f2dd 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -110,7 +110,6 @@ static inline int _atomic_read(atomic_t v)
     return v.counter;
 }
 
-
 /**
  * atomic_set - set atomic variable
  * @v: pointer of type atomic_t
@@ -217,6 +216,25 @@ static inline void atomic_inc(atomic_t *v)
 }
 
 /**
+ * atomic_inc_and_test - increment and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1
+ * and returns true if the result is zero, or false for all
+ * other cases.
+ */
+static inline int atomic_inc_and_test(atomic_t *v)
+{
+    unsigned char c;
+
+    asm volatile (
+        "lock; incl %0; sete %1"
+        : "=m" (*(volatile int *)&v->counter), "=qm" (c)
+        : "m" (*(volatile int *)&v->counter) : "memory" );
+    return c != 0;
+}
+
+/**
  * atomic_dec - decrement atomic variable
  * @v: pointer of type atomic_t
  * 
@@ -250,25 +268,6 @@ static inline int atomic_dec_and_test(atomic_t *v)
 }
 
 /**
- * atomic_inc_and_test - increment and test 
- * @v: pointer of type atomic_t
- * 
- * Atomically increments @v by 1
- * and returns true if the result is zero, or false for all
- * other cases.
- */ 
-static inline int atomic_inc_and_test(atomic_t *v)
-{
-    unsigned char c;
-
-    asm volatile (
-        "lock; incl %0; sete %1"
-        : "=m" (*(volatile int *)&v->counter), "=qm" (c)
-        : "m" (*(volatile int *)&v->counter) : "memory" );
-    return c != 0;
-}
-
-/**
  * atomic_add_negative - add and test if negative
  * @v: pointer of type atomic_t
  * @i: integer value to add
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 3/8] asm-arm/atomic.h: reorder macros to match x86-side
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
  2016-07-14  9:09 ` [PATCH v3 1/8] asm-arm/atomic.h: fix arm32|arm64 macros duplication Corneliu ZUZU
  2016-07-14  9:10 ` [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement Corneliu ZUZU
@ 2016-07-14  9:11 ` Corneliu ZUZU
  2016-07-14  9:12 ` [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h) Corneliu ZUZU
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:11 UTC (permalink / raw)
  To: xen-devel; +Cc: Julien Grall, Stefano Stabellini

Reorder macro definitions to match x86-side.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
---
Changed since v2: <nothing>
---
 xen/include/asm-arm/atomic.h | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index 32771e9..620c636 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -138,16 +138,15 @@ static inline void _atomic_set(atomic_t *v, int i)
 # error "unknown ARM variant"
 #endif
 
-#define atomic_inc(v)       atomic_add(1, v)
-#define atomic_dec(v)       atomic_sub(1, v)
-
-#define atomic_inc_and_test(v)  (atomic_add_return(1, v) == 0)
-#define atomic_dec_and_test(v)  (atomic_sub_return(1, v) == 0)
-#define atomic_inc_return(v)    (atomic_add_return(1, v))
-#define atomic_dec_return(v)    (atomic_sub_return(1, v))
-#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
-
-#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
+#define atomic_inc_return(v)        (atomic_add_return(1, v))
+#define atomic_dec_return(v)        (atomic_sub_return(1, v))
+
+#define atomic_sub_and_test(i, v)   (atomic_sub_return(i, v) == 0)
+#define atomic_inc(v)               atomic_add(1, v)
+#define atomic_inc_and_test(v)      (atomic_add_return(1, v) == 0)
+#define atomic_dec(v)               atomic_sub(1, v)
+#define atomic_dec_and_test(v)      (atomic_sub_return(1, v) == 0)
+#define atomic_add_negative(i,v)    (atomic_add_return(i, v) < 0)
 
 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
 
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h)
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
                   ` (2 preceding siblings ...)
  2016-07-14  9:11 ` [PATCH v3 3/8] asm-arm/atomic.h: reorder macros to match x86-side Corneliu ZUZU
@ 2016-07-14  9:12 ` Corneliu ZUZU
  2016-07-14 10:52   ` Stefano Stabellini
  2016-07-14  9:13 ` [PATCH v3 5/8] fix: make atomic_read() param const Corneliu ZUZU
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:12 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Jan Beulich

Create a common-side <xen/atomic.h> to establish, among others, prototypes of
atomic functions called from common-code. Done to avoid introducing
inconsistencies between arch-side <asm/atomic.h> headers when we make subtle
changes to one of them.

Some arm-side macros had to be turned into inline functions in the process.
Removed outdated comment ("NB. I've [...]").

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
Changed since v2:
  * sample code for atomic_cmpxchg() (doc-comment in <xen/atomic.h>) updated to
    use atomic_read() instead of directly accessing v.counter
---
 xen/include/asm-arm/atomic.h |  45 ++++++++----
 xen/include/asm-x86/atomic.h | 103 +-------------------------
 xen/include/xen/atomic.h     | 171 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 202 insertions(+), 117 deletions(-)
 create mode 100644 xen/include/xen/atomic.h

diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index 620c636..a79420a 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -2,6 +2,7 @@
 #define __ARCH_ARM_ATOMIC__
 
 #include <xen/config.h>
+#include <xen/atomic.h>
 #include <xen/prefetch.h>
 #include <asm/system.h>
 
@@ -95,15 +96,6 @@ void __bad_atomic_size(void);
     default: __bad_atomic_size(); break;                                \
     }                                                                   \
 })
-    
-/*
- * NB. I've pushed the volatile qualifier into the operations. This allows
- * fast accessors such as _atomic_read() and _atomic_set() which don't give
- * the compiler a fit.
- */
-typedef struct { int counter; } atomic_t;
-
-#define ATOMIC_INIT(i) { (i) }
 
 /*
  * On ARM, ordinary assignment (str instruction) doesn't clear the local
@@ -141,12 +133,35 @@ static inline void _atomic_set(atomic_t *v, int i)
 #define atomic_inc_return(v)        (atomic_add_return(1, v))
 #define atomic_dec_return(v)        (atomic_sub_return(1, v))
 
-#define atomic_sub_and_test(i, v)   (atomic_sub_return(i, v) == 0)
-#define atomic_inc(v)               atomic_add(1, v)
-#define atomic_inc_and_test(v)      (atomic_add_return(1, v) == 0)
-#define atomic_dec(v)               atomic_sub(1, v)
-#define atomic_dec_and_test(v)      (atomic_sub_return(1, v) == 0)
-#define atomic_add_negative(i,v)    (atomic_add_return(i, v) < 0)
+static inline int atomic_sub_and_test(int i, atomic_t *v)
+{
+    return atomic_sub_return(i, v) == 0;
+}
+
+static inline void atomic_inc(atomic_t *v)
+{
+    atomic_add(1, v);
+}
+
+static inline int atomic_inc_and_test(atomic_t *v)
+{
+    return atomic_add_return(1, v) == 0;
+}
+
+static inline void atomic_dec(atomic_t *v)
+{
+    atomic_sub(1, v);
+}
+
+static inline int atomic_dec_and_test(atomic_t *v)
+{
+    return atomic_sub_return(1, v) == 0;
+}
+
+static inline int atomic_add_negative(int i, atomic_t *v)
+{
+    return atomic_add_return(i, v) < 0;
+}
 
 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
 
diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index 5f9f2dd..3e99b03 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -2,6 +2,7 @@
 #define __ARCH_X86_ATOMIC__
 
 #include <xen/config.h>
+#include <xen/atomic.h>
 #include <asm/system.h>
 
 #define build_read_atomic(name, size, type, reg, barrier) \
@@ -79,56 +80,21 @@ void __bad_atomic_size(void);
     }                                                     \
 })
 
-/*
- * NB. I've pushed the volatile qualifier into the operations. This allows
- * fast accessors such as _atomic_read() and _atomic_set() which don't give
- * the compiler a fit.
- */
-typedef struct { int counter; } atomic_t;
-
-#define ATOMIC_INIT(i) { (i) }
-
-/**
- * atomic_read - read atomic variable
- * @v: pointer of type atomic_t
- *
- * Atomically reads the value of @v.
- */
 static inline int atomic_read(atomic_t *v)
 {
     return read_atomic(&v->counter);
 }
 
-/**
- * _atomic_read - read atomic variable non-atomically
- * @v atomic_t
- *
- * Non-atomically reads the value of @v
- */
 static inline int _atomic_read(atomic_t v)
 {
     return v.counter;
 }
 
-/**
- * atomic_set - set atomic variable
- * @v: pointer of type atomic_t
- * @i: required value
- *
- * Atomically sets the value of @v to @i.
- */
 static inline void atomic_set(atomic_t *v, int i)
 {
     write_atomic(&v->counter, i);
 }
 
-/**
- * _atomic_set - set atomic variable non-atomically
- * @v: pointer of type atomic_t
- * @i: required value
- *
- * Non-atomically sets the value of @v to @i.
- */
 static inline void _atomic_set(atomic_t *v, int i)
 {
     v->counter = i;
@@ -139,13 +105,6 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
     return cmpxchg(&v->counter, old, new);
 }
 
-/**
- * atomic_add - add integer to atomic variable
- * @i: integer value to add
- * @v: pointer of type atomic_t
- * 
- * Atomically adds @i to @v.
- */
 static inline void atomic_add(int i, atomic_t *v)
 {
     asm volatile (
@@ -154,25 +113,11 @@ static inline void atomic_add(int i, atomic_t *v)
         : "ir" (i), "m" (*(volatile int *)&v->counter) );
 }
 
-/**
- * atomic_add_return - add integer and return
- * @i: integer value to add
- * @v: pointer of type atomic_t
- *
- * Atomically adds @i to @v and returns @i + @v
- */
 static inline int atomic_add_return(int i, atomic_t *v)
 {
     return i + arch_fetch_and_add(&v->counter, i);
 }
 
-/**
- * atomic_sub - subtract the atomic variable
- * @i: integer value to subtract
- * @v: pointer of type atomic_t
- * 
- * Atomically subtracts @i from @v.
- */
 static inline void atomic_sub(int i, atomic_t *v)
 {
     asm volatile (
@@ -181,15 +126,6 @@ static inline void atomic_sub(int i, atomic_t *v)
         : "ir" (i), "m" (*(volatile int *)&v->counter) );
 }
 
-/**
- * atomic_sub_and_test - subtract value from variable and test result
- * @i: integer value to subtract
- * @v: pointer of type atomic_t
- * 
- * Atomically subtracts @i from @v and returns
- * true if the result is zero, or false for all
- * other cases.
- */
 static inline int atomic_sub_and_test(int i, atomic_t *v)
 {
     unsigned char c;
@@ -201,12 +137,6 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
     return c;
 }
 
-/**
- * atomic_inc - increment atomic variable
- * @v: pointer of type atomic_t
- * 
- * Atomically increments @v by 1.
- */ 
 static inline void atomic_inc(atomic_t *v)
 {
     asm volatile (
@@ -215,14 +145,6 @@ static inline void atomic_inc(atomic_t *v)
         : "m" (*(volatile int *)&v->counter) );
 }
 
-/**
- * atomic_inc_and_test - increment and test
- * @v: pointer of type atomic_t
- *
- * Atomically increments @v by 1
- * and returns true if the result is zero, or false for all
- * other cases.
- */
 static inline int atomic_inc_and_test(atomic_t *v)
 {
     unsigned char c;
@@ -234,12 +156,6 @@ static inline int atomic_inc_and_test(atomic_t *v)
     return c != 0;
 }
 
-/**
- * atomic_dec - decrement atomic variable
- * @v: pointer of type atomic_t
- * 
- * Atomically decrements @v by 1.
- */ 
 static inline void atomic_dec(atomic_t *v)
 {
     asm volatile (
@@ -248,14 +164,6 @@ static inline void atomic_dec(atomic_t *v)
         : "m" (*(volatile int *)&v->counter) );
 }
 
-/**
- * atomic_dec_and_test - decrement and test
- * @v: pointer of type atomic_t
- * 
- * Atomically decrements @v by 1 and
- * returns true if the result is 0, or false for all other
- * cases.
- */ 
 static inline int atomic_dec_and_test(atomic_t *v)
 {
     unsigned char c;
@@ -267,15 +175,6 @@ static inline int atomic_dec_and_test(atomic_t *v)
     return c != 0;
 }
 
-/**
- * atomic_add_negative - add and test if negative
- * @v: pointer of type atomic_t
- * @i: integer value to add
- * 
- * Atomically adds @i to @v and returns true
- * if the result is negative, or false when
- * result is greater than or equal to zero.
- */ 
 static inline int atomic_add_negative(int i, atomic_t *v)
 {
     unsigned char c;
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
new file mode 100644
index 0000000..d072912
--- /dev/null
+++ b/xen/include/xen/atomic.h
@@ -0,0 +1,171 @@
+/*
+ * include/xen/atomic.h
+ *
+ * Common atomic operations entities (atomic_t, function prototypes).
+ * Include _from_ arch-side <asm/atomic.h>.
+ *
+ * Copyright (c) 2016 Bitdefender S.R.L.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __XEN_ATOMIC_H__
+#define __XEN_ATOMIC_H__
+
+typedef struct { int counter; } atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.
+ */
+static inline int atomic_read(atomic_t *v);
+
+/**
+ * _atomic_read - read atomic variable non-atomically
+ * @v atomic_t
+ *
+ * Non-atomically reads the value of @v
+ */
+static inline int _atomic_read(atomic_t v);
+
+/**
+ * atomic_set - set atomic variable
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.
+ */
+static inline void atomic_set(atomic_t *v, int i);
+
+/**
+ * _atomic_set - set atomic variable non-atomically
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Non-atomically sets the value of @v to @i.
+ */
+static inline void _atomic_set(atomic_t *v, int i);
+
+/**
+ * atomic_cmpxchg - compare and exchange an atomic variable
+ * @v: pointer of type atomic_t
+ * @old: old value
+ * @new: new value
+ *
+ * Before calling, @old should be set to @v.
+ * Succeeds if @old == @v (likely), in which case stores @new in @v.
+ * Returns the initial value in @v, hence succeeds when the return value
+ * matches that of @old.
+ *
+ * Sample (tries atomic increment of v until the operation succeeds):
+ *
+ *  while(1)
+ *  {
+ *      int old = atomic_read(&v);
+ *      int new = old + 1;
+ *      if ( likely(old == atomic_cmpxchg(&v, old, new)) )
+ *          break; // success!
+ *  }
+ */
+static inline int atomic_cmpxchg(atomic_t *v, int old, int new);
+
+/**
+ * atomic_add - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v.
+ */
+static inline void atomic_add(int i, atomic_t *v);
+
+/**
+ * atomic_add_return - add integer and return
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static inline int atomic_add_return(int i, atomic_t *v);
+
+/**
+ * atomic_sub - subtract the atomic variable
+ * @i: integer value to subtract
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v.
+ */
+static inline void atomic_sub(int i, atomic_t *v);
+
+/**
+ * atomic_sub_and_test - subtract value from variable and test result
+ * @i: integer value to subtract
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v and returns
+ * true if the result is zero, or false for all
+ * other cases.
+ */
+static inline int atomic_sub_and_test(int i, atomic_t *v);
+
+/**
+ * atomic_inc - increment atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1.
+ */
+static inline void atomic_inc(atomic_t *v);
+
+/**
+ * atomic_inc_and_test - increment and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1
+ * and returns true if the result is zero, or false for all
+ * other cases.
+ */
+static inline int atomic_inc_and_test(atomic_t *v);
+
+/**
+ * atomic_dec - decrement atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1.
+ */
+static inline void atomic_dec(atomic_t *v);
+
+/**
+ * atomic_dec_and_test - decrement and test
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1 and
+ * returns true if the result is 0, or false for all other
+ * cases.
+ */
+static inline int atomic_dec_and_test(atomic_t *v);
+
+/**
+ * atomic_add_negative - add and test if negative
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns true
+ * if the result is negative, or false when
+ * result is greater than or equal to zero.
+ */
+static inline int atomic_add_negative(int i, atomic_t *v);
+
+#endif /* __XEN_ATOMIC_H__ */
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 5/8] fix: make atomic_read() param const
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
                   ` (3 preceding siblings ...)
  2016-07-14  9:12 ` [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h) Corneliu ZUZU
@ 2016-07-14  9:13 ` Corneliu ZUZU
  2016-07-14  9:26   ` Andrew Cooper
  2016-07-14  9:13 ` [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions Corneliu ZUZU
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:13 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Jan Beulich

This wouldn't let me make a param of a function that used atomic_read() const.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

---
Changed since v2: <nothing>
---
 xen/include/asm-arm/atomic.h | 2 +-
 xen/include/asm-x86/atomic.h | 2 +-
 xen/include/xen/atomic.h     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index a79420a..78dad29 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -102,7 +102,7 @@ void __bad_atomic_size(void);
  * strex/ldrex monitor on some implementations. The reason we can use it for
  * atomic_set() is the clrex or dummy strex done on every exception return.
  */
-static inline int atomic_read(atomic_t *v)
+static inline int atomic_read(const atomic_t *v)
 {
     return *(volatile int *)&v->counter;
 }
diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index 3e99b03..1729e29 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -80,7 +80,7 @@ void __bad_atomic_size(void);
     }                                                     \
 })
 
-static inline int atomic_read(atomic_t *v)
+static inline int atomic_read(const atomic_t *v)
 {
     return read_atomic(&v->counter);
 }
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
index d072912..6827468 100644
--- a/xen/include/xen/atomic.h
+++ b/xen/include/xen/atomic.h
@@ -32,7 +32,7 @@ typedef struct { int counter; } atomic_t;
  *
  * Atomically reads the value of @v.
  */
-static inline int atomic_read(atomic_t *v);
+static inline int atomic_read(const atomic_t *v);
 
 /**
  * _atomic_read - read atomic variable non-atomically
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
                   ` (4 preceding siblings ...)
  2016-07-14  9:13 ` [PATCH v3 5/8] fix: make atomic_read() param const Corneliu ZUZU
@ 2016-07-14  9:13 ` Corneliu ZUZU
  2016-07-14 10:50   ` Stefano Stabellini
  2016-07-14  9:14 ` [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless() Corneliu ZUZU
  2016-07-14  9:14 ` [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes Corneliu ZUZU
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:13 UTC (permalink / raw)
  To: xen-devel; +Cc: Julien Grall, Stefano Stabellini

Turn atomic_inc_return and atomic_dec_return atomic.h macros to inline
functions.

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
 xen/include/asm-arm/atomic.h | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index 78dad29..c69aae6 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -130,9 +130,6 @@ static inline void _atomic_set(atomic_t *v, int i)
 # error "unknown ARM variant"
 #endif
 
-#define atomic_inc_return(v)        (atomic_add_return(1, v))
-#define atomic_dec_return(v)        (atomic_sub_return(1, v))
-
 static inline int atomic_sub_and_test(int i, atomic_t *v)
 {
     return atomic_sub_return(i, v) == 0;
@@ -143,6 +140,11 @@ static inline void atomic_inc(atomic_t *v)
     atomic_add(1, v);
 }
 
+static inline int atomic_inc_return(atomic_t *v)
+{
+    return atomic_add_return(1, v);
+}
+
 static inline int atomic_inc_and_test(atomic_t *v)
 {
     return atomic_add_return(1, v) == 0;
@@ -153,6 +155,11 @@ static inline void atomic_dec(atomic_t *v)
     atomic_sub(1, v);
 }
 
+static inline int atomic_dec_return(atomic_t *v)
+{
+    return atomic_sub_return(1, v);
+}
+
 static inline int atomic_dec_and_test(atomic_t *v)
 {
     return atomic_sub_return(1, v) == 0;
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless()
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
                   ` (5 preceding siblings ...)
  2016-07-14  9:13 ` [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions Corneliu ZUZU
@ 2016-07-14  9:14 ` Corneliu ZUZU
  2016-07-14 10:00   ` Julien Grall
  2016-07-14  9:14 ` [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes Corneliu ZUZU
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:14 UTC (permalink / raw)
  To: xen-devel; +Cc: Julien Grall, Stefano Stabellini

The built-in leading underscores ('__') don't serve any purpose, so rename
__atomic_add_unless() -> atomic_add_unless().

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
 xen/include/asm-arm/arm32/atomic.h | 2 +-
 xen/include/asm-arm/arm64/atomic.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/include/asm-arm/arm32/atomic.h b/xen/include/asm-arm/arm32/atomic.h
index 78de60f..dc95518 100644
--- a/xen/include/asm-arm/arm32/atomic.h
+++ b/xen/include/asm-arm/arm32/atomic.h
@@ -121,7 +121,7 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
 	return oldval;
 }
 
-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
 {
 	int oldval, newval;
 	unsigned long tmp;
diff --git a/xen/include/asm-arm/arm64/atomic.h b/xen/include/asm-arm/arm64/atomic.h
index d640bef..f0e83be 100644
--- a/xen/include/asm-arm/arm64/atomic.h
+++ b/xen/include/asm-arm/arm64/atomic.h
@@ -114,7 +114,7 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
 	return oldval;
 }
 
-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
 {
 	int c, old;
 
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
  2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
                   ` (6 preceding siblings ...)
  2016-07-14  9:14 ` [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless() Corneliu ZUZU
@ 2016-07-14  9:14 ` Corneliu ZUZU
  2016-07-14  9:29   ` Andrew Cooper
  7 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:14 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Jan Beulich

- implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
  on X86 and also add prototypes for them in common <xen/atomic.h>

- add missing macro atomic_xchg for X86

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
---
 xen/include/asm-x86/atomic.h | 27 +++++++++++++++++++++++++++
 xen/include/xen/atomic.h     | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
index 1729e29..101eded 100644
--- a/xen/include/asm-x86/atomic.h
+++ b/xen/include/asm-x86/atomic.h
@@ -126,6 +126,11 @@ static inline void atomic_sub(int i, atomic_t *v)
         : "ir" (i), "m" (*(volatile int *)&v->counter) );
 }
 
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+    return arch_fetch_and_add(&v->counter, -i) - i;
+}
+
 static inline int atomic_sub_and_test(int i, atomic_t *v)
 {
     unsigned char c;
@@ -145,6 +150,11 @@ static inline void atomic_inc(atomic_t *v)
         : "m" (*(volatile int *)&v->counter) );
 }
 
+static inline int atomic_inc_return(atomic_t *v)
+{
+    return atomic_add_return(1, v);
+}
+
 static inline int atomic_inc_and_test(atomic_t *v)
 {
     unsigned char c;
@@ -164,6 +174,11 @@ static inline void atomic_dec(atomic_t *v)
         : "m" (*(volatile int *)&v->counter) );
 }
 
+static inline int atomic_dec_return(atomic_t *v)
+{
+    return atomic_sub_return(1, v);
+}
+
 static inline int atomic_dec_and_test(atomic_t *v)
 {
     unsigned char c;
@@ -186,4 +201,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
     return c;
 }
 
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+    int c, old;
+
+    c = atomic_read(v);
+    while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c)
+        c = old;
+    return c;
+}
+
+#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
+
 #endif /* __ARCH_X86_ATOMIC__ */
diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
index 6827468..529213e 100644
--- a/xen/include/xen/atomic.h
+++ b/xen/include/xen/atomic.h
@@ -111,6 +111,15 @@ static inline int atomic_add_return(int i, atomic_t *v);
 static inline void atomic_sub(int i, atomic_t *v);
 
 /**
+ * atomic_sub_return - sub integer and return
+ * @i: integer value to sub
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v and returns @v - @i.
+ */
+static inline int atomic_sub_return(int i, atomic_t *v);
+
+/**
  * atomic_sub_and_test - subtract value from variable and test result
  * @i: integer value to subtract
  * @v: pointer of type atomic_t
@@ -130,6 +139,14 @@ static inline int atomic_sub_and_test(int i, atomic_t *v);
 static inline void atomic_inc(atomic_t *v);
 
 /**
+ * atomic_inc_return - increment atomic variable and return
+ * @v: pointer of type atomic_t
+ *
+ * Atomically increments @v by 1 and returns @v + 1.
+ */
+static inline int atomic_inc_return(atomic_t *v);
+
+/**
  * atomic_inc_and_test - increment and test
  * @v: pointer of type atomic_t
  *
@@ -148,6 +165,14 @@ static inline int atomic_inc_and_test(atomic_t *v);
 static inline void atomic_dec(atomic_t *v);
 
 /**
+ * atomic_dec_return - decrement atomic variable and return
+ * @v: pointer of type atomic_t
+ *
+ * Atomically decrements @v by 1 and returns @v - 1.
+ */
+static inline int atomic_dec_return(atomic_t *v);
+
+/**
  * atomic_dec_and_test - decrement and test
  * @v: pointer of type atomic_t
  *
@@ -168,4 +193,15 @@ static inline int atomic_dec_and_test(atomic_t *v);
  */
 static inline int atomic_add_negative(int i, atomic_t *v);
 
+/**
+ * atomic_add_unless - add to atomic variable unless it has a specified value
+ * @v: pointer of type atomic_t
+ * @a: integer value to add
+ * @u: integer value @v must -not- be for the add to be performed
+ *
+ * If @v != @u, adds @a to @v and returns @v + @a.
+ * Otherwise returns @u (== @v).
+ */
+static inline int atomic_add_unless(atomic_t *v, int a, int u);
+
 #endif /* __XEN_ATOMIC_H__ */
-- 
2.5.0


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 5/8] fix: make atomic_read() param const
  2016-07-14  9:13 ` [PATCH v3 5/8] fix: make atomic_read() param const Corneliu ZUZU
@ 2016-07-14  9:26   ` Andrew Cooper
  2016-07-14  9:31     ` Corneliu ZUZU
  2016-07-14  9:33     ` Corneliu ZUZU
  0 siblings, 2 replies; 22+ messages in thread
From: Andrew Cooper @ 2016-07-14  9:26 UTC (permalink / raw)
  To: Corneliu ZUZU, xen-devel; +Cc: Julien Grall, Stefano Stabellini, Jan Beulich

On 14/07/16 10:13, Corneliu ZUZU wrote:
> This wouldn't let me make a param of a function that used atomic_read() const.
>
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

You have dropped a Reviewed-by: Stefano Stabellini
<sstabellini@kernel.org> from v2.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement
  2016-07-14  9:10 ` [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement Corneliu ZUZU
@ 2016-07-14  9:27   ` Andrew Cooper
  0 siblings, 0 replies; 22+ messages in thread
From: Andrew Cooper @ 2016-07-14  9:27 UTC (permalink / raw)
  To: Corneliu ZUZU, xen-devel; +Cc: Jan Beulich


[-- Attachment #1.1: Type: text/plain, Size: 241 bytes --]

On 14/07/16 10:10, Corneliu ZUZU wrote:
> Place atomic_inc_and_test() implementation after atomic_inc().
> Also empty line fix.
>
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

[-- Attachment #1.2: Type: text/html, Size: 805 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
  2016-07-14  9:14 ` [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes Corneliu ZUZU
@ 2016-07-14  9:29   ` Andrew Cooper
  2016-07-14  9:39     ` Corneliu ZUZU
  0 siblings, 1 reply; 22+ messages in thread
From: Andrew Cooper @ 2016-07-14  9:29 UTC (permalink / raw)
  To: Corneliu ZUZU, xen-devel; +Cc: Jan Beulich


[-- Attachment #1.1: Type: text/plain, Size: 349 bytes --]

On 14/07/16 10:14, Corneliu ZUZU wrote:
> - implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
>   on X86 and also add prototypes for them in common <xen/atomic.h>
>
> - add missing macro atomic_xchg for X86
>
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

[-- Attachment #1.2: Type: text/html, Size: 903 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 5/8] fix: make atomic_read() param const
  2016-07-14  9:26   ` Andrew Cooper
@ 2016-07-14  9:31     ` Corneliu ZUZU
  2016-07-14  9:33     ` Corneliu ZUZU
  1 sibling, 0 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:31 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel; +Cc: Julien Grall, Stefano Stabellini, Jan Beulich

On 7/14/2016 12:26 PM, Andrew Cooper wrote:
> On 14/07/16 10:13, Corneliu ZUZU wrote:
>> This wouldn't let me make a param of a function that used atomic_read() const.
>>
>> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
>> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> You have dropped a Reviewed-by: Stefano Stabellini
> <sstabellini@kernel.org> from v2.
>
> ~Andrew
>

Intentionally dropped, he reviewed the empty line fixes in ARM atomic.h 
- which were now moved to 1/8 (which includes Reviewed-by: [...]).

Zuzu C.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 5/8] fix: make atomic_read() param const
  2016-07-14  9:26   ` Andrew Cooper
  2016-07-14  9:31     ` Corneliu ZUZU
@ 2016-07-14  9:33     ` Corneliu ZUZU
  1 sibling, 0 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:33 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel; +Cc: Julien Grall, Stefano Stabellini, Jan Beulich

On 7/14/2016 12:26 PM, Andrew Cooper wrote:
> On 14/07/16 10:13, Corneliu ZUZU wrote:
>> This wouldn't let me make a param of a function that used atomic_read() const.
>>
>> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
>> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
> You have dropped a Reviewed-by: Stefano Stabellini
> <sstabellini@kernel.org> from v2.
>
> ~Andrew

Oh, that's right, sorry.

Zuzu C.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
  2016-07-14  9:29   ` Andrew Cooper
@ 2016-07-14  9:39     ` Corneliu ZUZU
  2016-07-14  9:44       ` Andrew Cooper
  0 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:39 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel; +Cc: Jan Beulich


[-- Attachment #1.1: Type: text/plain, Size: 574 bytes --]

On 7/14/2016 12:29 PM, Andrew Cooper wrote:
> On 14/07/16 10:14, Corneliu ZUZU wrote:
>> - implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
>>    on X86 and also add prototypes for them in common <xen/atomic.h>
>>
>> - add missing macro atomic_xchg for X86
>>
>> Signed-off-by: Corneliu ZUZU<czuzu@bitdefender.com>
>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

I'm not sure about atomic_sub_return(int i, atomic_t *v) implementation 
- is it ok? (calling arch_fetch_and_add(&v->counter, -i) with 2nd 
argument negative).

Zuzu C.

[-- Attachment #1.2: Type: text/html, Size: 1477 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
  2016-07-14  9:39     ` Corneliu ZUZU
@ 2016-07-14  9:44       ` Andrew Cooper
  2016-07-14  9:48         ` Corneliu ZUZU
  0 siblings, 1 reply; 22+ messages in thread
From: Andrew Cooper @ 2016-07-14  9:44 UTC (permalink / raw)
  To: Corneliu ZUZU, xen-devel; +Cc: Jan Beulich


[-- Attachment #1.1: Type: text/plain, Size: 784 bytes --]

On 14/07/16 10:39, Corneliu ZUZU wrote:
> On 7/14/2016 12:29 PM, Andrew Cooper wrote:
>> On 14/07/16 10:14, Corneliu ZUZU wrote:
>>> - implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
>>>   on X86 and also add prototypes for them in common <xen/atomic.h>
>>>
>>> - add missing macro atomic_xchg for X86
>>>
>>> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
>>
>> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> I'm not sure about atomic_sub_return(int i, atomic_t *v)
> implementation - is it ok? (calling arch_fetch_and_add(&v->counter,
> -i) with 2nd argument negative).

Looks ok to me.  Everything is signed integers in the internals.

There is a boundary condition when passing INT_MIN, but those exist
elsewhere as well.

~Andrew

[-- Attachment #1.2: Type: text/html, Size: 1927 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
  2016-07-14  9:44       ` Andrew Cooper
@ 2016-07-14  9:48         ` Corneliu ZUZU
  0 siblings, 0 replies; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14  9:48 UTC (permalink / raw)
  To: Andrew Cooper, xen-devel; +Cc: Jan Beulich


[-- Attachment #1.1: Type: text/plain, Size: 1011 bytes --]

On 7/14/2016 12:44 PM, Andrew Cooper wrote:
> On 14/07/16 10:39, Corneliu ZUZU wrote:
>> On 7/14/2016 12:29 PM, Andrew Cooper wrote:
>>> On 14/07/16 10:14, Corneliu ZUZU wrote:
>>>> - implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
>>>>    on X86 and also add prototypes for them in common <xen/atomic.h>
>>>>
>>>> - add missing macro atomic_xchg for X86
>>>>
>>>> Signed-off-by: Corneliu ZUZU<czuzu@bitdefender.com>
>>>
>>> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>>
>> I'm not sure about atomic_sub_return(int i, atomic_t *v) 
>> implementation - is it ok? (calling arch_fetch_and_add(&v->counter, 
>> -i) with 2nd argument negative).
>
> Looks ok to me.  Everything is signed integers in the internals.
>
> There is a boundary condition when passing INT_MIN, but those exist 
> elsewhere as well.
>
> ~Andrew

Thanks, thought so too - there should be no difference bit-wise when 
adding an unsigned int converted from an int vs adding the int directly.

Zuzu C.

[-- Attachment #1.2: Type: text/html, Size: 2503 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless()
  2016-07-14  9:14 ` [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless() Corneliu ZUZU
@ 2016-07-14 10:00   ` Julien Grall
  2016-07-14 10:03     ` Corneliu ZUZU
  0 siblings, 1 reply; 22+ messages in thread
From: Julien Grall @ 2016-07-14 10:00 UTC (permalink / raw)
  To: Corneliu ZUZU, xen-devel; +Cc: Stefano Stabellini

Hi Corneliu,

On 14/07/16 10:14, Corneliu ZUZU wrote:
> The built-in leading underscores ('__') don't serve any purpose, so rename
> __atomic_add_unless() -> atomic_add_unless().

The leading underscores are from the Linux code. We decided to keep 
those files unmodified to help syncing atomic code.

So I am not in favor of dropping the '__'. If you want to use these 
functions in the common code, then a wrapper in "asm-arm/atomic.h" 
should be introduced.

Regards,

>
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
> ---
>   xen/include/asm-arm/arm32/atomic.h | 2 +-
>   xen/include/asm-arm/arm64/atomic.h | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/xen/include/asm-arm/arm32/atomic.h b/xen/include/asm-arm/arm32/atomic.h
> index 78de60f..dc95518 100644
> --- a/xen/include/asm-arm/arm32/atomic.h
> +++ b/xen/include/asm-arm/arm32/atomic.h
> @@ -121,7 +121,7 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
>   	return oldval;
>   }
>
> -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
> +static inline int atomic_add_unless(atomic_t *v, int a, int u)
>   {
>   	int oldval, newval;
>   	unsigned long tmp;
> diff --git a/xen/include/asm-arm/arm64/atomic.h b/xen/include/asm-arm/arm64/atomic.h
> index d640bef..f0e83be 100644
> --- a/xen/include/asm-arm/arm64/atomic.h
> +++ b/xen/include/asm-arm/arm64/atomic.h
> @@ -114,7 +114,7 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
>   	return oldval;
>   }
>
> -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
> +static inline int atomic_add_unless(atomic_t *v, int a, int u)
>   {
>   	int c, old;
>
>

-- 
Julien Grall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless()
  2016-07-14 10:00   ` Julien Grall
@ 2016-07-14 10:03     ` Corneliu ZUZU
  2016-07-14 10:50       ` Stefano Stabellini
  0 siblings, 1 reply; 22+ messages in thread
From: Corneliu ZUZU @ 2016-07-14 10:03 UTC (permalink / raw)
  To: Julien Grall, xen-devel; +Cc: Stefano Stabellini

On 7/14/2016 1:00 PM, Julien Grall wrote:
> Hi Corneliu,
>
> On 14/07/16 10:14, Corneliu ZUZU wrote:
>> The built-in leading underscores ('__') don't serve any purpose, so 
>> rename
>> __atomic_add_unless() -> atomic_add_unless().
>
> The leading underscores are from the Linux code. We decided to keep 
> those files unmodified to help syncing atomic code.
>
> So I am not in favor of dropping the '__'. If you want to use these 
> functions in the common code, then a wrapper in "asm-arm/atomic.h" 
> should be introduced.
>
> Regards,

Ok, great. Either add a wrapper or maybe keeping the underscores on X86 
too and not including it's prototype in <xen/atomic.h>. What would you 
prefer?

Zuzu C.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless()
  2016-07-14 10:03     ` Corneliu ZUZU
@ 2016-07-14 10:50       ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2016-07-14 10:50 UTC (permalink / raw)
  To: Corneliu ZUZU; +Cc: Julien Grall, Stefano Stabellini, xen-devel

On Thu, 14 Jul 2016, Corneliu ZUZU wrote:
> On 7/14/2016 1:00 PM, Julien Grall wrote:
> > Hi Corneliu,
> > 
> > On 14/07/16 10:14, Corneliu ZUZU wrote:
> > > The built-in leading underscores ('__') don't serve any purpose, so rename
> > > __atomic_add_unless() -> atomic_add_unless().
> > 
> > The leading underscores are from the Linux code. We decided to keep those
> > files unmodified to help syncing atomic code.
> > 
> > So I am not in favor of dropping the '__'. If you want to use these
> > functions in the common code, then a wrapper in "asm-arm/atomic.h" should be
> > introduced.
> > 
> > Regards,
> 
> Ok, great. Either add a wrapper or maybe keeping the underscores on X86 too
> and not including it's prototype in <xen/atomic.h>. What would you prefer?

Add a wrapper

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions
  2016-07-14  9:13 ` [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions Corneliu ZUZU
@ 2016-07-14 10:50   ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2016-07-14 10:50 UTC (permalink / raw)
  To: Corneliu ZUZU; +Cc: Julien Grall, Stefano Stabellini, xen-devel

On Thu, 14 Jul 2016, Corneliu ZUZU wrote:
> Turn atomic_inc_return and atomic_dec_return atomic.h macros to inline
> functions.
> 
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


>  xen/include/asm-arm/atomic.h | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
> index 78dad29..c69aae6 100644
> --- a/xen/include/asm-arm/atomic.h
> +++ b/xen/include/asm-arm/atomic.h
> @@ -130,9 +130,6 @@ static inline void _atomic_set(atomic_t *v, int i)
>  # error "unknown ARM variant"
>  #endif
>  
> -#define atomic_inc_return(v)        (atomic_add_return(1, v))
> -#define atomic_dec_return(v)        (atomic_sub_return(1, v))
> -
>  static inline int atomic_sub_and_test(int i, atomic_t *v)
>  {
>      return atomic_sub_return(i, v) == 0;
> @@ -143,6 +140,11 @@ static inline void atomic_inc(atomic_t *v)
>      atomic_add(1, v);
>  }
>  
> +static inline int atomic_inc_return(atomic_t *v)
> +{
> +    return atomic_add_return(1, v);
> +}
> +
>  static inline int atomic_inc_and_test(atomic_t *v)
>  {
>      return atomic_add_return(1, v) == 0;
> @@ -153,6 +155,11 @@ static inline void atomic_dec(atomic_t *v)
>      atomic_sub(1, v);
>  }
>  
> +static inline int atomic_dec_return(atomic_t *v)
> +{
> +    return atomic_sub_return(1, v);
> +}
> +
>  static inline int atomic_dec_and_test(atomic_t *v)
>  {
>      return atomic_sub_return(1, v) == 0;
> -- 
> 2.5.0
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h)
  2016-07-14  9:12 ` [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h) Corneliu ZUZU
@ 2016-07-14 10:52   ` Stefano Stabellini
  0 siblings, 0 replies; 22+ messages in thread
From: Stefano Stabellini @ 2016-07-14 10:52 UTC (permalink / raw)
  To: Corneliu ZUZU
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Jan Beulich, xen-devel

On Thu, 14 Jul 2016, Corneliu ZUZU wrote:
> Create a common-side <xen/atomic.h> to establish, among others, prototypes of
> atomic functions called from common-code. Done to avoid introducing
> inconsistencies between arch-side <asm/atomic.h> headers when we make subtle
> changes to one of them.
> 
> Some arm-side macros had to be turned into inline functions in the process.
> Removed outdated comment ("NB. I've [...]").
> 
> Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
> Suggested-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> Changed since v2:
>   * sample code for atomic_cmpxchg() (doc-comment in <xen/atomic.h>) updated to
>     use atomic_read() instead of directly accessing v.counter
> ---
>  xen/include/asm-arm/atomic.h |  45 ++++++++----
>  xen/include/asm-x86/atomic.h | 103 +-------------------------
>  xen/include/xen/atomic.h     | 171 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 202 insertions(+), 117 deletions(-)
>  create mode 100644 xen/include/xen/atomic.h
> 
> diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
> index 620c636..a79420a 100644
> --- a/xen/include/asm-arm/atomic.h
> +++ b/xen/include/asm-arm/atomic.h
> @@ -2,6 +2,7 @@
>  #define __ARCH_ARM_ATOMIC__
>  
>  #include <xen/config.h>
> +#include <xen/atomic.h>
>  #include <xen/prefetch.h>
>  #include <asm/system.h>
>  
> @@ -95,15 +96,6 @@ void __bad_atomic_size(void);
>      default: __bad_atomic_size(); break;                                \
>      }                                                                   \
>  })
> -    
> -/*
> - * NB. I've pushed the volatile qualifier into the operations. This allows
> - * fast accessors such as _atomic_read() and _atomic_set() which don't give
> - * the compiler a fit.
> - */
> -typedef struct { int counter; } atomic_t;
> -
> -#define ATOMIC_INIT(i) { (i) }
>  
>  /*
>   * On ARM, ordinary assignment (str instruction) doesn't clear the local
> @@ -141,12 +133,35 @@ static inline void _atomic_set(atomic_t *v, int i)
>  #define atomic_inc_return(v)        (atomic_add_return(1, v))
>  #define atomic_dec_return(v)        (atomic_sub_return(1, v))
>  
> -#define atomic_sub_and_test(i, v)   (atomic_sub_return(i, v) == 0)
> -#define atomic_inc(v)               atomic_add(1, v)
> -#define atomic_inc_and_test(v)      (atomic_add_return(1, v) == 0)
> -#define atomic_dec(v)               atomic_sub(1, v)
> -#define atomic_dec_and_test(v)      (atomic_sub_return(1, v) == 0)
> -#define atomic_add_negative(i,v)    (atomic_add_return(i, v) < 0)
> +static inline int atomic_sub_and_test(int i, atomic_t *v)
> +{
> +    return atomic_sub_return(i, v) == 0;
> +}
> +
> +static inline void atomic_inc(atomic_t *v)
> +{
> +    atomic_add(1, v);
> +}
> +
> +static inline int atomic_inc_and_test(atomic_t *v)
> +{
> +    return atomic_add_return(1, v) == 0;
> +}
> +
> +static inline void atomic_dec(atomic_t *v)
> +{
> +    atomic_sub(1, v);
> +}
> +
> +static inline int atomic_dec_and_test(atomic_t *v)
> +{
> +    return atomic_sub_return(1, v) == 0;
> +}
> +
> +static inline int atomic_add_negative(int i, atomic_t *v)
> +{
> +    return atomic_add_return(i, v) < 0;
> +}
>  
>  #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
>  
> diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h
> index 5f9f2dd..3e99b03 100644
> --- a/xen/include/asm-x86/atomic.h
> +++ b/xen/include/asm-x86/atomic.h
> @@ -2,6 +2,7 @@
>  #define __ARCH_X86_ATOMIC__
>  
>  #include <xen/config.h>
> +#include <xen/atomic.h>
>  #include <asm/system.h>
>  
>  #define build_read_atomic(name, size, type, reg, barrier) \
> @@ -79,56 +80,21 @@ void __bad_atomic_size(void);
>      }                                                     \
>  })
>  
> -/*
> - * NB. I've pushed the volatile qualifier into the operations. This allows
> - * fast accessors such as _atomic_read() and _atomic_set() which don't give
> - * the compiler a fit.
> - */
> -typedef struct { int counter; } atomic_t;
> -
> -#define ATOMIC_INIT(i) { (i) }
> -
> -/**
> - * atomic_read - read atomic variable
> - * @v: pointer of type atomic_t
> - *
> - * Atomically reads the value of @v.
> - */
>  static inline int atomic_read(atomic_t *v)
>  {
>      return read_atomic(&v->counter);
>  }
>  
> -/**
> - * _atomic_read - read atomic variable non-atomically
> - * @v atomic_t
> - *
> - * Non-atomically reads the value of @v
> - */
>  static inline int _atomic_read(atomic_t v)
>  {
>      return v.counter;
>  }
>  
> -/**
> - * atomic_set - set atomic variable
> - * @v: pointer of type atomic_t
> - * @i: required value
> - *
> - * Atomically sets the value of @v to @i.
> - */
>  static inline void atomic_set(atomic_t *v, int i)
>  {
>      write_atomic(&v->counter, i);
>  }
>  
> -/**
> - * _atomic_set - set atomic variable non-atomically
> - * @v: pointer of type atomic_t
> - * @i: required value
> - *
> - * Non-atomically sets the value of @v to @i.
> - */
>  static inline void _atomic_set(atomic_t *v, int i)
>  {
>      v->counter = i;
> @@ -139,13 +105,6 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
>      return cmpxchg(&v->counter, old, new);
>  }
>  
> -/**
> - * atomic_add - add integer to atomic variable
> - * @i: integer value to add
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically adds @i to @v.
> - */
>  static inline void atomic_add(int i, atomic_t *v)
>  {
>      asm volatile (
> @@ -154,25 +113,11 @@ static inline void atomic_add(int i, atomic_t *v)
>          : "ir" (i), "m" (*(volatile int *)&v->counter) );
>  }
>  
> -/**
> - * atomic_add_return - add integer and return
> - * @i: integer value to add
> - * @v: pointer of type atomic_t
> - *
> - * Atomically adds @i to @v and returns @i + @v
> - */
>  static inline int atomic_add_return(int i, atomic_t *v)
>  {
>      return i + arch_fetch_and_add(&v->counter, i);
>  }
>  
> -/**
> - * atomic_sub - subtract the atomic variable
> - * @i: integer value to subtract
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically subtracts @i from @v.
> - */
>  static inline void atomic_sub(int i, atomic_t *v)
>  {
>      asm volatile (
> @@ -181,15 +126,6 @@ static inline void atomic_sub(int i, atomic_t *v)
>          : "ir" (i), "m" (*(volatile int *)&v->counter) );
>  }
>  
> -/**
> - * atomic_sub_and_test - subtract value from variable and test result
> - * @i: integer value to subtract
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically subtracts @i from @v and returns
> - * true if the result is zero, or false for all
> - * other cases.
> - */
>  static inline int atomic_sub_and_test(int i, atomic_t *v)
>  {
>      unsigned char c;
> @@ -201,12 +137,6 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
>      return c;
>  }
>  
> -/**
> - * atomic_inc - increment atomic variable
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically increments @v by 1.
> - */ 
>  static inline void atomic_inc(atomic_t *v)
>  {
>      asm volatile (
> @@ -215,14 +145,6 @@ static inline void atomic_inc(atomic_t *v)
>          : "m" (*(volatile int *)&v->counter) );
>  }
>  
> -/**
> - * atomic_inc_and_test - increment and test
> - * @v: pointer of type atomic_t
> - *
> - * Atomically increments @v by 1
> - * and returns true if the result is zero, or false for all
> - * other cases.
> - */
>  static inline int atomic_inc_and_test(atomic_t *v)
>  {
>      unsigned char c;
> @@ -234,12 +156,6 @@ static inline int atomic_inc_and_test(atomic_t *v)
>      return c != 0;
>  }
>  
> -/**
> - * atomic_dec - decrement atomic variable
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically decrements @v by 1.
> - */ 
>  static inline void atomic_dec(atomic_t *v)
>  {
>      asm volatile (
> @@ -248,14 +164,6 @@ static inline void atomic_dec(atomic_t *v)
>          : "m" (*(volatile int *)&v->counter) );
>  }
>  
> -/**
> - * atomic_dec_and_test - decrement and test
> - * @v: pointer of type atomic_t
> - * 
> - * Atomically decrements @v by 1 and
> - * returns true if the result is 0, or false for all other
> - * cases.
> - */ 
>  static inline int atomic_dec_and_test(atomic_t *v)
>  {
>      unsigned char c;
> @@ -267,15 +175,6 @@ static inline int atomic_dec_and_test(atomic_t *v)
>      return c != 0;
>  }
>  
> -/**
> - * atomic_add_negative - add and test if negative
> - * @v: pointer of type atomic_t
> - * @i: integer value to add
> - * 
> - * Atomically adds @i to @v and returns true
> - * if the result is negative, or false when
> - * result is greater than or equal to zero.
> - */ 
>  static inline int atomic_add_negative(int i, atomic_t *v)
>  {
>      unsigned char c;
> diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h
> new file mode 100644
> index 0000000..d072912
> --- /dev/null
> +++ b/xen/include/xen/atomic.h
> @@ -0,0 +1,171 @@
> +/*
> + * include/xen/atomic.h
> + *
> + * Common atomic operations entities (atomic_t, function prototypes).
> + * Include _from_ arch-side <asm/atomic.h>.
> + *
> + * Copyright (c) 2016 Bitdefender S.R.L.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#ifndef __XEN_ATOMIC_H__
> +#define __XEN_ATOMIC_H__
> +
> +typedef struct { int counter; } atomic_t;
> +
> +#define ATOMIC_INIT(i) { (i) }
> +
> +/**
> + * atomic_read - read atomic variable
> + * @v: pointer of type atomic_t
> + *
> + * Atomically reads the value of @v.
> + */
> +static inline int atomic_read(atomic_t *v);
> +
> +/**
> + * _atomic_read - read atomic variable non-atomically
> + * @v atomic_t
> + *
> + * Non-atomically reads the value of @v
> + */
> +static inline int _atomic_read(atomic_t v);
> +
> +/**
> + * atomic_set - set atomic variable
> + * @v: pointer of type atomic_t
> + * @i: required value
> + *
> + * Atomically sets the value of @v to @i.
> + */
> +static inline void atomic_set(atomic_t *v, int i);
> +
> +/**
> + * _atomic_set - set atomic variable non-atomically
> + * @v: pointer of type atomic_t
> + * @i: required value
> + *
> + * Non-atomically sets the value of @v to @i.
> + */
> +static inline void _atomic_set(atomic_t *v, int i);
> +
> +/**
> + * atomic_cmpxchg - compare and exchange an atomic variable
> + * @v: pointer of type atomic_t
> + * @old: old value
> + * @new: new value
> + *
> + * Before calling, @old should be set to @v.
> + * Succeeds if @old == @v (likely), in which case stores @new in @v.
> + * Returns the initial value in @v, hence succeeds when the return value
> + * matches that of @old.
> + *
> + * Sample (tries atomic increment of v until the operation succeeds):
> + *
> + *  while(1)
> + *  {
> + *      int old = atomic_read(&v);
> + *      int new = old + 1;
> + *      if ( likely(old == atomic_cmpxchg(&v, old, new)) )
> + *          break; // success!
> + *  }
> + */
> +static inline int atomic_cmpxchg(atomic_t *v, int old, int new);
> +
> +/**
> + * atomic_add - add integer to atomic variable
> + * @i: integer value to add
> + * @v: pointer of type atomic_t
> + *
> + * Atomically adds @i to @v.
> + */
> +static inline void atomic_add(int i, atomic_t *v);
> +
> +/**
> + * atomic_add_return - add integer and return
> + * @i: integer value to add
> + * @v: pointer of type atomic_t
> + *
> + * Atomically adds @i to @v and returns @i + @v
> + */
> +static inline int atomic_add_return(int i, atomic_t *v);
> +
> +/**
> + * atomic_sub - subtract the atomic variable
> + * @i: integer value to subtract
> + * @v: pointer of type atomic_t
> + *
> + * Atomically subtracts @i from @v.
> + */
> +static inline void atomic_sub(int i, atomic_t *v);
> +
> +/**
> + * atomic_sub_and_test - subtract value from variable and test result
> + * @i: integer value to subtract
> + * @v: pointer of type atomic_t
> + *
> + * Atomically subtracts @i from @v and returns
> + * true if the result is zero, or false for all
> + * other cases.
> + */
> +static inline int atomic_sub_and_test(int i, atomic_t *v);
> +
> +/**
> + * atomic_inc - increment atomic variable
> + * @v: pointer of type atomic_t
> + *
> + * Atomically increments @v by 1.
> + */
> +static inline void atomic_inc(atomic_t *v);
> +
> +/**
> + * atomic_inc_and_test - increment and test
> + * @v: pointer of type atomic_t
> + *
> + * Atomically increments @v by 1
> + * and returns true if the result is zero, or false for all
> + * other cases.
> + */
> +static inline int atomic_inc_and_test(atomic_t *v);
> +
> +/**
> + * atomic_dec - decrement atomic variable
> + * @v: pointer of type atomic_t
> + *
> + * Atomically decrements @v by 1.
> + */
> +static inline void atomic_dec(atomic_t *v);
> +
> +/**
> + * atomic_dec_and_test - decrement and test
> + * @v: pointer of type atomic_t
> + *
> + * Atomically decrements @v by 1 and
> + * returns true if the result is 0, or false for all other
> + * cases.
> + */
> +static inline int atomic_dec_and_test(atomic_t *v);
> +
> +/**
> + * atomic_add_negative - add and test if negative
> + * @v: pointer of type atomic_t
> + * @i: integer value to add
> + *
> + * Atomically adds @i to @v and returns true
> + * if the result is negative, or false when
> + * result is greater than or equal to zero.
> + */
> +static inline int atomic_add_negative(int i, atomic_t *v);
> +
> +#endif /* __XEN_ATOMIC_H__ */
> -- 
> 2.5.0
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-07-14 10:52 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-14  9:09 [PATCH v3 0/8] <asm/atomic.h> adjustments Corneliu ZUZU
2016-07-14  9:09 ` [PATCH v3 1/8] asm-arm/atomic.h: fix arm32|arm64 macros duplication Corneliu ZUZU
2016-07-14  9:10 ` [PATCH v3 2/8] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement Corneliu ZUZU
2016-07-14  9:27   ` Andrew Cooper
2016-07-14  9:11 ` [PATCH v3 3/8] asm-arm/atomic.h: reorder macros to match x86-side Corneliu ZUZU
2016-07-14  9:12 ` [PATCH v3 4/8] asm/atomic.h: common prototyping (add xen/atomic.h) Corneliu ZUZU
2016-07-14 10:52   ` Stefano Stabellini
2016-07-14  9:13 ` [PATCH v3 5/8] fix: make atomic_read() param const Corneliu ZUZU
2016-07-14  9:26   ` Andrew Cooper
2016-07-14  9:31     ` Corneliu ZUZU
2016-07-14  9:33     ` Corneliu ZUZU
2016-07-14  9:13 ` [PATCH v3 6/8] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions Corneliu ZUZU
2016-07-14 10:50   ` Stefano Stabellini
2016-07-14  9:14 ` [PATCH v3 7/8] arm/atomic.h: remove '__' prefix for __atomic_add_unless() Corneliu ZUZU
2016-07-14 10:00   ` Julien Grall
2016-07-14 10:03     ` Corneliu ZUZU
2016-07-14 10:50       ` Stefano Stabellini
2016-07-14  9:14 ` [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes Corneliu ZUZU
2016-07-14  9:29   ` Andrew Cooper
2016-07-14  9:39     ` Corneliu ZUZU
2016-07-14  9:44       ` Andrew Cooper
2016-07-14  9:48         ` Corneliu ZUZU

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.