P3L1: Scheduling Flashcards
What is the role of the CPU scheduler?
The CPU scheduler decides how and when processes and threads access the CPU, i.e., how and when tasks are selected from the ready queue to run on the CPU.
Does the CPU scheduler schedule user tasks, kernel tasks, or both?
Both
What are four reasons why a task might be added to the ready queue?
- An I/O operation the task has been waiting on has completed
- The task has been woken from a wait
- The task was just created, i.e., a new thread is created by forking
- The task was ready, ran on the CPU until its timeslice expired, then was interrupted and put back on ready queue
When is the CPU scheduler run?
Whenever the CPU becomes idle. This may be because a task completed, or was interrupted.
What’s another name for the ready queue?
Run queue
What happens when the CPU scheduler selects a task to be scheduled?
The task is dispatched to the CPU. This entails:
- Context switch, entering the context of new task
- Enter user mode
- Set the program counter
- Go!
What are four good metrics for comparing CPU schedulers?
- Throughput (# of processes executed)
- Average job completion time
- Average job wait time
- CPU utilization (% of CPU resources used)
For First-Come-First-Serve scheduling, what data structure should you use for the runqueue?
FIFO queue
For Shortest-Job-First scheduling, what data structure should you use for the runqueue?
Ordered queue or a tree
How do you calculate throughput?
jobs completed / time_to_complete_all_jobs
How do you calculate average completion time?
sum_of_times_to_complete_each_job / jobs_completed
How do you calculate average wait time?
sum_of_all_wait_times / jobs_completed
Wait time is the time from when process arrives until it begins executing
For Shortest-Job-First scheduling, we need to estimate how long a job will take. What are two heuristics we might use?
- How long did the job take last time?
2. How long did the job take, on average, over some previous window of time (say, the last n times the job ran)?
What is “Run to Completion” scheduling?
Simply when jobs run to completion, i.e., they cannot be interrupted/preempted by the scheduler
What is Preemptive scheduling?
When the scheduler can interrupt/preempt processes to run a different processes instead.
For example, a long process arrives first and starts executing. A shorter process arrives later. A “Shortest Job First” scheduler will preempt the long process and run the short process.
What is Priority Scheduling?
Scheduling based on some priority level. OS tasks may be given higher priority than user tasks, or interactive user tasks may be given higher priority than background tasks.
What are three data structures we could use to implement a runqueue when using a Priority Scheduler?
- Ordered queue
- Tree
- Multiple queues, with each queue assigned a priority level.
What is a danger of Priority Scheduling?
Starvation: Low priority tasks may never run