COA/Lesson 6 of 6/7 min read
I/O and Parallelism
I/O techniques, buses, Flynn's taxonomy, multicore and SIMD, GPUs, Amdahl's and Gustafson's laws, and shared vs distributed memory.
On this page
I/O techniques
The CPU talks to devices (disks, NICs, keyboards) through device controllers, each with status, control and data registers. There are three ways to move data.
| Technique | CPU involvement | Best for |
|---|---|---|
| Programmed I/O (polling) | CPU loops checking status | Very fast devices or tiny transfers |
| Interrupt-driven I/O | Device signals when ready | Keyboards, low-rate devices |
| Direct memory access | Controller copies blocks itself | Disks, network, large transfers |
Programmed I/O
The CPU repeatedly reads the device's status register (busy waiting or polling) until it is ready, then moves each word itself.
while (device.status != READY) { } // wastes CPU cycles
device.data = word;Simple, but wastes CPU time on slow devices. High-performance network stacks (DPDK, NVMe polling) use polling deliberately because at very high rates it beats the overhead of interrupts.
Interrupt-driven I/O lets the CPU do other work until the device signals completion, and block transfers can be offloaded entirely to a DMA controller. Both are covered from the OS side in the OS introduction and file systems and I/O.
Memory-Mapped I/O
How does the CPU address device registers?
- Memory-mapped I/O: device registers occupy part of the physical address space; ordinary
LOADandSTOREinstructions access them. Used by ARM, RISC-V and most modern systems. - Port-mapped (isolated) I/O: a separate address space accessed with special instructions like x86
INandOUT.
| Memory-mapped | Port-mapped | |
|---|---|---|
| Instructions | Regular load and store | Special I/O instructions |
| Address space | Shared with memory | Separate |
| Caching | Must be marked uncacheable | Not an issue |
Buses
A bus is a shared communication path with three groups of lines:
- Address bus: which location; width sets the addressable space (32 bits = 4 GB).
- Data bus: the data; width sets how much moves per transfer.
- Control bus: read/write, clock, interrupt request, bus grant.
Modern systems replace shared parallel buses with point-to-point serial links: PCIe lanes, NVMe over PCIe, DDR memory channels, and on-chip interconnects.
Bus Arbitration
When several masters (CPU, DMA controller) want the bus, an arbiter decides:
- Daisy chaining: grant passes along a chain; simple but position fixes priority.
- Centralized parallel arbitration: each device has its own request and grant lines to a central arbiter.
- Distributed arbitration: devices resolve priority among themselves (used in CAN bus).
Flynn's Taxonomy
Classifies architectures by instruction and data streams.
| Class | Instruction streams | Data streams | Example |
|---|---|---|---|
| SISD | Single | Single | Classic uniprocessor |
| SIMD | Single | Multiple | Vector units, GPUs |
| MISD | Multiple | Single | Rare; fault-tolerant flight systems |
| MIMD | Multiple | Multiple | Multicore CPUs, clusters |
SIMD
One instruction operates on many data elements at once. x86 SSE and AVX (128, 256, 512-bit registers) and ARM NEON add 4, 8 or 16 floats in a single instruction. Compilers auto-vectorize simple loops; it shines in image processing, ML and audio.
MIMD
Independent processors run independent instruction streams on independent data. Covers multicore chips (shared memory) and clusters (distributed memory).
Instruction-Level Parallelism
ILP runs independent instructions from a single thread at the same time, invisibly to the programmer: pipelining, superscalar issue, out-of-order execution and speculation (pipelining). ILP hit diminishing returns in the mid-2000s, which pushed the industry toward multicore.
Why multicore happened
The power wall: dynamic power is about C * V^2 * f. Raising frequency also needs higher voltage, so power and heat grew too fast. Instead of one faster core, chips added more cores at moderate clock speeds.
Multicore Processor
Several independent cores on one chip, each with private L1 and usually L2 caches, sharing L3 and the memory controller. Software must be written with multiple threads or processes to benefit.
| Level | Parallel unit | Managed by |
|---|---|---|
| Bit-level | Wider words | Hardware |
| Instruction-level | Instructions | Hardware and compiler |
| Data-level | Vector elements | SIMD, GPUs |
| Thread-level | Threads | OS and programmer |
| Request-level | Independent requests | Servers, clusters |
Hyper-Threading
Intel's name for simultaneous multithreading (SMT): one physical core keeps two hardware thread contexts (registers, PC) and interleaves their instructions to fill idle execution units, for example while one thread waits on a cache miss. Typically 15 to 30% more throughput, not 2x. The OS sees two logical CPUs per core.
GPU
A GPU has thousands of simple cores organized into streaming multiprocessors that execute groups of threads (warps of 32 in NVIDIA) in lockstep, a model called SIMT.
| CPU | GPU | |
|---|---|---|
| Cores | Few, complex | Thousands, simple |
| Optimized for | Latency of one thread | Throughput of many |
| Cache and control | Large | Small |
| Good at | Branchy, serial logic | Data-parallel math (graphics, ML) |
Branch divergence within a warp serializes the paths and hurts performance.
Amdahl's Law
The speedup from parallelizing is limited by the part that stays serial.
Speedup(N) = 1 / ((1 - P) + P / N)where P is the parallel fraction and N the number of processors.
Example: 90% parallel code on 10 cores: 1 / (0.1 + 0.9 / 10) = 1 / 0.19 = 5.3x. On infinite cores: 1 / 0.1 = 10x maximum. The 10% serial part caps everything.
| Parallel fraction | 4 cores | 16 cores | Infinite cores |
|---|---|---|---|
| 50% | 1.6x | 1.9x | 2x |
| 90% | 3.1x | 6.4x | 10x |
| 99% | 3.9x | 13.9x | 100x |
Amdahl's Law also applies to any optimization: speeding up a part that takes 20% of the runtime can never give more than 1.25x overall.
Gustafson's Law
Amdahl assumes a fixed problem size. In practice, more processors are used to solve bigger problems in the same time.
Scaled speedup = N - (1 - P) * (N - 1)With 90% parallel work on 10 cores: 10 - 0.1 * 9 = 9.1x. This is the more optimistic view behind weather simulation and ML training at scale.
Shared vs distributed memory
| Shared memory | Distributed memory | |
|---|---|---|
| Communication | Read and write shared variables | Explicit messages over a network |
| Programming | Threads, OpenMP, locks | MPI, RPC |
| Scaling | Limited by coherence and bandwidth | Scales to thousands of nodes |
| Hard part | Synchronization, races | Latency, partial failure |
NUMA
Non-Uniform Memory Access: in multi-socket servers, each CPU socket has its own local memory. Accessing local memory is fast; accessing another socket's memory crosses an interconnect and is slower. The OS and databases try to keep threads near their memory (NUMA-aware allocation). UMA (uniform) systems have equal access time from every core.
Quick revision
- I/O: programmed (polling) wastes CPU; interrupt-driven waits for the device; DMA moves blocks without the CPU.
- Memory-mapped I/O uses normal loads and stores; port-mapped uses special instructions.
- Flynn: SISD, SIMD, MISD, MIMD; GPUs and vector units are SIMD, multicore is MIMD.
- The power wall ended clock scaling and started the multicore era.
- SMT (Hyper-Threading) shares one core between two hardware threads for modest gains.
- Amdahl:
1 / ((1 - P) + P / N); the serial fraction caps speedup. - Gustafson: scale the problem with the processors for near-linear speedup.
- NUMA: local memory is faster than remote; keep threads near their data.