Why is flags being backed up before calling cli
Hi, I noticed that the flags register is being stored before doing 'cli' and then restored after calling 'sti'. - eg. in local_irq_save and local_irq_restore Can someone tell me the scenario that is being guarded against by backing up flags? Regards, Kashyap
Hi Kashyap, Sending to the group this time. On Thu, Jan 20, 2011 at 11:00 PM, C K Kashyap <ckkashyap@gmail.com> wrote:
Hi, I noticed that the flags register is being stored before doing 'cli' and then restored after calling 'sti'. - eg. in local_irq_save and local_irq_restore Can someone tell me the scenario that is being guarded against by backing up flags?
The flags typically includes the interrupt status register. If you have nested calls to local_irq_save/restore, like follows assume interrupts are enabled here local_irq_save interrupts are now disabled local_irq_save interrupts should continue to be disabled local_irq_restore At this point interrupts should be restored to the state they were at save time (i.e. disabled) If you didn't save the flags, then you wouldn't know whether to enable or disable interrupts at this point. local_irq_restore At this point interrupts should be restored to the state they were at save time (i.e. enabled). Dave Hylands
Hi,
I noticed that the flags register is being stored before doing 'cli' and then restored after calling 'sti'. - eg. in local_irq_save and local_irq_restore Can someone tell me the scenario that is being guarded against by backing up flags?
There are many functions in the kernel that can be accessed with interrupts enabled or disabled. A function X has no handy way to know whether its caller or another function has already disabled interrupts. However if X unconditionally re-enables interrupts at the end of its body, a caller that has disabled interrupts prior to calling it will find that interrupts are enabled once X returns - something unexpected and unacceptable. local_irq_save and local_irq_restore ensure that interrupts are re-enabled by the function of the call stack that actually disabled them. Alex.
participants (3)
-
Alexandre Courbot -
C K Kashyap -
Dave Hylands