"Linux kernel design and implementation" Reading notes--12th Chapter

Source: Internet
Author: User
Tags using git git clone

"Linux kernel design and implementation" Reading notes--12th chapter The first chapter introduction to Linux Kernel 1.1 UNIX history
    • Concise: Provides only system calls and has a very clear design purpose.
    • Abstraction: Most of the things in Unix are treated as files, and this abstraction enables the manipulation of data and devices through a set of identical system invocation interfaces (open (), read (), write (), Lseek (), close ()).
    • Portable: Written in C, it has amazing porting capabilities in front of a variety of hardware architectures.
    • The process is created quickly: there is a unique fork () system call that performs a task at a time of quality and quantity. Simple interprocess communication meta-language combines a single purpose program conveniently together, and this separation of strategy and mechanism ensures that the UNIX system has a clear hierarchical structure.
    • UNIX has evolved into a modern operating system that supports preemptive multitasking, multi-threading, virtual memory, paging, dynamic linking, and TCP/IP networking.
1.2 Quest Linus Footprint: Introduction to Linux
    1. Linux is a Unix-like system, but not UNIX. Linux does not use UNIX's source code directly, but it does not abandon Unix's design goals and ensures that the application programming interface is consistent.
    2. The Linux kernel is free public software .
    3. Linux is widely used, and Linux systems are based on the basic tools of the kernel, c libraries, Toolsets, and systems. In general, the term Linux is mainly referred to as the kernel.
1.3 Introduction to the operating system and the kernel

The scope of the processor's activity at any given point in time can be summarized as one of the following three:

    • Runs in kernel space, is in the process context, and 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.
    • Runs in user space and executes user processes.
Comparison of 1.4 Linux kernel and traditional Unix kernel

1. The operating system can be divided into two major camps: Single core, micro-core. The third big camp is the outer core (mainly used for scientific research systems).

2.Linux is a single core, so far, Linux is modular, multi-threaded and the kernel itself can be scheduled operating system.

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

    • Linux supports dynamic loading of kernel modules.
    • Linux supports symmetric multi-processing (SMP) mechanisms, which are not supported by traditional UNIX.
    • The Linux kernel can preempt, allowing the kernel to run tasks that have the ability to perform preferentially.
    • The Linux kernel does not differentiate between threads and other generic processes.
    • Linux provides an object-oriented device model with device classes, hot plug events, and a device file system for user space.
    • Linux ignores some of the poorly designed UNIX features and outdated standards that are hard to implement.
    • Linux embodies the essence of freedom.
1.5 Linux kernel version

There are two types of 1.Linux cores: stable (with industrial strength, can be widely applied and deployed), in development.

2.Linux naming mechanism:

If the version number is even, the kernel is stable, and if it is odd, the kernel is the development version.

1.6 Linux Kernel Developer community

The most important forum for this community: Linux kernel mailing list (LKML)

Chapter two starting from the kernel 2.1 get the kernel source code
    • Using Git

      git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.gitgit pull # 更新分支到Linux的最新分支
    • Install the kernel source code (if you use Git, you do not need to download the compressed file.) )

      tar xvjf linux-x.y.z.tar.bz2或者tar xvzf linux-x.y.z.tar.gz

Note: The kernel source code is generally installed in the/usr/src/linux directory, even if the new kernel is installed, the/usr/src/linux directory should be guaranteed intact.

    • Using Patches

      patch -p1 < ../patch-x.y.z
2.2 Kernel source Tree

The kernel source tree consists of many directories, and most directories contain more subdirectories. The root directory of the source tree and its subdirectories are shown in the table.

目录  描述arch    特定体系结构的源码crypto  Crypto APIDocumentation   内核源码文档drivers 设备驱动程序fs  VFS和各种文件系统include 内核头文件init    内核引导和初始化ipc 进程间通信代码kernel  像调度程序这样的核心子系统lib 通用内核函数mm  内存管理子系统和VMnet 网络子系统scripts 编译内核所用的脚本security    Linux安全模块sound   语音子系统usr 早期用户空间代码 (所谓的 initramfs)
2.3 Compiling kernel 2.3.1 configuration kernel

