尝试记录/调试 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/