void arch_spin_lock_wait(arch_spinlock_t *lp) { unsigned int cpu = SPINLOCK_LOCKVAL; unsigned int owner; int count; while (1) { owner = ACCESS_ONCE(lp->lock); /* Try to get the lock if it is free. */ if (!owner) { if (_raw_compare_and_swap(&lp->lock, 0, cpu)) return; continue; } /* Check if the lock owner is running. */ if (!smp_vcpu_scheduled(~owner)) { smp_yield_cpu(~owner); continue; } /* Loop for a while on the lock value. */ count = spin_retry; do { owner = ACCESS_ONCE(lp->lock); } while (owner && count-- > 0); if (!owner) continue; /* * For multiple layers of hypervisors, e.g. z/VM + LPAR * yield the CPU if the lock is still unavailable. */ if (!MACHINE_IS_LPAR) smp_yield_cpu(~owner); } }
void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags) { int count = spin_retry; unsigned int cpu = ~smp_processor_id(); unsigned int owner; local_irq_restore(flags); while (1) { owner = lp->owner_cpu; if (!owner || smp_vcpu_scheduled(~owner)) { for (count = spin_retry; count > 0; count--) { if (arch_spin_is_locked(lp)) continue; local_irq_disable(); if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) return; local_irq_restore(flags); } if (MACHINE_IS_LPAR) continue; } owner = lp->owner_cpu; if (owner) smp_yield_cpu(~owner); local_irq_disable(); if (_raw_compare_and_swap(&lp->owner_cpu, 0, cpu) == 0) return; local_irq_restore(flags); } }
void arch_lock_relax(int cpu) { if (!cpu) return; if (MACHINE_IS_LPAR && !arch_vcpu_is_preempted(~cpu)) return; smp_yield_cpu(~cpu); }
void arch_lock_relax(unsigned int cpu) { if (!cpu) return; if (MACHINE_IS_LPAR && smp_vcpu_scheduled(~cpu)) return; smp_yield_cpu(~cpu); }
void arch_spin_relax(arch_spinlock_t *lp) { unsigned int cpu = lp->lock; if (cpu != 0) { if (MACHINE_IS_VM || MACHINE_IS_KVM || !smp_vcpu_scheduled(~cpu)) smp_yield_cpu(~cpu); } }
void arch_spin_lock_wait_flags(arch_spinlock_t *lp, unsigned long flags) { int cpu = SPINLOCK_LOCKVAL; int owner, count, first_diag; local_irq_restore(flags); first_diag = 1; while (1) { owner = ACCESS_ONCE(lp->lock); /* Try to get the lock if it is free. */ if (!owner) { local_irq_disable(); if (__atomic_cmpxchg_bool(&lp->lock, 0, cpu)) return; local_irq_restore(flags); continue; } /* Check if the lock owner is running. */ if (first_diag && arch_vcpu_is_preempted(~owner)) { smp_yield_cpu(~owner); first_diag = 0; continue; } /* Loop for a while on the lock value. */ count = spin_retry; do { owner = ACCESS_ONCE(lp->lock); } while (owner && count-- > 0); if (!owner) continue; /* * 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); first_diag = 0; } } }
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; } }
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; } }
void _raw_write_lock_wait(arch_rwlock_t *rw, unsigned int prev) { unsigned int owner, old; int count = spin_retry; owner = 0; while (1) { if (count-- <= 0) { if (owner && !smp_vcpu_scheduled(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); smp_rmb(); if ((int) old >= 0) { prev = __RAW_LOCK(&rw->lock, 0x80000000, __RAW_OP_OR); old = prev; } if ((old & 0x7fffffff) == 0 && (int) prev >= 0) break; } }
void _raw_read_lock_wait(arch_rwlock_t *rw) { unsigned int owner, old; int count = spin_retry; #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES __RAW_LOCK(&rw->lock, -1, __RAW_OP_ADD); #endif owner = 0; while (1) { if (count-- <= 0) { if (owner && !smp_vcpu_scheduled(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); if ((int) old < 0) continue; if (_raw_compare_and_swap(&rw->lock, old, old + 1)) return; } }
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; } }
void _raw_write_lock_wait(arch_rwlock_t *rw) { unsigned int owner, old, prev; int count = spin_retry; prev = 0x80000000; owner = 0; while (1) { if (count-- <= 0) { if (owner && !smp_vcpu_scheduled(~owner)) smp_yield_cpu(~owner); count = spin_retry; } old = ACCESS_ONCE(rw->lock); owner = ACCESS_ONCE(rw->owner); if ((int) old >= 0 && _raw_compare_and_swap(&rw->lock, old, old | 0x80000000)) prev = old; else smp_rmb(); if ((old & 0x7fffffff) == 0 && (int) prev >= 0) break; } }