Linux Kernel and analysis experience

Source: Internet
Author: User

Job Directory: (1) How the computer works: http://www.cnblogs.com/20135335hs/p/5213394.html (2) How the operating system works: http://www.cnblogs.com/ 20135335hs/p/5248078.html (3) Linux system Boot process: http://www.cnblogs.com/20135335hs/p/5271708.html (4) Method of System call:/HTTP Www.cnblogs.com/20135335hs/p/5297310.html (5) analyzes the System_call interrupt processing process: http://www.cnblogs.com/20135335hs/p/5322899. HTML (6) analyzing the process of creating a new process for the Linux kernel: http://www.cnblogs.com/20135335hs/p/5347091.html (7) How Linux loads and launches an executable program:/HTTP Www.cnblogs.com/20135335hs/p/5373876.html (8) Understanding process scheduling timing and process switching processes: http://www.cnblogs.com/20135335hs/p/ 5398064.html Summary: 1. Understanding "How computers work"

The most basic is the von Neumann architecture, its core idea is to store the program computer, the main point is: Digital computer system using binary; the computer should be executed in the order of the program. 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. Articulate an understanding of how the "operating system works"

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. Clarification of the "Linux system startup Process" understanding

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. The Department How the system calls work

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. "System call processing process and extension to interrupt processing"

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. Understanding of the "Linux system creates a new 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. "Linux kernel mounts and launches 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. Understanding of the "Linux system General execution 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

Harvest: According to my own learning experience, just beginning to learn the kernel, I think to do is to build up in their own mind the framework of the core, understand the design concepts and construction ideas of each function, these ideas and ideas will be presented to you from the macro-clear context, like a tree to remove the branches and leaves of the trunk, At a glance; Of course, it will certainly involve specific implementation methods, functions, but at this point the contact function or method at the higher level of the kernel implementation, is the main (to) function, has been aware of these functions, for what design ideas, the realization of what kind of function, achieved what purpose, The idea of a familiar face is also set up here. As for the other auxiliary functions called by the main function is equivalent to branches and leaves, do not have to go into the deep.  At this point, the initial establishment of the kernel subsystem framework and code implementation of the association between, the association is actually very simple, such as a see a function name, I think of this function realized what function. Regret: Unconsciously, this course is over, the end of a very sudden, has been accustomed to the weekly fixed time, a fixed place to open the computer to learn Meng teacher This course, now say goodbye is really not give up, but also very nostalgia that full of life. Saying goodbye is just the end of the course, and I have a long way to study.

Linux Kernel and analysis experience

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.