🧠 What is Dispatch Latency?

Dispatch Latency is the time taken by the operating system to stop one process and start executing another after a context switch is triggered.

It is the delay between:

  • The moment a process becomes ready to run
    🕓 → and

  • The moment it actually starts executing on the CPU


📦 Includes:

Dispatch latency involves:

  • Saving the current process context (registers, stack pointer, PC)

  • Choosing the next process (scheduler decision)

  • Restoring the new process’s context

  • Switching CPU mode (kernel → user)

  • Jumping to the new process’s program counter

Think of it as the “gap time” between two processes owning the CPU.


⚠️ Why Does It Matter?

In normal systems:

  • High dispatch latency = slower responsiveness
    (e.g., UI lag, longer wait times)

In real-time systems:

  • High dispatch latency = missed deadlines

You can’t afford delay in scheduling high-priority, time-sensitive tasks (e.g., pacemakers, autonomous cars)


🧪 Real-World Impact

ExampleImpact
🖱️ Mouse input → App responseHigh latency = input lag
⏱️ Alarm clock process firesHigh latency = alarm triggers late
🚨 Airbag sensor in a carHigh latency = life-threatening delay

🔍 Dispatch Latency vs Context Switch Time

MetricWhat It Measures
Context Switch TimeJust the time to save + restore process state
Dispatch LatencyContext switch time + scheduling time + OS overhead before the new process starts running

🎯 How to Reduce It

  • Use real-time OS with low-latency schedulers (e.g., RTLinux, FreeRTOS)

  • Tune Linux kernel (disable preemption, avoid interrupts in critical sections)

  • Use priority-based scheduling with real-time guarantees


🧠 Interview-Ready Definition:

Dispatch latency is the total time taken by the OS to stop one process and start another after a scheduling decision is made. It includes the context switch time and all OS-level delays, and must be minimized for responsive or real-time systems.


🛤️ Analogy

Imagine a relay race —

  • Context switch is the act of passing the baton

  • Dispatch latency is the time from when the next runner is ready to go and the moment they actually start running