c - 登录 ISR、sprintf()、printk() 等等?

标签 c embedded isr

尝试记录/调试 ISR 时,我看到:

1) sprintf() 在“O'Reilly Linux Device Drivers”中用作示例

irqreturn_t short_interrupt(int irq, void *dev_id, struct pt_regs *regs)

{

    struct timeval tv;
    int written;

    do_gettimeofday(&tv);


    /* Write a 16 byte record. Assume PAGE_SIZE is a multiple of 16 */

    written = sprintf((char *)short_head,"%08u.%06u\n",

            (int)(tv.tv_sec % 100000000), (int)(tv.tv_usec));

    BUG_ON(written != 16);

    short_incr_bp(&short_head, written);

    wake_up_interruptible(&short_queue); /* awake any reading process */

    return IRQ_HANDLED;

}

与 printf() 不同,sprintf() 写入内存而不是控制台,并且似乎没有重入或阻塞问题,对吗?但我在其他论坛上看到过反对 sprintf() 的言论。我不确定这是否只是因为它的性能开销,还是其他原因?

2) printk() 是我见过的另一个人使用但又被指责的性能问题(也许没有别的原因?)

最近在 Linux 中记录或调试 ISR 时,通常使用什么好方法/函数?

最佳答案

关于 sprintf()。在任何 LXR 站点中进行搜索,例如 here :

Freetext search: sprintf (4096 estimated hits)
drivers/video/mbx/mbxdebugfs.c, line 100 (100%)
drivers/isdn/hisax/q931.c, line 1207 (100%)
drivers/scsi/aic7xxx_old/aic7xxx_proc.c, line 141

我认为这消除了任何疑虑。

对于printk()printk.h说:

/* If you are writing a driver, please use dev_dbg instead */

关于c - 登录 ISR、sprintf()、printk() 等等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12755937/

相关文章:

CURL 在多线程应用程序中共享接​​口和 cookie

shell - U-Boot:如何在另一个环境变量中评估一个环境变量

qt - QML预编译成字节码,有可能吗?

arm - STM32清除中断标志的正确方法

c - 带回调函数的驱动程序

c++ - 这是一个指针吗? (如果是这样,它是如何初始化的?)

c - 在 Windows 上运行用 Linux 编写的 C 程序

c++ - NSString & unichar 常量去重

embedded - 从嵌入式到桌面的可重用知识

embedded - ISR 中过早出现 'return' 会发生什么?