Linux Kernel Analysis Chapter fourth reading notes

Source: Internet
Author: User
Tags switches

Linux Kernel Analysis Chapter Fourth reading notes part--Process scheduling

process scheduling: process selection mode under operating system rules

facing the problem: multi-Task selection problem

Multitasking is an operating system that can concurrently execute multiple processes simultaneously, on a single-processor machine, which creates the illusion that multiple processes are running concurrently on a multiprocessor machine, which enables multiple processes to actually run concurrently and concurrently on different processors. Multitasking operating systems can cause multiple processes to clog or sleep in a single-processor or multiprocessor machine, which means that they are not actually put into execution until the work is done.

Multi-tasking systems can be divided into two categories: non-preemptive multitasking and preemptive multitasking. Linux provides preemptive multi-tasking.

Policy selection:

The general choice of tasks can be divided into: When a process is running, the system can be based on a certain principle, to deprive the processor that has been allocated to it, assign it to other processes. The principle of deprivation is: priority principle, short process priority principle, time slice principle.

Priority: Each task process has its own entry level, and the high person enters

time slices: Selecting processes based on basic time units

Usually Linux uses them in conjunction

The algorithm provides:

FIFO algorithm: The algorithm always assigns the processor to the process that first enters the ready queue, and once a process has been assigned to the processor, it executes until the process is complete or blocked before releasing the processor.

Short process first: the shortest CPU run-time priority scheduling algorithm, which selects the next "CPU execution period shortest" process from the ready queue, and assigns the processor to it.

Rotation method: In the time-sharing system, we adopt the method of temporal slice rotation. Simple rotation: The system queues up all the ready processes in a FIFO rule and assigns the processor to the process in the queue at a certain interval. In this way, all processes in the ready queue can be run with a processor for the time slice. Multi-level queuing method: divides all processes in the system into classes, one for each class.

Linux usually uses the fairness algorithm:

CFS algorithm: When you need to select the next running process, it will pick a process with minimal vruntime, which is actually the core of the CSF scheduling algorithm: Select the task with the smallest, vruntime. So the rest of this is about how to implement a process that chooses a minimum, vruntime value. Linux, Red black tree is called rbtree, it is a self-balancing binary search tree, red and black tree is a tree node form of data stored, the data will correspond to a key value, we can use these key values to quickly retrieve the data on the node

Select the structure as a red-black tree with the node as the smallest node

The second part--the context switch of the process Process Context Switch:In the operating system, switching the CPU to another process requires saving the state of the current process and recovering the state of another process: the current running task becomes ready (or suspended, deleted), and the other selected ready task is the current task. Context switching includes saving the running environment for the current task and recovering the running environment where the task will run. The PCB of the process is also called the PCB, that is, the task control block, which includes the process state, the value of the CPU register, etc. Typically, you save the current state of the CPU by performing a state save, and then perform a state recovery to start the operation again. Context switches can occur in three situations: interrupt processing, multitasking, and user-state switching. In interrupt processing, the other program "interrupts" the program that is currently running. When the CPU receives an interrupt request, a context switch is made between the running program and the program initiating the interrupt request. In multitasking, the CPU switches back and forth between the different programs, each with a corresponding processing time slice, and the CPU switching context between the two time slices. For some operating systems, a context switch is also made when a user-state switch is made, although this is not required. Linux real-time scheduling algorithm provides a soft real-time mode of operation, soft real-time meaning is that the kernel scheduling process, try to make the process before its limited time to run, but the kernel is not guaranteed to always meet the requirements of these processes. In contrast, the hard real-time system is guaranteed to meet any scheduling requirement under certain conditions. Linux does not guarantee the scheduling of real-time tasks. scheduling-related system calls:1  System call 2 related to the scheduling policy and the priority of the processor binding system call 3 Discard Processor Time Summary:

For our process scheduling, the basic idea is how to use the limited resources to maximize the use of means to help us solve the problem, the process of scheduling is also an unavoidable problem of computer operating system, we can assume that the CPU is our daily life of funds, How to better expenditure and income directly affect our daily life, the direction of process scheduling I think now is to expand the total CPU operation, while introducing an audit mechanism, to judge the process of demand and can use the minimum space for resources, the need to restore or small part of the context to restore and save, Or a similar part of the process to replace, you can introduce a smaller unit of operation, to the thread, in the process of co-application, it will be retained a copy of the 2 processes to achieve the purpose of sharing.

Linux Kernel Analysis Chapter fourth reading notes

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.