From: James Hogan <james.hogan@imgtec.com>
To: Peter Zijlstra <peterz@infradead.org>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
mingo@kernel.org, will.deacon@arm.com,
paulmck@linux.vnet.ibm.com
Subject: Re: [PATCH 12/20] arch,metag: Fold atomic_ops
Date: Tue, 13 May 2014 11:06:47 +0100 [thread overview]
Message-ID: <5371EEB7.4090604@imgtec.com> (raw)
In-Reply-To: <20140508135852.453864110@infradead.org>
On 08/05/14 14:58, Peter Zijlstra wrote:
> Many of the atomic op implementations are the same except for one
> instruction; fold the lot into a few CPP macros and reduce LoC.
>
> This also prepares for easy addition of new ops.
>
> Cc: James Hogan <james.hogan@imgtec.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Looks good and disassembly is unchanged for both lnkget/lnkset and lock1.
Acked-by: James Hogan <james.hogan@imgtec.com>
Let me know if you want this patch taken separately through the metag tree.
Thanks
James
> ---
> arch/metag/include/asm/atomic_lnkget.h | 121 ++++++++++++---------------------
> arch/metag/include/asm/atomic_lock1.h | 76 ++++++++------------
> 2 files changed, 77 insertions(+), 120 deletions(-)
>
> Index: linux-2.6/arch/metag/include/asm/atomic_lnkget.h
> ===================================================================
> --- linux-2.6.orig/arch/metag/include/asm/atomic_lnkget.h
> +++ linux-2.6/arch/metag/include/asm/atomic_lnkget.h
> @@ -27,85 +27,56 @@ static inline int atomic_read(const atom
> return temp;
> }
>
> -static inline void atomic_add(int i, atomic_t *v)
> -{
> - int temp;
> -
> - asm volatile (
> - "1: LNKGETD %0, [%1]\n"
> - " ADD %0, %0, %2\n"
> - " LNKSETD [%1], %0\n"
> - " DEFR %0, TXSTAT\n"
> - " ANDT %0, %0, #HI(0x3f000000)\n"
> - " CMPT %0, #HI(0x02000000)\n"
> - " BNZ 1b\n"
> - : "=&d" (temp)
> - : "da" (&v->counter), "bd" (i)
> - : "cc");
> +#define ATOMIC_OP(op) \
> +static inline void atomic_##op(int i, atomic_t *v) \
> +{ \
> + int temp; \
> + \
> + asm volatile ( \
> + "1: LNKGETD %0, [%1]\n" \
> + " " #op " %0, %0, %2\n" \
> + " LNKSETD [%1], %0\n" \
> + " DEFR %0, TXSTAT\n" \
> + " ANDT %0, %0, #HI(0x3f000000)\n" \
> + " CMPT %0, #HI(0x02000000)\n" \
> + " BNZ 1b\n" \
> + : "=&d" (temp) \
> + : "da" (&v->counter), "bd" (i) \
> + : "cc"); \
> +} \
> +
> +#define ATOMIC_OP_RETURN(op) \
> +static inline int atomic_##op##_return(int i, atomic_t *v) \
> +{ \
> + int result, temp; \
> + \
> + smp_mb(); \
> + \
> + asm volatile ( \
> + "1: LNKGETD %1, [%2]\n" \
> + " " #op " %1, %1, %3\n" \
> + " LNKSETD [%2], %1\n" \
> + " DEFR %0, TXSTAT\n" \
> + " ANDT %0, %0, #HI(0x3f000000)\n" \
> + " CMPT %0, #HI(0x02000000)\n" \
> + " BNZ 1b\n" \
> + : "=&d" (temp), "=&da" (result) \
> + : "da" (&v->counter), "bd" (i) \
> + : "cc"); \
> + \
> + smp_mb(); \
> + \
> + return result; \
> }
>
> -static inline void atomic_sub(int i, atomic_t *v)
> -{
> - int temp;
> -
> - asm volatile (
> - "1: LNKGETD %0, [%1]\n"
> - " SUB %0, %0, %2\n"
> - " LNKSETD [%1], %0\n"
> - " DEFR %0, TXSTAT\n"
> - " ANDT %0, %0, #HI(0x3f000000)\n"
> - " CMPT %0, #HI(0x02000000)\n"
> - " BNZ 1b\n"
> - : "=&d" (temp)
> - : "da" (&v->counter), "bd" (i)
> - : "cc");
> -}
> -
> -static inline int atomic_add_return(int i, atomic_t *v)
> -{
> - int result, temp;
> -
> - smp_mb();
> -
> - asm volatile (
> - "1: LNKGETD %1, [%2]\n"
> - " ADD %1, %1, %3\n"
> - " LNKSETD [%2], %1\n"
> - " DEFR %0, TXSTAT\n"
> - " ANDT %0, %0, #HI(0x3f000000)\n"
> - " CMPT %0, #HI(0x02000000)\n"
> - " BNZ 1b\n"
> - : "=&d" (temp), "=&da" (result)
> - : "da" (&v->counter), "bd" (i)
> - : "cc");
> +#define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
>
> - smp_mb();
> +ATOMIC_OPS(add)
> +ATOMIC_OPS(sub)
>
> - return result;
> -}
> -
> -static inline int atomic_sub_return(int i, atomic_t *v)
> -{
> - int result, temp;
> -
> - smp_mb();
> -
> - asm volatile (
> - "1: LNKGETD %1, [%2]\n"
> - " SUB %1, %1, %3\n"
> - " LNKSETD [%2], %1\n"
> - " DEFR %0, TXSTAT\n"
> - " ANDT %0, %0, #HI(0x3f000000)\n"
> - " CMPT %0, #HI(0x02000000)\n"
> - " BNZ 1b\n"
> - : "=&d" (temp), "=&da" (result)
> - : "da" (&v->counter), "bd" (i)
> - : "cc");
> -
> - smp_mb();
> -
> - return result;
> -}
> +#undef ATOMIC_OPS
> +#undef ATOMIC_OP_RETURN
> +#undef ATOMIC_OP
>
> static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
> {
> Index: linux-2.6/arch/metag/include/asm/atomic_lock1.h
> ===================================================================
> --- linux-2.6.orig/arch/metag/include/asm/atomic_lock1.h
> +++ linux-2.6/arch/metag/include/asm/atomic_lock1.h
> @@ -37,55 +37,41 @@ static inline int atomic_set(atomic_t *v
> return i;
> }
>
> -static inline void atomic_add(int i, atomic_t *v)
> -{
> - unsigned long flags;
> -
> - __global_lock1(flags);
> - fence();
> - v->counter += i;
> - __global_unlock1(flags);
> +#define ATOMIC_OP(op, c_op) \
> +static inline void atomic_##op(int i, atomic_t *v) \
> +{ \
> + unsigned long flags; \
> + \
> + __global_lock1(flags); \
> + fence(); \
> + v->counter c_op i; \
> + __global_unlock1(flags); \
> +} \
> +
> +#define ATOMIC_OP_RETURN(op, c_op) \
> +static inline int atomic_##op##_return(int i, atomic_t *v) \
> +{ \
> + unsigned long result; \
> + unsigned long flags; \
> + \
> + __global_lock1(flags); \
> + result = v->counter; \
> + result c_op i; \
> + fence(); \
> + v->counter = result; \
> + __global_unlock1(flags); \
> + \
> + return result; \
> }
>
> -static inline void atomic_sub(int i, atomic_t *v)
> -{
> - unsigned long flags;
> -
> - __global_lock1(flags);
> - fence();
> - v->counter -= i;
> - __global_unlock1(flags);
> -}
> -
> -static inline int atomic_add_return(int i, atomic_t *v)
> -{
> - unsigned long result;
> - unsigned long flags;
> +#define ATOMIC_OPS(op, c_op) ATOMIC_OP(op, c_op) ATOMIC_OP_RETURN(op, c_op)
>
> - __global_lock1(flags);
> - result = v->counter;
> - result += i;
> - fence();
> - v->counter = result;
> - __global_unlock1(flags);
> +ATOMIC_OPS(add, +=)
> +ATOMIC_OPS(sub, -=)
>
> - return result;
> -}
> -
> -static inline int atomic_sub_return(int i, atomic_t *v)
> -{
> - unsigned long result;
> - unsigned long flags;
> -
> - __global_lock1(flags);
> - result = v->counter;
> - result -= i;
> - fence();
> - v->counter = result;
> - __global_unlock1(flags);
> -
> - return result;
> -}
> +#undef ATOMIC_OPS
> +#undef ATOMIC_OP_RETURN
> +#undef ATOMIC_OP
>
> static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
> {
>
>
next prev parent reply other threads:[~2014-05-13 10:06 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-08 13:58 [PATCH 00/20] arch atomic 'cleanup' Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 01/20] x86: Kill atomic_or_long() Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 02/20] arch,alpha: Fold atomic_ops Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 03/20] arch,arc: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-09 9:34 ` Vineet Gupta
2014-05-09 10:22 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 04/20] arch,arm: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 18:31 ` Will Deacon
2014-05-08 13:58 ` [PATCH 05/20] arch,arm64: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 18:31 ` Will Deacon
2014-05-08 13:58 ` [PATCH 06/20] arch,avr32: " Peter Zijlstra
2014-05-09 18:32 ` Hans-Christian Egtvedt
2014-05-09 20:43 ` Peter Zijlstra
2014-05-09 20:51 ` Peter Zijlstra
2014-05-09 21:17 ` Peter Zijlstra
2014-05-13 20:40 ` Hans-Christian Egtvedt
2014-05-13 20:50 ` Peter Zijlstra
2014-05-14 7:43 ` Hans-Christian Egtvedt
2014-05-31 14:14 ` Peter Zijlstra
2014-06-06 6:25 ` Hans-Christian Egtvedt
2014-05-08 13:58 ` [PATCH 07/20] arch,cris: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 15:12 ` Geert Uytterhoeven
2014-05-08 16:06 ` Peter Zijlstra
2014-05-08 17:34 ` David Miller
2014-05-08 18:17 ` Peter Zijlstra
2014-05-08 20:27 ` David Miller
2014-05-09 8:14 ` Jesper Nilsson
2014-05-08 13:58 ` [PATCH 08/20] arch,hexagon: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-12 17:28 ` rkuo
2014-05-08 13:58 ` [PATCH 09/20] arch,ia64: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 10/20] arch,m32r: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 11/20] arch,m68k: " Peter Zijlstra
2014-05-09 9:08 ` Geert Uytterhoeven
2014-05-09 9:16 ` Peter Zijlstra
2014-05-09 9:16 ` Peter Zijlstra
2014-05-09 9:44 ` Geert Uytterhoeven
2014-05-08 13:58 ` [PATCH 12/20] arch,metag: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-13 10:06 ` James Hogan [this message]
2014-05-13 10:06 ` James Hogan
2014-05-08 13:58 ` [PATCH 13/20] arch,mips: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 14/20] arch,mn10300: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 15/20] arch,parisc: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 16/20] arch,powerpc: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 17/20] arch,sh: " Peter Zijlstra
2014-05-08 13:58 ` Peter Zijlstra
2014-05-08 13:58 ` [PATCH 18/20] arch,sparc: " Peter Zijlstra
2014-05-08 13:58 ` [PATCH 19/20] arch,xtensa: " Peter Zijlstra
2014-05-08 13:59 ` [PATCH 20/20] arch: Rewrite generic atomic support Peter Zijlstra
2014-05-08 15:24 ` Sam Ravnborg
2014-05-08 18:26 ` Peter Zijlstra
2014-05-20 13:05 ` [PATCH 14/20] arch,mn10300: Fold atomic_ops David Howells
2014-05-20 13:16 ` Peter Zijlstra
2014-05-20 13:16 ` Peter Zijlstra
2014-09-24 16:54 ` [PATCH 00/20] arch atomic 'cleanup' Will Deacon
2014-09-24 16:54 ` Will Deacon
2014-09-24 18:06 ` Peter Zijlstra
2014-09-24 18:09 ` Will Deacon
2014-09-24 18:09 ` Will Deacon
2014-09-25 5:03 ` Ingo Molnar
2014-09-25 5:03 ` Ingo Molnar
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=5371EEB7.4090604@imgtec.com \
--to=james.hogan@imgtec.com \
--cc=akpm@linux-foundation.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--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).