Linux Kernel Learning Summary

Source: Internet
Author: User

Li Zeyuan Original works reproduced please specify the source

"Linux kernel Analysis" MOOC course: http://mooc.study.163.com/course/USTC-1000029000

"Linux Kernel Learning Summary"

Happiness comes suddenly, this course is almost over ...

It's time to summarize the persistence of this period and give you a guide to the same Linux kernel.

In this course of study, according to the teacher's request, every class after each write a blog post, this is a good way to learn. When writing these articles, always have to read a few more videos, and then check the relevant information, in order to scrape into a complete document, but also to learn something better to share, to attract more people come to learn the Linux kernel, discussed together. This series of Bovenro are listed below, and you are welcome to correct them.

1. Graphical analysis of assembly code to understand how a computer works

Von Neumann architecture of the computer, also known as the storage program computer, from the hardware point of view, its working model is that the CPU reads in-memory instructions in turn to complete the work. But how does it complete a program written by programmers for non-linear execution? This lesson of the experiment, take a piece of assembly code as an example, detailed introduction of CPU calculation module, register and memory is how to work together!

2. Analysis of kernel Code of a simple time-slice rotation multi-channel program based on Mykernel

Mykernel is a kernel platform built by the teacher to open your own operating system, based on the Linux Kernel 3.9.4 source code. Through this talk of learning and experimentation, we know that the core function of the operating system is: process scheduling and interrupt mechanism, through the cooperation with the hardware to achieve multi-tasking, coupled with the support of the upper application software, and eventually become a computer system that can make it easy for users to operate.

3. Using GDB to track the Linux kernel boot process

Start_kernel () is the interface between the Assembly of the kernel and the C language, before which the kernel code is written in sinks, completing some of the most basic initialization and environment setup work. Start_kernel is like the main function in C code. Regardless of your focus on Linux kernel modules, you can always leave the Start_kernel function, because most of the initialization work of the module is done in Start_kernel. Following the experimental steps in this lesson, we can track the boot process of the Linux kernel.

4. Use the same system call using the Library function API and the embed assembly code in C code two ways

Even the simplest programs will inevitably use operations such as input, output, and exit, while doing so requires invoking the service provided by the operating system, which is called the system. Unless your program only completes mathematical operations such as subtraction, it is difficult to avoid using system calls. There are two ways to make a system call under the Linux platform: by using the encapsulated C Library (LIBC) or by assembly-direct invocation. This article starts with an example, describes the concept of system invocation, and how to use system calls.

5. Analyze the process of system_call interruption

Through GDB we can call the system kernel in the program such as Sys_write, Sys_time set breakpoints, and let the program stop at the breakpoint, the breakpoint tracking system call in the process. Since System_call is a function that is written entirely in sinks, although we can also set breakpoints at System_call, we cannot stop the system at System_call, so we cannot learn the process in a single-step tracking. However, System_call is the entry of all system calls and a function that cannot be crossed when the program is transferred from the user state to the kernel state, so we follow the teacher's simplified assembly code and the source code to learn its main process.

6. The description of the beginner Linux process and the creation of the process

To manage the process, the kernel must have a clear description of each process, and the process descriptor provides the process information that the kernel needs to understand. Process descriptor task_struct Source Link: http://codelab.shiyanlou.com/xref/linux-3.18.6/include/linux/sched.h#1235. In the development of Linux applications, a sub-process can be created through APIs such as fork, Vfork, and clone, and their corresponding system calls in the Linux kernel are sys_fork, sys_vfork, and Sys_clone functions, respectively. These functions will eventually call Do_fork to complete the creation of the child process. Do_fork primarily replicates the task_struct of the parent process, and then modifies the necessary information to get the task_struct of the child process.

7. Learn how the Linux kernel loads and starts an executable program

The Linux system can start a new process via the Execve API, which also calls the SYS_EXECVE system call, is responsible for replacing the new program code and data into the new process, opening the executable file, loading the dependent library file, requesting a new memory space, and finally executing the Start_ Thread (regs, Elf_entry, bprm->p), set NEW_IP, NEW_SP, complete the new process of code and data substitution, and then return, followed by the execution of the new process code.

8. Beginner Linux process scheduling and process switching process

The general implementation of the Linux system, the most common situation is: The running user-state process x switch to run the user-state process y process to go through the following steps

1). Running user-state process X

2). Interrupt occurred: Save Cs:eip/esp/eflags (current) to kernel stack, then load CS:EIP (entry of a specific ISR) and Ss:esp (Point to Ke Rnel stack).

3). Save_all//Save site, here is the process that has entered the kernel interrupt

4). Schedule () was called during interrupt processing or before the interrupt was returned, where Switch_to made a critical process context switch

5). After the label 1 begins to run the user-state process y (where Y has been switched out through the above steps so it can continue from label 1)

6). Restore_all//Recovery site

7). Iret-pop Cs:eip/ss:esp/eflags from kernel stack

8). Continue to run user-state process y

Summarize

Through this course of study, deepened my understanding of operating system theory, know how the Linux system is working, how to code reading, debugging to follow the verification of Linux system operating mechanism.

Linux as an extremely successful operating system, its core complex, profound, is undoubtedly difficult to learn, although in the course of the teacher Meng, cobwebs, I also very hard to finish all the video of this course, followed by the teacher's guidance completed all the exercises and tests, But I just feel that I was just standing in front of the door of this knowledge treasure House, the gate just exposed a gap, to learn something really too much!

Personally, in this course, it is important to learn how much kernel code (although it is also important), it is important to learn how to start learning the Linux kernel, the course gives us a lot of this hint, such as: How to debug the kernel, how to understand the kernel of the assembly code, how to analyze system calls Wait a minute.

In short, as a primer, this course has played a very good guiding role, the teacher led the door, practice on their own. So for me, this course is over, but the Linux kernel has just begun to learn ...

Linux Kernel Learning Summary

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.