Chinaunix

标题: printk实现疑惑 [打印本页]

作者: woshizzb    时间: 2014-07-22 22:22
标题: printk实现疑惑
截取printk的一段实现代码:
  1.     preempt_disable();
  2.     /* This stops the holder of console_sem just where we want him */
  3.     raw_local_irq_save(flags);
  4.     this_cpu = smp_processor_id();

  5.     /*
  6.      * Ouch, printk recursed into itself!
  7.      */
  8.     if (unlikely(printk_cpu == this_cpu)) {
  9.         /*
  10.          * If a crash is occurring during printk() on this CPU,
  11.          * then try to get the crash message out but make sure
  12.          * we can't deadlock. Otherwise just return to avoid the
  13.          * recursion and return - but flag the recursion so that
  14.          * it can be printed at the next appropriate moment:
  15.          */
  16.         if (!oops_in_progress) {
  17.             recursion_bug = 1;
  18.             goto out_restore_irqs;
  19.         }
  20.         zap_locks();
  21.     }
复制代码
里面有检测printk嵌套的判断。  但我比较疑惑这在什么情况下会发生? 因为一开始已经禁用了抢占和本地中断,printk如何嵌套?
我尝试了在printk中访问非法内存, 可惜串口直接挂死, 并未打印出   BUG: recent printk recursion!
作者: amarant    时间: 2014-07-23 08:04
可以直接往串口写东西
作者: hmsghnh    时间: 2014-07-23 13:02
比如pirntk 触发串口写,串口驱动l里面又printk。
作者: humjb_1983    时间: 2014-07-23 19:02
同一个流程中的嵌套,不涉及调度。。。
作者: blake326    时间: 2016-07-12 10:52
1. printk内部发生异常(比如bug或者内存硬件错误,关中断时异常还是可以响应的),bug后续代码又调用到了printk。
2. printk过程中(printk过程中会关中断的)发生fiq,比如有的系统的watchdog中断,后续也可能会调用到printk




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2