From: Richard Henderson <rth@twiddle.net>
To: linux-kernel@vger.kernel.org
Cc: ink@jurassic.park.msu.ru, mattst88@gmail.com,
linux-alpha@vger.kernel.org
Subject: [PATCH 4/7] alpha: Improve atomic_add_unless
Date: Tue, 16 Jul 2013 10:04:37 -0700 [thread overview]
Message-ID: <1373994280-12047-5-git-send-email-rth@twiddle.net> (raw)
In-Reply-To: <1373994280-12047-1-git-send-email-rth@twiddle.net>
Use ll/sc loops instead of C loops around cmpxchg.
Update the atomic64_add_unless block comment to match the code.
Signed-off-by: Richard Henderson <rth@twiddle.net>
---
arch/alpha/include/asm/atomic.h | 60 +++++++++++++++++++++++++----------------
1 file changed, 37 insertions(+), 23 deletions(-)
diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
index c2cbe4f..0dc18fc 100644
--- a/arch/alpha/include/asm/atomic.h
+++ b/arch/alpha/include/asm/atomic.h
@@ -186,17 +186,24 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
*/
static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
{
- int c, old;
- c = atomic_read(v);
- for (;;) {
- if (unlikely(c == (u)))
- break;
- old = atomic_cmpxchg((v), c, c + (a));
- if (likely(old == c))
- break;
- c = old;
- }
- return c;
+ int c, new, old;
+ smp_mb();
+ __asm__ __volatile__(
+ "1: ldl_l %[old],%[mem]\n"
+ " cmpeq %[old],%[u],%[c]\n"
+ " addl %[old],%[a],%[new]\n"
+ " bne %[c],2f\n"
+ " stl_c %[new],%[mem]\n"
+ " beq %[new],3f\n"
+ "2:\n"
+ ".subsection 2\n"
+ "3: br 1b\n"
+ ".previous"
+ : [old] "=&r"(old), [new] "=&r"(new), [c] "=&r"(c)
+ : [mem] "m"(*v), [a] "rI"(a), [u] "rI"((long)u)
+ : "memory");
+ smp_mb();
+ return old;
}
@@ -207,21 +214,28 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
* @u: ...unless v is equal to u.
*
* Atomically adds @a to @v, so long as it was not @u.
- * Returns the old value of @v.
+ * Returns true iff @v was not @u.
*/
static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
{
- long c, old;
- c = atomic64_read(v);
- for (;;) {
- if (unlikely(c == (u)))
- break;
- old = atomic64_cmpxchg((v), c, c + (a));
- if (likely(old == c))
- break;
- c = old;
- }
- return c != (u);
+ long c, tmp;
+ smp_mb();
+ __asm__ __volatile__(
+ "1: ldq_l %[tmp],%[mem]\n"
+ " cmpeq %[tmp],%[u],%[c]\n"
+ " addq %[tmp],%[a],%[tmp]\n"
+ " bne %[c],2f\n"
+ " stq_c %[tmp],%[mem]\n"
+ " beq %[tmp],3f\n"
+ "2:\n"
+ ".subsection 2\n"
+ "3: br 1b\n"
+ ".previous"
+ : [tmp] "=&r"(tmp), [c] "=&r"(c)
+ : [mem] "m"(*v), [a] "rI"(a), [u] "rI"(u)
+ : "memory");
+ smp_mb();
+ return !c;
}
#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
--
1.8.1.4
next prev parent reply other threads:[~2013-07-16 17:05 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-16 17:04 [PATCH 0/7] Minor Alpha updates for 3.11 Richard Henderson
2013-07-16 17:04 ` [PATCH 1/7] alpha: Add kcmp and finit_module syscalls Richard Henderson
2013-07-16 17:04 ` [PATCH 2/7] alpha: Eliminate compiler warning from memset macro Richard Henderson
2013-07-17 19:54 ` Matt Turner
2013-07-16 17:04 ` [PATCH 3/7] alpha: Modernize lib/mpi/longlong.h Richard Henderson
2013-07-16 17:19 ` Joe Perches
2013-07-16 18:55 ` Richard Henderson
2013-07-16 17:04 ` Richard Henderson [this message]
2013-07-16 17:04 ` [PATCH 5/7] alpha: Implement atomic64_dec_if_positive Richard Henderson
2013-07-16 17:04 ` [PATCH 6/7] alpha: Generate dwarf2 unwind info for various kernel entry points Richard Henderson
2013-07-16 17:04 ` [PATCH 7/7] alpha: Fix type compatibility warning for marvel_map_irq Richard Henderson
2013-07-16 23:35 ` [PATCH 0/7] Minor Alpha updates for 3.11 Rob Landley
2013-07-17 0:03 ` Michael Cree
2013-07-23 2:31 ` Rob Landley
2013-07-23 3:25 ` Michael Cree
2013-07-23 15:20 ` Richard Henderson
2013-07-24 10:25 ` Michael Cree
2013-07-24 17:55 ` Richard Henderson
2013-07-17 4:29 ` Matt Turner
2013-07-17 13:02 ` Richard Henderson
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=1373994280-12047-5-git-send-email-rth@twiddle.net \
--to=rth@twiddle.net \
--cc=ink@jurassic.park.msu.ru \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
/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
all inboxes | Powered by JetHome®