linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile
       [not found] <d6775e129db48371cdf86e94ddfaa1d15617bb8f.1186773842.git.segher@kernel.crashing.org>
@ 2007-08-11  0:15 ` Segher Boessenkool
  2007-08-11  0:36 ` Paul Mackerras
  2007-08-17  0:43 ` Paul Mackerras
  2 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2007-08-11  0:15 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: paulus, Segher Boessenkool, linux-arch, linux-kernel

Instead, use asm() like all other atomic operations already do.

Also use inline functions instead of macros; this actually
improves code generation (some code becomes a little smaller,
probably because of improved alias information -- just a few
hundred bytes total on a default kernel build, nothing shocking).

Signed-off-by: Segher Boessenkool <segher@kernel.crashing.org>
---
 include/asm-powerpc/atomic.h |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/include/asm-powerpc/atomic.h b/include/asm-powerpc/atomic.h
index c44810b..bc17506 100644
--- a/include/asm-powerpc/atomic.h
+++ b/include/asm-powerpc/atomic.h
@@ -5,7 +5,7 @@
  * PowerPC atomic operations
  */
 
-typedef struct { volatile int counter; } atomic_t;
+typedef struct { int counter; } atomic_t;
 
 #ifdef __KERNEL__
 #include <linux/compiler.h>
@@ -15,8 +15,19 @@ typedef struct { volatile int counter; } atomic_t;
 
 #define ATOMIC_INIT(i)		{ (i) }
 
-#define atomic_read(v)		((v)->counter)
-#define atomic_set(v,i)		(((v)->counter) = (i))
+static __inline__ int atomic_read(const atomic_t *v)
+{
+	int t;
+
+	__asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
+
+	return t;
+}
+
+static __inline__ void atomic_set(atomic_t *v, int i)
+{
+	__asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
+}
 
 static __inline__ void atomic_add(int a, atomic_t *v)
 {
@@ -240,12 +251,23 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
 
 #ifdef __powerpc64__
 
-typedef struct { volatile long counter; } atomic64_t;
+typedef struct { long counter; } atomic64_t;
 
 #define ATOMIC64_INIT(i)	{ (i) }
 
-#define atomic64_read(v)	((v)->counter)
-#define atomic64_set(v,i)	(((v)->counter) = (i))
+static __inline__ long atomic64_read(const atomic_t *v)
+{
+	long t;
+
+	__asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
+
+	return t;
+}
+
+static __inline__ void atomic64_set(atomic_t *v, long i)
+{
+	__asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
+}
 
 static __inline__ void atomic64_add(long a, atomic64_t *v)
 {
-- 
1.5.2.1.144.gabc40-dirty


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile
       [not found] <d6775e129db48371cdf86e94ddfaa1d15617bb8f.1186773842.git.segher@kernel.crashing.org>
  2007-08-11  0:15 ` [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile Segher Boessenkool
@ 2007-08-11  0:36 ` Paul Mackerras
  2007-08-17  0:43 ` Paul Mackerras
  2 siblings, 0 replies; 4+ messages in thread
From: Paul Mackerras @ 2007-08-11  0:36 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, linux-arch, linux-kernel

Segher Boessenkool writes:

> Instead, use asm() like all other atomic operations already do.
> 
> Also use inline functions instead of macros; this actually
> improves code generation (some code becomes a little smaller,
> probably because of improved alias information -- just a few
> hundred bytes total on a default kernel build, nothing shocking).
> 
> Signed-off-by: Segher Boessenkool <segher@kernel.crashing.org>

Looks OK to me.  In the hope that Chris Snook will pick it up and
include it with his other atomic changes:

Acked-by: Paul Mackerras <paulus@samba.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile
       [not found] <d6775e129db48371cdf86e94ddfaa1d15617bb8f.1186773842.git.segher@kernel.crashing.org>
  2007-08-11  0:15 ` [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile Segher Boessenkool
  2007-08-11  0:36 ` Paul Mackerras
@ 2007-08-17  0:43 ` Paul Mackerras
  2007-08-18  1:29   ` Segher Boessenkool
  2 siblings, 1 reply; 4+ messages in thread
From: Paul Mackerras @ 2007-08-17  0:43 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, linux-arch, linux-kernel

Segher Boessenkool writes:

> Instead, use asm() like all other atomic operations already do.

> +static __inline__ long atomic64_read(const atomic_t *v)

> +static __inline__ void atomic64_set(atomic_t *v, long i)

s/atomic_t/atomic64_t/ in both lines.  I've edited my copy of the patch.

Paul.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile
  2007-08-17  0:43 ` Paul Mackerras
@ 2007-08-18  1:29   ` Segher Boessenkool
  0 siblings, 0 replies; 4+ messages in thread
From: Segher Boessenkool @ 2007-08-18  1:29 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: linuxppc-dev, linux-arch, linux-kernel

>> Instead, use asm() like all other atomic operations already do.
>
>> +static __inline__ long atomic64_read(const atomic_t *v)
>
>> +static __inline__ void atomic64_set(atomic_t *v, long i)
>
> s/atomic_t/atomic64_t/ in both lines.  I've edited my copy of the 
> patch.

Ouch, sorry about that.


Segher


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-18  1:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <d6775e129db48371cdf86e94ddfaa1d15617bb8f.1186773842.git.segher@kernel.crashing.org>
2007-08-11  0:15 ` [PATCH] powerpc: Implement atomic{,64}_{read,write}() without volatile Segher Boessenkool
2007-08-11  0:36 ` Paul Mackerras
2007-08-17  0:43 ` Paul Mackerras
2007-08-18  1:29   ` Segher Boessenkool

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).