Spinlocks waiting with interrupts disabled / preempt disabled.

From: Christoph Lameter
Date: Tue May 06 2008 - 15:26:37 EST


We just had a couple of cases of systems failing because interrrupts were
not serviced. Turned out that we were trying to acquire the treelock for
write while lots of readers where starving the writer a bit. A device
timed out before the write lock was acquired.

If interrupts would be enabled while busy waiting then such scenarios
could be avoided.

Could we make the wait cases more interrupt / preempt friendly by
reenabling interrupts / preempt while waiting? We had this interrupt
friendly behavior for a long time on IA64. If we have a special busy case
then we can also not use atomic ops and thus acquire the cacheline only
for read.

F.e.

Index: linux/kernel/spinlock.c
===================================================================
--- linux.orig/kernel/spinlock.c 2008-05-05 12:22:16.000000000 -0500
+++ linux/kernel/spinlock.c 2008-05-06 14:05:43.953016660 -0500
@@ -132,10 +132,14 @@ unsigned long __lockfunc _write_lock_irq
{
unsigned long flags;

+retry:
local_irq_save(flags);
- preempt_disable();
- _raw_write_lock(lock);
- return flags;
+ if (_write_trylock(lock))
+ return flags;
+ local_irq_restore(flags);
+ while (!write_can_lock(lock))
+ cpu_relax();
+ goto retry;
}
EXPORT_SYMBOL(_write_lock_irqsave);

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/