Textbook Study Note 1: Chapter first to second 20135115 Xuan Wenjun

Source: Internet
Author: User
Tags using git

Chapter One introduction to the Linux kernel

Note: Xuan Wenjun, original works reproduced please indicate the source.

First, the History of Unix

1, 1969, Dennis Ritchie and Ken Thompson,unix.

2, Unix produced in the Bell Laboratory of a failure of the multi-user operating system Multics.

The first widely used version of UNIX is the 6th edition, called V6.

3. Further development:

University of California, Berkeley: BSD (Berkeley software distributions).

4, the UNIX system powerful root cause: the strategy and the mechanism separates the design idea, guaranteed the UNIX system to have the clear hierarchical structure.

(1) UNIX is simple: UNIX provides only hundreds of system calls and has a very clear design purpose.

(2) in Unix, everything is treated as a file.

(3) Unix kernel and related system Tools software is written in C language, so that UNIX in the face of a variety of hardware architecture has a surprising ability to transplant, and make the majority of developers easy to accept.

(4) The UNIX process is created very quickly and has a very unique fork () system call.

(5) UNIX provides a very simple yet stable inter-process communication meta-language, and the fast and concise process creation process enables UNIX programs to perform a task at a time of quality and quantity, while the simple and stable interprocess communication mechanism ensures that simple programs of these single purposes can be conveniently grouped together To solve the task of becoming more and more complex in reality.

5. UNIX has evolved into a modern operating system that supports preemptive multitasking, multi-threading, virtual memory, paging, dynamic linking, and TCP/IP networking.

Ii. Introduction of Linux

1, the production of Linux: 1991,linus Torvalds.

2, Linux is a Unix-like system.

3, the foundation of Linux system is the kernel, C library, tool set and system basic tools.

4, in general, the term Linux mainly refers to the kernel.

III. Introduction to operating systems and kernels

1, operating system: refers to the entire system is responsible for the completion of the most basic functions and system management of those parts. Includes kernels, device drivers, boot bootstrapper, command-line shell, or other kinds of user interfaces, basic file management tools, and system tools.

2, the user interface is the external representation of the operating system, the kernel is the inner core of the operating system.

3, the kernel is responsible for responding to interrupt the Interrupt service program, is responsible for managing multiple processes to share the processor Time Scheduler, is responsible for managing the process address space of the memory management program and network, interprocess communication and other system services program together.

4. Applications running in the system communicate with the kernel through system calls.

The application usually calls the library function, and then the library function through the system call interface, let the kernel perform various tasks on its behalf.

5. When an application executes a system call, we say that the kernel is executing on its behalf, the application is called to run through the system call in kernel space, and the kernel is called running in the process context.

6. The application completes the basic behavior of its work: The application is trapped in the kernel through the system call interface.

7, the kernel is also responsible for the management system hardware equipment.

8, interrupt usually corresponds to an interrupt number, the kernel through this interrupt number to find the corresponding interrupt service program, and call the program response and processing interrupts.

Many of the operating system's interrupt services, including Linux, are not executed in the context of the process, and they run in a specialized interrupt context that is unrelated to all processes.

9. The activity of each processor at any given point in time must be summed up as:

(1) Run in user space, execute user process.

(2) running in kernel space, in the process context, on behalf of a particular process execution.

(3) runs in kernel space, is in the interrupt context, is independent of any process, and handles a specific interrupt.

Example: When the CPU is idle, the kernel runs an empty process, in the process context, but runs in kernel space.

Iv. comparison between the Linux kernel and the traditional UNIX kernel

1, the Unix kernel is an inseparable static executable library.

The UNIX kernel typically requires a hardware system to provide a page mechanism (MMU) to manage memory.

2, single core and micro-core design comparison:

The operating system core can be divided into: single core and micro-core.

(1) Single-core: it is implemented as a single large process in its entirety, and also runs on a separate address space.

Typically stored on disk as a single static binary file.

Communication between the cores is trivial, and the kernel can call functions directly.

Characterized by simplicity and high performance, most UNIX systems are designed as single modules.

Example: Linux (modular design, preemptive kernel, kernel threading support, and dynamic loading of kernel modules).

(2) Micro-core: not as a single large process to achieve.

The microkernel functionality is divided into separate processes, each of which is called a server.

Process micro-kernel communication via messaging: The system uses interprocess communication (IPC) mechanisms.

