From: Andi Kleen <andi@firstfloor.org>
To: linux-kernel@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
x86@kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 28/29] x86, tsx: Add adaptive elision for rwsems
Date: Fri, 22 Mar 2013 18:25:22 -0700 [thread overview]
Message-ID: <1364001923-10796-29-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1364001923-10796-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
Convert the rwsem elision to be adaptive. This requires adding
4/8 bytes to the rwsem for the adaptation state. The algorithm
is the same as for other adaptive lock types. The elision
configuration is split for readers and writers.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
arch/x86/include/asm/rwsem.h | 22 +++++++++++++++++-----
arch/x86/kernel/rtm-locks.c | 10 ++++++++++
include/linux/rwsem.h | 3 +++
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
index f9297af..da6437c 100644
--- a/arch/x86/include/asm/rwsem.h
+++ b/arch/x86/include/asm/rwsem.h
@@ -39,6 +39,7 @@
#ifdef __KERNEL__
#include <asm/asm.h>
#include <linux/elide.h>
+#include <linux/jump_label.h>
/*
* The bias values and the counter type limits the number of
@@ -58,14 +59,18 @@
#define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS
#define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
-extern bool rwsem_elision;
+extern struct static_key rwsem_elision;
+extern struct elision_config readsem_elision_config;
+extern struct elision_config writesem_elision_config;
/*
* lock for reading
*/
static inline void __down_read(struct rw_semaphore *sem)
{
- if (elide_lock(rwsem_elision, sem->count == 0))
+ if (elide_lock_adapt(rwsem_elision, sem->count == 0,
+ &sem->elision_adapt,
+ &readsem_elision_config))
return;
asm volatile("# beginning down_read\n\t"
LOCK_PREFIX _ASM_INC "(%1)\n\t"
@@ -86,7 +91,9 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
{
long result, tmp;
- if (elide_lock(rwsem_elision, sem->count == 0))
+ if (elide_lock_adapt(rwsem_elision, sem->count == 0,
+ &sem->elision_adapt,
+ &readsem_elision_config))
return 1;
asm volatile("# beginning __down_read_trylock\n\t"
" mov %0,%1\n\t"
@@ -111,7 +118,9 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
{
long tmp;
- if (elide_lock(rwsem_elision, sem->count == 0))
+ if (elide_lock_adapt(rwsem_elision, sem->count == 0,
+ &sem->elision_adapt,
+ &readsem_elision_config))
return;
asm volatile("# beginning down_write\n\t"
LOCK_PREFIX " xadd %1,(%2)\n\t"
@@ -139,7 +148,9 @@ static inline int __down_write_trylock(struct rw_semaphore *sem)
{
long ret;
- if (elide_lock(rwsem_elision, sem->count == 0))
+ if (elide_lock_adapt(rwsem_elision, sem->count == 0,
+ &sem->elision_adapt,
+ &writesem_elision_config))
return 1;
ret = cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE,
RWSEM_ACTIVE_WRITE_BIAS);
@@ -195,6 +206,7 @@ static inline void __up_write(struct rw_semaphore *sem)
*/
static inline void __downgrade_write(struct rw_semaphore *sem)
{
+ /* if (sem->count == 0) return; */
asm volatile("# beginning __downgrade_write\n\t"
LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
/*
diff --git a/arch/x86/kernel/rtm-locks.c b/arch/x86/kernel/rtm-locks.c
index 40a0e7d..5a33a12 100644
--- a/arch/x86/kernel/rtm-locks.c
+++ b/arch/x86/kernel/rtm-locks.c
@@ -436,6 +436,15 @@ static unsigned rtm_patch(u8 type, u16 clobbers, void *ibuf,
struct static_key mutex_elision = STATIC_KEY_INIT_FALSE;
module_param(mutex_elision, static_key, 0644);
+struct static_key rwsem_elision = STATIC_KEY_INIT_FALSE;
+module_param(rwsem_elision, static_key, 0644);
+__read_mostly struct elision_config readsem_elision_config =
+ DEFAULT_ELISION_CONFIG;
+TUNE_ELISION_CONFIG(readsem, readsem_elision_config);
+__read_mostly struct elision_config writesem_elision_config =
+ DEFAULT_ELISION_CONFIG;
+TUNE_ELISION_CONFIG(writesem, writesem_elision_config);
+
void init_rtm_spinlocks(void)
{
if (!boot_cpu_has(X86_FEATURE_RTM))
@@ -464,6 +473,7 @@ void init_rtm_spinlocks(void)
static_key_slow_inc(&rwlock_elision);
static_key_slow_inc(&mutex_elision);
+ static_key_slow_inc(&rwsem_elision);
bitlock_elision = true;
}
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 436e430..fb96c565 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -28,6 +28,9 @@ struct rw_semaphore {
long count;
raw_spinlock_t wait_lock;
struct list_head wait_list;
+#ifdef CONFIG_RTM_LOCKS
+ short elision_adapt;
+#endif
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lockdep_map dep_map;
#endif
--
1.7.7.6
next prev parent reply other threads:[~2013-03-23 1:26 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-23 1:24 RFC: Kernel lock elision for TSX Andi Kleen
2013-03-23 1:24 ` [PATCH 01/29] tsx: Add generic noop macros for RTM intrinsics Andi Kleen
2013-03-25 3:39 ` Michael Neuling
2013-03-25 8:19 ` Andi Kleen
2013-03-25 8:50 ` Michael Neuling
2013-03-23 1:24 ` [PATCH 02/29] x86, tsx: Add " Andi Kleen
2013-03-25 3:40 ` Michael Neuling
2013-03-25 8:15 ` Andi Kleen
2013-03-25 8:54 ` Michael Neuling
2013-03-25 9:32 ` Andi Kleen
2013-03-23 1:24 ` [PATCH 03/29] tsx: Add generic disable_txn macros Andi Kleen
2013-03-23 1:24 ` [PATCH 04/29] tsx: Add generic linux/elide.h macros Andi Kleen
2013-03-23 1:24 ` [PATCH 05/29] x86, tsx: Add a minimal RTM tester at bootup Andi Kleen
2013-03-23 1:25 ` [PATCH 06/29] checkpatch: Don't warn about if ((status = _xbegin()) == _XBEGIN_STARTED) Andi Kleen
2013-03-25 3:39 ` Michael Neuling
2013-03-23 1:25 ` [PATCH 07/29] x86, tsx: Don't abort immediately in __read/write_lock_failed Andi Kleen
2013-03-23 1:25 ` [PATCH 08/29] locking, tsx: Add support for arch_read/write_unlock_irq/flags Andi Kleen
2013-03-23 1:25 ` [PATCH 09/29] x86, xen: Support arch_spin_unlock_irq/flags Andi Kleen
2013-03-23 1:25 ` [PATCH 10/29] locking, tsx: Add support for arch_spin_unlock_irq/flags Andi Kleen
2013-03-23 1:25 ` [PATCH 11/29] x86, paravirt: Add support for arch_spin_unlock_flags/irq Andi Kleen
2013-03-23 1:25 ` [PATCH 12/29] x86, tsx: Add a per thread transaction disable count Andi Kleen
2013-03-23 11:51 ` Borislav Petkov
2013-03-23 13:51 ` Andi Kleen
2013-03-23 15:52 ` Borislav Petkov
2013-03-23 16:25 ` Borislav Petkov
2013-03-23 17:16 ` Linus Torvalds
2013-03-23 17:32 ` Borislav Petkov
2013-03-23 18:01 ` Andi Kleen
2013-03-23 1:25 ` [PATCH 13/29] params: Add a per cpu module param type Andi Kleen
2013-03-23 1:25 ` [PATCH 14/29] params: Add static key module param Andi Kleen
2013-03-23 1:25 ` [PATCH 15/29] x86, tsx: Add TSX lock elision infrastructure Andi Kleen
2013-03-23 1:25 ` [PATCH 16/29] locking, tsx: Allow architecture to control mutex fast path owner field Andi Kleen
2013-03-23 1:25 ` [PATCH 17/29] x86, tsx: Enable lock elision for mutexes Andi Kleen
2013-03-23 1:25 ` [PATCH 18/29] locking, tsx: Abort is mutex_is_locked() Andi Kleen
2013-03-23 1:25 ` [PATCH 19/29] x86, tsx: Add support for rwsem elision Andi Kleen
2013-03-23 1:25 ` [PATCH 20/29] x86, tsx: Enable elision for read write spinlocks Andi Kleen
2013-03-23 1:25 ` [PATCH 21/29] locking, tsx: Protect assert_spin_locked() with _xtest() Andi Kleen
2013-03-23 1:25 ` [PATCH 22/29] locking, tsx: Add a trace point for elision skipping Andi Kleen
2013-03-23 1:25 ` [PATCH 23/29] x86, tsx: Add generic per-lock adaptive lock elision support Andi Kleen
2013-03-23 1:25 ` [PATCH 24/29] x86, tsx: Use adaptive elision for mutexes Andi Kleen
2013-03-23 1:25 ` [PATCH 25/29] x86, tsx: Add adaption support for spinlocks Andi Kleen
2013-03-23 1:25 ` [PATCH 26/29] x86, tsx: Add adaptation support to rw spinlocks Andi Kleen
2013-03-23 1:25 ` [PATCH 27/29] locking, tsx: Add elision to bit spinlocks Andi Kleen
2013-03-23 1:25 ` Andi Kleen [this message]
2013-03-23 1:25 ` [PATCH 29/29] tsx: Add documentation for lock-elision Andi Kleen
2013-03-23 17:11 ` RFC: Kernel lock elision for TSX Linus Torvalds
2013-03-23 18:00 ` Andi Kleen
2013-03-23 18:02 ` Andi Kleen
2013-03-24 14:17 ` Benjamin Herrenschmidt
2013-03-25 0:59 ` Michael Neuling
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=1364001923-10796-29-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.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