cregit-Linux how code gets into the kernel

Release 4.14 arch/s390/lib/spinlock.c

Directory: arch/s390/lib
// SPDX-License-Identifier: GPL-2.0
/*
 *    Out of line spinlock code.
 *
 *    Copyright IBM Corp. 2004, 2006
 *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
 */

#include <linux/types.h>
#include <linux/export.h>
#include <linux/spinlock.h>
#include <linux/init.h>
#include <linux/smp.h>
#include <asm/io.h>


int spin_retry = -1;


static int __init spin_retry_init(void) { if (spin_retry < 0) spin_retry = 1000; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky22100.00%1100.00%
Total22100.00%1100.00%

early_initcall(spin_retry_init); /** * spin_retry= parameter */
static int __init spin_retry_setup(char *str) { spin_retry = simple_strtoul(str, &str, 0); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky26100.00%1100.00%
Total26100.00%1100.00%

__setup("spin_retry=", spin_retry_setup);
static inline int arch_load_niai4(int *lock) { int owner; asm volatile( #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES " .long 0xb2fa0040\n" /* NIAI 4 */ #endif " l %0,%1\n" : "=d" (owner) : "Q" (*lock) : "memory"); return owner; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky28100.00%1100.00%
Total28100.00%1100.00%


static inline int arch_cmpxchg_niai8(int *lock, int old, int new) { int expected = old; asm volatile( #ifdef CONFIG_HAVE_MARCH_ZEC12_FEATURES " .long 0xb2fa0080\n" /* NIAI 8 */ #endif " cs %0,%3,%1\n" : "=d" (old), "=Q" (*lock) : "0" (old), "d" (new), "Q" (*lock) : "cc", "memory"); return expected == old; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky38100.00%1100.00%
Total38100.00%1100.00%


void arch_spin_lock_wait(arch_spinlock_t *lp) { int cpu = SPINLOCK_LOCKVAL; int owner, count; /* Pass the virtual CPU to the lock holder if it is not running */ owner = arch_load_niai4(&lp->lock); if (owner && arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); count = spin_retry; while (1) { owner = arch_load_niai4(&lp->lock); /* Try to get the lock if it is free. */ if (!owner) { if (arch_cmpxchg_niai8(&lp->lock, 0, cpu)) return; continue; } if (count-- >= 0) continue; count = spin_retry; /* * For multiple layers of hypervisors, e.g. z/VM + LPAR * yield the CPU unconditionally. For LPAR rely on the * sense running status. */ if (!MACHINE_IS_LPAR || arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); } }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky9881.67%750.00%
Gerald Schaefer1714.17%214.29%
Philipp Hachtmann21.67%214.29%
Thomas Gleixner21.67%214.29%
Christian Bornträger10.83%17.14%
Total120100.00%14100.00%

EXPORT_SYMBOL(arch_spin_lock_wait);
void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags) { int cpu = SPINLOCK_LOCKVAL; int owner, count; local_irq_restore(flags); /* Pass the virtual CPU to the lock holder if it is not running */ owner = arch_load_niai4(&lp->lock); if (owner && arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); count = spin_retry; while (1) { owner = arch_load_niai4(&lp->lock); /* Try to get the lock if it is free. */ if (!owner) { local_irq_disable(); if (arch_cmpxchg_niai8(&lp->lock, 0, cpu)) return; local_irq_restore(flags); continue; } if (count-- >= 0) continue; count = spin_retry; /* * For multiple layers of hypervisors, e.g. z/VM + LPAR * yield the CPU unconditionally. For LPAR rely on the * sense running status. */ if (!MACHINE_IS_LPAR || arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); } }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky5842.34%430.77%
Hisashi Hifumi5338.69%17.69%
Gerald Schaefer1913.87%215.38%
Philipp Hachtmann32.19%215.38%
Thomas Gleixner21.46%215.38%
Christian Bornträger10.73%17.69%
Heiko Carstens10.73%17.69%
Total137100.00%13100.00%

EXPORT_SYMBOL(arch_spin_lock_wait_flags);
int arch_spin_trylock_retry(arch_spinlock_t *lp) { int cpu = SPINLOCK_LOCKVAL; int owner, count; for (count = spin_retry; count > 0; count--) { owner = READ_ONCE(lp->lock); /* Try to get the lock if it is free. */ if (!owner) { if (__atomic_cmpxchg_bool(&lp->lock, 0, cpu)) return 1; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky6084.51%457.14%
Philipp Hachtmann811.27%114.29%
Christian Ehrhardt22.82%114.29%
Christian Bornträger11.41%114.29%
Total71100.00%7100.00%

EXPORT_SYMBOL(arch_spin_trylock_retry);
void _raw_read_lock_wait(arch_rwlock_t *rw) { int count = spin_retry; int owner, old; #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES __RAW_LOCK(&rw->lock, -1, __RAW_OP_ADD); #endif owner = 0; while (1) { if (count-- <= 0) { if (owner && arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); if (old < 0) continue; if (__atomic_cmpxchg_bool(&rw->lock, old, old + 1)) return; } }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky11698.31%675.00%
Thomas Gleixner10.85%112.50%
Christian Bornträger10.85%112.50%
Total118100.00%8100.00%

EXPORT_SYMBOL(_raw_read_lock_wait);
int _raw_read_trylock_retry(arch_rwlock_t *rw) { int count = spin_retry; int old; while (count-- > 0) { old = ACCESS_ONCE(rw->lock); if (old < 0) continue; if (__atomic_cmpxchg_bool(&rw->lock, old, old + 1)) return 1; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky6398.44%480.00%
Thomas Gleixner11.56%120.00%
Total64100.00%5100.00%

EXPORT_SYMBOL(_raw_read_trylock_retry); #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
void _raw_write_lock_wait(arch_rwlock_t *rw, int prev) { int count = spin_retry; int owner, old; owner = 0; while (1) { if (count-- <= 0) { if (owner && arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); smp_mb(); if (old >= 0) { prev = __RAW_LOCK(&rw->lock, 0x80000000, __RAW_OP_OR); old = prev; } if ((old & 0x7fffffff) == 0 && prev >= 0) break; } }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky12198.37%250.00%
Christian Bornträger21.63%250.00%
Total123100.00%4100.00%

EXPORT_SYMBOL(_raw_write_lock_wait); #else /* CONFIG_HAVE_MARCH_Z196_FEATURES */
void _raw_write_lock_wait(arch_rwlock_t *rw) { int count = spin_retry; int owner, old, prev; prev = 0x80000000; owner = 0; while (1) { if (count-- <= 0) { if (owner && arch_vcpu_is_preempted(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); if (old >= 0 && __atomic_cmpxchg_bool(&rw->lock, old, old | 0x80000000)) prev = old; else smp_mb(); if ((old & 0x7fffffff) == 0 && prev >= 0) break; } }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky11995.20%660.00%
Christian Ehrhardt32.40%110.00%
Christian Bornträger21.60%220.00%
Thomas Gleixner10.80%110.00%
Total125100.00%10100.00%

EXPORT_SYMBOL(_raw_write_lock_wait); #endif /* CONFIG_HAVE_MARCH_Z196_FEATURES */
int _raw_write_trylock_retry(arch_rwlock_t *rw) { int count = spin_retry; int old; while (count-- > 0) { old = ACCESS_ONCE(rw->lock); if (old) continue; if (__atomic_cmpxchg_bool(&rw->lock, 0, 0x80000000)) return 1; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky5286.67%466.67%
Christian Ehrhardt711.67%116.67%
Thomas Gleixner11.67%116.67%
Total60100.00%6100.00%

EXPORT_SYMBOL(_raw_write_trylock_retry);
void arch_lock_relax(int cpu) { if (!cpu) return; if (MACHINE_IS_LPAR && !arch_vcpu_is_preempted(~cpu)) return; smp_yield_cpu(~cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky3196.88%266.67%
Christian Bornträger13.12%133.33%
Total32100.00%3100.00%

EXPORT_SYMBOL(arch_lock_relax);

Overall Contributors

PersonTokensPropCommitsCommitProp
Martin Schwidefsky91586.57%1344.83%
Hisashi Hifumi575.39%13.45%
Gerald Schaefer363.41%26.90%
Philipp Hachtmann131.23%26.90%
Christian Ehrhardt121.14%13.45%
Thomas Gleixner111.04%310.34%
Christian Bornträger90.85%310.34%
Heiko Carstens20.19%26.90%
Paul Gortmaker10.09%13.45%
Greg Kroah-Hartman10.09%13.45%
Total1057100.00%29100.00%
Directory: arch/s390/lib
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.