Scheduling Flashcards
What does a scheduler do? What are its main components? What happens when a task is scheduled?
Scheduler puts threads on the CPU for execution.
Has a run queue and scheduling algorithm
Steps: Perform context switch, Enter user mode, Set PC, Execute
What is a ready queue and how do tasks end up there?
A ready queue is where tasks a ready to be put on the CPU. They end up there by:
- Initiating an I/O request
- Having their time slice on the CPU expire
- Being forked by a parent thread
- Initiated a wait
What is run to completion scheduling?
Once a tasks has been scheduled on the CPU, it runs until completion
What is First-Come-First-Served?
Tasks are scheduled onto CPU based on when it arrives. Use FIFO queue
What is Shortest Job First?
Exactly what it sounds like, you can use an ordered queue or a tree
What is preemptive scheduling?
Unlike run-to-completion scheduling, tasks can be interrupted. (SJF - if a shorter job enters the queue, interrupt current one)
How does the scheduler know how long a task will take to run?
History, last run time, windowed average of last n times
What is priority scheduling?
Run the task with the highest priority next - can use preemption if higher priority comes into the queue. Can have a queue for each priority level
What is thread starvation?
When a lower priority task is stuck in the run queue because higher priority tasks keep showing up
What is priority aging?
A technique used to combat thread starvation - set priority to some function of (assigned priority, time in queue)
What is priority inversion?
When a lower priority thread holds a mutex needed by a higher priority thread. Higher priority thread will be kept waiting and lower thread will finish first
How to combat priority inversion?
Temporarily boost the priority of mutex owner (the lower priority task) to match that of the thread that is waiting until mutex is released
What is round-robin scheduling?
Every task gets an equal time slice and the scheduler places them on the CPU in order.
Pros and Cons of RR Scheduling with time slices
+ shorter tasks finish sooner (w/o heuristics), more responsive, length I/O ops initiated sooner
- high overheads when timeslice expires
How to choose a timeslice based on I/O vs CPU bound
Want time(context switching)»_space; timeslice. CPU Bounds = want larger time slice, I/O Bound == smaller slices