Operating System - 5 Schedule

1 Background

Here Insert Picture Description
When switched, what principles related to switch the CPU scheduling
Here Insert Picture Description
to be performed when scheduling the conversion state, in particular relating to the operating mode, such as the operating mode -> blocking state and the like.
Here Insert Picture Description
Non-preemptive: After starting the process can not be bothered to ensure that efficiency is not high
preemptive: common scheduling policy (for that process user mode). Whether the kernel can seize? When a user process executes a system call, the kernel will not lead this process in a wait state, or running, or initiate the process of returning this system call, that kernel preemption does not occur
now, some systems you can do kernel preemption

2 scheduling principle

2.1 scheduling policy

2.2 Program Execution Model

Here Insert Picture Description
For a process, sometimes the CPU busy, sometimes will idle down (such as an I / O operation), we hope that when the CPU is idle down, using the CPU to other processes, in order to make full use of CPU

2.3 Comparison of scheduling algorithms guidelines

Evaluation scheduling algorithm:
Here Insert Picture Description
the CPU usage: the higher, the better the efficiency of the system
throughput: the higher the efficiency, the better the process of
turnaround time: start a process to complete the process, that is, the waiting time + service time
waiting time: in a ready state how much time before the other process to the CPU running operating mode
response time: peripheral issue a request which the processing has been completed the process, the sooner the better response time

2.4 vs throughput delay

Here Insert Picture Description
Low latency: fast response time
high bandwidth: high throughput
can be considered to be quickly reflected

2.5 equity goals

Here Insert Picture Description
Above the index, and fish can not have both
Here Insert Picture Description
Here Insert Picture Description
expect os can get a fair process by scheduling algorithms for each CPU services, that get the CPU time is generally fair, awaiting execution time is also generally fair

3 scheduling algorithm

Introduction roughly three kinds:

  1. The basic scheduling algorithms in the usual os
  2. Embedded real-time special scheduling algorithm
  3. Multicore (CPU) scheduling algorithm
    Here Insert Picture Description

3.1 First come, first served (FCFS)

Here Insert Picture Description
Here Insert Picture Description
Advantages: simple (first come first in the list, then the end of the list)
disadvantages: the average waiting time and the turnaround time will be relatively long, subject to the preceding process execution time, preemption is not considered, the response time is affected

3.2 short process priority (SPN / SRT)

Here Insert Picture Description
When the arrival of a process even shorter than the running process, there are two strategies:

  1. Non-preemptive mode: Whether it continues on the new ready queue
  2. Preemptive (the SRT): the currently running process remaining time slice: 8 to time slices: 5, is put into a ready state running, the new execution

Benefits: The average waiting time is less
Here Insert Picture Description
disadvantages:

  1. Short priority task, there will be a long hunger, lack of implementation of the long-term, does not satisfy the principle of equity
  2. I do not know the execution time of the algorithm is difficult to achieve
    Here Insert Picture Description
    Here Insert Picture Description
    since it does not know the execution time, then the process of estimates, estimated according to the execution history
    t the n- : How much execution time of the current accounting period
    tao the n- : estimates based on previous case execution time
    Here Insert Picture Description

3.3 the highest priority response ratio (HRRN)

Here Insert Picture Description
R, the longer the wait time, priority scheduling
is not considered to seize
still do not know the process execution time
takes into account the waiting time

3.4 Round Robin (Round Robin)

Here Insert Picture Description
Each process in turn uses the CPU
Here Insert Picture Description
is assumed to each process is assigned time slice 20, when executed P1, P1 needs 53 times, 20 times and he can perform, P2 only 8 can be executed, after executing P3
Here Insert Picture Description

  1. We need more time context switch, to allow time to perform each process can have
  2. Set time slice (the quantum of time): The too frequent switching will be too small, too large degradation of FCFS
    (Gong instant screen clear)
    Here Insert Picture Description
    the fairness of the RR FCFS the inferior
    efficiency depends on who should come FCFS, if the first to be long, it is inefficient

