"Linux kernel design and implementation" Chapter 2 reading notes one, get the kernel source code 1. Using Git
We used the GIT approach in our previous studies.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Update Branch to latest branch of Linux
Can be retrieved and kept consistent with the kernel's official code tree
2. Install the kernel source code
Compression form bzip2
tar xvjf linux -
tar xvzf linux -x.y.z.tar.gz
If you use Git to get and manage the kernel source code, you do not need to download the compressed files, run the git clone command, git will download the latest source code to extract.
The kernel source code is generally installed in the/usr/src/linux directory and should not be used for development. Do not modify the kernel as root.
Using Patches
Patch-p1 <. /patch-x.y.z
Second, the kernel source tree
Third, compile the kernel
Purpose: Compile the specific functions and drivers you need into the kernel.
1. Configuring the Kernel
The various variables ① can be configured are represented by the Config_ prefix.
- Two Choice One
- Three Choice One
- Yes
- No
- Module
module means that the configuration item is selected, but the implementation code is generated as a module
Configuration options can also be strings or integers
② Configuration Tool
$ make config 最简单的一种字符界面下的命令行工具; $ make menuconfig 基于ncurse库的图形界面工具; $ make gconfig 基于gtk+的图形工具; $ make defconfig 基于默认的配置为个人体系结构创建一个配置; $ make oldconfig 验证和更新配置;
If 内核已经启用了CONFIG_IKCONFIG_PROC选项(把完整的压缩过的内核配置文件存放在 /proc/config.gz , you can copy the configuration file from/proc and use it to compile a new kernel.
$ zcat/proc/config.gz > . config $ make oldconfig the kernel is configured so that it can be compiled .
2. Reduce the compilation of junk information
- If you want to see less spam, but do not miss error reporting and warning messages, redirect the output to $ make >. /Detritus
- REDIRECT useless output information to a black hole with no return value /dev/null in $ make >/dev/null
3. Derive multiple compilation jobs
- compile kernel with multiple jobs $ Make-JN (n: Number of jobs to be derived)
- 16-core processor $ make-j32 >/dev/null
4. Install the new kernel
Run as Root
All compiled modules will be installed under Lib/modules
Four, the characteristics of the core development1. Kernel programming cannot access C library and standard C header file
- The base header file is located in the Include/linux folder in the top-level directory of the kernel source code
- Architecture-Related header files: Under the Arch/<architecture>/include/asm directory of the kernel source tree
2. Kernel programming must use GNU C
- Inline functions: function is expanded at the point where it is called,
用static作关键字,用inline限定它。
- Pros: Eliminate the overhead of function calls and returns
- Cons: Code grows longer, consumes more memory space or instruction cache.
- Inline assembly: typically use ASM () directives to embed assembly code
- Branch Declaration
3. Kernel programming lacks a memory protection mechanism like user space
- In the kernel, should not access the illegal memory address, reference null pointer, otherwise the kernel will over;
- Memory in the kernel is not paged: Each byte is used, and the physical memory is reduced by one;
4. Difficult to perform floating-point arithmetic during kernel programming
5. The kernel gives each process only a small fixed-length stack
6. The kernel supports asynchronous interrupts, preemption, and SMP, and must always be aware of synchronization and concurrency7. Consider the importance of portability
"Linux kernel design and implementation" Chapter 2 reading notes