2008-07-23 22:28:58 +02:00
|
|
|
/*
|
|
|
|
* Split spinlock implementation out into its own file, so it can be
|
|
|
|
* compiled in a FTRACE-compatible way.
|
|
|
|
*/
|
|
|
|
#include <linux/spinlock.h>
|
2016-07-14 02:18:56 +02:00
|
|
|
#include <linux/export.h>
|
x86, ticketlock: Add slowpath logic
Maintain a flag in the LSB of the ticket lock tail which indicates
whether anyone is in the lock slowpath and may need kicking when
the current holder unlocks. The flags are set when the first locker
enters the slowpath, and cleared when unlocking to an empty queue (ie,
no contention).
In the specific implementation of lock_spinning(), make sure to set
the slowpath flags on the lock just before blocking. We must do
this before the last-chance pickup test to prevent a deadlock
with the unlocker:
Unlocker Locker
test for lock pickup
-> fail
unlock
test slowpath
-> false
set slowpath flags
block
Whereas this works in any ordering:
Unlocker Locker
set slowpath flags
test for lock pickup
-> fail
block
unlock
test slowpath
-> true, kick
If the unlocker finds that the lock has the slowpath flag set but it is
actually uncontended (ie, head == tail, so nobody is waiting), then it
clears the slowpath flag.
The unlock code uses a locked add to update the head counter. This also
acts as a full memory barrier so that its safe to subsequently
read back the slowflag state, knowing that the updated lock is visible
to the other CPUs. If it were an unlocked add, then the flag read may
just be forwarded from the store buffer before it was visible to the other
CPUs, which could result in a deadlock.
Unfortunately this means we need to do a locked instruction when
unlocking with PV ticketlocks. However, if PV ticketlocks are not
enabled, then the old non-locked "add" is the only unlocking code.
Note: this code relies on gcc making sure that unlikely() code is out of
line of the fastpath, which only happens when OPTIMIZE_SIZE=n. If it
doesn't the generated code isn't too bad, but its definitely suboptimal.
Thanks to Srivatsa Vaddagiri for providing a bugfix to the original
version of this change, which has been folded in.
Thanks to Stephan Diestelhorst for commenting on some code which relied
on an inaccurate reading of the x86 memory ordering rules.
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Link: http://lkml.kernel.org/r/1376058122-8248-11-git-send-email-raghavendra.kt@linux.vnet.ibm.com
Signed-off-by: Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Stephan Diestelhorst <stephan.diestelhorst@amd.com>
Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2013-08-09 16:21:58 +02:00
|
|
|
#include <linux/jump_label.h>
|
2008-07-23 22:28:58 +02:00
|
|
|
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
|
2015-04-24 20:56:38 +02:00
|
|
|
__visible void __native_queued_spin_unlock(struct qspinlock *lock)
|
|
|
|
{
|
|
|
|
native_queued_spin_unlock(lock);
|
|
|
|
}
|
|
|
|
PV_CALLEE_SAVE_REGS_THUNK(__native_queued_spin_unlock);
|
|
|
|
|
|
|
|
bool pv_is_native_spin_unlock(void)
|
|
|
|
{
|
|
|
|
return pv_lock_ops.queued_spin_unlock.func ==
|
|
|
|
__raw_callee_save___native_queued_spin_unlock;
|
|
|
|
}
|
|
|
|
|
2017-02-20 19:36:03 +01:00
|
|
|
__visible bool __native_vcpu_is_preempted(long cpu)
|
2016-11-15 16:47:06 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
PV_CALLEE_SAVE_REGS_THUNK(__native_vcpu_is_preempted);
|
|
|
|
|
|
|
|
bool pv_is_native_vcpu_is_preempted(void)
|
2016-11-02 10:08:33 +01:00
|
|
|
{
|
2016-11-15 16:47:06 +01:00
|
|
|
return pv_lock_ops.vcpu_is_preempted.func ==
|
|
|
|
__raw_callee_save___native_vcpu_is_preempted;
|
2016-11-02 10:08:33 +01:00
|
|
|
}
|
|
|
|
|
2008-07-23 22:28:58 +02:00
|
|
|
struct pv_lock_ops pv_lock_ops = {
|
|
|
|
#ifdef CONFIG_SMP
|
2015-04-24 20:56:38 +02:00
|
|
|
.queued_spin_lock_slowpath = native_queued_spin_lock_slowpath,
|
|
|
|
.queued_spin_unlock = PV_CALLEE_SAVE(__native_queued_spin_unlock),
|
|
|
|
.wait = paravirt_nop,
|
|
|
|
.kick = paravirt_nop,
|
2016-11-15 16:47:06 +01:00
|
|
|
.vcpu_is_preempted = PV_CALLEE_SAVE(__native_vcpu_is_preempted),
|
2015-04-24 20:56:38 +02:00
|
|
|
#endif /* SMP */
|
2008-07-23 22:28:58 +02:00
|
|
|
};
|
2008-08-20 20:31:07 +02:00
|
|
|
EXPORT_SYMBOL(pv_lock_ops);
|