diff mbox

[7/9] arm64: Add atomic macros to assembler.h

Message ID 73d234924f6de3b3b274d5d5648e4bbea6810450.1408736066.git.geoff@infradead.org (mailing list archive)
State New, archived
Headers show

Commit Message

Geoff Levand Aug. 22, 2014, 7:49 p.m. UTC
Add an assembler macro definition 'atomic' for performing generic
atomic operations.  Also add macro definitions for atomic_add,
atomic_sub, atomic_inc, and atomic_dec.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 arch/arm64/include/asm/assembler.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Catalin Marinas Aug. 26, 2014, 4:05 p.m. UTC | #1
On Fri, Aug 22, 2014 at 08:49:16PM +0100, Geoff Levand wrote:
> Add an assembler macro definition 'atomic' for performing generic
> atomic operations.  Also add macro definitions for atomic_add,
> atomic_sub, atomic_inc, and atomic_dec.

Same question as before. Why are this needed?
Geoff Levand Aug. 26, 2014, 7:40 p.m. UTC | #2
Hi Catalin,

On Tue, 2014-08-26 at 17:05 +0100, Catalin Marinas wrote:
> On Fri, Aug 22, 2014 at 08:49:16PM +0100, Geoff Levand wrote:
> > Add an assembler macro definition 'atomic' for performing generic
> > atomic operations.  Also add macro definitions for atomic_add,
> > atomic_sub, atomic_inc, and atomic_dec.
> 
> Same question as before. Why are this needed?

I use these in the smp-spin-table re-work I am doing to keep a
count of CPUs in the secondary_holding_pen, but those patches
are not yet ready for review.

I thought I'd post this now thinking theses macros might be of use
to someone else.  I could just put them into the smp-spin-table
series, please let me know.

-Geoff
Catalin Marinas Aug. 27, 2014, 8:25 a.m. UTC | #3
On Tue, Aug 26, 2014 at 08:40:53PM +0100, Geoff Levand wrote:
> On Tue, 2014-08-26 at 17:05 +0100, Catalin Marinas wrote:
> > On Fri, Aug 22, 2014 at 08:49:16PM +0100, Geoff Levand wrote:
> > > Add an assembler macro definition 'atomic' for performing generic
> > > atomic operations.  Also add macro definitions for atomic_add,
> > > atomic_sub, atomic_inc, and atomic_dec.
> > 
> > Same question as before. Why are this needed?
> 
> I use these in the smp-spin-table re-work I am doing to keep a
> count of CPUs in the secondary_holding_pen, but those patches
> are not yet ready for review.
> 
> I thought I'd post this now thinking theses macros might be of use
> to someone else.  I could just put them into the smp-spin-table
> series, please let me know.

Keeping them all together would be better. I don't like introducing
unused code.
diff mbox

Patch

diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
index 5901480..dad3118 100644
--- a/arch/arm64/include/asm/assembler.h
+++ b/arch/arm64/include/asm/assembler.h
@@ -23,6 +23,39 @@ 
 #include <asm/ptrace.h>
 #include <asm/thread_info.h>
 
+/**
+ * macro atomic - Macros for simple atomic operations.
+ *
+ * @op: The operation to perform.
+ * @reg: A 32 or 64 bit register to operate on.
+ * @value: The value for the operation.
+ * @tmp1:  A scratch register the same size as @reg.  Defaluts to x20.
+ * @tmp2: A 32 bit scratch register.  Defaluts to w21.
+ **/
+
+	.macro	atomic	op:req, reg:req, value:req, tmp1=x20, tmp2=w21
+.Latomic\@:	ldxr	\tmp1, [\reg]
+	\op	\tmp1, \tmp1, \value
+	stxr	\tmp2, \tmp1, [\reg]
+	cbnz	\tmp2, .Latomic\@
+	.endm
+
+	.macro	atomic_add	reg:req, value:req, tmp1=x20, tmp2=w21
+	atomic add, \reg, \value, \tmp1, \tmp2
+	.endm
+
+	.macro	atomic_sub	reg:req, value:req, tmp1, tmp2
+	atomic sub, \reg, \value, \tmp1, \tmp2
+	.endm
+
+	.macro	atomic_inc	reg:req, tmp1, tmp2
+	atomic add, \reg, 1, \tmp1, \tmp2
+	.endm
+
+	.macro	atomic_dec	reg:req, tmp1, tmp2
+	atomic sub, \reg, 1, \tmp1, \tmp2
+	.endm
+
 /*
  * Stack pushing/popping (register pairs only). Equivalent to store decrement
  * before, load increment after.