Skip to content

Commit e95e6f1

Browse files
David Vrabelingomolnar
authored andcommitted
locking/pvqspinlock, x86: Enable PV qspinlock for Xen
This patch adds the necessary Xen specific code to allow Xen to support the CPU halting and kicking operations needed by the queue spinlock PV code. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Signed-off-by: Waiman Long <Waiman.Long@hp.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Daniel J Blueman <daniel@numascale.com> Cc: Douglas Hatch <doug.hatch@hp.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Paolo Bonzini <paolo.bonzini@gmail.com> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com> Cc: Rik van Riel <riel@redhat.com> Cc: Scott J Norton <scott.norton@hp.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: virtualization@lists.linux-foundation.org Cc: xen-devel@lists.xenproject.org Link: http://lkml.kernel.org/r/1429901803-29771-12-git-send-email-Waiman.Long@hp.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent bf0c7c3 commit e95e6f1

2 files changed

Lines changed: 61 additions & 5 deletions

File tree

‎arch/x86/xen/spinlock.c‎

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,56 @@
1717
#include "xen-ops.h"
1818
#include "debugfs.h"
1919

20+
static DEFINE_PER_CPU(int, lock_kicker_irq) = -1;
21+
static DEFINE_PER_CPU(char *, irq_name);
22+
static bool xen_pvspin = true;
23+
24+
#ifdef CONFIG_QUEUED_SPINLOCK
25+
26+
#include <asm/qspinlock.h>
27+
28+
static void xen_qlock_kick(int cpu)
29+
{
30+
xen_send_IPI_one(cpu, XEN_SPIN_UNLOCK_VECTOR);
31+
}
32+
33+
/*
34+
* Halt the current CPU & release it back to the host
35+
*/
36+
static void xen_qlock_wait(u8 *byte, u8 val)
37+
{
38+
int irq = __this_cpu_read(lock_kicker_irq);
39+
40+
/* If kicker interrupts not initialized yet, just spin */
41+
if (irq == -1)
42+
return;
43+
44+
/* clear pending */
45+
xen_clear_irq_pending(irq);
46+
barrier();
47+
48+
/*
49+
* We check the byte value after clearing pending IRQ to make sure
50+
* that we won't miss a wakeup event because of the clearing.
51+
*
52+
* The sync_clear_bit() call in xen_clear_irq_pending() is atomic.
53+
* So it is effectively a memory barrier for x86.
54+
*/
55+
if (READ_ONCE(*byte) != val)
56+
return;
57+
58+
/*
59+
* If an interrupt happens here, it will leave the wakeup irq
60+
* pending, which will cause xen_poll_irq() to return
61+
* immediately.
62+
*/
63+
64+
/* Block until irq becomes pending (or perhaps a spurious wakeup) */
65+
xen_poll_irq(irq);
66+
}
67+
68+
#else /* CONFIG_QUEUED_SPINLOCK */
69+
2070
enum xen_contention_stat {
2171
TAKEN_SLOW,
2272
TAKEN_SLOW_PICKUP,
@@ -100,12 +150,9 @@ struct xen_lock_waiting {
100150
__ticket_t want;
101151
};
102152

103-
static DEFINE_PER_CPU(int, lock_kicker_irq) = -1;
104-
static DEFINE_PER_CPU(char *, irq_name);
105153
static DEFINE_PER_CPU(struct xen_lock_waiting, lock_waiting);
106154
static cpumask_t waiting_cpus;
107155

108-
static bool xen_pvspin = true;
109156
__visible void xen_lock_spinning(struct arch_spinlock *lock, __ticket_t want)
110157
{
111158
int irq = __this_cpu_read(lock_kicker_irq);
@@ -217,6 +264,7 @@ static void xen_unlock_kick(struct arch_spinlock *lock, __ticket_t next)
217264
}
218265
}
219266
}
267+
#endif /* CONFIG_QUEUED_SPINLOCK */
220268

221269
static irqreturn_t dummy_handler(int irq, void *dev_id)
222270
{
@@ -280,8 +328,16 @@ void __init xen_init_spinlocks(void)
280328
return;
281329
}
282330
printk(KERN_DEBUG "xen: PV spinlocks enabled\n");
331+
#ifdef CONFIG_QUEUED_SPINLOCK
332+
__pv_init_lock_hash();
333+
pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath;
334+
pv_lock_ops.queued_spin_unlock = PV_CALLEE_SAVE(__pv_queued_spin_unlock);
335+
pv_lock_ops.wait = xen_qlock_wait;
336+
pv_lock_ops.kick = xen_qlock_kick;
337+
#else
283338
pv_lock_ops.lock_spinning = PV_CALLEE_SAVE(xen_lock_spinning);
284339
pv_lock_ops.unlock_kick = xen_unlock_kick;
340+
#endif
285341
}
286342

287343
/*
@@ -310,7 +366,7 @@ static __init int xen_parse_nopvspin(char *arg)
310366
}
311367
early_param("xen_nopvspin", xen_parse_nopvspin);
312368

313-
#ifdef CONFIG_XEN_DEBUG_FS
369+
#if defined(CONFIG_XEN_DEBUG_FS) && !defined(CONFIG_QUEUED_SPINLOCK)
314370

315371
static struct dentry *d_spin_debug;
316372

‎kernel/Kconfig.locks‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ config ARCH_USE_QUEUED_SPINLOCK
240240

241241
config QUEUED_SPINLOCK
242242
def_bool y if ARCH_USE_QUEUED_SPINLOCK
243-
depends on SMP && (!PARAVIRT_SPINLOCKS || !XEN)
243+
depends on SMP
244244

245245
config ARCH_USE_QUEUE_RWLOCK
246246
bool

0 commit comments

Comments
 (0)