Process switching and general execution of the system

Source: Internet
Author: User

process switching and general execution of the system

20135109 Gao Yi Tong

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

SWITCH_TO analysis of key code for process switching

Timing analysis of 1, 1 process scheduling and process scheduling

(1) Classification of processes: I/O intensive, cpu-bound

(2) What is a scheduling policy: a set of rules that they decide when and how to choose a new process to run.

(3) The process priority of Linux is dynamic: Processes that are not allocated to the CPU over a long period of time increase priority, and processes that have been running on the CPU for a long time have a lower priority.

(4) The scheduling algorithm related code in the kernel uses a policy pattern similar to that in Ood. The scheduling algorithm is coupled with other places.

(5) Timing of process scheduling:

    • Interrupt processing (including clock interrupts, I/O interrupts, system calls, and exceptions), direct call to schedule (), or schedule () dispatched via the need_resched tag.
    • The user state process can only be dispatched passively, that is, dispatched during interrupt processing.
    • Kernel threads can call schedule () directly, or they can be dispatched during interrupt processing, either proactively or passively.

1, 2 process up and down switch related code analysis

(1) Process context switch: Hangs the process that is running on the CPU, is different from the Save field at the time of interruption, is in the same context before and after the interruption, but only from the user state to the kernel state, but the process switching is two process switching.

(2) information to be switched: User address space, control information, hardware context (interrupt also to save context), etc.

(3) Schedule () in the Context_switch in the switch_to switch register and the state of the stack, the position of the EIP.

(4) Thread.sp the bottom of the kernel stack; thread.ip the current process's EIP.

(5) The first instruction of the next process: Next_ip is generally $1f, which is ret_from_fork for newly created child processes.

Second, the general implementation of the Linux system process

2. General execution process Analysis of 1Linux system

(1) When an interrupt occurs: The CPU holds an EIP, and the ESP presses into the kernel stack x, loading the information about the kernel stack (the starting point of the service journey).

(2)Switch_to does a critical process context switch (the x core stack and the EIP switch to the next process stack).

(3) After the label 1 begins to run the user-state process Y.

(4)restore_all recovery site.

(5) Iret (EIP, Ss:eip saved when the pop out Y process is interrupted).

(6) Continue to run the switching process Y.

(7) Interrupt the context switch and the process context switch two processes.

2. Several special cases in the process of 2Linux system execution

(1) Kernel threads do not change the CS segment through interrupt processing (switching between the user-state process and kernel threads, and between kernel processes and kernel processes).

(2) The kernel thread actively dispatches schedule (), only the process context switches, no interrupt context is switched.

(3) Create a system call to the child process, where the execution start point is ret_form_fork (next_ip=ret_form_fork) When the child process returns.

2, 3 cores and dancers

(1) 0-3G user State, 3gG above the kernel state access.

(2) All processes are identical in the kernel State (code sharing).

(3) The kernel is a collection of various interrupt processing processes and kernel threads.

Iii. Overview of the Linux system architecture and implementation process

3.1Linux Operating System Architecture Overview

3, 2 The simplest and most complex operation--execute the LS command

(1) Enter the LS command under the console

    • Concept of interruption, terminal console device-driven concepts
    • Shell program Analysis input parameters, determine LS command
    • Call the system call Fork to generate a copy of the shell itself
    • Call the exec system call to put the LS executable file into memory
    • Returning from System call
    • Both the shell and the LS are executed.

3, 3 from the CPU and memory point of view of the implementation of Linux system

(1) Implementation of Linux systems from the perspective of CPU and memory

(2) The implementation of Linux system from the memory point of view

Process switching and general execution of the system

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.