0

我是 Linux 内核开发的新手,当我尝试通过在 timekeep.c 文件中添加 printk 函数来修改系统调用函数时,比如

 printk("BEGIN!$$$$$\n");

dmesg 实用程序为我提供如下输出:

[   75.919335] BEGIN!$$$$$
[   75.919337] BEGIN!$$$$$
[   75.919340] BEGIN!$$$$$
[   75.919343] BEGIN!$$$$$
[   75.919347] BEGIN!$$$$$
[   75.919349] BEGIN!$$$$$
[   75.919353] BEGIN!$$$$$
[   75.919355] BEGIN!$$$$$
[   75.919358] BEGIN!$$$$$
[   75.919361] BEGIN!$$$$$
[   75.919364] BEGIN!$$$$$
[   75.919367] BEGIN!$$$$$
[   75.919370] BEGIN!$$$$$
[   75.919374] BEGIN!$$$$$

我真的不明白 [] 中的那些是如何生成的。有人可以给我一个提示吗?

4

2 回答 2

2

您的内核启用了 CONFIG_PRINTK_TIME 选项。此选项负责printk()消息之前的此时间戳字段。从内核配置选项

 "Selecting this option causes time stamps of the `printk()` messages to be
  added to the output of the `syslog()` system call and at the console."

来源:https ://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/lib/Kconfig.debug#n2

此选项可在内核配置时通过“Kernel Hacking”配置字段进行配置。您可以从内核命令行参数启用/禁用它:(printk.time=0禁用)或printk.time=1(启用)。

于 2013-05-27T16:27:09.183 回答
0

它们实际上dmesg是系统启动后以秒为单位的时间戳。

您可以放心地忽略它们,除非您实际上是在寻找时间问题(例如,驾驶员需要 30 秒才能完成本应更快的事情)。

如果你想要一种更易读的格式,你可以使用dmesg -T,但你会失去一些精度。

pax> dmesg -T | tail -5l

[Mon May 27 09:08:58 2013] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[Mon May 27 09:09:00 2013] usblp0: removed
[Mon May 27 09:09:00 2013] usblp0: USB Bidirectional printer dev 3 if 0 alt 0 proto 2 vid 0x03F0 pid 0x3A02
[Mon May 27 09:09:09 2013] eth0: no IPv6 routers present
[Mon May 27 10:09:59 2013] usblp0: removed

您也可以完全删除它们,dmesg -t但您将丢失所有时间信息。

pax> dmesg -t | tail -5l

ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
usblp0: removed
usblp0: USB Bidirectional printer dev 3 if 0 alt 0 proto 2 vid 0x03F0 pid 0x3A02
eth0: no IPv6 routers present
usblp0: removed
于 2013-05-27T02:40:22.730 回答