The server's respective independence effectively avoids the failure of one server harmful another, the modular system allows one server to swap out for another server.

All micro-kernel-based systems that are actually applied have the majority or all of the servers in the kernel.

Example: Windows NT kernel.

3. Differences between the Linux kernel and the traditional UNIX system

V. Linux kernel version

1, the Linux kernel has two kinds: stable and in development.

2. Version naming rules:

The version number can reflect whether the kernel is a stable version or a developing version: If the number is even---stable, odd---the development board.

Chapter II starting from the kernel

First, access to the kernel source code

1. Using Git

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

After downloading the code, you can update your branch to the latest branch of Linux: Git pull

2. Install kernel source code

If the kernel compression form is bzip2, run:

Tar xvjf linux-x.y.z.tar.bz2

If the kernel is compressed in the form of GNU Zip, run:

Tar xvzf linux-x.y.z.tar.gz

The extracted source code is located in the linux-x.y.z. Directory.

The kernel source code is generally installed in the/usr/src/linux directory.

3. Using Patches

To apply incremental patches, start with your internal source tree and simply run:

Patch-p1 <. /patch-x.y.z

Second, the kernel source tree

1. Root directory description of kernel source tree

Third, compile the kernel

1. Configuring the Kernel

(1) Configuration item: Two select one (yes/no), three choose one (Yes/no/module).

(2) The driver is generally a three-choice configuration item.

(3) configuration options can also be strings or integers.

(4) Simplified kernel configuration:

A. Command-line tool under the character interface: Make config, which iterates through all configuration items individually.

B. Using the graphical interface tool based on the NCurse library: Make Menuconfig.

C. GTK +-based graphical tools: Make Gconfig.

D. Based on the default configuration: Make Defconfig.

These configuration items are stored in the. config file in the root directory of the kernel code.

(5) Verify and update the configuration: Make Oldconfig.

(6) configuration options Config_ikconfig_proc The complete compressed kernel configuration file is stored under/proc/config.gz, and when you compile a new kernel, you can easily clone the current configuration.

(7) If your current kernel has this option enabled, you can copy the configuration file from/proc and use it to compile a new kernel:

zcar/proc/config.gz >. config

Make Oldconfig

(8) After the kernel is configured, use the make command to compile it.

2, reduce the compilation of junk information

Make >: /detritus: As little as possible to see the spam information, do not miss error reporting and warning messages, use this command to redirect the output.

Make >/dev/null: redirect useless output information to black hole/dev/null with no return value.

3. Multiple compilation jobs derived

Make-jn

n represents the number of jobs to be derived

4. Install the new kernel

By running make Modules_install as root, you can install all the compiled modules into the correct home directory/lib/modules.

Four, the characteristics of the core development

Differences relative to the development of applications within the user space:

1, no libc library or no standard header file

(1) The base header file is located in the Include directory under the top-level directory of the kernel source tree.

(2) The architecture-related header file set is located in the Arch/<architecture>/include/asm directory of the kernel source tree.

(3) PRINTK () allows you to set a priority by specifying a flag.

2. GNU C

(1) inline function: A function that has a relatively high time requirement and a shorter length.

(2) When defining an inline function: Use static as the keyword and inline to qualify it.

Example: static inline void Wolf (unsigned long tail_size)

In the kernel, for type safety and legibility, it is preferable to use inline functions instead of complex macros.

(3) inline assembly: Embed assembly code using ASM () directives.

(4) Branch declaration: When a condition occurs frequently, or if the condition is rarely present, likely () and unlikely () can be used.

3. No memory protection mechanism

Memory errors that occur in the kernel can cause oops.

The memory in the kernel is not paged.

4. Do not use floating-point numbers easily in the kernel

5, the volume of small and fixed stack

The kernel stack size is two pages, the kernel stack of the 32-bit machine is the kernel stack of the 8kb,64 bit machine is 16KB.

6. Synchronization and concurrency

7, the importance of portability

Summarize:

The first to second two chapters mainly introduce the development of Linux and the method of acquiring, compiling and installing Linux kernel. Understanding the development history of Linux helped me to get to know Linux and the similarities and differences between Linux and UNIX. Linux contains the imprint of Unix, but it also has its own characteristics. Learning about Linux kernel knowledge also made me aware of the Linux system installation process.

Textbook Study Note 1: Chapter first to second 20135115 Xuan Wenjun

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.