Pipelining Fundamentals: Speedup, Throughput, and Hazards
Pipelining is a technique in computer architecture that divides instruction execution into a sequence of stages so that multiple instructions overlap in time. The key performance ideas are latency (time for one instruction to complete) and throughput (rate at which instructions complete). Pipelining works best when stage delays are balanced and hazards are minimized.
A pipeline of stages has a pipeline fill period and a pipeline drain period: the first instruction completes after roughly cycles (one per stage), and afterward the pipeline can ideally complete one instruction per cycle (or per fixed interval), yielding high throughput. In ideal conditions (no hazards and full utilization), speedup improves because overlap increases the amount of useful work done per unit time.
To reason about performance, we typically use:
- Stage latency (must fit the clock period)
- CPI (higher CPI indicates stalls/hazards)
- Throughput
- Speedup
Pipeline hazards are situations that prevent the next instruction from advancing to the next stage on time. These hazards reduce throughput by forcing stalls or squashing/restarting work. The classic hazard categories are structural hazards, data hazards, and control hazards.
Mermaid overview of an ideal pipeline overlap:
Note: Precise formula forms (e.g., using CPI, cycle counts, or ideal speedup equations) depend on whether you assume fixed pipeline stage timing and whether you model start-up/steady-state behavior. The concepts of fill/drain, throughput, and hazards remain consistent.
Pipelining Basics (instruction-level parallelism, hazards overview)
Ideal throughput and speedup intuition
In a simple pipeline where each stage completes in one cycle and the CPU can issue a new instruction every cycle, the pipeline ideally achieves:
- After the pipeline is full: completes 1 instruction per cycle (throughput maximized).
- Overall completion time: depends on how many instructions you execute due to the initial fill and final drain effects.
We can characterize performance by separating startup from steady state:
- Pipeline fill takes about extra cycles before the first cycle where every stage is busy.
- After that, each additional instruction arrives with a new cycle’s worth of overlap.
This leads to the commonly taught qualitative model:
- With pipelining, the first instruction experiences latency similar to the whole non-pipelined execution.
- Subsequent instructions benefit from overlap, increasing throughput dramatically.
Pipeline speedup increases as:
- the number of pipeline stages grows (more opportunity for overlap),
- the workload has enough instructions to amortize fill/drain,
- hazards are rare so the pipeline runs close to full utilization.
Speedup vs throughput: even if speedup (for a finite program) looks limited by fill/drain, throughput (steady-state rate) can still be close to ideal once the pipeline is fully utilized.
Qualitative pipeline execution timeline: fill vs steady-state
Illustrates how overlap makes completion rate approach the ideal after fill.
Pipeline hazards: what they are and why they matter
A hazard occurs when an instruction cannot proceed to the next pipeline stage as planned.
In practice, hazards create two main effects:
- Stalls / bubbles: inserted cycles where useful work cannot proceed.
- Squashes / flushes: wrong-path instructions are cancelled when control flow is resolved.
Hazard categories
-
Structural hazards
Example: two instructions require the same memory port in a cycle. -
Data hazards
Example dependency patterns:- RAW (Read After Write): a consumer needs a value produced by an earlier instruction that hasn’t written it back yet.
- Mitigations include stalling until data is ready and forwarding/bypassing to supply results directly from intermediate pipeline stages.
-
Control hazards
Example: the pipeline fetches instructions based on a prediction, but later determines the branch outcome was different. Mitigations include:- stalling until the branch condition is known,
- branch prediction (speculate),
- pipeline flushing when the speculation is wrong.
How hazards reduce throughput in cycle-by-cycle terms
- 1Step 1
If each stage takes one cycle and no hazards occur, you can fetch/advance a new instruction every cycle, reaching near-maximum throughput.
- 2Step 2
When an instruction reaches a stage but required conditions are not met (resource busy, operand not ready, branch direction unknown), the pipeline cannot advance correctly.
- 3Step 3
For structural/data hazards you typically insert bubbles to wait. For control hazards you may flush wrong-path work.
- 4Step 4
Each stall increases average cycles per instruction: even one bubble per few instructions measurably lowers throughput.
- 5Step 5
Once the hazard condition is resolved, the pipeline resumes overlapping execution, returning toward ideal throughput.
Speedup and throughput: connecting the ideas
To link everything quantitatively, a standard approach is to express performance using CPI and relate execution time to cycle counts.
A common framing:
- Execution time is proportional to .
- Pipelining aims to reduce CPI toward its ideal value (often near 1 in an ideal pipeline), but hazards increase CPI by adding stalls/flush overhead.
So:
- Throughput increases when CPI decreases.
- Speedup comes from reduced total cycles compared with a non-pipelined design.
Pipeline hazards are the principal reason real CPI exceeds the ideal, turning theoretical speedup into smaller realized speedup.
Pro Tip: Think “steady-state throughput” vs “finite-workload speedup”
Even if a pipeline has fill/drain overhead, once stabilized it can complete about one instruction per cycle (in ideal conditions). For short programs, speedup may look modest; for long programs, throughput dominates.
Warning: Hazards don’t just add delay—they change where time is spent
A stall wastes pipeline bandwidth for multiple stages (a bubble prevents progress across the pipeline). A control hazard can waste more work due to flushing wrong-path instructions.
Pipeline hazards: quick mental models
Typical pipeline performance lifecycle (from cold start to steady state)
Pipeline fill
Cold startEarly cycles execute partial work across the pipeline; completion rate ramps up."
Steady state overlap
Sustained executionIdeally one instruction completes per cycle (maximum throughput) if hazards are rare."
Stalls/flushes
Hazard eventsData/control hazards increase CPI by inserting bubbles or reducing useful work."
Recovery
After resolutionOnce hazards clear (operands ready, branch resolved), overlap resumes."
Pipelining speed, throughput, and hazards
Knowledge Check
In an ideal -stage pipeline with no hazards, after what point does throughput approach its maximum?