Fourth Chapter reading notes process scheduling

Source: Internet
Author: User

Fourth Chapter reading notes process Scheduling what is process schedulingnow the operating system is multi-tasking, in order to enable more tasks to better run on the system at the same time, need a management program to manage the computer on the simultaneous running of the various tasks (that is, the process).
    • This management program is the scheduler, its function is simple to say:

      1. Decide which processes to run and which processes to wait on
      2. Determine how long each process runs

      In addition, in order to achieve a better user experience, the running process can be interrupted immediately by other more urgent processes.

      In short, scheduling is a balanced process. On the one hand, it is to ensure that each running process can maximize the use of the CPU (that is, as few switching processes, process switching too much, the CPU time will be wasted on switching), on the other hand, to ensure that the process can be fair use of the CPU (that is, to prevent a process of exclusive CPU for a long time).

      One, scheduling policy 4.1 process type
    • I/O consumption process: Most of the time is used to submit I/O requests or wait for I/O requests, often in a running state, but running for a short time, waiting for the request process to be in a blocking state. such as interactive programs.

    • Processor-consuming process: Most of the time is spent executing code, unless it is preempted or kept running.

    • Integrated type: I/O consumption type and processor consumption type.

    • The scheduling strategy seeks to strike a balance between rapid process responsiveness (short response times) and maximum system utilization (high throughput).

      4.2 Scheduling Concepts
    • Priority: Scheduling based on process value and process ratings for processor time requirements.

    • Time slice: Indicates the time that the process can run continuously before it is preempted, and specifies a default time slice. Long time slices lead to a poor response to system interactivity,

    • The program parallelism effect is poor, the time slice is too short to increase the processor time that the process switch brings. Contradiction!

    • The inter-slice exhaustion process runs out of date and is temporarily not operational. The process time slice is recalculated until all process time slices are exhausted.

    • The Linux scheduler increases the priority of the interactive program, provides a longer time slice, and implements dynamic adjustment of priority and time slice length mechanism.

    • Process preemption: Linux systems are preemptive and always run with high priority processes.

4.3 strategy
    • Determines when the scheduler will let the process run.

      4.3.1 I/O consumption and processor-intensive processes
    • I/O consumption: Most of the time I am submitting 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.

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.

    • With a priority, you can decide who will run first. However, for the scheduler, it is not the end of the run time, you must know how often the next schedule.

      Then there is the concept of time slices. A time slice is a numeric value that indicates how long a process can continue to run before it is preempted.

      It can also be thought of as the time that the process ran before the next scheduled occurrence (unless the process actively abandons the CPU, or there is a real-time process to preempt the CPU).

      The size of the time slice setting is not simple, set large, the system response is slow (long schedule), set small, process frequent switching brought about by the processor consumption. The default time slice is typically 10ms

Activities of the 4.3.4 scheduling policy
1/0 消耗型的,因为它大部分时间都在等待用户的键盘输入〈无论用户的输入速度有多快,都不可能赶上处理的速度λ 用户总是希望按下键系统就能马上响应。视频编码程序是处理器消耗型的。
4.4 Linux Scheduling algorithm 4.4.1 Scheduler class

provided in a modular manner, to allow different types of processes to be targeted to select
The choice of scheduling.

4.4.2 Process Scheduling 4.4.3 Fair dispatch in Unix System

CFS's cowardice is to allow each process to run for a period of time, cycle round, select the least-run process as the next running process, instead of taking the practice of allocating time slices to each process, and calculating how long a process should run based on the total number of running processes. - -

The nice value in CFS is
The weight of the processor running as a process gets: the higher the Nice value (the lower the priority) process is on the lower processor
Use weight.

The number of running processes tends to be infinite, and each has the least amount of time to get the LMS running.

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.5 Linux scheduling 4.5.1 time accounting
所有的调度器都必须对进程运行时间做记账。CFS 使用调度器实体结构(定义在文件<linux/sched.h>的 struct_sched _entity 中)来追踪进程运行记账。CFS 使用 vruntime 变量来记录一个程序到底运行了多长时间以及它还应该再运行多久。定义在kemeVsched_fair.c 文件中的 update_curr()函数实现了该记账功能。update_ currO 计算了当前进程的执行时间,并且将其存放在变量delta_exec 中,update_ curr()是囱系统定时器周期性调用。
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
2 进程把自己标记成休眠状态,从可执行红黑树中移出,放入等待队列,然后调用 schedule()选择和执行一个其他进程。唤醒的过程刚好相反进程被设置为可执行状态,然后再从等待队列中移到可执行红黑树中。
4.6.1 User preemption
    • User preemption occurs when the following conditions occur:

    • When returning user space from system transfer;
    • When returning user space from an interrupt handler;

4.6.2 kernel preemption

Kernel preemption can occur in:

schedule()如果内核中的任务阻塞(这同样也会导敖调用 schedule()
4.7 Real-Time scheduling strategy

Two strategies
Sched_fifo and SCHED_RR

Sched_fifo implements a simple, first-in, first-out, scheduling and counting timid
SCHED_RR is a sched_fifo with the time alarm, a real-time rotation scheduling calculation hang.

4.8 Scheduling-related system calls

There are 2 main types of scheduling related system calls:

1) related to scheduling policies and process priorities (that is, the above mentioned parameters, priorities, time slices, etc.)-the first 8 in the table below

2) processor-related-the last 3 in the table below

System calls

Describe

Nice ()

Set the nice value of a process

Sched_setscheduler ()

Set the scheduling policy for the process, that is, what scheduling algorithm the set process takes

Sched_getscheduler ()

Get the scheduling algorithm for a process

Sched_setparam ()

Set the real-time priority of a process

Sched_getparam ()

Gets the real-time priority of the process

Sched_get_priority_max ()

Get the maximum value of real-time priority, due to user rights issues, non-root users cannot set real-time priority to 99

Sched_get_priority_min ()

Gets the minimum value for the real-time priority, similar to the above

Sched_rr_get_interval ()

Gets the time slice of the process

Sched_setaffinity ()

The processing affinity of the set process is, in fact, the mask flag of cpu_allowed stored in task_struct. Each bit of the mask corresponds to a processor that is available on a system, and the default all bits are set, that is, the process can be executed on all processors in the system.

This function allows the user to set different masks so that the process can only run on one or more processors in the system.

Sched_getaffinity ()

Get processing affinity for a process

Sched_yield ()

Temporarily let the processor

Fourth Chapter reading notes 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.