blob: 48a706f641f2bc9cf37d70749fe2f0cf4d8aa81e [file] [log] [blame]
Waiman Longd73a3392015-04-24 14:56:31 -04001#ifndef _ASM_X86_QSPINLOCK_H
2#define _ASM_X86_QSPINLOCK_H
3
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -04004#include <asm/cpufeature.h>
Waiman Longd73a3392015-04-24 14:56:31 -04005#include <asm-generic/qspinlock_types.h>
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -04006#include <asm/paravirt.h>
Waiman Longd73a3392015-04-24 14:56:31 -04007
8#define queued_spin_unlock queued_spin_unlock
9/**
10 * queued_spin_unlock - release a queued spinlock
11 * @lock : Pointer to queued spinlock structure
12 *
13 * A smp_store_release() on the least-significant byte.
14 */
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040015static inline void native_queued_spin_unlock(struct qspinlock *lock)
Waiman Longd73a3392015-04-24 14:56:31 -040016{
17 smp_store_release((u8 *)lock, 0);
18}
19
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040020#ifdef CONFIG_PARAVIRT_SPINLOCKS
21extern void native_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
22extern void __pv_init_lock_hash(void);
23extern void __pv_queued_spin_lock_slowpath(struct qspinlock *lock, u32 val);
24extern void __raw_callee_save___pv_queued_spin_unlock(struct qspinlock *lock);
25
26static inline void queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
27{
28 pv_queued_spin_lock_slowpath(lock, val);
29}
30
31static inline void queued_spin_unlock(struct qspinlock *lock)
32{
33 pv_queued_spin_unlock(lock);
34}
Peter Zijlstra3cded412016-11-15 16:47:06 +010035
36#define vcpu_is_preempted vcpu_is_preempted
Waiman Long6c629852017-02-20 13:36:03 -050037static inline bool vcpu_is_preempted(long cpu)
Peter Zijlstra3cded412016-11-15 16:47:06 +010038{
39 return pv_vcpu_is_preempted(cpu);
40}
Peter Zijlstra (Intel)f233f7f2015-04-24 14:56:38 -040041#else
42static inline void queued_spin_unlock(struct qspinlock *lock)
43{
44 native_queued_spin_unlock(lock);
45}
46#endif
47
Peter Zijlstraa6b27782015-09-05 16:55:05 +020048#ifdef CONFIG_PARAVIRT
Peter Zijlstra43b3f022015-09-04 17:25:23 +020049#define virt_spin_lock virt_spin_lock
Peter Zijlstra43b3f022015-09-04 17:25:23 +020050static inline bool virt_spin_lock(struct qspinlock *lock)
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040051{
52 if (!static_cpu_has(X86_FEATURE_HYPERVISOR))
53 return false;
54
Peter Zijlstra43b3f022015-09-04 17:25:23 +020055 /*
56 * On hypervisors without PARAVIRT_SPINLOCKS support we fall
57 * back to a Test-and-Set spinlock, because fair locks have
58 * horrible lock 'holder' preemption issues.
59 */
60
61 do {
62 while (atomic_read(&lock->val) != 0)
63 cpu_relax();
64 } while (atomic_cmpxchg(&lock->val, 0, _Q_LOCKED_VAL) != 0);
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040065
66 return true;
67}
Peter Zijlstraa6b27782015-09-05 16:55:05 +020068#endif /* CONFIG_PARAVIRT */
Peter Zijlstra (Intel)2aa79af2015-04-24 14:56:36 -040069
Waiman Longd73a3392015-04-24 14:56:31 -040070#include <asm-generic/qspinlock.h>
71
72#endif /* _ASM_X86_QSPINLOCK_H */