On Fri, Dec 21, 2012 at 3:50 PM, Rik van Riel <riel@xxxxxxxxxx> wrote:
@@ -53,12 +55,11 @@ static __always_inline void __ticket_spin_lock(arch_spinlock_t *lock)
inc = xadd(&lock->tickets, inc);
+ if (inc.head == inc.tail)
+ goto out;
+
+ ticket_spin_lock_wait(lock, inc);
+ out:
why not just:
if (inc.head != inc.tail)
ticket_spin_lock_wait(lock, inc)
+++ b/arch/x86/kernel/smp.c
@@ -113,6 +113,20 @@ static atomic_t stopping_cpu = ATOMIC_INIT(-1);
static bool smp_no_nmi_ipi = false;
/*
+ * Wait on a congested ticket spinlock.
+ */
+void ticket_spin_lock_wait(arch_spinlock_t *lock, struct __raw_tickets inc)
+{
+ for (;;) {
+ cpu_relax();
+ inc.head = ACCESS_ONCE(lock->tickets.head);
+
+ if (inc.head == inc.tail)
+ break;
+ }
Why not just:
do {
cpu_relax()
inc.head = ...
} while (inc.head != inc.tail);
Other than that, no problems with the principle of it.