Re: Spinlocks under uniprocessor running non preemptible kernel
- From: MAx <mahesh1280@xxxxxxxxx>
- Date: Fri, 21 Sep 2007 03:30:54 -0700
On Sep 21, 2:38 pm, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:
MAx <mahesh1...@xxxxxxxxx> writes:
I've read that spinlocks can cause system hangs if used on a
uniprocessor system which has a nonpremptible kernel running.
I've seen many spinlocks used in linux 2.4.x version running on
uniprocessor systems and there doesn't seem to be any problem with
them.
My question is how is it possible?
A 'spin lock' is something which roughly works like the code below
struct lock {
int locked;
}
void lock_it(struct lock *lock)
{
while (swap(lock->locked, 1) == 1);
}
void unlock_it(struct lock *lock)
{
lock->locked = 0;
}
'swap' is supposed to be a primitive (usually, a special assembly
instruction) which atomically stores the new value in the location
given as first argument and returns the old value. If a process
running on an uniprocessor system tries to acquired a locked spin lock
with interrupts disabled, the loop in lock_it can never terminate
because no other code will ever be executed by this CPU again. If the
kernel is non-preemtible, interrupt handlers may still execute, but
the scheduler will never schedule another process.
But the only purpose of spin locks is to prevent that processes
running on other CPUs enter the critical section and for the local
CPU, where the busy-loop cannot work, the same is accomplished by
disabling interrupts on this CPU (spin_lock_irq/ spin_lock_irqsave/
spin_lock_irqrestore). Because there are no other CPUs on an
uniprocessor, the 'spinning' parts of the spin locking code are only
actually compiled if building a kernel for a
mulitprocessor.
If a multiprocessor kernel is running on an uniprocessor system,
disabling interrupts/ preemption before trying locking the spin lock
means that neither an interrupt handler nor another process can try to
lock a locked spin lock, so the busy-wait-loop never actually loops
(interrupts/ preemption is are reenabled after unlocking the spin
lock).
Does that mean spinlocks do not do the job they are meant to do on a
uniprocessor system with
linux 2.4.x(non-preemptible kernel)
.
- Follow-Ups:
- Re: Spinlocks under uniprocessor running non preemptible kernel
- From: Gil Hamilton
- Re: Spinlocks under uniprocessor running non preemptible kernel
- From: Josef Moellers
- Re: Spinlocks under uniprocessor running non preemptible kernel
- From: Rainer Weikusat
- Re: Spinlocks under uniprocessor running non preemptible kernel
- References:
- Spinlocks under uniprocessor running non preemptible kernel
- From: MAx
- Re: Spinlocks under uniprocessor running non preemptible kernel
- From: Rainer Weikusat
- Spinlocks under uniprocessor running non preemptible kernel
- Prev by Date: Re: Help - how to save network configuration made by ethtool?
- Next by Date: Re: Spinlocks under uniprocessor running non preemptible kernel
- Previous by thread: Re: Spinlocks under uniprocessor running non preemptible kernel
- Next by thread: Re: Spinlocks under uniprocessor running non preemptible kernel
- Index(es):
Relevant Pages
|