20135327 Guo Hao--Reading notes one

Source: Internet
Author: User
Tags using git

Reading notes one by one, Linux kernel introduction 1.1 Unix History

Although Unix has been used for 40 of years, computer scientists still consider it to be the most powerful and excellent system in the existing operating system.

1.2 Quest Linus Footprint: Introduction to Linux

Linux is a non-commercial product, which is one of its most interesting features. In fact, Linux is a collaborative development project on the Internet.

Linux is widely used and contains many things. Linux systems are based on basic tools for kernels, c libraries, toolsets, and systems

In general, the term Linux mainly refers to the kernel.

1.3 Introduction to the operating system and the kernel

Due to the increasing complexity of some existing commercial operating systems and the design of the lack of land, the precise definition of the operating system does not have a unified standard. Many users take what they see on the monitor screen as a matter of course, as the operating system. In general, of course, the operating system refers to the parts of the system that are responsible for the most basic functions and systems management. These sections should include kernels, device drivers, boot bootstrapper, command-line shells, or other kinds of user interfaces, basic file management tools, and system tools. These are essential things one by one don't think you can just have a browser and a player. The word system actually contains the operating system and all the applications that run on it. Of course, the subject is the kernel. The user interface is the external representation of the operating system, and the kernel is the inner core of the operating system. Other parts of the system must rely on the services provided by this part of the software, such as managing hardware devices, allocating system resources, etc. The kernel is sometimes called a manager or an operating system core. Typically, a kernel consists of a scheduler that is responsible for interrupting the interrupt service, managing multiple processes to share processor time, and a system service program that manages the process address space, such as the memory management program and the network, interprocess communication, and so on.
When an application executes a system call, we say that the kernel is executing on its behalf. If further explained, in this case, the application is called to run through the system call in kernel space, while the kernel is called running in the process context. This interaction one by one-the application through the system call interface into the kernel is one of the basic behavior of the application to complete its work.

Comparison between the 1.4Linux kernel and the traditional UNIX kernel

There are significant differences between the Linux kernel and the traditional UNIX system:

Linux supports dynamic loading of kernel modules. While the Linux kernel is a single-player game, it allows for the dynamic removal and loading of some kernel code when needed.

Linux supports symmetric multi-processing (SMP) mechanisms, although many variants of UNIX also support SMP, but traditional UNIX does not support this mechanism.
The Linux kernel can preempt (preemptive). Unlike traditional Unix variants, the Linux kernel has the ability to allow tasks that run in the kernel to take precedence. of the other Unix products, only Solaris and Dish IX support preemption, but most UNIX cores do not support preemption.

Linux The implementation of Chan Cheng support is more interesting: the kernel does not differentiate between threads and other generic processes. For the kernel, all processes are the same one by one are just some of the shared resources.

Linux provides an object-oriented device model with device classes, hot-plug events, and a user-Kongkuo device file System (SYSFS).

Linux ignores some of the Unix features that are thought to be poorly designed, like STREAMS, which also ignores outdated standards that are difficult to implement.

Linux embodies the essence of the word freedom. The existing Linux feature set is the result of the free development of the Linux Open development model.

No matter how different Linux and Unix are, it has a very deep Unix imprint on it.

1.5 Linux kernel version

Chapter two starting from the kernel 2.1 get the kernel source code

Login to the Linux kernel official website http://www.kemel.org, can be at any time to take the current version of the Linux source code, can be a complete compression form (using the TAR command to create a compressed file), or can be an incremental patch form.

2.1.1 Using Git
Over the past few years, Linus and his core developers have started using a new version of the control system to manage the Linux kernel source code. This system created by Linus is called Git.

2.1.2 Install the Kernel Dew Code
Kernel compression is released in two forms, GNU zip (gzip) and bzip2. BZIP2 is the default and preferred form because it has the advantage over gzip on compression. The Linux kernel, published in bzip2 form, is called linux-x.y.z.tar.bz2, where x.y.z is a specific version of the kernel source code.

2.1.3 Using Patches
In the Linux kernel community, patches are common language. You can post changes to the code as patches, or you can receive changes made by others as patches.

2.2 Kernel source Tree
The kernel source tree consists of many directories, and most of the forks contain more subdirectories.

2.3 Compiling the kernel

2.3.1 Configuring the Kernel
Because the Linux source is readily available, it means that it can be configured and customized before compiling it. Indeed, you can compile the specific features and drivers you need into the kernel. Before compiling the kernel, you must first configure it.

These configuration items are either two selected or three selected. The second choice is yes or No. For example, CONFIG PREEMPT is a two-choice, indicating whether the kernel preemption function is turned on. Three choices can be yes, no, or module. The module means that the configuration item is selected, but the implementation code for this part of the feature is generated in the form of a module, a standalone piece of code that can be dynamically installed. In the case of three choices, the Yes option means that the code is compiled into the master kernel image, not as a module. Drivers typically use three to select one of the configuration items.

The configuration option can also be a string or an integer.

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

