Debugging technology of Embedded Linux
Print kernel debug information: PRINTK
The function is similar to the printf function, except that the PRINTK function runs in kernel space and the printf function runs in user space. In other words, Linux kernel programs like Linux drivers can only output debugging information using the PRINTK function. The PRINTK function is implemented in the Printk.c file, and the path to the file is as follows:
/root/kernel/linux_kernel_2.6.36/kerne/printk.c
Prevent PRINTK functions from reducing Linux drive performance
Although you can easily write messages to a log file or console using the PRINTK function. However, the heavy use of the PRINTK function to frequently manipulate log files or console device files (/dev/console) can severely affect the performance of Linux drivers (because the speed of writing disks is much faster than reading and writing memory), so This requires the Linux driver to use the PRINTK function to output messages only during the development phase, and to remove the PRINTK function that might affect performance when the official friend Linux driver is driven. Of course, the easiest way to think about it is to delete the PRINTK function, or annotate the PRINTK function. But it is troublesome to do so, and it is equally troublesome to add the PRINTK function later. To control the output of the PRINTK function, and it is convenient to implement, the best way is undoubtedly to use the C language compiler instructions (#if, #else, #endif等)
Data interaction through a virtual file system (/PROC)
In Linux file systems,/proc is often used as a tool for data interaction between kernel space and user space. The/proc file system behaves in a similar manner to the device file system (/dev). /proc is a virtual file system, which means that/proc is not a real file system, but a memory map. All read and write/proc are read and write to the memory, so reading and writing the/proc file system is much faster than reading/writing the/dev file system. As a result, the/proc file system can also serve as a tool for Linux to interact with user-space programs. There is a lot of system information that is provided to the outside world through the/proc file system by the kernel space program.
Android Deep Explore (Vol. 1) HAL and Driver development reading experience 10