Linux Kernel Analysis--Understanding process scheduling time tracking analysis process scheduling and process switching process

Source: Internet
Author: User
Tags switches

20135125 Chen Zhiwei

+ Original works reproduced please specify the source

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

Experimental principle:

1. Different types of processes have different requirements for scheduling requirements:
First Category:
-i/o-bound: Frequent I/O, often spending a lot of time waiting for I/O operations to complete
-cpu-bound: Computationally intensive, requiring a lot of CPU time to perform operations
Second Category:
-Batch process: Do not need to interact with the user, usually run in the background;
-Real-time process: real-time demand, not blocked by low priority processes, short response time, stable;
-Interactive process: requires frequent interaction with the user; fast response time

2. Process scheduling interrupt processing (including clock interrupts, I/O interrupts, system calls, and exceptions), call schedule () directly, or return to the user state based on the need_resched tag call schedule ();  the user-state process can only be passively dispatched. Kernel threads can directly call schedule () for process switching, or they can be dispatched during interrupt processing, which means that kernel threads can be scheduled or passively dispatched as a special kind of process, and kernel threads are special processes that have no user state in the kernel state. Kernel threads can be either actively scheduled or passively dispatched. The user-state process cannot implement the active scheduling, but can only be dispatched by a point in time after the kernel state, that is, scheduling during interrupt processing. The schedule () function selects a new process to run and invokes Context_switch for context switching, which calls switch_to for critical context switching     next = Pick_next_task (RQ, prev);//The Process scheduling algorithm encapsulates this function internally      context_switch (RQ, Prev, next);//process Context switch      switch_ To take advantage of Prev and next two parameters: Prev points to the current process, next points to the scheduled process  3.linux process scheduling and process switching content: (1) starting from the schedule (), several different types of processes between the scheduling choice; The scheduling selection algorithm between processes of the same type first prohibits preemption, obtains the current CPU, the execution queue of the CPU, the process being executed on the queue, and the exchange count information of the process and frees the lock that the process occupies. After that, for the disable interrupt, update the run queue clock, the spin clock of the queue is locked, and then the Thread_flag in the current process is cleared tif_need_resched. If the process is not in a running state and can be preempted, if the process is in a non-blocking suspend, change it to run, otherwise call the Deactivate_task () function, and modify the context exchange number. where the Denqueue_task () function is called in the Deactive_task () function: (2) from the change of the IP value of the CPU, it is explained that after the SWITCH_TO macro is executed, the execution Analysis (3) stack switch position, before and after the switch stack, Current_ Thread_info changes the flags of the current process, pushes the base address of the current stack, saves the current stack top, switches the kernel stack, and saves the EIP (4) address space for the current process, explainingThe switching of the address space does not affect the execution of subsequent switch codes (5) The source location (6) of the change in the process represented by the current macro changes the information about the kernel stack in the Task Status section source location   Experiment Summary:Schedule () regain the large kernel lock when needed, re-enable kernel preemption, and check if some other process has set the TLF_NEED_RESCHED flag for the current process, and if so, the entire schedule () function restarts, otherwise the function ends. The core function of the Linux dispatch encapsulates the framework of the kernel scheduler for the Schedule,schedule function. The detail implementation invokes the function implementation in the specific scheduling class. When the switching process has been selected, the processing of the user's virtual space begins, and then the process switches switch_to (). The so-called process switching is mainly the switch of the stack, which is done by the macro operation Switch_to ().

Linux Kernel Analysis--Understanding process scheduling time tracking analysis process scheduling and process switching process

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.