Linux kernel Analysis (eighth week)

Source: Internet
Author: User

Process switching and general execution of the system

SWITCH_TO analysis of key code for process switching

1. Process scheduling and its timing analysis

Classification:
The first classification i/o-bound: frequent I/O; it takes a lot of time to wait for I/O operations to complete
Cpu-bound: computationally intensive; requires a lot of CPU time to calculate
The second classification batch process: does not have to interact with the user, usually in the background; no quick response (compiler, scientific calculation)

Real-time processes: real-time requirements, not blocked by low-priority processes, short response times, stable (video/audio, mechanical)
Interactive process: frequent interaction with users; spend a lot of time waiting for user input, fast response time (shell; text editor)
Scheduling in Linux is a mix of various scheduling strategies and algorithms:
is based on time-sharing and priority;
The priority of the process is dynamic;
* The kernel's scheduling algorithm related code uses a policy pattern similar to that in Ood
  

Timing of process scheduling:
Schedule function: Find a process in the run queue, assign the CPU to it (direct call or scatter tag need_reched)
During interrupt processing, call schedule () directly, or return to the User State schedule () to return according to the tag;
Kernel threads directly call schedule () for thread switching (kernel threads are special processes that have no user state in the kernel state);

User state can not be active scheduling, only to fall into the kernel state after a certain point in time to dispatch (only passive scheduling);


2. Process context switch related code analysis

Switching of processes:

Suspend a process that is executing on the CPU, unlike the Save field at the time of the outage, before and after the interrupt is in the same process context, from the user state to the kernel state, including all the information required for process execution (user address space; control information; hardware context)


Schedule () Select a new process to run, call Context_switch for context switch, this macro calls Switch_to for critical context switch
Next=pick_next_task
Context_switch (context Switch)
Switch_to (Pre,next,last)

*NEXT_IP is generally $1f, for newly created child processes are ret_from_fork

Second, the general implementation of the Linux system process

1. General implementation Process

Running x→ interrupt →save_all (save scene) → interrupt process or interrupt return before calling schedule (), where switch_to for context switching → label 1 starts running process y→restore_all (recovery site) →iret_ pop→ continue to run User State Y


2. Special Circumstances

Kernel thread interrupt No process user state, kernel state conversion;
Kernel thread actively calls schedule (), only process context switches, no interrupt context switch;
The system call that creates the child process starts at the execution of the child process, and returns the user state (Next_ip=ret_from_fork)
A situation in which a new executable program is loaded and returned to the user state (such as Exceve)


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


Iii. Overview of the Linux system architecture and implementation process

1. Architecture Overview

2. Execute the LS command → determine the command →fork generate a copy of the shell itself →exce load the LS executable into memory → return from system call
3. From the CPU and memory point of view the Linux execution process

Four, the experiment

 


            
    

Linux kernel Analysis (eighth week)

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.