Scheduling Flashcards
What is a scheduler?
A is a software that helps schedule the processes in an operating system. It helps to keep all computer resources busy and allows multiple users to share system resources effectively.
A process may leave the CPU for one the following reasons:
- Completes execution
- Requests a resource
- Voluntarily release CPU
- Involuntarily releases CPU
(preempted)
Scheduling Policy
decides when thread leaves and
which thread is selected to replace it
Scheduling Mechanism
determines how the process
manager carries out its duties
Scheduling Mechanism has 3 parts
- Enqueuer
- Dispatcher
- Context switcher
- Enqueuer
Places a pointer to thread descriptor into ready list (priority placement may happen then or later when thread is selected) - Dispatcher Selects one ready thread and allocates CPU to that thread by performing context switch
- Context switcher Saves the contents of all CPU registers (PC, IR, condition status) for the thread being moved out and places the new thread in.
What does a CPU scheduler do
Selects from among the processes in ready queue, and allocates a CPU core to one of them
CPU scheduling decisions may take place when a process:
- Switches from running to waiting state
- Switches from running to ready state
- Switches from waiting to ready
- Terminates
For situations 1 and 4, there is no choice in terms of scheduling. A new process (if one exists in the ready queue) must be selected for execution.
The dispatcher
Responsible for the context switch of the current task to a new task.
- This involves:
- Switching context
- Switching to user mode
- Jumping to the proper location in the user program to restart that program
Dispatch latenc
Time it takes for the dispatcher to stop one process and start another running
Preemptive and Nonpreemptive Scheduling
Ponpreemptive no choice (1 and 4)
Preemptive have a choice (2 and 3)
Register Overhead:
Each register must be saved and restored during a context switch to ensure that a process can resume execution exactly where it left off. This involves reading the current register values and storing them in a safe location (usually in the process’s control block in memory), then loading the next process’s saved register values back into the registers.
Context Switch Phases:
- Save process 1’s context
- Load dispatcher’s context
- Save dispatcher’s context
- Load process 2’s context
Switching Cost
- 50 nanoseconds to store 1 unit of data
- 32 bit bus / 50 nanoseconds for each register
- 32 general registers and 8 status registers
40 x 50 nanaseconds = 2 microseconds - 2 microseconds more to load another thread
- Total time: over 4 microseconds (including dispatch in and out)
Preemptive Scheduling and Race Conditions
- Preemptive scheduling can result in race conditions when data are shared among several processes.
- Consider the case of two processes that share data. While one process is updating the data, it is preempted so that the second process can run. The second process then tries to read the data, which are in an inconsistent state.
Scheduling Algorithm Optimization Criteria
- Max CPU utilization
- Max throughput
- Min turnaround time
- Min waiting time
- Min response time