linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	Russell King <linux@armlinux.org.uk>
Subject: [PATCHv2 09/16] atomics/arm: define atomic64_fetch_add_unless()
Date: Tue, 29 May 2018 16:43:39 +0100	[thread overview]
Message-ID: <20180529154346.3168-10-mark.rutland@arm.com> (raw)
In-Reply-To: <20180529154346.3168-1-mark.rutland@arm.com>

As a step towards unifying the atomic/atomic64/atomic_long APIs, this
patch converts the arch/arm implementation of atomic64_add_unless() into
an implementation of atomic64_fetch_add_unless().

A wrapper in <linux/atomic.h> will build atomic_add_unless() atop of
this, provided it is given a preprocessor definition.

No functional change is intended as a result of this patch.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Russell King <linux@armlinux.org.uk>
---
 arch/arm/include/asm/atomic.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
index 74460aa00fa0..852e1fee72b0 100644
--- a/arch/arm/include/asm/atomic.h
+++ b/arch/arm/include/asm/atomic.h
@@ -486,11 +486,11 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
 	return result;
 }
 
-static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
+static inline long long atomic64_fetch_add_unless(atomic64_t *v, long long a,
+						  long long u)
 {
-	long long val;
+	long long oldval, newval;
 	unsigned long tmp;
-	int ret = 1;
 
 	smp_mb();
 	prefetchw(&v->counter);
@@ -499,23 +499,23 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
 "1:	ldrexd	%0, %H0, [%4]\n"
 "	teq	%0, %5\n"
 "	teqeq	%H0, %H5\n"
-"	moveq	%1, #0\n"
 "	beq	2f\n"
-"	adds	%Q0, %Q0, %Q6\n"
-"	adc	%R0, %R0, %R6\n"
-"	strexd	%2, %0, %H0, [%4]\n"
+"	adds	%Q1, %Q0, %Q6\n"
+"	adc	%R1, %R0, %R6\n"
+"	strexd	%2, %1, %H1, [%4]\n"
 "	teq	%2, #0\n"
 "	bne	1b\n"
 "2:"
-	: "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
+	: "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
 	: "r" (&v->counter), "r" (u), "r" (a)
 	: "cc");
 
-	if (ret)
+	if (oldval != u)
 		smp_mb();
 
-	return ret;
+	return oldval;
 }
+#define atomic64_fetch_add_unless atomic64_fetch_add_unless
 
 #define atomic64_add_negative(a, v)	(atomic64_add_return((a), (v)) < 0)
 #define atomic64_inc(v)			atomic64_add(1LL, (v))
-- 
2.11.0

  parent reply	other threads:[~2018-05-29 15:44 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-29 15:43 [PATCHv2 00/16] atomics: API cleanups Mark Rutland
2018-05-29 15:43 ` [PATCHv2 01/16] atomics/treewide: s/__atomic_add_unless/atomic_fetch_add_unless/ Mark Rutland
2018-06-04 23:24   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 02/16] atomics/treewide: remove redundant atomic_inc_not_zero() definitions Mark Rutland
2018-06-04 23:24   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 03/16] atomics/treewide: make atomic64_inc_not_zero() optional Mark Rutland
2018-06-04 23:17   ` Palmer Dabbelt
2018-06-05  5:34     ` Mark Rutland
2018-05-29 15:43 ` [PATCHv2 04/16] atomics/treewide: make atomic_fetch_add_unless() optional Mark Rutland
2018-06-04 23:24   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 05/16] atomics: prepare for atomic64_fetch_add_unless() Mark Rutland
2018-06-05  9:26   ` Peter Zijlstra
2018-06-05  9:53     ` Mark Rutland
2018-06-05 10:54       ` Michael Ellerman
2018-06-05 11:08         ` Mark Rutland
2018-06-06  8:57           ` Michael Ellerman
2018-05-29 15:43 ` [PATCHv2 06/16] atomics/generic: define atomic64_fetch_add_unless() Mark Rutland
2018-05-29 15:43 ` [PATCHv2 07/16] atomics/alpha: " Mark Rutland
2018-05-29 15:43 ` [PATCHv2 08/16] atomics/arc: " Mark Rutland
2018-05-29 15:43 ` Mark Rutland [this message]
2018-05-29 15:43 ` [PATCHv2 10/16] atomics/powerpc: " Mark Rutland
2018-05-29 15:43 ` [PATCHv2 11/16] atomics/riscv: " Mark Rutland
2018-06-04 23:17   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 12/16] atomics/treewide: make atomic64_fetch_add_unless() optional Mark Rutland
2018-05-29 15:43 ` [PATCHv2 13/16] atomics/treewide: make test ops optional Mark Rutland
2018-06-04 23:17   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 14/16] atomics/treewide: remove atomic_inc_not_zero_hint() Mark Rutland
2018-05-29 15:43 ` [PATCHv2 15/16] atomics/treewide: make unconditional inc/dec ops optional Mark Rutland
2018-06-04 23:17   ` Palmer Dabbelt
2018-05-29 15:43 ` [PATCHv2 16/16] atomics/treewide: make conditional " Mark Rutland
2018-05-30 11:23 ` [PATCHv2 00/16] atomics: API cleanups Mark Rutland
2018-05-30 13:34   ` Mark Rutland
2018-06-05  9:43 ` Peter Zijlstra

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=20180529154346.3168-10-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).