Week5_Lec 1-2
CPU调度
CPU scheduling
Basic Concepts - Typical Program Behavior
–Maximun CPU utilization obtained with multiprogramming
–CPU-I/O Burst Cycle: Process execution consists of a cycle of CPU excution and I/O wait
CPU Scheduling: Part 1
–Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them
–Non-preemptive(cooperative) scheduling : once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state
–Dispatcher module gives control of the process selected by the short-term scheduler, this involves:
1.switching context
2.switching to user mode
3.jumping to the proper location in the program to restart that program
–Dispatch latency: time it takes for the dispatcher to stop one process and start another running.
Scheduling Criteria:
1.CPU utilization: keep the CPU as busy as possible :40%-90%.
2.Throughput: no. of processes that complete their execution per time unit
3.Turnaround time: amount of time to execute a particular process
4.Waiting time: amount of time a process has been waiting in the ready queue=completion time - arrival time - execution time
5.Response time (for time-sharing environment): amount of time it takes from when a job was submitted until the first response is produced, not output (excludes speed of output device)
CPU Scheduling Algorithms
- First Come First Sever (FCFS)
- Shortest-Job-First Scheduling (SJF)
- Shortest Remaining Time First (SRTF)
- Priority Scheduling
- Round Robin Scheduling (RR)
- Multilevel Queue Scheduling
Turnaround time:
the interval from the time of submission of a process to the time of completion.
Average turnaround time:
https://blog.csdn.net/weixin_36465540/article/details/105560419?spm=1001.2014.3001.5506
1.FCFS(先来先服务)
1.
Waiting time :
P1 = 24 - 0 - 24 = 0
P2 = 27 - 0 - 3 = 24
P3 = 30 - 0 - 3 = 27
Average waiting time = ( 0 + 24 + 27 ) / 3 = 17
2
Waiting time :
P1 = 30 - 0 - 24 = 6
P2 = 3 - 0 - 3 = 0
P3 = 6 - 0 - 3 = 3
Average waiting time = ( 6 + 0 + 3 ) / 3 = 3
3.
2.SJ(P)F(短进程优先)
1.
Waiting time :
P1 = 0 - 0 = 0
P2 = 8 - 2 = 6
P3 = 7 - 4 = 3
P4 = 12 - 5 = 7
Average waiting time = ( 0 + 6 + 3 + 7 ) / 4 = 4
2.
3.SRTF(最短剩余时间优先)
Waiting time :
P1 = 16 - 7 - 0 = 9
P2 = 7 - 4 - 3 = 1
P3 = 5 - 1 - 4 = 0
P4 = 11 - 4 - 5 = 2
Average waiting time = ( 9 + 1 + 0 + 2 ) / 4 = 3
4.RR(时间轮转调度算法)
1.
Waiting time :
P1 = 134- 0 = 134
P2 = 37 - 0 = 37
P3 = 162 - 0 = 162
P4 = 121 - 0 = 121
Average waiting time = ( 134 + 37 +162 + 121 ) / 4 = 113.5
3.
4.
5.
5.Highest Response ratio Next(HRRN)
优先进行高响应进程
Asymmetric multiprocessing(非对称多处理):
only one processor accesses the system data structures, alleviating the need for data sharing.(只有一个处理器访问系统数据结构,减轻了数据共享的需要。)
Hard real-time systems(硬件实时系统):
required to complete a critical task within a guaranteed amount of time.(要求在保证的时间内完成一项关键任务。)
Soft real-time computing(软件实时计算):
requires that critical processes receive priority over less fortunate ones.(要求关键进程优先于不太幸运的进程。)
starvation:(饥饿现象)
A potential problem where low priority processes may never excdute.(即进程长时间得不到调度)