Debug information for the print kernel PRINTK:
The difference between printk and printf :
the function of the PRINTK function is similar to the printf function, but the printk function runs the kernel space,PRINTK The function runs in user space. In other words, linux kernel programs like Linux drivers can only output debugging information using the prink function.
Second, you should prevent the PRINTK function from writing messages to the log file or console easily, but a large number of PRINTK functions that frequently manipulate log files or console device files can severely affect Linux- driven performance, so this requires the Linux driver to only use the printk function to output messages during the development phase , in the official release of Linux PRINTK functions that may affect performance are removed when driving .
The data is then interacted with by the virtual file system.
Necessity: In linux file system, /proc /proc is a virtual file system, which means Span style= "FONT-FAMILY:CALIBRI;" >/proc /proc operation of military-to-memory read and write operations. So read and write /proc Span style= "FONT-FAMILY:CALIBRI;" >/dev quick. Therefore, /proc file system is also available as linux The tool that drives interaction with user-space programs.
A lot of information is provided through the /proc file system by the kernel space program to the outside session. For example: The current system memory resource is read through The/proc/meminfo file, the reader can use the following command: View The contents of the/proc/meminfo file:Cat /proc/meminfo. we can do this by executing Free command to see if the displayed information is Meminfo matches some of the content in the file.
In Linux drivers, you can use kernel functions to Create and delete virtual files in the/proc directory, as well as to establish and delete virtual directories.
1. Create_proc_entry Create proc file
struct Proc_dir_entry *create_proc_entry (const char *name, mode_t mode,struct proc_dir_entry *parent);
Name: The filename to be created;
Mode: The protection mask for the file;
Parent: determines the directory in which the file resides and, if NULL , the location is /proc .
2. Proc_mkdir Create a directory
/* the function creates a directory under parent directory name* * /
struct Proc_dir_entry * PROC_MKDIR (const char *name,struct proc_dir_entry *parent);
@name: The name of the directory to create
@parent: The parent directory of this directory
3.remove_proc_entry Deleting a file or directory
/* This function Deletes a file or directory from the proc file system.
* Note:1 . Is removed by the parameter name , rather than by the pointer returned at creation time.
* 2. This function does not recursively delete files under the directory.
* 3. The data variable holds the allocated memory, freeing the corresponding memory before deleting the file.
* */
void Remove_proc_entry (const char *name,struct proc_dir_entry *parent);
@name: The name of the file or directory to be deleted
@parent: The parent directory where
4.create_proc_read_entry Creating a read-only proc file
struct Proc_dir_entry * create_proc_read_entry (const char
*name,mode_t mode,struct proc_dir_entry *parent,read_proc_t*
Read_proc,void *data);
@name: The file name to create
@mode: The properties of the file to be created default 0755
@parent: The parent directory of this file
@read_proc: When the user reads this file, the kernel calls the function
@data: Parameters passed to Read_proc
Note: Before deleting the virtual file directory, delete the virtual files in the directory.
Executing the build.sh script file will install the proc_demo driver on Ubuntu Linux, the Development Board, or On Android virtual machines. Then execute the following command to view The contents of the/proc/proc_demo directory.
Ls–al/proc/proc_demo/bin2dec
Cat/proc/proc_demo/bin2dec
Cat/proc_demo/readonly
Debug the User space program with gdb , remotely debug the user space program with gdbserver , and debug the kernel program remotely with KGDB.
Summary:proc-makedir
Name: virtual directory names
Parent: proc-dir-entry struct pointer for the parent directory of the virtual directory
Creat-proc-entry
Name: virtual file names
Mode: access permissions for virtual files
Parent: proc-dir-entry struct pointer to the parent directory of the virtual file
Cereat-proc-read-entry
Name: virtual file System
Mode: access permissions for virtual files
Base: The virtual file directory
Pro-dir-entry: struct pointer
read-proc-: A function pointer that handles read actions
Data: for the virtual file system
Remove-proce-entry:
Name: The names of the virtual files to be deleted
Parent: Virtual file parents directory
Proc-dir-entry: struct pointer
In this chapter I have learned:
1. Print the kernel debug information printk.
2. the data is then interacted with by the virtual file system.
Android Exploration and drive development and thinking (Ten)