Android Deep Explore (Vol. 1) HAL and Driver development reading experience 10

Source: Internet
Author: User

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

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.