dmesg saved me from an installing
CUDA driver issue this month, I decide to write this short post to introduce it. According to Wikipedia:
dmesg (display message or driver message) is a command on most Unix-like operating systems that prints the message buffer of the kernel. The output of this command typically contains the messages produced by the device drivers.
Unix/Linux systems, kernel, kernel modules (e.g., device drivers), and even user-space processes may output logs in kernel buffer. So
dmesg is a neat tool for debugging purpose (please refer Linux Performance Analysis in 60,000 Milliseconds). Compared to
Linux provides more options. So this post will use
Linux as an example.
Firstly, how to know the underlying kernel buffer size? It depends on
CONFIG_LOG_BUF_SHIFT. On my
$ zcat /proc/config.gz | grep CONFIG_LOG_BUF_SHIFT CONFIG_LOG_BUF_SHIFT=17
Linux supports many handy options. E.g.
-H is used to display in human-readable format:
$ dmesg -H [Apr15 09:26] Linux version 5.0.5-arch1-1-ARCH ([email protected]) (gcc version 8.2.1 20181127 (GCC)) #1 SMP PREE> [ +0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=5bee8879-dca0-4b3a-8abd-1bdf96e17a1f rw quiet [ +0.000000] KERNEL supported cpus: [ +0.000000] Intel GenuineIntel [ +0.000000] AMD AuthenticAMD [ +0.000000] Hygon HygonGenuine [ +0.000000] Centaur CentaurHauls ......
dmesg only shows user-space messages:
$ dmesg -u -H [Apr15 09:26] systemd: systemd 241.67-1-arch running in system mode. (+PAM +AUDIT -SELINUX -IMA -APPARMOR +SMACK -S> [ +0.021954] systemd: Detected architecture x86-64. [ +0.021551] systemd: Set hostname to <tesla-p100>. [ +0.098510] systemd: Listening on Journal Socket (/dev/log). [ +0.000203] systemd: Set up automount Arbitrary Executable File Formats File System Automount Point. [ +0.000032] systemd: Listening on Device-mapper event daemon FIFOs. [ +0.000047] systemd: Listening on udev Control Socket. [ +0.001751] systemd: Listening on Process Core Dump Socket. [ +0.000010] systemd: Reached target System Time Synchronized. [ +0.000050] systemd: Listening on Journal Socket. [ +0.273822] systemd-journald: Received request to flush runtime journal from PID 1 (END)
To know about other options, please refer manual.
Last but not least,
dmesg‘s source code is a good place to learn how to develop command line applications on
dmesg into your toolkit, maybe it will save you one day too.