* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
Operating Systems Concept
?What is an operating system?
?Operating system architecture
?Process concept
?CPU scheduling
?Memory management
?File and I/O systems
CPU Scheduling
?Scheduling Criteria
?CPU Utilization
?Throughput =Number -of-Completed-Processes/ Sec
?Turnaround Time
?Completion time – Submission time
?Waiting Time
?Time spent in the ready queue
?Average vs Worst-Case vs Combination
?variance
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
CPU Scheduling
?First-In-First-Out (FIFO) Scheduling
?Select the first process in the queue for execution!
?“Fair” but lengthy waiting for urgent processes! -> Shortest Job First??
PCBi … ..
Ready Queue
PCBjPCBk PCBa
CPU Scheduling – FIFO
? Processes Burst CPU Time Arrival Time
P1 24 0
P2 3 1
P3 3 1
0 24 27 30
Average Waiting Time = (0 + 23 +26) / 3
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
CPU Scheduling
?Priority-Driven Scheduling
…
Priority-decreasing
0 1 2
PCBi PCBj
PCBk
• Select the highest-priority process to run and de-queue it!
• Hook the running process back to the ready queue!
• Starvation problem?!!
Ready Queue
* “Operating system concept”, Silberschatz and Galvin, Addison Wesley, pp. 133-137.
CPU Scheduling – Priority
? Processes Burst CPU Time Arrival Time Priority
P1 24 0 3
P2 3 1 2
P3 3 1 1
0 1 30
Average Waiting Time = (6 + 0 +3) / 3
4 7
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
CPU Scheduling
?Round-Robin Priority-Driven Scheduling
? N processes, quantum = ?, (N *?) cycle time!
? How small ? should be? Any limitation?
…
Priority-decreasing
0 1 2
PCBi PCBj
PCBk Ready Queue
Run CPU for a “time quantum” (time slice), e.g. 10ms
Pop
Insert here or at a lower priority
CPU Scheduling – RR
? Processes Burst CPU Time Arrival Time Priority
P1 24 0 1
P2 3 1 1
P3 3 1 1
0 2 30
Average Waiting Time = (6 + 5 +6) / 3
4 6
Quantum = 2
8 9 10
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2001.
CPU Scheduling
Bottom Half Top Half processes User
Space OS
hardware
Timer expires to
• Expire the running process’s time quota
• Keep the accounting info for each process
System calls such as I/O req which may cause the releasing CPU of another process!
Process Concept - Revisiting
Process i OS Process j
Save state into PCB[i]
..
Load state from PCB[j]
Save state into PCB[i]
Load state from PCB[j]
.. ....
Interrupt or system call
Interrupt or system call
dispatch