4.2.37 · D1Operating Systems

Foundations — I - O management — polling, interrupt-driven, DMA

2,004 words9 min readBack to topic

This page assumes nothing. If the parent note used a word or a symbol, we build it here from the ground up, in the order that each idea needs the previous one.


0. What is a "device", really?

Picture two boxes that cannot see inside each other:

Figure — I - O management — polling, interrupt-driven, DMA
  • The left box is the CPU — the brain that does calculations, running at ~nanosecond speed.
  • The right box is the device — slow, running at ~millisecond speed.
  • The red wire between them is the only way they communicate.

The whole topic lives on that red wire: how the CPU talks across it.


1. Bit and byte — the units of data

The picture: a byte is a row of 8 light switches.

  • Each switch is a bit (up = 1, down = 0).
  • Eight switches together = one byte.
  • The parent note says "transfer one unit of data" — that unit is usually a byte (or a word, a few bytes the CPU handles at once).
Recall Why do we count in bytes here?

Because the three methods differ in how much CPU work per byte. To compare them we must count per byte, so we need the byte as our ruler. ::: A byte is the natural unit of a single I/O transfer.

KB in "4 KB" means kilobyte bytes (precisely in memory contexts). So KB bytes — that number in the parent's example is just .


2. Registers — the mailboxes on the device

The CPU cannot reach inside the device. Instead the device exposes a few tiny memory slots called registers. Think of them as labelled mailboxes bolted to the outside of the device.

Figure — I - O management — polling, interrupt-driven, DMA

The picture shows three mailboxes:

  • The red mailbox is the status register — it is red because the entire topic is about who keeps checking this one flag.
  • The status register is set by the device, read by the CPU.
  • The command register is written by the CPU, read by the device.

How the CPU reaches these mailboxes (special I/O instructions vs. treating them like ordinary memory addresses) is its own subject — see Memory-mapped I/O vs Port-mapped I/O.


3. The busy-wait loop and the symbol while

The parent shows:

while (status_register.busy == 1) ;

Let's read this like a sentence, symbol by symbol:

  • while (condition) ; means "keep doing nothing, as long as the condition is true." The lone semicolon ; is an empty action — the loop's whole job is to check again.
  • status_register.busy reads the busy flag out of the status mailbox.
  • == 1 asks "is it equal to ?" (double-equals == is a question, not an assignment).

So the whole line means: "As long as the device says busy=1, loop back and check again, doing nothing useful." That is busy-waiting — the picture is a person refreshing a page over and over.


4. Time symbols — , ,

The parent's formulas use three time symbols. Each is just "how long some action takes".

Picture a long bar (the device's wait ) chopped into many tiny slices (each slice = one poll ):

Figure — I - O management — polling, interrupt-driven, DMA

The symbol in the parent ("") means "is very much bigger than" — not just bigger, overwhelmingly bigger. It marks the condition under which interrupts clearly beat polling.


5. Interrupt, ISR, and "context"

Saving and restoring this snapshot is itself work — that is a big chunk of . The full mechanics are Context switching.


6. The bus and DMA

Figure — I - O management — polling, interrupt-driven, DMA

The picture shows the single-lane bus:

  • Normally the CPU drives on it.
  • During a DMA transfer the red DMA controller hops on to move a block.
  • Because it's one lane, when DMA is driving, the CPU must briefly wait — this is cycle stealing (DMA "steals" a bus cycle). That's why the parent warns DMA does not make the CPU 100% free.

Prerequisite map

bit and byte

device registers

status register and busy flag

busy-wait loop

Polling

time symbols Tdev tpoll tint

Interrupt driven IO

interrupt signal

context save and restore

memory bus one lane

DMA controller

DMA

Compare CPU work


Equipment checklist

Before reading the parent note, you should be able to answer each of these. Cover the right side and test yourself.

What is one bit, and how many bits in a byte?
A bit is a single 0/1; a byte is 8 bits.
Roughly how much faster is a CPU (ns) than a disk (ms)?
About a million to ten million times faster.
Name the three device registers and who writes each.
Status (device sets, CPU reads), Data (byte transferred), Command (CPU writes).
What does the busy-wait line while(busy==1); do?
Loops doing nothing, re-checking the status flag until the device is ready.
Difference between = and ==?
= sets a value; == asks a yes/no question.
What do , , each measure?
Device ready-time, cost of one poll, cost of servicing one interrupt.
Why does count wasted polls?
It's how many tiny poll-slices fit inside the long device wait.
What does the symbol mean?
"Very much greater than."
What is an interrupt and what is an ISR?
A hardware "pay attention" signal; a small routine the CPU runs to handle it.
What is "context" and why save it?
The CPU's current instruction and register snapshot; save it to resume exactly where it left off after the ISR.
Why can't the CPU be fully free during DMA?
DMA and CPU share one bus lane; DMA steals cycles (cycle stealing).
What do and mean in plain words?
Work grows with N bytes vs. work stays constant regardless of N.

Now you carry every symbol the parent note assumed. Return to the main I/O management note and the Hinglish version, and each formula will read like plain English.