linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <clameter@sgi.com>
To: linux-mm@kvack.org
Cc: apw@shadowen.org, Andrea Arcangeli <andrea@qumranet.com>,
	Hugh Dickins <hugh@veritas.com>,
	holt@sgi.com, steiner@sgi.com
Subject: [patch 3/5] Add capability to check if rwsems are contended.
Date: Wed, 25 Jun 2008 17:36:35 -0700	[thread overview]
Message-ID: <20080626003833.399527531@sgi.com> (raw)
In-Reply-To: <20080626003632.049547282@sgi.com>

[-- Attachment #1: rwsem_is_contended --]
[-- Type: text/plain, Size: 3451 bytes --]

Add a function to rw_semaphores to check if there are any processes
waiting for the semaphore. Add rwsem_needbreak() to sched.h that works
in the same way as spinlock_needbreak().

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>

---
 include/linux/rwsem.h |    2 ++
 include/linux/sched.h |    9 +++++++++
 lib/rwsem-spinlock.c  |   12 ++++++++++++
 lib/rwsem.c           |   12 ++++++++++++
 4 files changed, 35 insertions(+)

Index: linux-2.6/include/linux/rwsem.h
===================================================================
--- linux-2.6.orig/include/linux/rwsem.h	2008-06-09 20:20:59.037591344 -0700
+++ linux-2.6/include/linux/rwsem.h	2008-06-09 20:28:47.359341232 -0700
@@ -57,6 +57,8 @@ extern void up_write(struct rw_semaphore
  */
 extern void downgrade_write(struct rw_semaphore *sem);
 
+extern int rwsem_is_contended(struct rw_semaphore *sem);
+
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 /*
  * nested locking. NOTE: rwsems are not allowed to recurse
Index: linux-2.6/include/linux/sched.h
===================================================================
--- linux-2.6.orig/include/linux/sched.h	2008-06-09 20:20:59.045591415 -0700
+++ linux-2.6/include/linux/sched.h	2008-06-09 20:28:47.389841510 -0700
@@ -2071,6 +2071,15 @@ static inline int spin_needbreak(spinloc
 #endif
 }
 
+static inline int rwsem_needbreak(struct rw_semaphore *sem)
+{
+#ifdef CONFIG_PREEMPT
+	return rwsem_is_contended(sem);
+#else
+	return 0;
+#endif
+}
+
 /*
  * Reevaluate whether the task has signals pending delivery.
  * Wake the task if so.
Index: linux-2.6/lib/rwsem-spinlock.c
===================================================================
--- linux-2.6.orig/lib/rwsem-spinlock.c	2008-06-09 20:20:59.053591561 -0700
+++ linux-2.6/lib/rwsem-spinlock.c	2008-06-09 20:28:47.402091148 -0700
@@ -305,6 +305,18 @@ void __downgrade_write(struct rw_semapho
 	spin_unlock_irqrestore(&sem->wait_lock, flags);
 }
 
+int rwsem_is_contended(struct rw_semaphore *sem)
+{
+	/*
+	 * Racy check for an empty list. False positives or negatives
+	 * would be okay. False positive may cause a useless dropping of
+	 * locks. False negatives may cause locks to be held a bit
+	 * longer until the next check.
+	 */
+	return !list_empty(&sem->wait_list);
+}
+
+EXPORT_SYMBOL(rwsem_is_contended);
 EXPORT_SYMBOL(__init_rwsem);
 EXPORT_SYMBOL(__down_read);
 EXPORT_SYMBOL(__down_read_trylock);
Index: linux-2.6/lib/rwsem.c
===================================================================
--- linux-2.6.orig/lib/rwsem.c	2008-06-09 20:20:59.061591425 -0700
+++ linux-2.6/lib/rwsem.c	2008-06-09 20:28:47.402091148 -0700
@@ -251,6 +251,18 @@ asmregparm struct rw_semaphore *rwsem_do
 	return sem;
 }
 
+int rwsem_is_contended(struct rw_semaphore *sem)
+{
+	/*
+	 * Racy check for an empty list. False positives or negatives
+	 * would be okay. False positive may cause a useless dropping of
+	 * locks. False negatives may cause locks to be held a bit
+	 * longer until the next check.
+	 */
+	return !list_empty(&sem->wait_list);
+}
+
+EXPORT_SYMBOL(rwsem_is_contended);
 EXPORT_SYMBOL(rwsem_down_read_failed);
 EXPORT_SYMBOL(rwsem_down_write_failed);
 EXPORT_SYMBOL(rwsem_wake);

-- 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2008-06-26  0:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-26  0:36 [patch 0/5] [RFC] Conversion of reverse map locks to semaphores Christoph Lameter
2008-06-26  0:36 ` [patch 1/5] Move tlb handling into free_pgtables() Christoph Lameter
2008-06-26  0:36 ` [patch 2/5] Move tlb flushing inside of unmap vmas Christoph Lameter
2008-06-26  0:36 ` Christoph Lameter [this message]
2008-06-26  0:36 ` [patch 4/5] Convert i_mmap_lock to a rw semaphore Christoph Lameter
2008-06-26  0:36 ` [patch 5/5] Convert anon_vma spinlock to " Christoph Lameter
2008-06-26  1:05   ` Andrea Arcangeli
2008-06-26 17:23     ` Christoph Lameter
2008-06-26 17:27       ` Andrea Arcangeli
2008-06-26  0:53 ` [patch 0/5] [RFC] Conversion of reverse map locks to semaphores Andrea Arcangeli
2008-06-26 17:19   ` Christoph Lameter
2008-06-27  8:53 ` Peter Zijlstra
2008-06-27 15:46   ` Christoph Lameter
2008-06-27 16:38     ` 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=20080626003833.399527531@sgi.com \
    --to=clameter@sgi.com \
    --cc=andrea@qumranet.com \
    --cc=apw@shadowen.org \
    --cc=holt@sgi.com \
    --cc=hugh@veritas.com \
    --cc=linux-mm@kvack.org \
    --cc=steiner@sgi.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