2.3.2 Reduce compilation of junk information
If you want to see as little spam as possible, but you don't want to miss out on error reporting and warning messages, you can redirect the output with the following command:
$ make >: /detritus
Once you need to view the compiled output information, you can view this file. However, because errors and warnings are displayed on the screen, it is unlikely that you will need to see this file. In fact, I just typed in the following command:
$ make >/dev/null
You can redirect useless output information to a black hole/dev/null with no return value.

2.3.3 Derivation of multiple compilation jobs
The Make program splits the compilation process into multiple parallel jobs. Each of these jobs runs independently and concurrently, which helps to greatly speed up the compilation process on multiprocessor systems and improves processor utilization, since compiling large source trees also includes the time it takes for i/0 to wait (that is, the time it takes the processor to wait for the i/0 request to complete).

2.3.4 Installing a new kernel
After the kernel has been compiled, you will need to install it as well. How the installation is related to the architecture and boot Boot tool (bootloader) one by one refer to the instructions for the Boot boot tool, copy the kernel image to the appropriate location according to its instructions, and install it as per the boot requirements. Be sure to have one or two bootable kernels at any time to prevent problems with the newly compiled kernel.

2.4 Features of kernel development

The most important differences include the following:

    • Kernel programming can neither access the C library nor access the standard C header files.
    • The kernel programming must use GNU C. • Kernel programming lacks memory protection mechanisms like user space.
    • Floating-point arithmetic is difficult to perform during kernel programming. • The kernel gives each process only a small fixed-length heap of money.
    • Because the kernel supports asynchronous interrupts, preemption, and SMP, you must always be aware of synchronization and concurrency.
    • Consider the importance of portability.

2.4.1 No libc library or no standard header file

Unlike the user-space application, the kernel cannot link to the standard C function library one by one or any of the other libraries. There are many reasons for this, including the paradox of having a chicken or an egg first. But the main reason is speed and size. For the kernel, the complete C library one by one is too large and inefficient for even a subset of it.

2.4.2 GNU C,
Like any Unix kernel, the Linux kernel is written in C. Somewhat surprisingly, the kernel does not fully conform to the ANSI C standard. In fact, whenever possible, kernel developers always have to use the extended portions of many of the languages that GCC provides. (GCC is a collection of various GNU compilers that contain C compilers that compile the kernel or compile other code written in C on Linux systems.) )

    • 1. Inline (inline) functions C99 and GNU c support inline functions. The name of the inline can reflect how it works, and the function will expand where it is called. This eliminates the overhead associated with function calls and returns (register storage and recovery).
    • 2. Inline sinks The Gee compiler supports embedding assembly directives in C functions. Of course, when the kernel is programmed, it can only be used if the corresponding architecture is known. We typically embed assembly code using ASM () directives
    • 3. Branch Luming for conditional selection statements, GCC has built an instruction for optimization, and when a condition is frequently present, or if the condition is rarely present, the compiler can optimize the conditional branching selection based on this instruction. The kernel encapsulates this directive into macros, such as likely () and unlikely (), which makes it easier to use.

2.4.3 No memory protection mechanism

2.4.4 do not use floating-point numbers easily in the kernel

2.4.5 volume small and fixed stack

2.4.6 Synchronization and concurrency

The kernel is prone to race conditions. and single-threaded user-space programs, many of the features of the kernel require the ability to access shared data well, which requires a synchronization mechanism to ensure that there are no competitive conditions, especially:

    • Linux is a preemptive multitasking operating system. The kernel's process scheduler improvised scheduling and rescheduling of processes. The kernel must be synchronized with these tasks.
    • The Linux kernel supports symmetric multi-processor systems (SMP). So, without proper protection, kernel code that executes on two or more processors at the same time is likely to have access to the same shared resource at the same time.
    • Interrupts come asynchronously, completely ignoring the code that is currently executing. That is, if it is not properly protected, it is entirely possible for the interrupt to come when the code accesses the resource, so that the middle-line handler can access the same resource.
    • The Linux kernel can be preempted. So, without proper protection, a piece of code executing in the kernel might be preempted by another section of code, potentially causing several pieces of code to access the same stack at the same time.
    • Commonly used to solve the competition is the spin lock and signal volume

The importance of 2.4.7 portability

Summary:

The first chapter will take us from the Unix historical perspective to understand the Linux kernel and Linux operating system of the past life. Today UNIX systems have become a family of operating systems that have similar application programming interfaces (APIs) and are based on similar design concepts. But it is also a unique operating system, from the germination to now has more than 40 years of history. To learn about Linux, we must first recognize Unix systems.

The second chapter mainly introduces some basic knowledge of the Linux kernel: from where to fetch the source code, how to compile it, and how to install the new kernel. So, let's look at the differences between kernel programs and user-space programs, and the common programming structure used in the kernel. Although the kernel is unique in many ways, it does not differ significantly from other large software projects from now on.

20135327 Guo Hao--Reading notes one

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.