Home > System Tutorial > LINUX > body text

Linux kernel source code reading experience sharing

WBOY
Release: 2024-01-26 21:57:32
forward
1077 people have browsed it

With the gradual popularity of Linux, many people are already familiar with the installation and settings of Linux. In line with the vigorous development of Linux, more and more people want to learn more about Linux. If you want to have a deep understanding of Linux, you need to read and analyze the source code of the Linux kernel.

Linux kernel source code can be obtained from many sources. Generally speaking, under the installed Linux system, the content in the /usr/src/linux directory is the kernel source code. You can also download it from the Internet, and the decompressed files are usually located in the Linux directory. There are many versions of the kernel source code, and the latest stable version is 2.2.14.

Many people have a sense of anxiety about reading the Linux kernel, although it is unnecessary. In fact, it is indeed difficult to read a large and complex system code like the Linux kernel, and it is not as unattainable as imagined. As long as you have perseverance, difficulties can be overcome. There is no need to be afraid of insufficient proficiency. In fact, there are many things about Linux shutdown commands that we never attend meetings and learn by doing, right?

To do anything, you need skills and tools. The right approach can guide the work, and good tools can get twice the result with half the effort. The same is true for reading the Linux kernel source code. Next, I will introduce some of my experience in reading kernel source code, and finally introduce a reading tool under the Window platform.

For source code reading, if you want to go smoothly, it is best to have a certain understanding of the source code knowledge background in advance. For linux kernel source codelinux kernel code reading tool, I think the basic requirements are: 1. Basic knowledge of the operating system; 2. Familiar with C language, preferably with knowledge of assembly language and GNUC's extended knowledge of Standard C. In addition, before reading, you should also know the overall distribution of the Linux kernel source code. We know that modern operating systems usually consist of process management, memory management, file systems, drivers, networks, etc. If you look at the Linux kernel source code, you can see that each directory roughly corresponds to those aspects. The Linux kernel source code is composed as follows (assumed to be relative to the linux directory):

archThis subdirectory contains the core code related to the hardware architecture supported by this core source code. For example, for the X86 platform, it is i386.

include This directory includes most of the core include files. There is also a subdirectory for each supported architecture.

init This directory contains the core startup code.

mmThis directory contains all video memory management code. The video memory management code related to the specific hardware architecture is located in the arch/*/mm directory. For example, the one corresponding to X86 is arch/i386/mm/fault.c.

driversAll device drivers in the system are located in this directory. It is further defined into several types of device drivers, each of which also has a corresponding subdirectory, such as the sound card driver corresponding to drivers/sound.

ipcThis directory contains the core inter-process communication code.

modulesThis directory contains modules that have been built and can be loaded dynamically.

fsLinux supported file system code. Different file systems have different corresponding subdirectories. For example, the ext2 file system corresponds to the ext2 subdirectory.

linux内核代码在线_linux内核代码怎么看_linux 内核代码阅读工具

Kernel main core code. At the same time, the code related to the processor structure is placed in the arch/*/kernel directory.

Net core network part code. Each subdirectory above corresponds to an aspect of the network.

libThis directory contains the core library code. Library code related to the processor architecture is placed in the arch/*/lib/ directory.

scriptsThis directory contains script files used to configure the core.

DocumentationThis directory contains documents for reference.

After you understand the structure of the source code, you can start reading. Regarding reading skills or order, there are so-called horizontal and vertical distinctions. The so-called horizontal view is to proceed gradually along the execution order of the program; the so-called vertical view to see what kind of system Linux is is to proceed in modules. Although they are not absolute, they are often combined together. For Linux source code, the startup code can be followed step by step along the Linux startup sequence. Its general process is as follows (taking the X86 platform as an example):

./larch/i386/boot/bootSect.S-->./larch/i386/boot/setup.S-->./larch/i386/kernel/head.S-->./ start_kernel() in init/main.c. As for parts such as video memory management, you can take them out separately for reading and analysis. My feeling is: it is best to read the startup code in order at first, and then read the special topics, such as the process part, the video memory management part, etc. Each function should be followed step by step. In fact, this is an iterative processlinux kernel code reading tool, it is impossible to understand after reading it once.

The above is the detailed content of Linux kernel source code reading experience sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:itcool.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!