xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Corneliu ZUZU <czuzu@bitdefender.com>
To: xen-devel@lists.xen.org
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v4 7/7] asm/atomic.h: implement missing and add common prototypes
Date: Fri, 15 Jul 2016 09:52:13 +0300	[thread overview]
Message-ID: <1468565533-385-1-git-send-email-czuzu@bitdefender.com> (raw)
In-Reply-To: <1468565278-32535-1-git-send-email-czuzu@bitdefender.com>

ARM (<asm-arm/atomic.h>):
* add atomic_add_unless() wrapper over __atomic_add_unless()
  (for common-code interface, i.e. <xen/atomic.h>)

X86 (<asm-x86/atomic.h>):
* implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless()
* implement missing macro atomic_xchg()

COMMON (<xen/atomic.h>):
* add prototypes for the aforementioned newly implemented X86 functions in
  common <xen/atomic.h>

Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
Changed since v3:
  * add wrapper over arm-side __atomic_add_unless() instead of removing the
    leading underscores
---
 xen/include/asm-arm/atomic.h |  5 +++++
 xen/include/asm-x86/atomic.h | 27 +++++++++++++++++++++++++++
 xen/include/xen/atomic.h     | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)

diff --git a/xen/include/asm-arm/atomic.h b/xen/include/asm-arm/atomic.h
index c69aae6..b6aaf57 100644
--- a/xen/include/asm-arm/atomic.h
+++ b/xen/include/asm-arm/atomic.h
@@ -170,6 +170,11 @@ static inline int atomic_add_negative(int i, atomic_t *v)
     return atomic_add_return(i, v) < 0;
 }
 
+static inline int atomic_add_unless(atomic_t *v, int a, int u)
+{
+    return __atomic_add_unless(v, a, u);
+}
+
 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
 
 #endif /* __ARCH_ARM_ATOMIC__ */
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

  parent reply	other threads:[~2016-07-15  6:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15  6:47 [PATCH v4 0/7] <asm/atomic.h> adjustments Corneliu ZUZU
2016-07-15  6:48 ` [PATCH v4 1/7] asm-arm/atomic.h: fix arm32|arm64 macros duplication Corneliu ZUZU
2016-07-15  9:28   ` Julien Grall
2016-07-15  9:55     ` Corneliu ZUZU
2016-07-15 10:06       ` Julien Grall
2016-07-15 10:17         ` Corneliu ZUZU
2016-07-15  6:48 ` [PATCH v4 2/7] asm-x86/atomic.h: minor: proper atomic_inc_and_test() placement Corneliu ZUZU
2016-07-15  6:49 ` [PATCH v4 3/7] asm-arm/atomic.h: reorder macros to match x86-side Corneliu ZUZU
2016-07-15  9:28   ` Julien Grall
2016-07-15  6:50 ` [PATCH v4 4/7] asm/atomic.h: common prototyping (add xen/atomic.h) Corneliu ZUZU
2016-07-15  9:30   ` Julien Grall
2016-07-15  9:59     ` Corneliu ZUZU
2016-07-15  6:50 ` [PATCH v4 5/7] xen/atomic.h: fix: make atomic_read() param const Corneliu ZUZU
2016-07-15  9:31   ` Julien Grall
2016-07-15  6:51 ` [PATCH v4 6/7] asm-arm/atomic.h: atomic_{inc, dec}_return: macros to inline functions Corneliu ZUZU
2016-07-15  6:59   ` Corneliu ZUZU
2016-07-15  6:52 ` Corneliu ZUZU [this message]
2016-07-15  9:34   ` [PATCH v4 7/7] asm/atomic.h: implement missing and add common prototypes Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468565533-385-1-git-send-email-czuzu@bitdefender.com \
    --to=czuzu@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).