Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / loongarch / include / asm / qspinlock.h
blobe76d3aa1e1ebe7dcae953bf6dc89d55802e05cfc
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_LOONGARCH_QSPINLOCK_H
3 #define _ASM_LOONGARCH_QSPINLOCK_H
5 #include <linux/jump_label.h>
7 #ifdef CONFIG_PARAVIRT
9 DECLARE_STATIC_KEY_FALSE(virt_spin_lock_key);
11 #define virt_spin_lock virt_spin_lock
13 static inline bool virt_spin_lock(struct qspinlock *lock)
15 int val;
17 if (!static_branch_unlikely(&virt_spin_lock_key))
18 return false;
21 * On hypervisors without PARAVIRT_SPINLOCKS support we fall
22 * back to a Test-and-Set spinlock, because fair locks have
23 * horrible lock 'holder' preemption issues.
26 __retry:
27 val = atomic_read(&lock->val);
29 if (val || !atomic_try_cmpxchg(&lock->val, &val, _Q_LOCKED_VAL)) {
30 cpu_relax();
31 goto __retry;
34 return true;
37 #endif /* CONFIG_PARAVIRT */
39 #include <asm-generic/qspinlock.h>
41 #endif // _ASM_LOONGARCH_QSPINLOCK_H