Understanding kernel logging and printk
There is still a lot to cover regarding the logging of kernel messages via the printk
kernel API. This section delves into some of the details. It’s important for a budding kernel/driver developer like you to clearly understand these topics.
We saw earlier, in the A quick first look at the kernel printk() section, the essentials of using the kernel printk
API’s functionality (have another look at it if you wish to). Here, we will explore a lot more with respect to the printk()
API’s usage. Let’s get going!
Using the kernel memory ring buffer
The kernel log buffer is simply a memory buffer within the kernel virtual address space where the printk
output is saved (logged). More technically, it’s the global __log_buf[]
variable. Its definition in the kernel source is as follows:
kernel/printk/printk.c
#define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)
#define LOG_BUF_LEN_MAX (u32)(1 <<...