From: Linus Torvalds <torvalds@linux-foundation.org>
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
Jeremy Fitzhardinge <jeremy@goop.org>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@elte.hu>, Joe Perches <joe@perches.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] Fair rwlock
Date: Sat, 16 Aug 2008 14:33:01 -0700 (PDT) [thread overview]
Message-ID: <alpine.LFD.1.10.0808161422290.3324@nehalem.linux-foundation.org> (raw)
In-Reply-To: <20080816211954.GB7358@Krystal>
On Sat, 16 Aug 2008, Mathieu Desnoyers wrote:
>
> Tweakable contention behavior seems interesting, but I don't think it
> deals with the fact that on a mainline kernel, when an interrupt handler
> comes in and asks for a read lock, it has to get it on the spot.
Right. Which is exactly why I'd suggest using the extra space for saying
"this CPU is busy-looping waiting for a write lock", and then the
read-lock contention case can say
- ok, there's a pending write lock holder on _my_ CPU, so I need to just
succeed right away despite the fact that there is contention.
In other words, there are a few cases:
- you actually *got* the write lock
interrupts obviously have to be disabled here, because any reader can
simply not get the lock.
- you are waiting to get the write lock.
Mark this CPU as "pending" in the rwlock (by making the extended thing
be a queue, or by simply only ever allowing a single pendign CPU), and
re-enable interrupts while you wait for it. An interrupt that comes in
and wants a read-lock sees that it's pending, so it should then ignore
the contention bit, and only wait for the write bit to go away.
See? This way you only need to actually disable interrupts while holding
literally the lock, not while waiting for it. While still giving priority
to writers (except for the _one_ CPU, where new readers will have to get
through).
So this way you can be fair, and not allow readers to starve a writer. The
only reader that is allowed past a waiting writer is the reader on that
same CPU.
And notice how the fast-path needs no spinlock or anything else - it's
still just a single locked instruction. In comparison, if I read your
example code right, it is absolutely horrid and has an extra spinlock
access for the fair_write_lock case.
Linus
next prev parent reply other threads:[~2008-08-16 21:34 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-16 7:39 [PATCH] x86_64 : support atomic ops with 64 bits integer values Mathieu Desnoyers
2008-08-16 15:04 ` H. Peter Anvin
2008-08-16 15:43 ` Mathieu Desnoyers
2008-08-16 17:30 ` Linus Torvalds
2008-08-16 21:19 ` [RFC PATCH] Fair rwlock Mathieu Desnoyers
2008-08-16 21:33 ` Linus Torvalds [this message]
2008-08-17 7:53 ` [RFC PATCH] Fair low-latency rwlock v3 Mathieu Desnoyers
2008-08-17 16:17 ` Linus Torvalds
2008-08-17 19:10 ` [RFC PATCH] Fair low-latency rwlock v5 Mathieu Desnoyers
2008-08-17 21:30 ` [RFC PATCH] Fair low-latency rwlock v5 (updated benchmarks) Mathieu Desnoyers
2008-08-18 18:59 ` [RFC PATCH] Fair low-latency rwlock v5 Linus Torvalds
2008-08-18 23:25 ` Paul E. McKenney
2008-08-19 6:04 ` Mathieu Desnoyers
2008-08-19 7:33 ` Mathieu Desnoyers
2008-08-19 9:06 ` Mathieu Desnoyers
2008-08-19 16:48 ` Linus Torvalds
2008-08-21 20:50 ` [RFC PATCH] Writer-biased low-latency rwlock v8 Mathieu Desnoyers
2008-08-21 21:00 ` Linus Torvalds
2008-08-21 21:15 ` Linus Torvalds
2008-08-21 22:22 ` Linus Torvalds
2008-08-23 5:09 ` Mathieu Desnoyers
2008-08-23 18:02 ` Linus Torvalds
2008-08-23 20:30 ` Mathieu Desnoyers
2008-08-23 21:40 ` Linus Torvalds
2008-08-21 21:26 ` H. Peter Anvin
2008-08-21 21:41 ` Linus Torvalds
2008-08-25 19:20 ` [RFC PATCH] Fair low-latency rwlock v5 Peter Zijlstra
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=alpine.LFD.1.10.0808161422290.3324@nehalem.linux-foundation.org \
--to=torvalds@linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=jeremy@goop.org \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@polymtl.ca \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®