1. Configuration Items

    • Option two: Yes or no
    • Option three: Yes or no or module (module means that the configuration is selected, generated as a module. Drivers typically use three to select one of the configuration items)
字符页面的命令行工具:make config图形界面工具:make menuconfig基于默认配置为体系结构创建一个配置:make defconfig 验证和更新配置:make oldconfig
2.3.2 Reduce compilation of junk information
    • We want to see error and warning messages at compile time, but not interested in the spam that is rushing over the screen, you can use the following techniques to achieve your wishes:
      Make > Some_other_file
    • Once you need to view the compiled output information, you can view the file. However, because errors and warnings are displayed on the screen, it is unlikely that you will need to see this file. Actually, I just typed in the following command.
      $ make >/dev/null
      This redirects useless output information to a black hole/dev/null with no return value.
2.3.3 Derivation of multiple compilation jobs
    • In order to compile the kernel with multiple jobs, use the following command:
      $ make-jn
    • Here, N is the number of jobs to be derived, and in practice, one or two jobs are generally derived from each processor. For example, on a dual processor, you can enter the following command:
      $ make–j4
2.3.4 Installing a new kernel
    • The installation of the module is automatic and independent of the architecture. As Root, just run:
      % make Modules_install
      You can install all the compiled modules into the correct home directory/lib.
2.4 Features of kernel development

Differences between Linux kernel programming and application development in user space

    • Linux kernel cannot access C library when programming
    • The Linux kernel must be programmed with the GNU C
    • Linux kernel programming lacks the memory protection mechanism like user space.
    • Floating point numbers are difficult to use when programming the Linux kernel.
    • The kernel has only a small fixed-length stack.
    • 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
    • Most of the commonly used C library functions have been implemented in the kernel. For example, a function group that operates on a string is located in the Lib/string.c file. You can use them as long as you include the <linux/string.h> header files.
    • Of all the functions that are not implemented, the most famous is the printf () function. Although the kernel code cannot call printf (), it can call the PRINTK () function.
2.4.2 GNU C

The C language used by kernel developers covers the ISO C995 standard and GNU C extension features.

    • inline (inline) functions
    • inline assembly
    • Branch Declaration
2.4.3 No memory protection mechanism
    • If a user program tries to make an illegal memory visit, the kernel discovers the error, sends the SIGSEGV, and ends the process.
    • Memory errors that occur in the kernel cause oops, which is the most common type of error that occurs in the kernel.
    • The memory in the kernel is not paged.
2.4.4 do not use floating-point numbers easily in the kernel
    • What happens when you execute a floating-point instruction, because the architecture is different, the kernel chooses differently, but the kernel usually catches traps and handles them accordingly.
    • Unlike the user-space process, the kernel does not perfectly support floating-point operations because it cannot be caught in itself .
2.4.5 volume small and fixed stack
    • The exact size of the kernel stack changes with the architecture. On x86, the size of the stack is configured at compile time, which can be either 4KB or 8KB.
    • Historically, the size of the kernel stack is two pages, which means that the 32-bit machine core stack is 8KB, and the 64-bit machine is 16KB, which is fixed.
    • Each processor has its own stack.
2.4.6 Synchronization and concurrency
    • Linux is a preemptive multitasking operating system. The kernel's process scheduler improvised scheduling and rescheduling of processes. The kernel must synchronize these tasks.
    • The Linux kernel supports multi-processor systems.
    • Interrupts come asynchronously, completely ignoring the code that is currently executing.
    • The Linux kernel can be preempted.
The importance of 2.4.7 portability
    • Linux is a portable operating system,
    • The architecture-related code must be properly separated from the specific directory in the kernel tree.

"Linux kernel design and implementation" Reading notes--12th Chapter

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.