All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <fweisbec@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Mandeep Singh Baines <msb@google.com>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: [RFC][PATCH 2/2] add a counter for writers spinning on a rwlock
Date: Sun, 25 Jan 2009 12:50:23 -0800 (PST)	[thread overview]
Message-ID: <497cd08f.0c11660a.33a7.ffffdf39@mx.google.com> (raw)

This patch adds a counter for writers that enter a rwlock slow path.
For example it can be useful for slow background tasks which perform some jobs
on the tasklist, such as the hung_task detector (kernel/hung_task.c).

It adds a inc/dec pair on the slow path and 4 bytes for each rwlocks, so the overhead
is not null.

Only x86 is supported for now, writers_spinning_lock() will return 0 on other archs (which
is perhaps not a good idea).

Comments?

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 arch/Kconfig                          |    4 ++++
 arch/x86/Kconfig                      |    1 +
 arch/x86/include/asm/spinlock.h       |    5 +++++
 arch/x86/include/asm/spinlock_types.h |    1 +
 arch/x86/lib/rwlock_64.S              |   10 +++++++---
 include/linux/spinlock.h              |    7 +++++++
 6 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 550dab2..86c22e0 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -106,3 +106,7 @@ config HAVE_CLK
 	  The <linux/clk.h> calls support software clock gating and
 	  thus are a key power management tool on many systems.
 
+config HAVE_NB_WRITERS_SPINNING_LOCK
+	bool
+
+
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 967e114..0aeae17 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -40,6 +40,7 @@ config X86
 	select HAVE_GENERIC_DMA_COHERENT if X86_32
 	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	select USER_STACKTRACE_SUPPORT
+	select HAVE_NB_WRITERS_SPINNING_LOCK
 
 config ARCH_DEFCONFIG
 	string
diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
index 139b424..d9ee21b 100644
--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -283,6 +283,11 @@ static inline int __raw_write_trylock(raw_rwlock_t *lock)
 	return 0;
 }
 
+static inline int __raw_writers_spinning_lock(raw_rwlock_t *lock)
+{
+	return lock->spinning_writers;
+}
+
 static inline void __raw_read_unlock(raw_rwlock_t *rw)
 {
 	asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
diff --git a/arch/x86/include/asm/spinlock_types.h b/arch/x86/include/asm/spinlock_types.h
index 845f81c..163e6de 100644
--- a/arch/x86/include/asm/spinlock_types.h
+++ b/arch/x86/include/asm/spinlock_types.h
@@ -13,6 +13,7 @@ typedef struct raw_spinlock {
 
 typedef struct {
 	unsigned int lock;
+	unsigned int spinning_writers;
 } raw_rwlock_t;
 
 #define __RAW_RW_LOCK_UNLOCKED		{ RW_LOCK_BIAS }
diff --git a/arch/x86/lib/rwlock_64.S b/arch/x86/lib/rwlock_64.S
index 05ea55f..9589b74 100644
--- a/arch/x86/lib/rwlock_64.S
+++ b/arch/x86/lib/rwlock_64.S
@@ -9,14 +9,18 @@
 ENTRY(__write_lock_failed)
 	CFI_STARTPROC
 	LOCK_PREFIX
+	incl 4(%rdi) /* add ourself as a spinning writer */
+1:	LOCK_PREFIX
 	addl $RW_LOCK_BIAS,(%rdi)
-1:	rep
+2:	rep
 	nop
 	cmpl $RW_LOCK_BIAS,(%rdi)
-	jne 1b
+	jne 2b
 	LOCK_PREFIX
 	subl $RW_LOCK_BIAS,(%rdi)
-	jnz  __write_lock_failed
+	jnz  1b
+	LOCK_PREFIX
+	decl 4(%rdi)
 	ret
 	CFI_ENDPROC
 END(__write_lock_failed)
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index e0c0fcc..8ce22af 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -121,6 +121,13 @@ do {								\
 
 #define spin_is_locked(lock)	__raw_spin_is_locked(&(lock)->raw_lock)
 
+#ifdef CONFIG_HAVE_NB_WRITERS_SPINNING_LOCK
+#define writers_spinning_lock(rwlock)				\
+	__raw_writers_spinning_lock(&(rwlock)->raw_lock)
+#else
+#define writers_spinning_lock(rwlock)	0
+#endif
+
 #ifdef CONFIG_GENERIC_LOCKBREAK
 #define spin_is_contended(lock) ((lock)->break_lock)
 #else
-- 
1.6.1



             reply	other threads:[~2009-01-25 20:50 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-25 20:50 Frederic Weisbecker [this message]
2009-01-26 13:32 ` [RFC][PATCH 2/2] add a counter for writers spinning on a rwlock Ingo Molnar
2009-01-26 13:48 ` Peter Zijlstra
2009-01-26 15:25   ` Frédéric Weisbecker
2009-01-26 15:37     ` Peter Zijlstra
2009-01-26 16:04       ` Frédéric Weisbecker
2009-01-26 17:36         ` Mandeep Baines
2009-01-26 17:41           ` Peter Zijlstra
2009-01-27  0:30             ` [PATCH v4] softlockup: remove hung_task_check_count Mandeep Singh Baines
2009-01-27  9:27               ` Frederic Weisbecker
2009-01-27 13:26               ` Ingo Molnar
2009-01-27 18:48                 ` Mandeep Singh Baines
2009-01-28  8:25                   ` Peter Zijlstra
2009-01-29  1:42                     ` Mandeep Singh Baines
2009-01-30 20:41                       ` Mandeep Singh Baines
2009-01-30 20:46                       ` [PATCH 1/2] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-01-30 20:49                       ` [PATCH 2/2] softlockup: check all tasks in hung_task Mandeep Singh Baines
2009-01-31 19:22                         ` Peter Zijlstra
2009-02-03  0:05                           ` [PATCH 2/2 v2] " Mandeep Singh Baines
2009-02-03 12:23                             ` Ingo Molnar
2009-02-03 20:56                               ` [PATCH 2/2 v3] " Mandeep Singh Baines
2009-02-04 19:43                                 ` Ingo Molnar
2009-02-05  4:35                                   ` [PATCH 2/2 v4] " Mandeep Singh Baines
2009-02-05 14:34                                     ` Ingo Molnar
2009-02-05 17:48                                       ` Andrew Morton
2009-02-05 18:07                                         ` Ingo Molnar
2009-02-05 18:30                                           ` Andrew Morton
2009-02-05 18:58                                             ` Ingo Molnar
2009-02-05 18:40                                         ` Mandeep Singh Baines
2009-02-05 17:56                                       ` [PATCH] softlockup: convert read_lock in hung_task to rcu_read_lock Mandeep Singh Baines
2009-02-05 18:13                                         ` Ingo Molnar

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=497cd08f.0c11660a.33a7.ffffdf39@mx.google.com \
    --to=fweisbec@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=msb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.