On 6/8/07, keshetti85-linux@xxxxxxxxxxx <keshetti85-linux@xxxxxxxxxxx
> wrote:
No it wont deadlock, but very bad things can happen if you dont use the irqsave & restore. Since you are NOT saving the old state of interrupt flags, you *MIGHT* end up enabling interrupts, while in fact they should have remained disabled. Check this piece of code
f1()
{
spin_lock_irq(&lock1);
spin_lock_irq(&lock2);
/* Do xyz */
spin_unlock_irq(&lock2);
/* Do something which REQUIRES interrupts being disabled */
/* But Interrupts are ENABLED here!! - since the unlock enabled interrupts without restoring prev state... */
spin_unlock_irq(&lock1);
}
(This typically happens across functions, but I just wanted to make it clear)
/* Also this is the way the intr_handler() should be written in the code you cited above */
int intr_handler(XXXX)
{
/* You are ALREADY in the interrupt handler - no one can preempt you! - so dont need to disable IRQs again! */
spin_lock(&lock);
do_some_thing;
spin_unlock(&lock);
}
Bhanu
> This helps prevent deadlocks where the code is potentially accessed
> from interrupt context also.
do you mean to say if I write some code like this ...
spin_lock_t lock = SPIN_LOCK_UNLOCKED ;
void some_function(void)
{
spin_lock_irq(&lock);
do_some_thing;
spin_unlock_irq(&lock);
}
int intr_handler(XXXX)
{
spin_lock_irq(&lock);
do_some_thing;
spin_unlock_irq(&lock);
}
will it cause deadlock?
No it wont deadlock, but very bad things can happen if you dont use the irqsave & restore. Since you are NOT saving the old state of interrupt flags, you *MIGHT* end up enabling interrupts, while in fact they should have remained disabled. Check this piece of code
f1()
{
spin_lock_irq(&lock1);
spin_lock_irq(&lock2);
/* Do xyz */
spin_unlock_irq(&lock2);
/* Do something which REQUIRES interrupts being disabled */
/* But Interrupts are ENABLED here!! - since the unlock enabled interrupts without restoring prev state... */
spin_unlock_irq(&lock1);
}
(This typically happens across functions, but I just wanted to make it clear)
/* Also this is the way the intr_handler() should be written in the code you cited above */
int intr_handler(XXXX)
{
/* You are ALREADY in the interrupt handler - no one can preempt you! - so dont need to disable IRQs again! */
spin_lock(&lock);
do_some_thing;
spin_unlock(&lock);
}
> Spinlocks are used in the kernel only, so I kinda missed the point here.
> Can you rephrase?
Actually I thought that spin_lock_irqsave will save the total context.
I understood it now.
-Mahesh.
Bhanu
--
The box said "Requires Windows Vista or better." So I installed LINUX