What happens when an interrupt comes while in middle of printk?
Dear All, What happens if an interrupt comes while in middle of printk execution and the interrupt handler has a printk in it? There is a chance that the log_buf could be corrupted. isn't it? Best Regards, Manty
On February 24, 2015 10:07:59 PM EST, manty kuma <mantykuma@gmail.com> wrote:
Dear All,
What happens if an interrupt comes while in middle of printk execution and the interrupt handler has a printk in it?
There is a chance that the log_buf could be corrupted. isn't it?
Best Regards, Manty
Manty, I admit to never looking, but I think you will find printk is atomic in someway. You should review the source code to be sure. Also remember the kernel is smp (symmetric multi-processing), so if printks were not atomic you would have line corruption far more frequently than just when an interrupt hits at the wrong time. I've never seen corruption of that type. (Or at least not recently. I seem to remember that issue in the 1980's, but that was the UNIX kernel.) Greg -- Sent from my Android device with K-9 Mail. Please excuse my brevity.
On 2015-02-24 10:41 PM, greg.freemyer@gmail.com wrote:
On February 24, 2015 10:07:59 PM EST, manty kuma <mantykuma@gmail.com> wrote:
Dear All,
What happens if an interrupt comes while in middle of printk execution and the interrupt handler has a printk in it?
There is a chance that the log_buf could be corrupted. isn't it?
Best Regards, Manty
Manty,
I admit to never looking, but I think you will find printk is atomic in someway. You should review the source code to be sure.
Also remember the kernel is smp (symmetric multi-processing), so if printks were not atomic you would have line corruption far more frequently than just when an interrupt hits at the wrong time.
I've never seen corruption of that type. (Or at least not recently. I seem to remember that issue in the 1980's, but that was the UNIX kernel.)
Greg
Greg, You are right here as printk works anywhere needed after console is enabled in the boot of the kernel. The only issue is if you are too early in the kernel's boot cycle you need to use early_printk, to my knowledge through most architectures support this function including x86. Nick
[2015-02-25T08:37:59+0530]: "manty kuma" (manty-kuma): ,----[ manty-kuma ] | What happens if an interrupt comes while in middle of printk execution and | the interrupt handler has a printk in it? | | There is a chance that the log_buf could be corrupted. isn't it? `---- no this doesn't happen. look at vprintk_emit(...) which invokes local_irq_save(...).
essentially, printk tries to acquire console_lock. if it succeeds all is well. otherwise, output is dumped to a log buffer. when the current holder of console_lock, unlocks it, log buffer is emptied... --- thanks anupam
participants (4)
-
anupam kapoor -
greg.freemyer@gmail.com -
manty kuma -
nick