Home Home > GIT Browse > SLE15
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavidlohr Bueso <dbueso@suse.de>2016-06-14 10:06:02 -0700
committerDavidlohr Bueso <dbueso@suse.de>2016-06-14 10:06:02 -0700
commit34a6c94e68b1a50a996207937e6c89eac0974005 (patch)
tree939b620bc360ab8a1666b5761e524226eaa5c0b9
parent969a7a8a064f4fb8bfe0657e9dd3647d0dd0b693 (diff)
locking/mutex: Optimize mutex_trylock() fast-path (bsc#969756).rpm-4.4.13-46
-rw-r--r--patches.suse/0001-locking-mutex-Optimize-mutex_trylock-fast-path.patch136
-rw-r--r--series.conf1
2 files changed, 137 insertions, 0 deletions
diff --git a/patches.suse/0001-locking-mutex-Optimize-mutex_trylock-fast-path.patch b/patches.suse/0001-locking-mutex-Optimize-mutex_trylock-fast-path.patch
new file mode 100644
index 0000000000..0e2d3e7345
--- /dev/null
+++ b/patches.suse/0001-locking-mutex-Optimize-mutex_trylock-fast-path.patch
@@ -0,0 +1,136 @@
+From 6428671bae97caa7040e24e79e969fd87908f4f3 Mon Sep 17 00:00:00 2001
+From: Peter Zijlstra <peterz@infradead.org>
+Date: Wed, 1 Jun 2016 20:58:15 +0200
+Subject: [PATCH] locking/mutex: Optimize mutex_trylock() fast-path
+Git-commit: 6428671bae97caa7040e24e79e969fd87908f4f3
+Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
+Patch-mainline: Queued in -tip locking/core for v4.8
+References: bsc#969756
+
+A while back Viro posted a number of 'interesting' mutex_is_locked()
+users on IRC, one of those was RCU.
+
+RCU seems to use mutex_is_locked() to avoid doing mutex_trylock(), the
+regular load before modify pattern.
+
+While the use isn't wrong per se, its curious in that its needed at all,
+mutex_trylock() should be good enough on its own to avoid the pointless
+cacheline bounces.
+
+[SLE12-SP2 backport, I have ommited the RCU fix as it is not valid in
+the context of SP2 -- dbueso]
+
+Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
+Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
+Acked-by: Paul McKenney <paulmck@linux.vnet.ibm.com>
+Acked-by: Davidlohr Bueso <dave@stgolabs.net>
+Cc: Andrew Morton <akpm@linux-foundation.org>
+Cc: Linus Torvalds <torvalds@linux-foundation.org>
+Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
+Cc: Peter Zijlstra <peterz@infradead.org>
+Cc: Thomas Gleixner <tglx@linutronix.de>
+Cc: Waiman Long <Waiman.Long@hpe.com>
+Link: http://lkml.kernel.org/r/20160601185815.GW3190@twins.programming.kicks-ass.net
+Signed-off-by: Ingo Molnar <mingo@kernel.org>
+Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
+
+---
+ arch/ia64/include/asm/mutex.h | 2 +-
+ arch/powerpc/include/asm/mutex.h | 2 +-
+ arch/x86/include/asm/mutex_32.h | 2 +-
+ arch/x86/include/asm/mutex_64.h | 6 +++---
+ include/asm-generic/mutex-dec.h | 2 +-
+ include/asm-generic/mutex-xchg.h | 6 +++++-
+ 6 files changed, 12 insertions(+), 8 deletions(-)
+
+diff --git a/arch/ia64/include/asm/mutex.h b/arch/ia64/include/asm/mutex.h
+index f41e66d65e31..28cb819e0ff9 100644
+--- a/arch/ia64/include/asm/mutex.h
++++ b/arch/ia64/include/asm/mutex.h
+@@ -82,7 +82,7 @@ __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
+ static inline int
+ __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+ {
+- if (cmpxchg_acq(count, 1, 0) == 1)
++ if (atomic_read(count) == 1 && cmpxchg_acq(count, 1, 0) == 1)
+ return 1;
+ return 0;
+ }
+diff --git a/arch/powerpc/include/asm/mutex.h b/arch/powerpc/include/asm/mutex.h
+index 127ab23e1f6c..078155fa1189 100644
+--- a/arch/powerpc/include/asm/mutex.h
++++ b/arch/powerpc/include/asm/mutex.h
+@@ -124,7 +124,7 @@ __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
+ static inline int
+ __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+ {
+- if (likely(__mutex_cmpxchg_lock(count, 1, 0) == 1))
++ if (likely(atomic_read(count) == 1 && __mutex_cmpxchg_lock(count, 1, 0) == 1))
+ return 1;
+ return 0;
+ }
+diff --git a/arch/x86/include/asm/mutex_32.h b/arch/x86/include/asm/mutex_32.h
+index 85e6cda45a02..e9355a84fc67 100644
+--- a/arch/x86/include/asm/mutex_32.h
++++ b/arch/x86/include/asm/mutex_32.h
+@@ -101,7 +101,7 @@ static inline int __mutex_fastpath_trylock(atomic_t *count,
+ int (*fail_fn)(atomic_t *))
+ {
+ /* cmpxchg because it never induces a false contention state. */
+- if (likely(atomic_cmpxchg(count, 1, 0) == 1))
++ if (likely(atomic_read(count) == 1 && atomic_cmpxchg(count, 1, 0) == 1))
+ return 1;
+
+ return 0;
+diff --git a/arch/x86/include/asm/mutex_64.h b/arch/x86/include/asm/mutex_64.h
+index 07537a44216e..d9850758464e 100644
+--- a/arch/x86/include/asm/mutex_64.h
++++ b/arch/x86/include/asm/mutex_64.h
+@@ -118,10 +118,10 @@ do { \
+ static inline int __mutex_fastpath_trylock(atomic_t *count,
+ int (*fail_fn)(atomic_t *))
+ {
+- if (likely(atomic_cmpxchg(count, 1, 0) == 1))
++ if (likely(atomic_read(count) == 1 && atomic_cmpxchg(count, 1, 0) == 1))
+ return 1;
+- else
+- return 0;
++
++ return 0;
+ }
+
+ #endif /* _ASM_X86_MUTEX_64_H */
+diff --git a/include/asm-generic/mutex-dec.h b/include/asm-generic/mutex-dec.h
+index fd694cfd678a..c54829d3de37 100644
+--- a/include/asm-generic/mutex-dec.h
++++ b/include/asm-generic/mutex-dec.h
+@@ -80,7 +80,7 @@ __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
+ static inline int
+ __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+ {
+- if (likely(atomic_cmpxchg_acquire(count, 1, 0) == 1))
++ if (likely(atomic_read(count) == 1 && atomic_cmpxchg_acquire(count, 1, 0) == 1))
+ return 1;
+ return 0;
+ }
+diff --git a/include/asm-generic/mutex-xchg.h b/include/asm-generic/mutex-xchg.h
+index a6b4a7bd6ac9..3269ec4e195f 100644
+--- a/include/asm-generic/mutex-xchg.h
++++ b/include/asm-generic/mutex-xchg.h
+@@ -91,8 +91,12 @@ __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
+ static inline int
+ __mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
+ {
+- int prev = atomic_xchg_acquire(count, 0);
++ int prev;
+
++ if (atomic_read(count) != 1)
++ return 0;
++
++ prev = atomic_xchg_acquire(count, 0);
+ if (unlikely(prev < 0)) {
+ /*
+ * The lock was marked contended so we must restore that
+--
+2.6.6
+
diff --git a/series.conf b/series.conf
index df1a878854..3ac0ac508b 100644
--- a/series.conf
+++ b/series.conf
@@ -369,6 +369,7 @@
patches.suse/0001-locking-mutex-Set-and-clear-owner-using-WRITE_ONCE.patch
patches.suse/0001-locking-rtmutex-Only-warn-once-on-a-trylock-from-bad.patch
patches.suse/0001-locking-rwsem-Optimize-write-lock-by-reducing-operat.patch
+ patches.suse/0001-locking-mutex-Optimize-mutex_trylock-fast-path.patch
########################################################
# locking/rcu