The use of the PRINTK 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 debug information using the PRINTK function
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 file Udev/console can severely affect the performance of Linux drivers (because the speed of writing disks is far from the speed of reading and writing memory), so this requires that Linux drivers be used only during the development phase PRINTK The function output message is removed from the PRINTK function that may 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, etc.). Print Kernel debug information: PRINTK
The PRINTK function is prototyped as follows:
asmlinkage int PRINTK (const char * fmt, ...)
The PRINTK file is a simple 4-digit text file that is the default for that file.
6 4 1 7
If you want to modify the contents of the PRINTK file, require that any information be output to the console, you can execute the following command on the Linux terminal.
#echo 8 >/PROC/SYS/KERNEL/PRINTK
The contents of the modified PRINTK file are as follows:
8 4 1 7
Execute a command like the following to compile and install the Printk_demo driver.
# sh build.sh
Prevent PRINTK functions from reducing Linux drive performance:
Modifies the Printk_demo driver code of the upper-section, defines a Pr_debug macro by compiling instructions, and controls whether the PRINTK function is invoked by modifying the conditional value of the compilation instruction.
Data interaction through a virtual file system (/PROC):
Android Deep Explore--hal and driver Development----The Tenth chapter reading notes