On 06/12/12 18:27, Xinxin Jin wrote:> Hi, I have some confusion on local_irq_save() and local_irq_restore().
> From the definitions, you can see that local_irq_save()
> calls local_irq_disable(). But why there is no local_irq_enable() in
> local_irq_restore?
>
> #define local_irq_save(x)
> ({
> local_save_flags(x);
> local_irq_disable();
> })
>
> #define local_irq_restore(x)
> ({
> BUILD_BUG_ON(sizeof(x) != sizeof(long));
> asm volatile ( "push" __OS " %0 ; popf" __OS
> : : "g" (x) : "memory",
"cc" );
> })
>
>
The interrupt flag is part of the rflags register.
irq_save "saves" the current state of the flags register in the
parameter you give it, then disables interrupt, and irq_restore puts
flags back to the saved state.
As a result, you can nest calls like:
// Lets define interrupts to currently be enabled
irq_save()
// Interrupts are disabled
irq_save()
// Interrupts are disabled
irq_restore()
// Interrupts are still disabled
irq_restore()
// Interrupts are now enabled.
save/restore pairs are for code where you do not know whether interrupts
are enabled or disabled at the entry point, but need to be certain that
interrupts are disabled between the pair, and also certain that you
don''t enable interrupts early because of nesting.
~Andrew
>
> --
> Xinxin
--
Andrew Cooper - Dom0 Kernel Engineer, Citrix XenServer
T: +44 (0)1223 225 900, http://www.citrix.com
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel