Chapter One: Introduction to the Linux kernel
I. Unix and Linux
UNIX is a powerful, robust, and stable operating system.
1.UnixKernel features
- Very concise: Provide only hundreds of system calls and have a clear purpose;
- In Unix , most things are treated as files (or are committed);
- Unix kernel is the related system tool software is written in C language, which makes the system has a strong portability;
- Unix processes are created very quickly, with the goal of performing a task at once with quality and quantity
2.Linuxwith theUnixsimilarities
- Linux is a Unix -based class system, such as it also implements the Unix API;
- But it differs from Unix, and does not utilize UNIX kernel source code;
- Linux is a non-commercial product and anyone can participate in its development
- Unix kernel vs . Linux kernel
- The Unix kernel is an inseparable static executable library that typically requires a hardware system to provide a page mechanism (MMU) to manage memory;
- Linux supports dynamic loading of kernel modules and is preemptive.
. Linuxthe system is based on the kernel,Clibraries, and basic tools for toolsets and systems.
Ii. Introduction to operating system and kernel
Operating systems are those parts of the entire system that are responsible for the most basic functions and systems management.
- Kernel
- Device drivers
- To start the boot program
- Command line Shell or other kind of user interface
- Basic file management tools and System Tools
The kernel is isolated from normal applications, is generally system-state, has a protected memory space, and has all the permissions to access hardware devices.
This system state and the protected memory space, collectively known as the kernel space.
Applications running in the system communicate with the kernel through system calls.
Kernel classification
- Single core (e.g. most Unix and Linux)
- The kernel is implemented as a large, separate process and runs on a separate address space
- Simple, high performance
- Microkernel (e.g. Windows NT)
- The functionality of the microkernel is divided into separate functions, each of which is called a server, facilitates the processing of inter-core communication, and uses the IPC mechanism;
The basic behavior of the application to complete its work is:
The application is trapped in the kernel through the system call interface.
The activity of the processor must be one of the following three:
- Run in user space, execute user process
- Runs in kernel space, is in the process context, executes on behalf of a particular process
- Runs in kernel space, is in the interrupt context, is independent of any process, and handles a specific interrupt
Chapter two departs from the kernel 1.Source Code Control
- Using Git
- Git as a version control system to manage the Linux kernel source code;
- Download and update the latest version:
- git clone git://[ URL ]
- Kernel source code is generally installed in the /usr/src/linux directory, this source tree is not used for development
- Source Code Tree
- There are many directories worth noticing:
- Arch: Source code for a particular architecture;
- Include: kernel header file;
- Kernel: A core subsystem such as a scheduler.
2. Kernel source tree
3. Compiling the kernel
- Purpose: Compile the functions you need into the kernel
- Steps:
- Configuring the Kernel
- Premise: The various variables that can be configured are represented by the config_ prefix. There are two options (yes or no) and three select one (there is also a module, that is , The configuration item is selected but compiled in the form of modules); "My personal understanding is that This option is required for program code that is similar to a driver that requires modularity, which is more independent of the functionality but not necessarily open at all times.
- Way:
- Make config"This has been done in the experiment, it should belong to the kind of fool-by-one traversal (for the system is relatively simple case)"
- Make Menuconfig
- Make Gconfig
- Subsequent:
- Configuration options ConfigIkconfigproc put the full compressed configuration file under /proc/config.gz , so that when compiling the new kernel, you can copy it directly.
- Deriving multiple compilation jobs
- In general, each processor will derive 1--2 jobs to improve processor utilization
- Make-j32 >/dev/null"with a core processor as an example"
- Install the new kernel
- run make modules_install as root
- All compiled modules will be installed under lib/modules
- Kernel development can neither access C Library nor access standard C header files
Response: Theinclude/linux folder contains the required kernel header files.
- The kernel programming must use the GNU C
4. Features of kernel development
Inline functions:
The function expands at the point where it is called.
When defining, you need to use static as a keyword to qualify it with inline.
Inline functions must be defined before they are used, and are generally defined in the header file.
The kernel takes precedence over the use of inline functions instead of macros.
Inline assembly:
Assembly code is typically embedded using asm () directives, which are not optimized with volatile representations
- Branch declaration:
Unlikely (x)-X rarely appears, seldom occurs, usually false
Likely (y)-y often appears, usually true
- Kernel programming lacks a memory protection mechanism like user space
The memory in the kernel is not paged.
- Difficult to perform floating-point arithmetic during kernel programming
- The kernel gives each process only a small fixed-length stack
- Because the kernel supports asynchronous interrupts, preemption, and SMP, you must always be aware of synchronization and concurrency
SMP: Symmetric multi-processing system.
Common ways to solve competition: spin locks and semaphores.
- To consider the importance of portability
such as keeping the byte order, the four bits on it, does not assume the word length and page lengths .
Summary: The content of these two chapters is relatively small, or easy to understand, because there are Lou teachers of the school-time professors, all aspects of the same as in the review of the knowledge of learning. The author also wrote very interesting, a kind of more approachable feeling.
Linux kernel design and implementation of a book reading the 12th chapter integration