Skip to content
Related Articles

Related Articles

Improve Article

Difference between “Dispatch Latency” and “Context Switch” in operating systems

  • Last Updated : 17 Aug, 2021
Geek Week

A process in a multitasking system is brought from the secondary memory to the main memory and sometimes switched back to the secondary memory. Thus, there are several states of a process throughout its lifecycle. Context Switching is an important part of that whole lifecycle.

Dispatcher is a module that gives control of the CPU to the process selected by the short-term scheduler, this involves:

  • switching context
  • switching to user mode
  • jumping to the proper location in the user program to continue executing that program.

Context Switching :
It is the process of storing the state of an old process and load the saved state for the new process via a context switch. Context of a process is represented in the PCB (process control block).
During context switch a process’ attributes like registers, pointer, program counter etc which are all stored in the PCB are saved in a per-process stack in kernel memory and a new process takes its place by either updating its PCB if it’s an old process or creating a new PCB if it’s a new process.
Context switching offers a high degree of multitasking and helps to get better utilization of the operating system.

Dispatch Latency :
It is the time taken by the dispatcher in context switching of a process from run state and putting another process in the run state.
Dispatch latency is an overhead, and the system does no useful work while context switching.
Some hardware provides multiple sets of registers per CPU which allows multiple contexts to be loaded at once.

Position of Dispatch Latency inside an Application Response Time

Dispatch latency is a small part of the whole application response time.



Expanded View of Dispatch Latency inside Application Response Time

Dispatch latency consists of an old task releasing its resources (wakeup) and then rescheduling the new task (dispatch), all of this also comes under context switching.
Let’s look at an example to understand context switching and dispatch latency.

Example –

Priority – 
P1 > P2 > P3 > P4 > P5 > P6

Ready Queue –  

P2P3P4P5P6

Running –  

P1

Task P7 with priority greater than P1 comes into ready queue.

Now Ready Queue will be  – 

P2P3P4P5P6P7

Short term scheduler chooses P7 to swap with P1 in running state.



Context Switching – 
1. P1’s context (PCB) is saved and stored in a per-process stack in kernel memory.

2. P7’s context (PCB) is updated.

The time elapsed in steps 1 and 2 is the dispatch latency.

Running –

P7

Both “Context Switching” and “Dispatch Latency” are related to the dispatcher, which comes into play after the short term scheduler decides which process to bring from the ready queue to the running state.

Dispatch LatencyContext Switching
The amount of time taken by the dispatcher to pause one process 
and start another is called dispatch latency.
The process of saving the state of a previously running process or thread 
and loading the initial or previously saved state of a new process by the dispatcher. 
Dispatch latency is a time value.Context switching is a process.
It is a consequence of context switching.It is performed by the dispatcher, when initiated by an interrupt.
Latency is dependent on hardware support.The more complex the OS and PCB, the longer the context switch.

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :