Simple Schedulers
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.
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?
Shortest-Job First
-
Minimizes waiting time!
-
They are probably waiting for something else, which can be done in parallel with CPU use.
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.
-