Linux kernel Analysis Week eighth-understanding the process of process scheduling and process switching during time tracking analysis

Source: Internet
Author: User
Tags prev switches

Experimental principle: I. Timing of dispatchDifferent types of processes have different scheduling requirements the first category:       i/o-bound             frequent i/o            usually spends a lot of time waiting for I/O operations to complete      CPU-bound         & nbsp   COMPUTE intensive             takes a lot of CPU time to do the second classification      batch process (batch process)  & nbsp           don't have to interact with users, usually run in the background             don't have to respond quickly       &NBSP ;     Typical batch process: compiler, scientific calculation     real-time process (real-time process)              There are real-time requirements that should not be blocked by low-priority processes             response time is short, to be stable             Typical real-time processes: Video /audio, mechanical control     Interactive process (interactive process)              need to interact with users frequently So it takes a lot of time to wait for user input             response time is faster, with average latency less than 50~150ms          Typical interactive programs: shell, text editing programs, graphics applications, etc. second, the timing of the process schedulinginterrupt processing (including clock interrupts, I/O interrupts, system calls, and exceptions), call schedule () directly, or call schedule () based on the need_resched tag when returning to the user state;The user-state process can only be dispatched passively. Kernel threads can directly call schedule () for process switching, or in the process of interrupt processing, which means that kernel threads as a special kind of process can be active scheduling, but also can be passively dispatched;kernel threads are special processes that only have a kernel state without a user 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);// Process scheduling algorithms encapsulate this function internally Context_switch (RQ, Prev, next);//process Context switch switch_to takes advantage of the prev and next two parameters: Prev points to the current process, and next points to the scheduled process third, Linux process scheduling and process switchingContent: (1) starting from schedule (), the scheduling choice between several different types of processes; The scheduling selection algorithm between the same types of processes first prohibits preemption, gets the current CPU, the execution queue of the CPU, the process that is executing on the queue, and the Exchange count information for 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_ The 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. Interpreting the switch of the address space does not affect subsequent switch code Execution (5) The source location of the change in the process represented by the current macro (6) changes in the information about the kernel stack in the Task Status section source location Experimental Process:as with last week's experiment, first remove the menu from the cloneSingle-Step debugging set breakpoints Experiment Summary:through learning, we learned that Linux uses the stack for process scheduling. 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 Week eighth-understanding the process of process scheduling and process switching during time tracking analysis

Related Article

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.