From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xen.org
Cc: stefano.stabellini@citrix.com, tim@xen.org,
Ian Campbell <ian.campbell@citrix.com>,
ian.jackson@citrix.com
Subject: [PATCH 6/9] tools: memshr: arm64 support
Date: Fri, 15 Mar 2013 13:15:47 +0000 [thread overview]
Message-ID: <1363353350-32251-6-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1363353334.520.7.camel@zakaz.uk.xensource.com>
I'm not mad keen on propagating these sorts of asm atomic operations throughout
our code base. Other options would be:
- use libatomic-ops, http://www.hpl.hp.com/research/linux/atomic_ops/, although
this doesn't seem to be as widespread as I would like (not in RHEL5 for
example)
- use a pthread lock. This is probably the simplest/best option but I wasn't
able to figure out the locking hierarchy of this code
So I've coped out and just copied the appropriate inlines here.
I also nuked some stray ia64 support and fixed a coment in the arm32 version
while I was here.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
tools/memshr/bidir-hash.c | 48 +++++++++++++++++++++++++++++++++-----------
1 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/tools/memshr/bidir-hash.c b/tools/memshr/bidir-hash.c
index 45d473e..bed8179 100644
--- a/tools/memshr/bidir-hash.c
+++ b/tools/memshr/bidir-hash.c
@@ -100,22 +100,13 @@ int __hash_iterator(struct __hash *h,
void *d);
static void hash_resize(struct __hash *h);
-#if defined(__ia64__)
-#define ia64_fetchadd4_rel(p, inc) do { \
- uint64_t ia64_intri_res; \
- asm volatile ("fetchadd4.rel %0=[%1],%2" \
- : "=r"(ia64_intri_res) : "r"(p), "i" (inc) \
- : "memory"); \
-} while (0)
-static inline void atomic_inc(uint32_t *v) { ia64_fetchadd4_rel(v, 1); }
-static inline void atomic_dec(uint32_t *v) { ia64_fetchadd4_rel(v, -1); }
-#elif defined(__arm__)
+#if defined(__arm__)
static inline void atomic_inc(uint32_t *v)
{
unsigned long tmp;
int result;
- __asm__ __volatile__("@ atomic_add\n"
+ __asm__ __volatile__("@ atomic_inc\n"
"1: ldrex %0, [%3]\n"
" add %0, %0, #1\n"
" strex %1, %0, [%3]\n"
@@ -130,7 +121,7 @@ static inline void atomic_dec(uint32_t *v)
unsigned long tmp;
int result;
- __asm__ __volatile__("@ atomic_sub\n"
+ __asm__ __volatile__("@ atomic_dec\n"
"1: ldrex %0, [%3]\n"
" sub %0, %0, #1\n"
" strex %1, %0, [%3]\n"
@@ -140,6 +131,39 @@ static inline void atomic_dec(uint32_t *v)
: "r" (v)
: "cc");
}
+
+#elif defined(__aarch64__)
+
+static inline void atomic_inc(uint32_t *v)
+{
+ unsigned long tmp;
+ int result;
+
+ asm volatile("// atomic_inc\n"
+"1: ldxr %w0, [%3]\n"
+" add %w0, %w0, #1\n"
+" stxr %w1, %w0, [%3]\n"
+" cbnz %w1, 1b"
+ : "=&r" (result), "=&r" (tmp), "+o" (v)
+ : "r" (v)
+ : "cc");
+}
+
+static inline void atomic_dec(uint32_t *v)
+{
+ unsigned long tmp;
+ int result;
+
+ asm volatile("// atomic_dec\n"
+"1: ldxr %w0, [%3]\n"
+" sub %w0, %w0, #1\n"
+" stxr %w1, %w0, [%3]\n"
+" cbnz %w1, 1b"
+ : "=&r" (result), "=&r" (tmp), "+o" (v)
+ : "r" (v)
+ : "cc");
+}
+
#else /* __x86__ */
static inline void atomic_inc(uint32_t *v)
{
--
1.7.2.5
next prev parent reply other threads:[~2013-03-15 13:15 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-15 13:15 [PATCH 00/09] arm: tools: build for arm64 and enable cross-compiling for both arm32 and arm64 Ian Campbell
2013-03-15 13:15 ` [PATCH 1/9] tools: Use AC_SYS_LARGEFILE instead of calling getconf(1) Ian Campbell
2013-03-15 15:35 ` Ian Jackson
2013-03-15 13:15 ` [PATCH 2/9] blktap2: use sys/eventfd.h if it is available Ian Campbell
2013-03-15 15:24 ` Ian Jackson
2013-03-15 13:15 ` [PATCH 3/9] tools: only build blktap1 on x86 Ian Campbell
2013-03-15 15:24 ` Ian Jackson
2013-03-15 13:15 ` [PATCH 4/9] tools: only check for Python devel tools if not cross-compiling Ian Campbell
2013-03-15 15:27 ` Ian Jackson
2013-03-15 13:15 ` [PATCH 5/9] tools: libxc: arm64 support Ian Campbell
2013-03-15 15:26 ` Ian Jackson
2013-03-15 16:31 ` Tim Deegan
2013-03-15 13:15 ` Ian Campbell [this message]
2013-03-15 15:29 ` [PATCH 6/9] tools: memshr: " Ian Jackson
2013-03-19 15:52 ` Stefano Stabellini
2013-03-15 13:15 ` [PATCH 7/9] xenctx: Support arm64 Ian Campbell
2013-03-15 15:30 ` Ian Jackson
2013-03-15 15:43 ` Ian Campbell
2013-03-15 13:15 ` [PATCH 8/9] xen: arm64 uses the same I/O ABI as arm32 Ian Campbell
2013-03-19 15:48 ` Stefano Stabellini
2013-03-15 13:15 ` [PATCH 9/9] xen: arm: remove PSR_MODE_MASK from public interface Ian Campbell
2013-03-19 15:49 ` Stefano Stabellini
2013-04-11 10:09 ` [PATCH 00/09] arm: tools: build for arm64 and enable cross-compiling for both arm32 and arm64 Ian Campbell
[not found] <mailman.26350.1363354644.1399.xen-devel@lists.xen.org>
2013-03-15 14:30 ` [PATCH 6/9] tools: memshr: arm64 support Andres Lagar-Cavilla
2013-03-15 14:35 ` Ian Campbell
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=1363353350-32251-6-git-send-email-ian.campbell@citrix.com \
--to=ian.campbell@citrix.com \
--cc=ian.jackson@citrix.com \
--cc=stefano.stabellini@citrix.com \
--cc=tim@xen.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).