All of lore.kernel.org
 help / color / mirror / Atom feed
* [parisc-linux] memory barriers, spinlocks, debuglocks, oh my
@ 2004-08-27 16:37 Kyle McMartin
       [not found] ` <1093625820.2010.26.camel@mulgrave>
  2004-08-28 22:15 ` Kyle McMartin
  0 siblings, 2 replies; 12+ messages in thread
From: Kyle McMartin @ 2004-08-27 16:37 UTC (permalink / raw)
  To: parisc-linux

Not knowing anything about how 2.4 works, I hope this is enough,
ping me if it isn't, and I'll take another look.

	Regards,
		Kyle

arch/parisc/lib/locks.c         |    6 ++++++
include/asm-parisc/atomic.h     |   10 ++++++++--
include/asm-parisc/spinlock_t.h |   19 +++++++++++--------
3 files changed, 25 insertions(+), 10 deletions(-)


Index: arch/parisc/lib/locks.c
===================================================================
RCS file: /var/cvs/linux-2.4/arch/parisc/lib/locks.c,v
retrieving revision 1.1
diff -u -r1.1 locks.c
--- arch/parisc/lib/locks.c	16 Nov 2002 07:28:08 -0000	1.1
+++ arch/parisc/lib/locks.c	27 Aug 2004 16:12:50 -0000
@@ -22,6 +22,7 @@
 
 void spin_lock(spinlock_t *lock)
 {
+	mb();
 	int cpu = smp_processor_id();
 	unsigned int stuck = INIT_STUCK;
 	while (!__spin_trylock(lock)) {
@@ -39,19 +40,23 @@
 	}
 	lock->owner_pc = (unsigned long)__builtin_return_address(0);
 	lock->owner_cpu = cpu;
+	mb();
 }
 
 int spin_trylock(spinlock_t *lock)
 {
+	mb();
 	if (!__spin_trylock(lock))
 		return 0;
 	lock->owner_cpu = smp_processor_id(); 
 	lock->owner_pc = (unsigned long)__builtin_return_address(0);
+	mb();
 	return 1;
 }
 
 void spin_unlock(spinlock_t *lp)
 {
+	mb();
   	if ( lp->lock )
 		printk("spin_unlock(%p): no lock cpu %d curr PC %p %s/%d\n",
 		       lp, smp_processor_id(), __builtin_return_address(0),
@@ -63,6 +68,7 @@
 	lp->owner_pc = lp->owner_cpu = 0;
 	wmb();
 	lp->lock = 1;
+	mb();
 }
 
 #endif
Index: include/asm-parisc/atomic.h
===================================================================
RCS file: /var/cvs/linux-2.4/include/asm-parisc/atomic.h,v
retrieving revision 1.10
diff -u -r1.10 atomic.h
--- include/asm-parisc/atomic.h	13 Sep 2002 21:43:37 -0000	1.10
+++ include/asm-parisc/atomic.h	27 Aug 2004 16:13:00 -0000
@@ -30,8 +30,14 @@
  *
  * XXX REVISIT these could be renamed and moved to spinlock_t.h as well
  */
-#define SPIN_LOCK(x)	do { while(__ldcw(&(x)->lock) == 0); } while(0)
-#define SPIN_UNLOCK(x)  do { (x)->lock = 1; } while(0)
+#define SPIN_LOCK(x)    mb();     \
+                        do { while(__ldcw(&(x)->lock) == 0); } \
+                        while(0); \
+                        mb()
+#define SPIN_UNLOCK(x)  mb();     \
+                        do { (x)->lock = 1; } \
+                        while(0); \
+                        mb()
 
 #else	/* CONFIG_SMP */
 
Index: include/asm-parisc/spinlock_t.h
===================================================================
RCS file: /var/cvs/linux-2.4/include/asm-parisc/spinlock_t.h,v
retrieving revision 1.5
diff -u -r1.5 spinlock_t.h
--- include/asm-parisc/spinlock_t.h	7 May 2003 17:20:29 -0000	1.5
+++ include/asm-parisc/spinlock_t.h	27 Aug 2004 16:13:00 -0000
@@ -68,15 +68,18 @@
  * Writing this with asm also ensures that the unlock doesn't
  * get reordered
  */
-#define spin_unlock(x) \
-	__asm__ __volatile__ ("stw,ma  %%sp,0(%0)" : : "r" (&(x)->lock) : "memory" )
+#define spin_unlock(x) do { mb(); \
+ 	__asm__ __volatile__ ("stw,ma  %%sp,0(%0)" : : "r" (&(x)->lock) : "memory" ); \
+        mb(); } while(0)
+
+#define spin_unlock_wait(x) mb(); \
+ do { barrier(); } while(((volatile spinlock_t *)(x))->lock == 0); \
+ mb()
 
-#define spin_unlock_wait(x)     do { barrier(); } while(((volatile spinlock_t *)(x))->lock == 0)
-
-#define spin_lock(x) do { \
+#define spin_lock(x) do { mb(); \
 	while (__ldcw (&(x)->lock) == 0) \
 		while ((x)->lock == 0) ; \
-} while (0)
+        mb(); } while (0)
 
 #else
 
@@ -85,12 +88,12 @@
 
 /* Define 6 spinlock primitives that don't depend on anything else. */
 
-#define spin_lock_init(x)       do { (x)->lock = 1; (x)->owner_cpu = 0; (x)->owner_pc = 0; } while(0)
+#define spin_lock_init(x)       mb(); do { (x)->lock = 1; (x)->owner_cpu = 0; (x)->owner_pc = 0; } while(0); mb()
 #define spin_is_locked(x)       ((x)->lock == 0)
 void spin_lock(spinlock_t *lock);
 int spin_trylock(spinlock_t *lock);
 void spin_unlock(spinlock_t *lock);
-#define spin_unlock_wait(x)     do { barrier(); } while(((volatile spinlock_t *)(x))->lock == 0)
+#define spin_unlock_wait(x)     mb(); do { barrier(); } while(((volatile spinlock_t *)(x))->lock == 0); mb()
 
 #endif
 
-- 
Kyle McMartin
_______________________________________________
parisc-linux mailing list
parisc-linux@lists.parisc-linux.org
http://lists.parisc-linux.org/mailman/listinfo/parisc-linux

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

end of thread, other threads:[~2004-08-30  4:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-27 16:37 [parisc-linux] memory barriers, spinlocks, debuglocks, oh my Kyle McMartin
     [not found] ` <1093625820.2010.26.camel@mulgrave>
     [not found]   ` <20040827170342.GD25975@baldric.uwo.ca>
2004-08-28 16:57     ` Joel Soete
2004-08-28 17:07       ` Kyle McMartin
2004-08-28 22:15 ` Kyle McMartin
2004-08-29 16:11   ` Joel Soete
2004-08-29 16:13     ` Kyle McMartin
2004-08-30  4:06       ` Grant Grundler
2004-08-30  4:14         ` Kyle McMartin
2004-08-30  4:30           ` Grant Grundler
2004-08-30  4:37             ` Kyle McMartin
2004-08-29 16:14     ` Thibaut VARENE
2004-08-29 17:45     ` John David Anglin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.