Linux kernel process scheduling

Source: Internet
Author: User

Concept:

Process scheduling determines how long the process is running and how much time it runs.

Process scheduling is not too complex principle, the principle of maximizing the use of processor time is: As long as there are executable programs, then there will always be a process in execution, if the number of processes can be run more than the processor, then destined to have a part of the process is waiting.

Multi-tasking operating system:

Preemptive multitasking mode: A scheduling system that determines which process is running.

Non-preemptive multitasking mode: The process itself determines when to stop CPU usage.

Linux is a preemptive type.

Scheduling algorithm

Linux There are two major types of scheduling algorithms, CFS ( fully fair scheduling algorithm) and real-time scheduling algorithm.

CFS

CFS defines a new model that arranges a virtual clock for each process in the CFS_RQ (CFS run queue), Vruntime. If a process is executed, its vruntime will increase over time (i.e. tick arrival). Processes that do not get executed vruntime unchanged.
The scheduler always chooses Vruntime to run the slowest process to execute. This is called "complete fairness". In order to differentiate between different priority processes, the high-priority process vruntime grows so slowly that it may get more running opportunities.

CFS uses red-black trees to organize the tasks that can be run, and it is conceivable that a red-black tree sorted by Vruntime is the PID of the process. This ensures that the CFS can quickly find the vruntime smallest process and put it into operation.

Understand a probably can, detailed implementation can refer to: http://www.cnblogs.com/tianguiyu/articles/6091378.html

Real-Time Scheduling algorithm

Understanding: The real-time scheduling algorithm is a static priority algorithm, in order to meet the rapid response. Linux tries to ensure that these processes are always successful in preemption.

With sleep and wake up

Sleep (blocked) is a special non-executable state. This is important, and if there is no sleep, the scheduler may choose a process that is temporarily unwilling to be executed, and sleep must be done using polling.

Linux sleep is achieved by waiting for a queue. Waiting queues, like task queues, are also a double-ended loop linked list. The process performs a sleep operation and puts itself into the waiting queue: The next time the scheduler is scheduled, the scheduler ignores the processes in the waiting queue.

The tasks in the wait queue are not automatically awakened, but require other processes to invoke the Wake method to wake up, and the Wake method can wake the waiting queue on a random process, or all processes. The wake operation modifies the status of the process to be operational and then puts the process into a red-black tree.

I understand: it is generally a process of all threads (for Linux, is also a process) coordination of work, for example, for the lock, blocking all threads in the lock will go into the same waiting queue, once the other thread freed the lock, Then other threads, such as the main process, are responsible for waking up the thread on the wait queue to preempt the lock.

Context Switches

When the process switches, the processor state of the previous process is saved and then switched to the processor state of the next process, including but not limited to: stack information, program counters, register information.

Linux kernel process scheduling

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.