Open In App

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

Improve
Improve
Like Article
Like
Save
Share
Report

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 –  

P2 P3 P4 P5 P6

Running –  

P1

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

Now Ready Queue will be  – 

P2 P3 P4 P5 P6 P7

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 Latency Context 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.
Time Taken by Dispatch Latency is  Usually a few microseconds or milliseconds. Time Taken by Context Switch is typically tens or hundreds of microseconds or milliseconds.
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.
Dispatch Latency Occurs during Execution of a process. Context Switching Occurs during  Switching between two or more processes.
Resource Affected by  Dispatch Latency is CPU. Resource Affected by Context Switch is CPU and memory.
Overhead of Dispatch Latency is Minimal. Overhead of Context Switch Can be significant, especially for high context-switching environments.
Cause of Dispatch Latency Inherent delay in the OS scheduling algorithm. Cause of Context switching Interrupts from I/O devices, system calls or preemption by higher priority processes.
Impact of Dispatch Latency   affects process performance. Context switching Can impact system performance if done too frequently.

Last Updated : 13 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads