CS Atlas GATE 2027
COA course
0 / 87 complete

COA/Phase 6 · I/O: Interrupts & DMA

Lesson 6.1.2 · Item 74 of 87

Programmed I/O: polling, busy-waiting and its CPU cost

Read at your own pace. Try the questions before opening the answers.

On this page

0 · Recall Warm-up

Answer from memory first. Answers are in the Answer Vault at the bottom.

1 · The Hook

🎣

The simplest I/O loop: "is the device ready? no. is it ready? no. is it ready? yes: take the byte." The CPU does nothing else while asking. For a slow keyboard that wastes almost everything; for a fast disk it may be the only way to keep up. GATE asks you to compute exactly how much CPU time this polling eats.

2 · Predict First

🤔

A 500 MHz CPU polls a mouse 30 times per second; each poll costs 400 cycles. What fraction of the CPU's time goes to polling?

Make a guess in your head. The answer opens Section 3.

3 · Core Concept

💡

Predict First — the answer

30 × 400 = 12,000 cycles per second out of 500,000,000: 0.0024%. Negligible for a mouse.

Programmed I/O

The CPU itself moves every word, under program control:

  • Read the device's status register.
  • If not ready, go back to 1 (busy-waiting).
  • Read (or write) the data register; store the word in memory.
  • Repeat for the next word.

The CPU is busy for the whole transfer, including all the waiting.

Cost of polling

If the CPU polls r times per second and each poll costs p cycles on an f-Hz CPU:

Fraction of CPU time = r × p / f.

To never miss data, the CPU must poll at least as often as the device produces units: r ≥ (data rate) ÷ (bytes per poll).

Example (disk): 4 MB/s (decimal), 16 bytes per poll → 250,000 polls/s; 400 cycles each → 10⁸ cycles/s of a 500 MHz CPU = 20%.

Pure busy-waiting

If the CPU waits in a loop for every byte of a slow device, it is 100% busy for the duration of the transfer: transferring 1 KB from a 10 KB/s device keeps it busy for 0.1 s.

When polling is fine

  • The device is fast and almost always ready (little wasted waiting).
  • The CPU has nothing else to do.

Otherwise, use interrupts (Chapter 6.2) or DMA.

4 · Visual

Programmed I/O loop

  WAIT: IN   R1, STATUS        ; read status port
        AND  R1, R1, #READY
        BZ   R1, WAIT          ; not ready -> ask again   (busy-waiting)
        IN   R2, DATA          ; read the byte
        STORE R2, (R3)+        ; save it, advance pointer
        ... repeat for the next byte

5 · Worked Examples

Example 1 Easy

A 1 GHz CPU polls a device 1,000 times per second at 200 cycles per poll. Fraction of CPU time?

Solution

2 × 10⁵ / 10⁹ = 0.02%.

Example 2 Medium

A network card delivers 2 MB/s (decimal) in 8-byte units. Each poll takes 250 cycles; the CPU runs at 2 GHz. What fraction of CPU time does polling take if it polls exactly as often as needed?

Solution

Polls/s = 2×10⁶ / 8 = 250,000; cycles = 6.25×10⁷; fraction = 3.125%.

Example 3 GATE

A device sends 1 byte every 100 µs. The CPU busy-waits for each byte (programmed I/O). For how long is the CPU busy while 500 bytes arrive?

Solution

The whole time: 500 × 100 µs = 50 ms.

6 · GATE Traps

⚠️

  • Polling cost = polls per second × cycles per poll ÷ clock.
  • The minimum polling rate comes from data rate ÷ bytes per transfer.
  • Busy-waiting means the CPU is occupied for the entire transfer.
  • Rates in I/O questions are usually decimal (1 MB/s = 10⁶ B/s) unless stated.

7 · Memory Hook

🧠

"Polling pays for asking, even when the answer is no."

8 · Connect the Dots

Chapter 6.1 is complete: interfaces, ports and programmed I/O. Chapter 6.2 lets the device do the asking: interrupts, and then DMA, which moves whole blocks without the CPU.

9 · Self-Test

GATE format. Try every question before opening the vault.

Q1NAT2 marksPolling fraction

A 400 MHz CPU polls a device 50,000 times per second; each poll takes 160 cycles. Percentage of CPU time spent polling?

Numerical answer: ________

Q2NAT2 marksRequired polls

A device transfers 1 MB/s (decimal) in 4-byte words; the 1 GHz CPU must poll once per word at 100 cycles per poll. Percentage of CPU time?

Numerical answer: ________

Q3NAT1 markBusy-wait time

A device sends 1 byte every 50 µs; the CPU busy-waits. How many ms is the CPU tied up while 2,000 bytes arrive?

Numerical answer: ________

Q4MCQ1 markProgrammed I/O

In programmed I/O:

  • (A) the device writes to memory by itself
  • (B) a controller moves blocks without the CPU
  • (C) the CPU checks the status register and moves every word
  • (D) the device interrupts the CPU for each word

Q5MSQ2 marksWhen polling works

Polling is a reasonable choice when:

  • (A) the CPU has nothing else useful to do
  • (B) the device is almost always ready
  • (C) the device is slow and rarely ready
  • (D) data arrives in large blocks at high speed and the CPU must keep working

10 · Rule Card

  • Programmed I/O: CPU checks status, moves each word; busy-waits.
  • Polling fraction = r × p / f; minimum r = data rate ÷ bytes per poll.
  • Busy-waiting occupies the CPU for the whole transfer.
  • I/O rates: decimal unless stated.

11 · Concept Ledger

Unlocked in this lesson. From here on, these terms may be used.

programmed I/Opollingbusy-waitingpolling ratepolling CPU overhead

12 · Answer Vault

Answer Vault

Try the questions first. Open when you are ready to check.

Recall Warm-up

  • Ports in memory space with LOAD/STORE vs separate space with IN/OUT.
  • CPI_base + m_I·P + f_mem·m_D·P.
  • rows × row-refresh time / refresh period.

Self-Test

Q1 Answer: 22 marks

8×10⁶ / 4×10⁸ = 2%.

Re-read: Lesson 6.1.2 — Programmed I/O: polling, busy-waiting and its CPU cost

Q2 Answer: 2.52 marks

250,000 × 100 = 2.5×10⁷ of 10⁹.

Re-read: Lesson 6.1.2 — Programmed I/O: polling, busy-waiting and its CPU cost

Q3 Answer: 1001 mark

2000 × 50 µs.

Re-read: Lesson 6.1.2 — Programmed I/O: polling, busy-waiting and its CPU cost

Q4 Answer: (C)1 mark

The program does all the work.

  • (A) is wrong: That is DMA.
  • (B) is wrong: That is DMA.
  • (D) is wrong: That is interrupt-driven I/O.

Re-read: Lesson 6.1.2 — Programmed I/O: polling, busy-waiting and its CPU cost

Q5 Answer: (A) (B)2 marks

Slow devices waste polls; fast block transfers suit DMA.

  • (C) is wrong: Most polls find nothing.
  • (D) is wrong: DMA fits better.

Re-read: Lesson 6.1.2 — Programmed I/O: polling, busy-waiting and its CPU cost

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.