mirror of
https://github.com/torvalds/linux.git
synced 2024-12-20 18:11:47 +00:00
626e5fbc14
A qspinlock can be unlocked simply by writing zero to the locked byte. This can be implemented in the generic code, so do that and remove the arch-specific override for x86 in the !PV case. Signed-off-by: Will Deacon <will.deacon@arm.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Waiman Long <longman@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: boqun.feng@gmail.com Cc: linux-arm-kernel@lists.infradead.org Cc: paulmck@linux.vnet.ibm.com Link: http://lkml.kernel.org/r/1524738868-31318-11-git-send-email-will.deacon@arm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
80 lines
2.0 KiB
C
80 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _ASM_X86_QSPINLOCK_H
|
|
#define _ASM_X86_QSPINLOCK_H
|
|
|
|
#include <linux/jump_label.h>
|
|
#include <asm/cpufeature.h>
|
|
#include <asm-generic/qspinlock_types.h>
|
|
#include <asm/paravirt.h>
|
|
|
|
#define _Q_PENDING_LOOPS (1 << 9)
|
|
|
|
#ifdef CONFIG_PARAVIRT_SPINLOCKS
|
|
extern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
|
|
extern void __pv_init_lock_hash(void);
|
|
extern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
|
|
extern void __raw_callee_save___pv_queued_spin_unlock(struct qspinlock *lock);
|
|
|
|
#define queued_spin_unlock queued_spin_unlock
|
|
/**
|
|
* queued_spin_unlock - release a queued spinlock
|
|
* @lock : Pointer to queued spinlock structure
|
|
*
|
|
* A smp_store_release() on the least-significant byte.
|
|
*/
|
|
static inline void native_queued_spin_unlock(struct qspinlock *lock)
|
|
{
|
|
smp_store_release(&lock->locked, 0);
|
|
}
|
|
|
|
static inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
|
|
{
|
|
pv_queued_spin_lock_slowpath(lock, val);
|
|
}
|
|
|
|
static inline void queued_spin_unlock(struct qspinlock *lock)
|
|
{
|
|
pv_queued_spin_unlock(lock);
|
|
}
|
|
|
|
#define vcpu_is_preempted vcpu_is_preempted
|
|
static inline bool vcpu_is_preempted(long cpu)
|
|
{
|
|
return pv_vcpu_is_preempted(cpu);
|
|
}
|
|
#endif
|
|
|
|
#ifdef CONFIG_PARAVIRT
|
|
DECLARE_STATIC_KEY_TRUE(virt_spin_lock_key);
|
|
|
|
void native_pv_lock_init(void) __init;
|
|
|
|
#define virt_spin_lock virt_spin_lock
|
|
static inline bool virt_spin_lock(struct qspinlock *lock)
|
|
{
|
|
if (!static_branch_likely(&virt_spin_lock_key))
|
|
return false;
|
|
|
|
/*
|
|
* On hypervisors without PARAVIRT_SPINLOCKS support we fall
|
|
* back to a Test-and-Set spinlock, because fair locks have
|
|
* horrible lock 'holder' preemption issues.
|
|
*/
|
|
|
|
do {
|
|
while (atomic_read(&lock->val) != 0)
|
|
cpu_relax();
|
|
} while (atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL) != 0);
|
|
|
|
return true;
|
|
}
|
|
#else
|
|
static inline void native_pv_lock_init(void)
|
|
{
|
|
}
|
|
#endif /* CONFIG_PARAVIRT */
|
|
|
|
#include <asm-generic/qspinlock.h>
|
|
|
|
#endif /* _ASM_X86_QSPINLOCK_H */
|