操作系统学习笔记(5) CPU Scheduling
1. Basic Concepts
为了提高CPU的利用率
从直方图中可以看到,大部分的kernel 中的CPU-burst很短(不到8ms),且大部分时间都没有CPU burst。所以可以在代价不大的情况下对CPU进行调度
CPU Scheduler
此处提及的必然是short-term scheduler
**执行目的:**从ready queue中取进程,并为它们中的一个分配CPU
在进程处于以下场景时,CPU scheduling可以进行决策:
- Switches from running to waiting state
- Switches from running to ready state
- Switches from waiting to ready
- terminates
其中只做1和4的调度是不可中断的(nonpreemptive)
都做的是可中断的(preemptive)
现代的OS绝大多数都是preemptive
Dispatcher
给与CPU被short-term调度选中的process的控制权,这包括:
- switching context
- switching to user mode
- jumping to the proper location in the user program to restart/resume that program
Dispatch Latency
Dispatcher起作用产生的时延
2. Scheduling Criteria
- CPU利用率(utilization)
- 吞吐率(Throughout)