Computer Organisation and Architecture · I/O Interface and Interrupts
MIPS and CPU Speed vs Slow I/O Devices
Overview
The CPU executes millions of instructions per second, while I/O devices such as a keyboard supply data at only a few characters per second.
Under programmed I/O the CPU polls the device's status flag in a loop, so almost all of its execution capability is spent waiting rather than doing useful work.
Key concepts
- MIPS (Million Instructions Per Second): a measure of CPU speed — the number of instructions the CPU can execute in one second, expressed in millions. Executing instructions per second is 1 MIPS.
- Speed mismatch problem: the CPU is extremely fast but I/O devices are very slow; this mismatch holds for most devices. A program that makes the CPU wait for a slow device wastes almost all of the CPU's capability.
- Busy waiting: continuously checking the status flag in a loop. The CPU does no useful work; it simply checks the flag again and again. (The term also appears in Operating Systems.)
- Programmed I/O: the polling approach in which the CPU repeatedly checks the device status; its main disadvantage is the massive waste of CPU time when devices are slow.
How it works
The programmed I/O loop that reads one character from the keyboard into the input register consists of three instructions:
- Read/check the status flag (is input ready?).
- Branch back to step 1 if the flag is not set (loop).
- Move the character from the input register into the ALU (the actual data transfer).
Reasoning:
- The CPU can execute instructions per second (1 MIPS).
- Each execution of the "move input to ALU" instruction transfers exactly one character.
- So in one second the CPU has the capacity to read characters (1 million characters per second).
- But the input is typed by a human at only 10 characters per second.
- In the time the CPU could have executed instructions (read characters), it actually reads only 10 characters; the rest of the time is spent waiting.
- After each character arrives, the flag is set to 1. At 10 characters per second, one character arrives every 0.1 second.
- During that 0.1 second the CPU keeps checking the flag continuously — it repeatedly executes the check and branch instructions.
- In 0.1 second the CPU could execute instructions, and all of them are just the two loop instructions (check flag, branch).
So out of every instructions, only one word is actually transferred; the remaining instructions are wasted. - To transfer just one word, the CPU executes instructions: the check-flag instruction times and the branch instruction times. Only then is one input moved.
Drawing the diagram…
Formulas
- Instructions per second clock rate CPI (standard relation; the result is stated directly as instructions/second)
- Symbols:
- characters per second — rate at which the I/O device supplies input
- time per character — interval between two successive inputs
- instructions per second — CPU execution capability
Worked examples
CPU capability vs keyboard input rate
Given:
- CPU speed instructions per second MIPS
- Each input instruction reads 1 character
- Keyboard input rate characters per second
Step 1 — CPU capacity in characters per second: million characters/second.
Step 2 — Time to receive one character: second. microseconds (since ; equivalently s).
Step 3 — Instructions the CPU could execute in that 0.1 second: instructions.
Step 4 — What those instructions actually are: All of them are the two loop instructions (check flag, branch):
- Check-flag instruction executed times
- Branch instruction executed times
- Only then is 1 word (1 character) moved into the ALU.
Step 5 — Conclusion: Out of every instructions, only one word is transferred; the rest are wasted. The CPU is busy waiting, not doing useful work.
Comparison
| Aspect | CPU | I/O device (keyboard) |
|---|---|---|
| Speed | instructions/second (1 MIPS) | 10 characters/second |
| Capacity per second | characters | 10 characters |
| Time per unit | 1 µs per instruction | 0.1 s per character |
| Utilisation during transfer | Almost fully wasted in the polling loop | Working at its own slow rate |
Revision summary
- MIPS = million instructions per second; instructions/second = 1 MIPS.
- One input instruction transfers one character, so the CPU's read capacity equals its instruction rate ( characters/second here).
- A slow device (10 characters/second) forces the CPU to wait 0.1 second per character.
- In 0.1 second the CPU executes instructions, all of them check-flag and branch loop instructions — only one word is transferred.
- Continuously checking the flag is busy waiting: the CPU does no useful work.
- The check-flag instruction runs times and the branch instruction times for every single word transferred.
- Programmed I/O's main disadvantage is the massive waste of CPU time when devices are slow.
Previous-year exam insights
- MIPS = clock rate / (CPI x );
equivalently execution time = instruction count x CPI / clock rate.
MIPS alone is not a reliable speed measure because it ignores instruction mix and CPI differences.
Asked inUGC NET 2015 - For DMA/block transfer, the maximum transfer rate is limited by the fraction of memory-bus (or CPU) cycles available to the device: transfer rate = (bus cycles per second available to I/O) x (bytes per cycle).
Cycles used by the CPU for instruction fetch/execute are unavailable to the device.
Asked inUGC NET 2015 - In programmed I/O the CPU polls the status flag;
the fraction of CPU time wasted is (time spent polling)/(time per character), and useful CPU utilisation = transfer instruction time / total time per character. - Interrupt-driven I/O removes busy waiting: the CPU does useful work until the device raises an interrupt, then services it; DMA further removes per-word CPU involvement by transferring blocks directly between device and memory.
- Average machine cycles per instruction and the fraction of cycles using the memory bus determine effective memory bandwidth: memory accesses per second = (instructions per second) x (cycles per instruction) x (fraction of cycles that are memory cycles).
Asked inUGC NET 2015 - 1 MIPS means instructions per second;
time per instruction = 1 µs at 1 MIPS. Convert rates carefully: 1 byte/s = 8 bits/s, and in these rate problems.