woshizzb 发表于 2014-07-22 22:22

printk实现疑惑

截取printk的一段实现代码:    preempt_disable();
    /* This stops the holder of console_sem just where we want him */
    raw_local_irq_save(flags);
    this_cpu = smp_processor_id();

    /*
   * Ouch, printk recursed into itself!
   */
    if (unlikely(printk_cpu == this_cpu)) {
      /*
         * If a crash is occurring during printk() on this CPU,
         * then try to get the crash message out but make sure
         * we can't deadlock. Otherwise just return to avoid the
         * recursion and return - but flag the recursion so that
         * it can be printed at the next appropriate moment:
         */
      if (!oops_in_progress) {
            recursion_bug = 1;
            goto out_restore_irqs;
      }
      zap_locks();
    }
里面有检测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
页: [1]
查看完整版本: printk实现疑惑