Re: [2.6] Missing _raw_write_trylock for PPC/SMP

From: Kyle Moffett
Date: Fri May 21 2004 - 02:42:26 EST


On May 20, 2004, at 17:12, Kyle Moffett wrote:
The PPC/32 architecture is missing the SMP definition of the _raw_write_trylock
function. I'm not strong enough on PowerPC assembly but it would be nice if
someone could write up an implementation for linux/include/asm-ppc/spinlock.h

I found the time to brush up on my assembly a little, and using the PPC/32 and
PPC/64 implementations of _raw_write_lock and the PPC/64 implementation
of _raw_write_trylock for reference I hacked together a patch. There are
probably bugs in it as I'm still a little rusty, so it needs someone skilled in PPC
assembly to review it, but hopefully it will work. I'll try compiling it into my
kernel tomorrow to see if it works. (I won't have access to the machine in
question untill then, sorry).

Cheers,
Kyle Moffett


--- a/include/asm-ppc/spinlock.h 2004-05-09 22:32:28.000000000 -0400
+++ linux/include/asm-ppc/spinlock.h 2004-05-20 20:12:44.000000000 -0400
@@ -135,6 +135,28 @@
: "cr0", "memory");
}

+static __inline__ int _raw_write_trylock(rwlock_t *rw)
+{
+ unsigned int tmp;
+ unsigned int ret;
+
+ __asm__ __volatile__(
+"1: lwarx %0,0,%2 # write_trylock\n\
+ cmpwi 0,%0,0\n\
+ li %1,0\n\
+ bne- 2f\n"
+ PPC405_ERR77(0,%1)
+" stwcx. %3,0,%2\n\
+ bne- 1b\n\
+ li %1,1\n\
+ isync\n\
+2:" : "=&r"(tmp), "=&r"(ret)
+ : "r"(&rw->lock), "r"(-1)
+ : "cr0", "memory");
+
+ return ret;
+}
+
static __inline__ void _raw_write_lock(rwlock_t *rw)
{
unsigned int tmp;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/