Re: spin_lock_irq vs. spin_lock_irqsave.

From: Andrew Morton (andrewm@uow.edu.au)
Date: Sat Jun 17 2000 - 10:03:59 EST


Daniel Kobras wrote:
>
> Hi!
>
> I'd like to know the terms under which saving and restoring processor
> flags can be omitted? In other words, how can I determine if I have to use
> spin_lock_irqsave or if spin_lock_irq is sufficient? I had a look into
> Documentation/spinlocks.txt, but unfortunately the _irq/_bh variants
> aren't even mentioned.

It's a secret.

Basically, you should use the irqsave version if there's any chance that
an interrupt routine could claim the same lock. This is because the
current CPU could get interrupted, try to grab the lock and would
deadlock.

Similarly, you should use spin_lock_bh if this lock can be claimed by
"bottom half" handlers: timer handlers, tasklets, old-style BH-handlers,
etc. spin_lock_irqsave is a 'superset' of spin_lock_bh: it will protect
you from bh's as well as interrupts.

If in doubt, use spin_lock_irqsave and sleep well at night.

Have a look at Documentation/DocBook/kernel-locking.pdf (do a 'make
pdfdocs' at toplevel first). It's good.

BTW: CPU flags should always be saved and restored in the same function
- it's not correct to pass the flags to another function and allow that
function to restore them. Breaks on SPARC, apparently. Does Rusty's
doc cover this??

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



This archive was generated by hypermail 2b29 : Fri Jun 23 2000 - 21:00:14 EST