From: Michel Lespinasse <walken@google.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
David Howells <dhowells@redhat.com>, Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Waychison <mikew@google.com>,
Suleiman Souhlal <suleiman@google.com>,
Ying Han <yinghan@google.com>,
Michel Lespinasse <walken@google.com>
Subject: [PATCH 08/10] rwsem: down_read_unfair infrastructure support
Date: Fri, 14 May 2010 05:39:40 -0700 [thread overview]
Message-ID: <1273840782-5920-9-git-send-email-walken@google.com> (raw)
In-Reply-To: <1273840782-5920-1-git-send-email-walken@google.com>
Add rwsem_down_read_unfair_failed() function in the non-generic rwsem
library code, similar to rwsem_down_read_failed() except that blocked
threads are placed at the head of the queue.
Signed-off-by: Michel Lespinasse <walken@google.com>
---
lib/rwsem.c | 22 +++++++++++++++++++++-
1 files changed, 21 insertions(+), 1 deletions(-)
diff --git a/lib/rwsem.c b/lib/rwsem.c
index 2dd1a1b..f0589b2 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -34,6 +34,7 @@ struct rwsem_waiter {
unsigned int flags;
#define RWSEM_WAITING_FOR_READ 0x00000001
#define RWSEM_WAITING_FOR_WRITE 0x00000002
+#define RWSEM_UNFAIR 0x00000004
};
/* Wake types for __rwsem_do_wake(). Note that RWSEM_WAKE_NO_ACTIVE and
@@ -186,7 +187,11 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
if (list_empty(&sem->wait_list))
adjustment += RWSEM_WAITING_BIAS;
- list_add_tail(&waiter.list, &sem->wait_list);
+
+ if (flags & RWSEM_UNFAIR)
+ list_add(&waiter.list, &sem->wait_list);
+ else
+ list_add_tail(&waiter.list, &sem->wait_list);
/* we're now waiting on the lock, but no longer actively locking */
count = rwsem_atomic_update(adjustment, sem);
@@ -228,6 +233,21 @@ rwsem_down_read_failed(struct rw_semaphore *sem)
-RWSEM_ACTIVE_READ_BIAS);
}
+#ifdef __HAVE_DOWN_READ_UNFAIR
+
+/*
+ * wait for the read lock to be granted - skip waiting threads
+ */
+asmregparm struct rw_semaphore __sched *
+rwsem_down_read_unfair_failed(struct rw_semaphore *sem)
+{
+ return rwsem_down_failed_common(sem,
+ RWSEM_WAITING_FOR_READ | RWSEM_UNFAIR,
+ -RWSEM_ACTIVE_READ_BIAS);
+}
+
+#endif
+
/*
* wait for the write lock to be granted
*/
--
1.7.0.1
next prev parent reply other threads:[~2010-05-14 12:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-14 12:39 [PATCH 00/10] V2: rwsem changes + down_read_unfair() proposal Michel Lespinasse
2010-05-14 12:39 ` [PATCH 01/10] x86 rwsem: minor cleanups Michel Lespinasse
2010-05-14 12:39 ` [PATCH 02/10] rwsem: fully separate code pathes to wake writers vs readers Michel Lespinasse
2010-05-14 12:39 ` [PATCH 03/10] rwsem: lighter active count checks when waking up readers Michel Lespinasse
2010-05-14 12:39 ` [PATCH 04/10] rwsem: let RWSEM_WAITING_BIAS represent any number of waiting threads Michel Lespinasse
2010-05-14 12:39 ` [PATCH 05/10] rwsem: wake queued readers when writer blocks on active read lock Michel Lespinasse
2010-05-14 12:39 ` [PATCH 06/10] rwsem: smaller wrappers around rwsem_down_failed_common Michel Lespinasse
2010-05-14 12:39 ` [PATCH 07/10] generic rwsem: implement down_read_unfair Michel Lespinasse
2010-05-14 12:39 ` Michel Lespinasse [this message]
2010-05-14 12:39 ` [PATCH 09/10] x86 rwsem: down_read_unfair implementation Michel Lespinasse
2010-05-14 12:39 ` [PATCH 10/10] Use down_read_unfair() for /sys/<pid>/exe and /sys/<pid>/maps files Michel Lespinasse
2010-05-14 15:13 ` [PATCH 00/10] V2: rwsem changes + down_read_unfair() proposal Linus Torvalds
2010-05-17 21:28 ` Michel Lespinasse
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=1273840782-5920-9-git-send-email-walken@google.com \
--to=walken@google.com \
--cc=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mikew@google.com \
--cc=mingo@elte.hu \
--cc=suleiman@google.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=yinghan@google.com \
/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
Powered by JetHome