Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPU Scheduling David Ferry CSCI 3500 – Operating Systems

Similar presentations


Presentation on theme: "CPU Scheduling David Ferry CSCI 3500 – Operating Systems"— Presentation transcript:

1 CPU Scheduling David Ferry CSCI 3500 – Operating Systems
Saint Louis University St. Louis, MO 63103

2 Recall Multiprogramming
CPU time is shared by rapidly switching between processes with context switching: Each time a context switch occurs the OS scheduler runs picks what process gets to run next. When picked, a process gets to run for one scheduling quantum, commonly 1ms. Process A Process B Process C CSCI Operating Systems

3 The Scheduling Question
Blocked Ready Scheduler swaps off Scheduled onto processor Running Given a collection of programs that are ready to run, how do we pick a winner? CSCI Operating Systems

4 Scheduling Considerations
Scheduling is an old field with a lot of alternatives. Some possible metrics: Resource fairness – ensure all processes get equal 1/N processor time. Perceived fairness – Perfect resource fairness might not yield desirable performance, so we prioritize some processes. CSCI Operating Systems

5 Scheduling Considerations
Response time – Minimize the amount of time it takes a program to respond to events such as key presses. Job completion – Maximize the number of processes retired from the system. No starvation – Make sure that all processes get to run eventually. CSCI Operating Systems

6 Implementation Considerations
The scheduler is perhaps the most performance-critical piece of code on the planet. Typically runs 1000 times per second on a desktop machine. If we have 30 computers in this classroom, that’s running at least 30,000 per second. The scheduler is entirely overhead- it only serves to manage the system, but is not an end in itself. CSCI Operating Systems

7 Two Program Archetypes
Compute-bound: Spends most of its time churning through instructions with the processor. Limited interaction between program and user, or program and other devices. E.g. simulation, video encoding, video decoding I/O Bound: Spends most of its time waiting for user or other device such as hard drive. Bursty workload behavior. E.g. text editor, web browser CSCI Operating Systems

8 CSCI 3500 - Operating Systems
Types of Systems Batch systems: Important that they run efficiently, but nobody is waiting Characterized by large computationally intensive workloads that take hours or days Tend to be compute-bound tasks Interactive systems: Must respond promptly to user input Heterogenous workloads: text editor, compiler, watch video, play a game, listen to music, maybe all simultaneously… Mixed I/O bound and compute-bound tasks CSCI Operating Systems

9 Non-Preemptive (no multiprocessing) Batch Scheduling Algorithms
FIFO – first in, first out – executes programs in the order they are created in the system. Never starves a process Unpredictable task response/finish time SJF – shortest job first – executes programs in order of shortest to longest. Does not do multiprocessing. Needs an estimate of process length, but this might be as simple as looking at program name. E.g. “ls” will probably always be quick. CSCI Operating Systems

10 Interactive Scheduling Algorithms
Round-Robin – Go through all processes in some arbitrary order, giving each a single quantum of processor time. Fixed quantum, variable fairness Less fair to I/O bound tasks Can have large response times Completely Fair Scheduling (CFS) – Processes that use less CPU time are afforded higher priority and longer time slices Variable quantum, fixed fairness Current default Linux scheduler I/O bound tasks tend to have short response times CSCI Operating Systems

11 CSCI 3500 - Operating Systems
Scheduling Examples Suppose the following jobs enter the system at the same time, ties broken in alphabetical order: Process Execution Time A 2ms B 3ms C D 5ms E 1ms CPU Timeline Shortest Job First E A C B D CPU Timeline First-in, First Out A B C D E CSCI Operating Systems

12 Recall: Scheduling Terms
Job Release – The time at which a job becomes eligible to execute on the system Response Time – The time between job release and the start of execution Finish Time – The time between job release and the end of execution CSCI Operating Systems

13 Non-Preemptive FIFO Scheduling
First-in, First Out A B C D E 0ms 2ms 5ms 7ms 12ms 13ms Process Execution Time Response Time Finish Time A 2ms 0ms B 3ms 5ms C 7ms D 12ms E 1ms 13ms Average Response Time: ( )/5 = 5.2ms Average Finish Time: ( )/5 = 7.8ms CSCI Operating Systems

14 Non-Preemptive Shortest Job First
A C B D 0ms 1ms 3ms 5ms 8ms 13ms Process Execution Time Response Time Finish Time A 2ms 1ms 3ms B 5ms 8ms C D 13ms E 0ms Average Response Time: ( )/5 = 3.4ms Average Finish Time: ( )/5 = 6ms CSCI Operating Systems

15 Preemptive Round Robin
A B C D E A B C D B D D D 1 2 3 4 5 6 8 10 13 Process Execution Time Response Time Finish Time A 2ms 0ms 6ms B 3ms 1ms 10ms C 8ms D 5ms 13ms E 4ms Average Response Time: ( )/5 = 3ms Average Finish Time: ( )/5 = 8.2ms CSCI Operating Systems

16 Heuristics vs. Guarantees
A scheduler guarantees behavior if that behavior will always happen. A heuristic behavior is a tendency we expect, but is not guaranteed. Question: Does Round Robin guarantee a short response time? CSCI Operating Systems

17 Heuristics vs. Guarantees
A scheduler guarantees behavior if that behavior will always happen. A heuristic behavior is a tendency we expect, but is not guaranteed. Question: Does Round Robin guarantee a short response time? No! In fact, RR guarantees the “shortest possible” response time, but not that this is “short.” Consider a system with 1000 processes and a 1ms quantum, or 100 processes and a 10ms quantum Real-time schedulers tend to make precise guarantees CSCI Operating Systems

18 Completely Fair Scheduling
Observation: Round Robin (i.e. a fixed time quantum) can lead to long response times and is less fair to I/O bound tasks Why? Solution: Each process is entitled to a certain amount of time budget, and the process with the most time budget remaining has highest priority. CSCI Operating Systems

19 CSCI 3500 - Operating Systems
CFS Implementation Uses Red-Black Tree- not a perfect binary tree, but enough to guarantee O(log(n)) operations Scheduler picks leftmost node to run If node finishes, it is removed from tree If not, runs until it blocks or runs out of time, and is reinserted into tree in time with new execution time Virtual Runtime is the measure of execution time Accounts for priority levels, nice values, process groups, so full calculation is tricky For default priority: new_VR = old_VR + elapsed_time New processes inherit VR of parent 24 9 36 11 31 48 CSCI Operating Systems


Download ppt "CPU Scheduling David Ferry CSCI 3500 – Operating Systems"

Similar presentations


Ads by Google