P3L1: Scheduling Flashcards
What decides how and when process (and their threads) access shared CPUs?
CPU Scheduler
What is the CPU Scheduler concerned with?
Schedules tasks running user-level processes/threads as well as kernel-level threads
What events kick off the CPU Scheduler?
- CPU becomes idle
- New task becomes ready (checks for priority on new task and previous tasks to potentially interrupt current running task)
- timeslice expired timeout (when a running thread has used up its time on the CPU)
Describe the Steps for when the Scheduler dispatches a thread on the CPU
- context switch
- enter user mode
- set program counter
- execute/run
Choose task from ready queue means?
Scheduling
Name the scheduling type that, as soon as a task is assigned to the CPU, it will run until it finishes/completes
Run-to-Completion Scheduling
Define the First-Come First-Servce (FCFS) Algorithm for scheduling
- Schedules tasks in order of arrived
- A runqueue is useful, the runqueue should be First-In First-Out (FIFO)
Define the Shortest Job First (SJF) algorithm for scheduling
- Schedules tasks in order of their execution time
- Runqueue will maintained as an ordered queue by task execution time OR utilize a tree where the nodes are organized by execution time
Formula for Throughput
Throughput = (# of Tasks) / (Total Execution Time, or "Makespan")
Formula for Avg. Completion Time
Avg. Completion Time = (Sum of Times to Complete Each Task) / (# of Tasks)
Order of Task is important!!!!
Formula for Avg. Wait Time
Avg. Wait Time = (Total Wait Time to Start Each Tasks) / (# of Tasks)
Order of Task is important!!!!
What does it mean to preempt (what is preemption)?
Interrupt a task to start another
How do we determine execution time?
heuristics based on history are utilized to determine job running time/execution time
What is Windoqwed Average?
The average execution time of a task over the last n times
What is Priority Scheduling?
When tasks have different priority levels that help indicate which tasks to schedule
- highest priority task gets scheduled next or preempts the current running task
How does Priority Scheduling determine priority?
- Different runqueues for each priority level
- Tree ordered based on priority level
What is a drawback/danger of Priority Scheduling and how do we address it?
- Low priority task stuck in a runqueue (due to higher priorty tasks being always present); “runqueue starvation”
- “Priority Aging” - priority = f(actual priority, time spent in runqueue)
We can change the priority of a task through some function, based on the original priority and the time it has spent in the current runqueue
Describe Priority Inversion and how we might combat it
Priority Inversion is when the completion of tasks does not follow the exact priority scheduling due to conflicts in mutex locks. We can combat this through temporarily boosting the priority of the current mutex owner until they do not need the mutex anymore, ensuring that the mutex is then unlocked for higher priority tasks. We lower the priority of the tasks once it releases the mutex
Define Round Robin Scheduling
- Pick up first task from queue (like FCFS)
- Task my yield, to wait on I/O (unlike FCFS)
- Next task is picked up while first task waits on I/O to finish. First task is placed at end of queue.
- Second task will run to completion or until it has to wait, at that point is yields to next task in queue and is put in back of queue
and so on / this goes on until all tasks are complete
How does Round Robin Scheduling work with priorities?
Basic Round Robin Scheduling but with the inclusion on preemption based on priority level
What is the maximum amount of uninterrupted time given to a task?
timeslice or “time quantum”
Can a task run for less than the set timeslice time?
True - could end early, or have to wait on I/O, synchronization, mutex, etc.
task will be placed on the queue if interrupted
higher priority tasks will also interrupt/preempt
How do we minimize overheads for scheduling that uses timeslices?
the timeslice value should be larger than the context switch time by a significant enough time
What are benefits/downsides of adding Timeslice Scheduling to RoundRobin?
Benefits
- short tasks finish sooner
- more responsive
- lengthy I/O operations initiated sooner
Downsides
- overheads: interrupt, schedule, context switches