0
0
Operating Systemsknowledge~5 mins

Programmed I/O vs interrupt-driven I/O in Operating Systems - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Programmed I/O vs interrupt-driven I/O
O(n)
Understanding Time Complexity

We want to understand how the time taken by Programmed I/O and interrupt-driven I/O changes as the amount of data or number of I/O operations increases.

How does the way the CPU handles input/output affect the overall execution time?

Scenario Under Consideration

Analyze the time complexity of these two I/O methods.


// Programmed I/O example
while (data_not_ready()) {
  check_device_status();
}
read_data();

// Interrupt-driven I/O example
// CPU does other work
// When device ready, interrupt triggers
void interrupt_handler() {
  read_data();
}
    

This code shows how Programmed I/O waits actively for data, while interrupt-driven I/O lets the CPU do other work until data is ready.

Identify Repeating Operations

Look at what repeats in each method.

  • Programmed I/O primary operation: Continuously checking device status in a loop.
  • Programmed I/O how many times: Repeats until data is ready, which depends on device speed.
  • Interrupt-driven I/O primary operation: CPU runs other tasks; device signals when ready via interrupt.
  • Interrupt-driven I/O how many times: Interrupt handler runs only when data is ready, not repeatedly checking.
How Execution Grows With Input

Consider how time spent waiting or handling I/O grows as more data arrives.

Input Size (n)Programmed I/O Approx. OperationsInterrupt-driven I/O Approx. Operations
10Many repeated checks per data item, total high10 interrupt calls, CPU free otherwise
100Much more repeated checking, grows quickly100 interrupt calls, CPU mostly free
1000Very large number of checks, CPU mostly busy waiting1000 interrupt calls, CPU efficiently used

Pattern observation: Programmed I/O time grows quickly because CPU waits actively; interrupt-driven I/O scales better as CPU does other work between interrupts.

Final Time Complexity

Time Complexity: O(n)

This means the time spent handling I/O grows linearly with the number of data items, but programmed I/O wastes CPU time checking repeatedly, while interrupt-driven I/O uses CPU time more efficiently.

Common Mistake

[X] Wrong: "Programmed I/O is always faster because it checks immediately for data."

[OK] Correct: Constant checking wastes CPU time and slows down other tasks, making overall performance worse as data grows.

Interview Connect

Understanding how different I/O methods affect CPU time helps you explain system efficiency clearly and shows you can think about resource use in real systems.

Self-Check

"What if the device sends data in large bursts instead of one item at a time? How would that affect the time complexity of interrupt-driven I/O?"