CREATE OWN LIBRARY

Context Switch and Dispatcher

 

Context Switch (Process switch)

Some interrupt to cause the operating system to change the CPU from a running process to another process or to run a kernel routine. Before suspending and resuming the running process, the system needs to save the current context of this process. Actually, context is represented in the Process Control Block and process context (see the differenceof the process. It includes the value of CPU registers, the process state, and memory management information

 

Switching the CPU from the current process to another process requires performing a state save ofCPUthe current process and a state restore of a different process. This task is known as a context switch.

 

When a context switching occurs, the kernel saves the process context and PCB of the old process and loads the saved context of the new process scheduled to run.

 

Context-switch time is pure overhead because the system does no useful work while switching.

 

Switching speed varies from machine to machine, depending on the memory speed, the number of registers that must be copied, and the existence of special instructions. A typical speed is a few milliseconds.

 

Context switch occurs: 

 i) When a process running state to blocked state (For example, due to I/O request).

 

ii) When a process running state to ready state. (For example, due to an interrupt like clock interrupt, time slice, memory faults).

 

iii) When a process running state to terminated state. (For example, when an exit system is called) 

 

Fig: 17

 

Dispatcher:

It is a small program dispatcher which switches the CPU from one process to another process selected by short time scheduling. Dispatcher resides at main memory.

 

It plays a role in context switching. 

 

It switches the process from kernel mode to user mode.

 

It helps to restart the program by jumping to the proper location in the user program.

 

The time taken by the dispatcher to stop one process and start another process is called "Dispatch Latency".

 

Dispatch Latency: The amount of time required for the scheduling dispatcher to stop one process and start another is known as dispatch latency.