The patch titled Directed yield: direct yield of spinlocks for s390. has been added to the -mm tree. Its filename is directed-yield-direct-yield-of-spinlocks-for-s390.patch See http://www.zip.com.au/~akpm/linux/patches/stuff/added-to-mm.txt to find out what to do about this ------------------------------------------------------ Subject: Directed yield: direct yield of spinlocks for s390. From: Martin Schwidefsky <schwidefsky@xxxxxxxxxx> Use the new diagnose 0x9c in the spinlock implementation for s390. It yields the remaining timeslice of the virtual cpu that tries to acquire a lock to the virtual cpu that is the current holder of the lock. Signed-off-by: Martin Schwidefsky <schwidefsky@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxx> --- arch/s390/kernel/head31.S | 11 ++++ arch/s390/kernel/head64.S | 11 ++++ arch/s390/lib/spinlock.c | 62 +++++++++++++++++----------- include/asm-s390/setup.h | 1 include/asm-s390/spinlock.h | 31 +++++++++----- include/asm-s390/spinlock_types.h | 6 +- 6 files changed, 87 insertions(+), 35 deletions(-) diff -puN arch/s390/kernel/head31.S~directed-yield-direct-yield-of-spinlocks-for-s390 arch/s390/kernel/head31.S --- a/arch/s390/kernel/head31.S~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/arch/s390/kernel/head31.S @@ -254,6 +254,16 @@ startup_continue: oi 3(%r12),0x80 # set IDTE flag .Lchkidte: +# +# find out if the diag 0x9c is available +# + mvc __LC_PGM_NEW_PSW(8),.Lpcdiag9c-.LPG1(%r13) + stap __LC_CPUID+4 # store cpu address + lh %r1,__LC_CPUID+4 + diag %r1,0,0x9c # test diag 0x9c + oi 2(%r12),1 # set diag9c flag +.Lchkdiag9c: + lpsw .Lentry-.LPG1(13) # jump to _stext in primary-space, # virtual and never return ... .align 8 @@ -281,6 +291,7 @@ startup_continue: .Lpccsp:.long 0x00080000,0x80000000 + .Lchkcsp .Lpcmvpg:.long 0x00080000,0x80000000 + .Lchkmvpg .Lpcidte:.long 0x00080000,0x80000000 + .Lchkidte +.Lpcdiag9c:.long 0x00080000,0x80000000 + .Lchkdiag9c .Lmemsize:.long memory_size .Lmchunk:.long memory_chunk .Lmflags:.long machine_flags diff -puN arch/s390/kernel/head64.S~directed-yield-direct-yield-of-spinlocks-for-s390 arch/s390/kernel/head64.S --- a/arch/s390/kernel/head64.S~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/arch/s390/kernel/head64.S @@ -251,6 +251,17 @@ startup_continue: 0: # +# find out if the diag 0x9c is available +# + la %r1,0f-.LPG1(%r13) # set program check address + stg %r1,__LC_PGM_NEW_PSW+8 + stap __LC_CPUID+4 # store cpu address + lh %r1,__LC_CPUID+4 + diag %r1,0,0x9c # test diag 0x9c + oi 6(%r12),1 # set diag9c flag +0: + +# # find out if we have the MVCOS instruction # la %r1,0f-.LPG1(%r13) # set program check address diff -puN arch/s390/lib/spinlock.c~directed-yield-direct-yield-of-spinlocks-for-s390 arch/s390/lib/spinlock.c --- a/arch/s390/lib/spinlock.c~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/arch/s390/lib/spinlock.c @@ -24,57 +24,76 @@ static int __init spin_retry_setup(char } __setup("spin_retry=", spin_retry_setup); -static inline void -_diag44(void) +static inline void _raw_yield(void) { -#ifdef CONFIG_64BIT if (MACHINE_HAS_DIAG44) -#endif asm volatile("diag 0,0,0x44"); } -void -_raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc) +static inline void _raw_yield_cpu(int cpu) +{ + if (MACHINE_HAS_DIAG9C) + asm volatile("diag %0,0,0x9c" + : : "d" (__cpu_logical_map[cpu])); + else + _raw_yield(); +} + +void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc) { int count = spin_retry; + unsigned int cpu = ~smp_processor_id(); while (1) { if (count-- <= 0) { - _diag44(); + unsigned int owner = lp->owner_cpu; + if (owner != 0) + _raw_yield_cpu(~owner); count = spin_retry; } if (__raw_spin_is_locked(lp)) continue; - if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) + if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) { + lp->owner_pc = pc; return; + } } } EXPORT_SYMBOL(_raw_spin_lock_wait); -int -_raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc) +int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc) { - int count = spin_retry; + unsigned int cpu = ~smp_processor_id(); + int count; - while (count-- > 0) { + for (count = spin_retry; count > 0; count--) { if (__raw_spin_is_locked(lp)) continue; - if (_raw_compare_and_swap(&lp->lock, 0, pc) == 0) + if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) { + lp->owner_pc = pc; return 1; + } } return 0; } EXPORT_SYMBOL(_raw_spin_trylock_retry); -void -_raw_read_lock_wait(raw_rwlock_t *rw) +void _raw_spin_relax(raw_spinlock_t *lock) +{ + unsigned int cpu = lock->owner_cpu; + if (cpu != 0) + _raw_yield_cpu(~cpu); +} +EXPORT_SYMBOL(_raw_spin_relax); + +void _raw_read_lock_wait(raw_rwlock_t *rw) { unsigned int old; int count = spin_retry; while (1) { if (count-- <= 0) { - _diag44(); + _raw_yield(); count = spin_retry; } if (!__raw_read_can_lock(rw)) @@ -86,8 +105,7 @@ _raw_read_lock_wait(raw_rwlock_t *rw) } EXPORT_SYMBOL(_raw_read_lock_wait); -int -_raw_read_trylock_retry(raw_rwlock_t *rw) +int _raw_read_trylock_retry(raw_rwlock_t *rw) { unsigned int old; int count = spin_retry; @@ -103,14 +121,13 @@ _raw_read_trylock_retry(raw_rwlock_t *rw } EXPORT_SYMBOL(_raw_read_trylock_retry); -void -_raw_write_lock_wait(raw_rwlock_t *rw) +void _raw_write_lock_wait(raw_rwlock_t *rw) { int count = spin_retry; while (1) { if (count-- <= 0) { - _diag44(); + _raw_yield(); count = spin_retry; } if (!__raw_write_can_lock(rw)) @@ -121,8 +138,7 @@ _raw_write_lock_wait(raw_rwlock_t *rw) } EXPORT_SYMBOL(_raw_write_lock_wait); -int -_raw_write_trylock_retry(raw_rwlock_t *rw) +int _raw_write_trylock_retry(raw_rwlock_t *rw) { int count = spin_retry; diff -puN include/asm-s390/setup.h~directed-yield-direct-yield-of-spinlocks-for-s390 include/asm-s390/setup.h --- a/include/asm-s390/setup.h~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/include/asm-s390/setup.h @@ -39,6 +39,7 @@ extern unsigned long machine_flags; #define MACHINE_IS_P390 (machine_flags & 4) #define MACHINE_HAS_MVPG (machine_flags & 16) #define MACHINE_HAS_IDTE (machine_flags & 128) +#define MACHINE_HAS_DIAG9C (machine_flags & 256) #ifndef __s390x__ #define MACHINE_HAS_IEEE (machine_flags & 2) diff -puN include/asm-s390/spinlock.h~directed-yield-direct-yield-of-spinlocks-for-s390 include/asm-s390/spinlock.h --- a/include/asm-s390/spinlock.h~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/include/asm-s390/spinlock.h @@ -11,6 +11,8 @@ #ifndef __ASM_SPINLOCK_H #define __ASM_SPINLOCK_H +#include <linux/smp.h> + static inline int _raw_compare_and_swap(volatile unsigned int *lock, unsigned int old, unsigned int new) @@ -31,34 +33,46 @@ _raw_compare_and_swap(volatile unsigned * (the type definitions are in asm/spinlock_types.h) */ -#define __raw_spin_is_locked(x) ((x)->lock != 0) +#define __raw_spin_is_locked(x) ((x)->owner_cpu != 0) #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) #define __raw_spin_unlock_wait(lock) \ - do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0) + do { while (__raw_spin_is_locked(lock)) \ + _raw_spin_relax(lock); } while (0) -extern void _raw_spin_lock_wait(raw_spinlock_t *lp, unsigned int pc); -extern int _raw_spin_trylock_retry(raw_spinlock_t *lp, unsigned int pc); +extern void _raw_spin_lock_wait(raw_spinlock_t *, unsigned int pc); +extern int _raw_spin_trylock_retry(raw_spinlock_t *, unsigned int pc); +extern void _raw_spin_relax(raw_spinlock_t *lock); static inline void __raw_spin_lock(raw_spinlock_t *lp) { unsigned long pc = 1 | (unsigned long) __builtin_return_address(0); + int old; - if (unlikely(_raw_compare_and_swap(&lp->lock, 0, pc) != 0)) - _raw_spin_lock_wait(lp, pc); + old = _raw_compare_and_swap(&lp->owner_cpu, 0, ~smp_processor_id()); + if (likely(old == 0)) { + lp->owner_pc = pc; + return; + } + _raw_spin_lock_wait(lp, pc); } static inline int __raw_spin_trylock(raw_spinlock_t *lp) { unsigned long pc = 1 | (unsigned long) __builtin_return_address(0); + int old; - if (likely(_raw_compare_and_swap(&lp->lock, 0, pc) == 0)) + old = _raw_compare_and_swap(&lp->owner_cpu, 0, ~smp_processor_id()); + if (likely(old == 0)) { + lp->owner_pc = pc; return 1; + } return _raw_spin_trylock_retry(lp, pc); } static inline void __raw_spin_unlock(raw_spinlock_t *lp) { - _raw_compare_and_swap(&lp->lock, lp->lock, 0); + lp->owner_pc = 0; + _raw_compare_and_swap(&lp->owner_cpu, lp->owner_cpu, 0); } /* @@ -135,7 +149,6 @@ static inline int __raw_write_trylock(ra return _raw_write_trylock_retry(rw); } -#define _raw_spin_relax(lock) cpu_relax() #define _raw_read_relax(lock) cpu_relax() #define _raw_write_relax(lock) cpu_relax() diff -puN include/asm-s390/spinlock_types.h~directed-yield-direct-yield-of-spinlocks-for-s390 include/asm-s390/spinlock_types.h --- a/include/asm-s390/spinlock_types.h~directed-yield-direct-yield-of-spinlocks-for-s390 +++ a/include/asm-s390/spinlock_types.h @@ -6,16 +6,16 @@ #endif typedef struct { - volatile unsigned int lock; + volatile unsigned int owner_cpu; + volatile unsigned int owner_pc; } __attribute__ ((aligned (4))) raw_spinlock_t; #define __RAW_SPIN_LOCK_UNLOCKED { 0 } typedef struct { volatile unsigned int lock; - volatile unsigned int owner_pc; } raw_rwlock_t; -#define __RAW_RW_LOCK_UNLOCKED { 0, 0 } +#define __RAW_RW_LOCK_UNLOCKED { 0 } #endif _ Patches currently in -mm which might be from schwidefsky@xxxxxxxxxx are origin.patch git-s390.patch reduce-max_nr_zones-remove-display-of-counters-for-unconfigured-zones-s390-fix.patch reduce-max_nr_zones-remove-display-of-counters-for-unconfigured-zones-s390-fix-fix.patch out-of-memory-notifier.patch out-of-memory-notifier-tidy.patch bootmem-use-max_dma_address-instead-of-low32limit.patch own-header-file-for-struct-page.patch convert-s390-page-handling-macros-to-functions.patch convert-s390-page-handling-macros-to-functions-fix.patch s390-fix-cmm-kernel-thread-handling.patch make-touch_nmi_watchdog-imply-touch_softlockup_watchdog-on-fix.patch simplify-update_times-avoid-jiffies-jiffies_64-aliasing-problem-2.patch directed-yield-cpu_relax-variants-for-spinlocks-and-rw-locks.patch directed-yield-direct-yield-of-spinlocks-for-powerpc.patch directed-yield-direct-yield-of-spinlocks-for-s390.patch kill-wall_jiffies.patch generic-ioremap_page_range-implementation.patch generic-ioremap_page_range-flush_cache_vmap.patch generic-ioremap_page_range-s390-conversion.patch s390-update-fs3270-to-use-a-struct-pid.patch add-regs_return_value-helper.patch introduce-kernel_execve.patch rename-the-provided-execve-functions-to-kernel_execve.patch provide-kernel_execve-on-all-architectures.patch provide-kernel_execve-on-all-architectures-fix.patch remove-the-use-of-_syscallx-macros-in-uml.patch sh64-remove-the-use-of-kernel-syscalls.patch remove-remaining-errno-and-__kernel_syscalls__-references.patch - To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html