qspinlock.h 1.6 KB
Newer Older
1 2 3
#ifndef _ASM_X86_QSPINLOCK_H
#define _ASM_X86_QSPINLOCK_H

4
#include <asm/cpufeature.h>
5
#include <asm-generic/qspinlock_types.h>
6
#include <asm/paravirt.h>
7 8 9 10 11 12 13 14

#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.
 */
15
static inline void native_queued_spin_unlock(struct qspinlock *lock)
16 17 18 19
{
	smp_store_release((u8 *)lock, 0);
}

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#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);

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);
}
#else
static inline void queued_spin_unlock(struct qspinlock *lock)
{
	native_queued_spin_unlock(lock);
}
#endif

42
#define virt_spin_lock virt_spin_lock
43

44
static inline bool virt_spin_lock(struct qspinlock *lock)
45 46 47 48
{
	if (!static_cpu_has(X86_FEATURE_HYPERVISOR))
		return false;

49 50 51 52 53 54 55 56 57 58
	/*
	 * 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);
59 60 61 62

	return true;
}

63 64 65
#include <asm-generic/qspinlock.h>

#endif /* _ASM_X86_QSPINLOCK_H */