printk inside an interrupt handler , is it really that bad?

谁说胖子不能爱 提交于 2019-11-30 05:14:59

The printk function is not just inserting into a queue/buffer -- assuming the log level is high enough, the output from printk will be emitted to the console immediately, as part of the call to printk. This is especially slow if the console is, say, on a serial port. But in any case, printk does introduce pretty substantial overhead and can affect timing.

If you have a timing critical place where you want to get some debug output, you can look at using the trace_printk function in modern kernels. This actually does just put input into the trace ringbuffer, and you can read it later. Take a look at this article for full details.

Yes, it is very bad since printf most probably is not reentrant. What can happen is that the main program calls printf, an interrupt arrives while printf is executing, and then the IRQ handler calls printf again: very bad things may happen (e.g., deadlock, corrupt internal buffers, etc.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!