Android Deep Explore--hal and driver Development----The Tenth chapter reading notes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.