From: Martin Schwidefsky <schwidefsky@de.ibm.com>
Subject: s390/spinlock: use cpu alternatives to enable niai instruction
Patch-mainline: v4.15-rc1
Git-commit: f554be42fd0fd8dd14680c67f2db26b3e7de9670
References: FATE#322614,LTC#160173,bsc#1066354
Summary: kernel: add niai spinlock optimization
Description: Exploit the semaphore-assist facility introduced with IBM z14
to improve the system behaviour in case of congested spinlocks.
Upstream-Description:
s390/spinlock: use cpu alternatives to enable niai instruction
Enable niai instruction in the spinlock code at run-time for machines
on which facility 49 is available (zEC12 and newer).
Signed-off-by: Vasily Gorbik <gor@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Acked-by: Hannes Reinecke <hare@suse.com>
---
arch/s390/include/asm/spinlock.h | 5 ++---
arch/s390/lib/spinlock.c | 9 +++------
2 files changed, 5 insertions(+), 9 deletions(-)
--- a/arch/s390/include/asm/spinlock.h
+++ b/arch/s390/include/asm/spinlock.h
@@ -13,6 +13,7 @@
#include <asm/atomic_ops.h>
#include <asm/barrier.h>
#include <asm/processor.h>
+#include <asm/alternative.h>
#define SPINLOCK_LOCKVAL (S390_lowcore.spinlock_lockval)
@@ -92,9 +93,7 @@ static inline void arch_spin_unlock(arch
{
typecheck(int, lp->lock);
asm volatile(
-#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
- " .long 0xb2fa0070\n" /* NIAI 7 */
-#endif
+ ALTERNATIVE("", ".long 0xb2fa0070", 49) /* NIAI 7 */
" st %1,%0\n"
: "=Q" (lp->lock) : "d" (0) : "cc", "memory");
}
--- a/arch/s390/lib/spinlock.c
+++ b/arch/s390/lib/spinlock.c
@@ -10,6 +10,7 @@
#include <linux/spinlock.h>
#include <linux/init.h>
#include <linux/smp.h>
+#include <asm/alternative.h>
#include <asm/io.h>
int spin_retry = -1;
@@ -37,9 +38,7 @@ static inline int arch_load_niai4(int *l
int owner;
asm volatile(
-#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
- " .long 0xb2fa0040\n" /* NIAI 4 */
-#endif
+ ALTERNATIVE("", ".long 0xb2fa0040", 49) /* NIAI 4 */
" l %0,%1\n"
: "=d" (owner) : "Q" (*lock) : "memory");
return owner;
@@ -50,9 +49,7 @@ static inline int arch_cmpxchg_niai8(int
int expected = old;
asm volatile(
-#ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES
- " .long 0xb2fa0080\n" /* NIAI 8 */
-#endif
+ ALTERNATIVE("", ".long 0xb2fa0080", 49) /* NIAI 8 */
" cs %0,%3,%1\n"
: "=d" (old), "=Q" (*lock)
: "0" (old), "d" (new), "Q" (*lock)