- Grab attention of processor
- Preemptive: external interrupt, like timer
- Nonpreemptive: system call (trap), I/O request, process exit
- Save the state of current process
- Dump PC and registers of current process (at the start of the ready queue) into PCB
- Select new process to run
- Short Term Scheduler scheduling algorithm result → select a PCB to “dispatch”
- Dispatch the selected process
- Call Dispatcher for the closest PCB in the Ready Queue, load state of the selected PCB into processor registers (PC, Register File)
The scheduler does not call any process to run. Instead it rearranges the PCB queues and then returns to the first out of the queue.
TLB
Context Switching
- Kernels can have page maps, but the kernel page map doesn’t change when we do a Context Switch. Hence the user/kernel flag.
- When we do a Context Switch, the PTBR changes, and consequently the page table we have access to changes to that of the new proccess.
- Each process owns its own user space. Therefore, we must purge all of the cached user entries in the TLB after a Context Switch because they still point to the memory space of the previous process. Whatever user entries the old process cached in the TLB are useless to the new process, because the two process don’t share their memory.
- Cached kernel entries do not need to be purged because the kernel space is shared by all processes.
Link to original
- The Dispatcher is responsible for performing this purge