Today
-
Simple schedulers.
-
Slightly more complex schedulers.
ASST2
Checkpoint
-
If you have not finished
ASST2.1
, you’re way behind. -
If you have finished several of
sys_{open,close,lseek}…
, you’re OK.
Review: Scheduling: What?
-
Scheduling is the process of choosing the next thread (or threads) to run on the CPU (or CPUs).
Review: Scheduling: Why?
-
CPU multiplexing: we have more threads that cores to run them on.
-
Kernel privilege: we are in charge of allocating the CPU and must try to make good decisions. Applications rely on it.
Review: Scheduling: When?
-
When a thread voluntarily gives up the CPU by calling yield().
-
When a thread makes a blocking system call and must sleep until the call completes.
-
When a thread exits.
-
When the kernel decides that a thread has run for long enough—and uses a timer interrupt to take control.
Review: Human-Computer Interaction (and Expectations)
-
What do you expect from your machine?
-
Respond (Click)
-
Continue (Watch, or active waiting)
-
Finish (Expect, or passive waiting)
-
Review: Scheduling Goals
-
How well does it meet deadlines—unpredictable or predictable?
-
How completely does it allocate system resources?
-
No point having idle CPU, memory, or disk bandwidth when something useful could be happening.
-
-
On human-facing systems, deadlines (or interactivity) usually wins. Why?
-
Your time is more valuable than your computer’s.
-
-
Performance: making great scheduling decisions is futile if the decision process itself takes forever.
Review: Conflicting Goals
-
Scheduling is a balance between meeting deadlines and optimizing resource allocation.
-
Responsiveness and continuity require meeting deadlines—unpredictable or predictable.
Why Schedule: Questions?
Scheduling Information
Today we will talk about schedulers that use three kinds of additional information in order to choose what thread to run next:
-
What will happen next? Oracular schedulers can cannot be implemented but can be a good point of comparison.
-
What just happened? Typical schedulers—and many other operating system algorithms—use the past to predict the future.
-
What does the user want? Schedulers usually have ways to incorporate user input.
The Know Nothings
Random Scheduling
-
Choose a scheduling quantum. This is the maximum amount of time any thread will be able to run at one time.
-
Then:
-
Choose a thread a random from the ready pile.
-
Run the thread until it it blocks or the scheduling quantum expires.
-
-
Just return it to the ready pile!
Round-Robin Scheduling
-
Choose a scheduling quantum. This is the maximum amount of time any thread will be able to run at one time.
-
Establish an ordered ready queue. For example, when a thread is created add it to the tail of the ready queue.
-
Then:
-
Choose the thread at the head of the ready queue.
-
Run the thread until it it blocks or the scheduling quantum expires.
-
If its scheduling quantum expires, place it at the tail of the ready queue.
-
-
What happens when a thread leaves the waiting state?
-
Could put it at the head of the ready queue, or at the tail.
-
The Know Nothings
-
The random and round robin scheduling algorithms:
-
require no information about a threads past, present, or future, and
-
accept no user input.
-
-
These are rarely useful algorithms except as straw men to compare other approaches to.
-
Both penalize—or at least do not reward—threads that give up the CPU before their quantums expire.
-
As one exception, round robin scheduling is sometimes used once other scheduling decisions have been made and a set of threads are considered equivalent.
-
As an example, you might rotate round-robin though a set of threads with the same priority.
-
The Know-It-Alls
Let’s say we can predict the future. What might we like to know about the thread we are about to execute?
-
How long is it going to use the CPU!
-
Will it block or yield?
-
How long will it wait?
The Know-It-Alls
Shortest-Job First
-
Minimizes waiting time!
-
They are probably waiting for something else, which can be done in parallel with CPU use.
The Know-It-Alls
Oracular Spectacular
-
Control flow is unpredictable.
-
Users are unpredictable.
-
What did the thread do recently? It will probably keep doing that.
Multi-Level Feedback Queues
-
Choose a scheduling quantum. This is the maximum amount of time any thread will be able to run at one time.
-
Establish some number of queues; each represents a level.
-
Threads from the highest-level queues are chosen first.
-
Then:
-
Choose and run a thread from the highest-level non-empty queue.
-
If the thread blocks or yields, promote it to a higher level queue.
-
If the thread must be preempted at the end of a quantum, demote it to a lower level queue.
-
Multi-Level Feedback Queues
Monday: The Story of the Linux Completely Fair Scheduler
-
How one Australian anaesthetist changed the Linux kernel forever… and then gave up.
-
The scheduler may be fair, but is Linux development?
-
A fascinating view into the Linux community, and a good story highlighting many aspects of large-scale community-driven operating systems development.
-
Including discussion of the BFS (Brain F*ck Scheduler).