Over 3.5-level feedback queue (MLFQ) (dynamic adjustment)

Here Insert Picture Description
The ready queue is divided into a number of different queues, queues of a different take different scheduling algorithms. For example, the most advanced queuing take a short process priority, a lower queue to take FCFS, considering the characteristics of the process of
Here Insert Picture Description
adding a process starting with the interactive process (i / O-intensive), a higher priority, there will be time to wait, the longer the waiting time , noting that the higher the priority. After the interaction done, start a lot of computing, CPU time may be longer (CPU intensive), with a time slice will soon, once a time slice runs out, they took him down to the next priority, time slice the more, the lower the priority.
The process needs to interact placed at a higher priority, so that once get what it needs, will be able to respond immediately executed.

3.6 Fair Share (Fair-share scheduling)

Emphasize fair
for servers (scientific computing), more than multiple users share one computer, some users have more open process, some less open to achieve a fair sharing at the user level, fair call to the CPU
latest linux this has taken the algorithm
Here Insert Picture Description

3.7 Algorithm Evaluation

Here Insert Picture Description
Mathematical model, such as the establishment of a queue to build a simulator to discuss how the algorithm
is more desirable to run in a real system, in order to see a real impact, after all scheduling algorithms and hardware also has a relationship
Here Insert Picture Description

4 real-time scheduling

4.1 Real-Time Systems

Here Insert Picture Description

  • Used in industrial control, such as trains, machine tools, embedded factories need to ensure that certain tasks are completed within the stipulated time
  • Features real-time systems: certainty and predictability
  • Divided into:
    • Strong real-time systems: the need to be completed within guaranteed time-critical tasks that must be completed (if not complete important tasks on time can have disastrous consequences, not promptly let go of the dam water will have serious consequences)
    • Soft real-time systems: requirements important process with high priority, as far as possible complete, non-essential (in the video, 60 frames per second, will not have too serious consequences)

Measure a process can be completed substantial demand, some of the terms used to describe it:
Here Insert Picture Description
Released Time: let the process in the ready time
Relative deadline: relative time, each time period to complete a specific task
Execution time: time of execution of
Absolute deadline : final deadline, the end of the implementation period of time can not exceed this
Here Insert Picture Description
figure,

  • Period p = 5,
  • Blue execution time can not exceed p

Here Insert Picture Description

4.2 Schedulability

Here Insert Picture Description
Static priority scheduling: Before you put the task execution priority identified, according to the priority selection task, within the specified time to perform complete
dynamic priority scheduling: With the execution of the task, the cycle will change at different times its priority It will be different

4.3 Rate Monotonic (RM)

Here Insert Picture Description
Before starting to prioritize, the shorter the period of implementation of a higher priority

4.4 Deadline earliest priority (EDF)

Here Insert Picture Description

5 Multi-processor scheduling (multi-CPU)

Here Insert Picture Description
os should be considered:

  • The process on the CPU
  • Each CPU workload balancing

6 priority inversion

Here Insert Picture Description
Here Insert Picture Description
Priority: Tl> T2> T3
T3 is performed first, when performing access to the shared resource t2, when t3, T1 to the start of execution Tl to time t4, T1 have access to shared resources, but the shared resource is T3 occupied and not released, turn to the implementation T3, when t5, T2 to start execution T2, T6 to time, proceed T3, this time, Tl consistent execution is not completed
Here Insert Picture Description
solution:

  1. Priority inheritance: when T1 have access to shared resources, the priority mentioned T3 and T1, where this, again T2, T2 is not performed

Here Insert Picture Description
The priority of what resources need to process statistics, these resources are given priority, so that priority is equal to the highest process calls the resource: 2. priority ceiling

Published 16 original articles · won praise 0 · Views 238

Guess you like

Origin blog.csdn.net/qq_42713936/article/details/105210927