Linux PARISC architecture development
 help / color / mirror / Atom feed
From: Grant Grundler <grundler@parisc-linux.org>
To: Matthew Wilcox <matthew@wil.cx>
Cc: parisc-linux@lists.parisc-linux.org
Subject: Re: [parisc-linux] some more questions about __raw_write_trylock() hppa implementation
Date: Thu, 31 Aug 2006 00:06:37 -0600	[thread overview]
Message-ID: <20060831060637.GF3999@colo.lackof.org> (raw)
In-Reply-To: <20060831035932.GB4919@parisc-linux.org>

On Wed, Aug 30, 2006 at 09:59:32PM -0600, Matthew Wilcox wrote:
> Actually, there is a problem with the write locks that I
> noticed during replying to this mail the first time.
> Then palinux crashed.  How ironic.
> Grant and I are fixing that right now ...

Willy,
Here's the patch I ended up with.
Diff is also parked on gsyprf11:~grundler/diff-2.6.18-rc4-pa4-rwlocks-01

This is currently running on iodine (a500-5x).
I don't know how this needs to be tested other than running
"make -j4" on the kernel build. Maybe glibc/toolchain build?

Please feel free to apply with your own commit comment, additional
changes, and S-o-B line.

And kudos for catching this. It's another non-trivial problem that's
been around for a while.

thanks,
grant

Commit Comment:
	We can't use generic__raw_read_trylock() since that will hang instead
	of returning a failure if the rwlock->lock isn't available.
	Similarly, __raw_write_trylock() is broken in that it would
	hang too instead of returning a failure.

Signed-off-by: Grant Grundler <grundler@parisc-linux.org>


diff --git a/include/asm-parisc/spinlock.h b/include/asm-parisc/spinlock.h
index a93960e..d4048a6 100644
--- a/include/asm-parisc/spinlock.h
+++ b/include/asm-parisc/spinlock.h
@@ -60,7 +60,6 @@ static inline int __raw_spin_trylock(raw
  * but only one writer.
  */
 
-#define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
 
 /* read_lock, read_unlock are pretty straightforward.  Of course it somehow
  * sucks we end up saving/restoring flags twice for read_lock_irqsave aso. */
@@ -68,19 +67,25 @@ #define __raw_read_trylock(lock) generic
 static  __inline__ void __raw_read_lock(raw_rwlock_t *rw)
 {
 	__raw_spin_lock(&rw->lock);
-
 	rw->counter++;
-
 	__raw_spin_unlock(&rw->lock);
 }
 
 static  __inline__ void __raw_read_unlock(raw_rwlock_t *rw)
 {
 	__raw_spin_lock(&rw->lock);
-
 	rw->counter--;
+	__raw_spin_unlock(&rw->lock);
+}
+
+static  __inline__ int __raw_read_trylock(raw_rwlock_t *rw)
+{
+	if (!__raw_spin_trylock(&rw->lock))
+		return 0;
 
+	rw->counter++;
 	__raw_spin_unlock(&rw->lock);
+	return 1;
 }
 
 /* write_lock is less trivial.  We optimistically grab the lock and check
@@ -121,15 +126,15 @@ static  __inline__ void __raw_write_unlo
 
 static  __inline__ int __raw_write_trylock(raw_rwlock_t *rw)
 {
-	__raw_spin_lock(&rw->lock);
+	if (!__raw_spin_trylock(&rw->lock))
+		return 0;
+
 	if (rw->counter != 0) {
-		/* this basically never happens */
 		__raw_spin_unlock(&rw->lock);

  reply	other threads:[~2006-08-31  6:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-30 20:23 [parisc-linux] some more questions about __raw_write_trylock() hppa implementation Joel Soete
2006-08-31  3:59 ` Matthew Wilcox
2006-08-31  6:06   ` Grant Grundler [this message]
2006-08-31 12:31     ` Matthew Wilcox
2006-08-31 13:01       ` Michael S. Zick
2006-08-31 13:13         ` Matthew Wilcox
2006-08-31 16:08           ` Grant Grundler
2006-08-31 16:27       ` Grant Grundler
2006-09-01 14:01         ` Matthew Wilcox
2006-09-01 15:57           ` Grant Grundler
2006-09-01 17:19             ` Matthew Wilcox

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=20060831060637.GF3999@colo.lackof.org \
    --to=grundler@parisc-linux.org \
    --cc=matthew@wil.cx \
    --cc=parisc-linux@lists.parisc-linux.org \
    /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