Processor scheduling
Article Directory
1. The concept and level of processor scheduling
1. Basic concepts of scheduling
Processor scheduling is to select a process from the ready queue according to a certain algorithm and assign the processor to it to run
2. Three levels of scheduling
(1) Advanced scheduling
Select one or more jobs from the backup queue of external storage, allocate resources such as memory to them, establish corresponding processes (build PCB), and enable them to obtain the right to compete for processors
Note: Advanced scheduling mainly refers to the problem of transfer. Only the timing of transfer needs to be determined by the operating system, and the timing of transfer must be waiting for the end of the job.
(2) Intermediate scheduling
Decide which process is in a suspended state to reload into memory
Suspended state: temporarily transferred to the external memory waiting process is suspended, but the PCB will not be transferred to the external memory, but the resident memory
Note: Intermediate scheduling occurs more frequently than advanced scheduling
(3) Low-level scheduling
Select a process from the ready queue according to a certain algorithm and assign the processor to it
Note: Low-level scheduling is the most basic type of scheduling in the operating system, with the highest frequency
3. The seven-state model of the process
4. Contact and comparison of three-tier scheduling
- Knowledge review
Second, the timing and method of process scheduling
1. Timing of process scheduling
2. The method of process scheduling
(1) Non-deprivation scheduling method
Also known as non-preemptive mode, only the process is allowed to actively give up the processor. Even if a more urgent task arrives during the running process, the current process will continue to use the processor until the process terminates or actively requests to enter the blocking state
(2) Deprivation of scheduling methods
Also known as preemption mode, when a process is executing on the processor, if there is a more urgent process that needs to use the processor, the executing process is immediately suspended and the processor is assigned to the more urgent process
3. Process switching
(1) Process switching refers to the process of letting one process give up the processor and another process occupying the processor
(2) The process of process switching is completed
① Save various data of the original running process
② Restore various data of the new process
Note: Process switching comes at a price. If processes are switched too frequently, the efficiency of the entire system will decrease
- Knowledge review
Three, the evaluation index of the scheduling algorithm
1. CPU utilization
Refers to the ratio of CPU busy time to total time
Utilization = busy time / total time
2. System throughput
Refers to the number of jobs completed per unit of time.
System throughput = how many jobs are completed in total / how much time is spent in total
3. Turnaround time
Refers to the time interval from when the job is submitted to the system to when the job is completed (the shorter the time, the higher the user satisfaction)
turnaround time = job completion time-job submission time
Average Turnaround Time = Sum of Turnover Time of Each Job / Number of Jobs
Weighted turnaround time = job turnaround time (completion time-submission time) / actual operation time of the job (must be >= 1)
Average weighted turnaround time = sum of weighted turnaround time for each job / number of jobs
4. Waiting time
Refers to the sum of the time the job/process is waiting for the processor (the shorter the time, the higher the user satisfaction)
(1) For the process, the
waiting time refers to the sum of the time waiting to be served after the process is established
(2) For the job,
not only the waiting time after the process is established, but also the time the job waits in the external storage backup queue
5. Response time
Refers to the time from the user submitting the request to the first response (the shorter the time, the higher the user satisfaction)
- Knowledge review
Fourth, the introduction of scheduling algorithm
1. First come first served (FCFS)
Schedule according to the order of arrival of the process (the current process will execute the next process after the execution, and will not be preempted), as shown in the figure:
Summarized as follows:
2. Short job priority (SJF)
Each time you schedule, select the job/process that has arrived and has the shortest running time (the next process will be executed after the current process is executed, and will not be preempted), as
shown in the figure: summarized as follows:
3. The shortest remaining time first (SRTN)
Whenever a process joins the ready queue, that is, when the ready queue changes, it needs to be scheduled. If the remaining time of the newly arrived process is shorter than the remaining time of the currently running process, the new process preempts the processor, and the currently running process returns to To the ready queue, in addition, when a process is completed, it also needs to be scheduled (the current process will be preempted)
Note: The shortest remaining time priority algorithm is the preemptive short job priority algorithm, as shown in the figure:
4. High response ratio first (HRRN)
Only when the currently running process voluntarily gives up the CPU, scheduling is required. During scheduling, the response ratio of all ready processes is calculated, and the processor with the highest response ratio is selected. (The current process will execute the next process after the current process is executed. seize)
Response ratio = (waiting time + time required for service) / time required for service, as shown in the figure:
Summarized as follows:
5. Time slice rotation (RR)
Take turns to let the processes in the ready queue execute a time slice in turn (the current process will be preempted)
Note:
(1) The process of the upper processor selected each time is the process at the head of the ready queue.
(2) After a process is executed, it will move to the end of the ready queue.
(3) The time slice of a process arrives, just processed Confidential move to the end of the ready queue while a new process arrives at the ready queue, the new process first arrives at the end of the ready queue
Detailed explanation of the time slice rotation algorithm process (assuming the time slice size is 2), as shown in the figure:
(1) 0时刻,只有P1,P1运行2时间片
(2) 2时刻,P1下处理机(P1剩3),同时P2到达,P2先进入就绪队列(P2 → P1),P2运行2时间片
(3) 4时刻,P2下处理机(P2剩2),同时P3到达,P3比P2先到达就绪队列(P1 → P3 → P2),P1运行2时间片
(4) 5时刻,P4到达,此时的就绪队列(P1 → P3 → P2 → P4)
(5) 6时刻,P1下处理机(P1剩1),P3运行1时间片,此时的就绪队列(P3 → P2 → P4 → P1)
(6) 7时刻,P3下处理机(P3运行结束),P2运行2时间片
(7) 9时刻,P2下处理机(P2运行结束),P4运行2时间片,就绪队列(P4 → P1)
(8) 11时刻,P4下处理机(P4剩4),P1运行1时间片
(9) 12时刻,P1下处理机(P1运行结束),此后一直运行P4,16时刻所有进程结束
Note:
(1) If the time slice is too large so that each process can be completed in one time slice, this algorithm will degenerate into a first-come, first-served algorithm, so the time slice cannot be too large
(2) If the time slice is too small, the process Switching is too frequent, so the time slice cannot be too small
Summarized as follows:
6. Priority scheduling
(1) Non-preemptive priority scheduling algorithm.
Each time you schedule, select the process that has arrived and has the highest priority (the next process will be executed after the current process is executed, and will not be preempted), as shown in the figure:
* P2 and P4 has the same priority, the first one is executed first
(2) The preemptive priority scheduling algorithm
selects the process that has arrived and has the highest priority each time during scheduling. Scheduling occurs when the current process actively abandons the processor, and preemption occurs when the ready queue changes (the current process will be Preemption), as shown in the figure:
* The priority of I/O-type processes should be appropriately increased
Summarized as follows:
7. Multi-level feedback queue scheduling
(1) Set up a multi-level ready queue, the priority of each level of queues is from high to low, and the time slice is from small to large
(2) When a new process arrives, it enters the first-level queue and queues up according to the FCFS principle to wait for the allocated time slice. After the time slice process has not ended, the process enters the end of the next level queue. If it is already in the lowest level queue at this time, it is put back to the end of the lowest level queue.
(3) Only when the Kth level queue is empty, Only then will the process at the head of the K + 1 queue be allocated a time slice
(4) The process of the preempted processor is put back to the end of the original queue
Detailed execution process, as shown in the figure:
P1 runs for 1 time slice (P1 remains 7), P1 enters the second level queue, P2 reaches the first level queue, P2 runs 1 time slice (P2 has 3 remaining), P2 enters the second level queue, and the first level queue is Empty, execute P1 of the second level queue, P1 runs for 2 time slices (P1 has 5 remaining), P1 enters the third level queue, executes P2 of the second level queue, P2 runs for 1 time slice (P2 is preempted, P2 is left 2 ), P3 reaches the first level queue, executes P3, P3 runs for 1 time slice (P3 runs end), executes P2 of the second level queue, P2 runs 2 time slices (P2 runs end), and executes P1 until the end of the remaining time
Summarized as follows: