]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/x86/include/asm/qspinlock.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_QSPINLOCK_H
3 #define _ASM_X86_QSPINLOCK_H
5 #include <linux/jump_label.h>
6 #include <asm/cpufeature.h>
7 #include <asm-generic/qspinlock_types.h>
8 #include <asm/paravirt.h>
11 #define _Q_PENDING_LOOPS (1 << 9)
13 #define queued_fetch_set_pending_acquire queued_fetch_set_pending_acquire
15 static __always_inline
bool __queued_RMW_btsl(struct qspinlock
*lock
)
17 GEN_BINARY_RMWcc(LOCK_PREFIX
"btsl", lock
->val
.counter
,
18 "I", _Q_PENDING_OFFSET
, "%0", c
);
21 static __always_inline u32
queued_fetch_set_pending_acquire(struct qspinlock
*lock
)
25 if (__queued_RMW_btsl(lock
))
26 val
|= _Q_PENDING_VAL
;
28 val
|= atomic_read(&lock
->val
) & ~_Q_PENDING_MASK
;
33 #define queued_spin_unlock queued_spin_unlock
35 * queued_spin_unlock - release a queued spinlock
36 * @lock : Pointer to queued spinlock structure
38 * A smp_store_release() on the least-significant byte.
40 static inline void native_queued_spin_unlock(struct qspinlock
*lock
)
42 smp_store_release(&lock
->locked
, 0);
45 #ifdef CONFIG_PARAVIRT_SPINLOCKS
46 extern void native_queued_spin_lock_slowpath(struct qspinlock
*lock
, u32 val
);
47 extern void __pv_init_lock_hash(void);
48 extern void __pv_queued_spin_lock_slowpath(struct qspinlock
*lock
, u32 val
);
49 extern void __raw_callee_save___pv_queued_spin_unlock(struct qspinlock
*lock
);
51 static inline void queued_spin_lock_slowpath(struct qspinlock
*lock
, u32 val
)
53 pv_queued_spin_lock_slowpath(lock
, val
);
56 static inline void queued_spin_unlock(struct qspinlock
*lock
)
58 pv_queued_spin_unlock(lock
);
61 #define vcpu_is_preempted vcpu_is_preempted
62 static inline bool vcpu_is_preempted(long cpu
)
64 return pv_vcpu_is_preempted(cpu
);
67 static inline void queued_spin_unlock(struct qspinlock
*lock
)
69 native_queued_spin_unlock(lock
);
73 #ifdef CONFIG_PARAVIRT
74 DECLARE_STATIC_KEY_TRUE(virt_spin_lock_key
);
76 void native_pv_lock_init(void) __init
;
78 #define virt_spin_lock virt_spin_lock
79 static inline bool virt_spin_lock(struct qspinlock
*lock
)
81 if (!static_branch_likely(&virt_spin_lock_key
))
85 * On hypervisors without PARAVIRT_SPINLOCKS support we fall
86 * back to a Test-and-Set spinlock, because fair locks have
87 * horrible lock 'holder' preemption issues.
91 while (atomic_read(&lock
->val
) != 0)
93 } while (atomic_cmpxchg(&lock
->val
, 0, _Q_LOCKED_VAL
) != 0);
98 static inline void native_pv_lock_init(void)
101 #endif /* CONFIG_PARAVIRT */
103 #include <asm-generic/qspinlock.h>
105 #endif /* _ASM_X86_QSPINLOCK_H */