"Linux kernel Design and implementation" Chapter 4th book Finishing

Source: Internet
Author: User

Fourth Chapter process scheduling

4.1 Multi-tasking

Multitasking operating systems can cause multiple processes to clog or sleep, whether on a single-processor or multi-processing machine.

Non-preemptive multitasking: it will execute until the process itself stops running itself.

Preemptive multitasking: The time a process can run before it is preempted is pre-set.

Process scheduling for 4.2 Linux

O (1) Scheduler

O (1) has a multi-processor environment of 10, but lacks an interactive process.

4.3 strategy

4.3.1 I/O consumption and processor-intensive processes

I/O consumption type: Most of the time in the submission or waiting for I/O requests;

Processor consumption: Most of the time executing code. Not part of the I/O driver type.

4.3.2 Process Priority

The same priority is scheduled on a rotational basis.

The scheduler always chooses that the time slice is not exhausted and the high priority process runs.

Linux two different priority ranges:

Nice value: -20~+19, default 0, the higher the value, the lower the priority.

Real-time Priority: Configurable, range 0~99, the larger the value, the greater the priority.

4.3.3 Time Slice

The nice value as a weight will adjust the processor time usage ratio used by the process.

I/O consumption: No long time slices are required.

Processor consumption: longer and better time slices are required.

Activities of the 4.3.4 scheduling policy

The text-editing program is obviously 1/0 consumable, because it waits most of the time for the user's keyboard input, no matter how fast the user's input speed is,

It's impossible to catch up with the speed of processing. The user always wants to press the key system to respond immediately. Viewport

The frequency-coded program is processor-consumable.

4.4Linux Scheduling algorithm

4.4.1 Scheduler Class

Provided in a modular way, the purpose is to allow different types of processes to selectively select scheduling algorithms.

4.4.3 Fair Dispatch

Weight of use;

The number of running processes tends to be infinite, each of which can get the LMS running time at least;

The processor time obtained by any process is determined by the relative difference of the nice value of its own and all other running processes.

Implementation of 4.5Linux Scheduling

4.5.1 Time Accounting

All schedulers must be billed for the process run time.

The Update_curr () function defined in the Kemevsched_fair.c file implements the accounting function.

4.5.2 Process Selection

(1) Pick the next task

You look down from the tree's root node along the left child node and find the leaf node, and you find the process with the least vruntime value.

(2) Adding a process to the tree

Occurs when a process becomes operational (awakened) or is called Through a fork () call the first time the process is created.

Call _enqueue_entity () for a heavy insert operation to actually insert the data item into the red and black tree.

(3) Remove a process from the tree

Occurs when a process is blocked (becomes non-operational) or terminated (end run).

Completed by the auxiliary function _dequeue_entityo.

4.5.3 Scheduler Entry

The primary entry point is the function schedule (), which is defined in the file KEMEL/SCHED.C.

4.5.4 Sleep and wake up

The kernel operates the same 2 processes mark itself as dormant, move out of the executable red-black tree, put in the wait queue, and then call Schedule () to select and execute a different process.

The process of waking up is just the opposite of the process being set to executable state, and then moving from the wait queue to the executable red-black tree.

4.6 Preemption and Context switching

4.6.1 User preemption

Arises in the following cases:

When the user space is returned from the system, when the user space is returned from the interrupt handler;

4.6.2 kernel preemption

Occurs in the following situations:

The interrupt handler is executing, and before the kernel space is returned, the kernel code is once again preemptive, if the task in the kernel explicitly calls schedule ();

If the task in the kernel is blocked (this also invokes schedule ().

4.7 Real-Time scheduling strategy

两种:SCHED_FIFO和 SCHED_RR。

4.8 Scheduling-related system calls

4.8.1 system calls related to scheduling policies and priorities

Sched_setparam () and Sched__getparam () are used to set and get the real-time priority of a process, respectively

The nice () function calls the kernel's set_ user_ nice () function, which sets the Static_prio and Prio values for the task_struct of the process.

4.8.2 system calls related to processor bindings

Forces the specified "this process must run on these processors anyway".

"Linux kernel Design and implementation" Chapter 4th book Finishing

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.