Re: question on spinlocks

From: Robert Love (rml@tech9.net)
Date: Sun Sep 01 2002 - 17:08:12 EST


On Sun, 2002-09-01 at 17:53, Thunder from the hill wrote:

> If it was his least problem! He'll run straight into a "schedule w/IRQs
> disabled" bug.

No, the "schedule with irqs disabled" message is on involuntary
reschedule (e.g. kernel preemption) when interrupts are disabled.

It "safe" (maybe not sane) to call schedule() with interrupts disabled -
some system calls and scheduler code do it since interrupts will be
unconditionally enabled when rescheduled or upon returning to
user-space. E.g., see sys_sched_yield().

The actual problem with the above is that when schedule() returns,
interrupts will be on and that is probably not the intention of the
author. What Oliver probably wants to do is:

        spin_lock_irq(&lck);
        ...
        spin_unlock(&lck);
        schedule();
        spin_lock_irq(&lck);
        ...
        spin_unlock_irq(&lck);

The first unlock not having the irq-enable is an optimization as
described above. Also note I did not use irqsave... if there is a
chance interrupts were previously disabled and you have who-knows-what
sort of call-chain behind you, it is probably not safe to go calling
schedule() and reenabling interrupts anyhow.

        Robert Love

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



This archive was generated by hypermail 2b29 : Sat Sep 07 2002 - 22:00:14 EST