5.2.9 · D3Processor Datapath & Pipelining

Worked examples — Pipeline throughput and CPI

1,942 words9 min readBack to topic

This page is the drill ground for the parent topic. Before we compute anything, let us list every kind of question the topic can throw at you. Then we solve one example per cell, so you never meet a scenario you haven't already seen.


The scenario matrix

Every exam question about pipeline performance lands in one of these cells. Our job is to hit them all.

# Cell (case class) What makes it tricky Hit by
A Ideal fill-up — exact cycles for instructions the "" fill cost, small Ex 1
B Limiting value why CPI collapses to Ex 1
C Clock period from unbalanced stages pick the max, add register overhead Ex 2
D Speedup vs single-cycle sum-of-stages ÷ pipe period Ex 2
E CPI with data + control hazards combine two stall sources Ex 3
F Forwarding removes stalls before/after CPI difference Ex 4
G Branch prediction improvement accuracy → mispredict rate flip Ex 5
H Degenerate: 1-stage / perfectly balanced edge where pipelining does nothing Ex 6
I Zero-hazard vs all-hazard extremes CPI floor and a worst case Ex 6
J Superscalar: CPI < 1 IPC > 1, real-world word problem Ex 7
K Exam twist: which processor is faster? GHz alone is a trap Ex 8

Prerequisite links if a cell needs backup: 5.2.03-Data-hazards, 5.2.05-Control-hazards, 5.2.07-Forwarding-and-bypassing, 5.3.02-Superscalar-architecture, 5.1.05-CPU-performancemetrics.


Example 1 — Cells A & B: exact cycles and the limit

Forecast: guess now — does CPI fall or rise as grows? Toward what number?

Figure — Pipeline throughput and CPI

Look at the figure: each row is one instruction sliding right by one stage per cycle. The staircase takes cycles just to reach the WB corner for the first instruction; after that, one finishes every single cycle.

Step 1 — Count the fill. The first instruction needs all cycles to travel IF→ID→EX→MEM→WB. Why this step? Nothing can finish before the pipe is full — this is the unavoidable start-up cost.

Step 2 — Count the steady state. After the first finishes, the remaining instructions finish one per cycle. Why? Each later instruction is one cycle behind the one ahead — the assembly-line rhythm.

Step 3 — Divide to get CPI.

Total cycles CPI
1 5 5.000
5 9 1.800
100 104 1.040
1000004 1.000004

Step 4 — The limit. As , the constant becomes negligible next to : Why a limit here? CPI is a per-instruction average; the fixed fill cost gets shared over ever more instructions, so its per-instruction share vanishes.

Verify: For : ✓. Single instruction gives CPI (equals latency — pipelining gives you nothing for one instruction, exactly as expected).


Example 2 — Cells C & D: clock period and speedup

Forecast: which stage sets the clock, and will speedup reach the ideal ?

Figure — Pipeline throughput and CPI

Step 1 — Pick the slowest stage. All stages tick on the same clock edge, so the clock can only be as fast as the slowest one allows. Why max, not average? A worker who is slow holds up the whole line even if others are fast.

Step 2 — Add register overhead. Why? Each stage's result must be latched into the pipeline register before the next edge.

Step 3 — Single-cycle period = sum of all stages. With no overlap one instruction walks through every stage in one long cycle:

Step 4 — Speedup. Why below ? The stage imbalance (EX hogs the clock) plus the ps overhead steal the ideal .

Verify: ✓. Ideal (balanced, no overhead) would be — our correctly sits below it.


Example 3 — Cell E: CPI with both hazard types

Forecast: will CPI land nearer or ?

Step 1 — Branch stalls per instruction. Only mispredicted branches cost cycles: Why the triple product? Fraction that are branches × fraction of those that mispredict × cycles each wastes.

Step 2 — Data-hazard stalls per instruction.

Step 3 — Add to the ideal floor of 1.

Step 4 — Throughput. Why divide by CPI? Each instruction now eats cycles, so fewer finish per second.

Verify: ✓ (back to the raw cycle rate). Ideal throughput would be ; we get of it.


Example 4 — Cell F: forwarding erases stalls

Forecast: how much CPI does forwarding buy back?

Step 1 — CPI without forwarding.

Step 2 — CPI with forwarding. Stalls drop to : Why zero? The EX result is handed straight to the next EX input, so nobody waits for writeback.

Step 3 — Cycles saved per instruction.

Verify: speedup — forwarding here recovers the entire hazard penalty, exactly matching the parent note's claim. ✓


Example 5 — Cell G: better branch prediction

Forecast: how many CPI points does going accurate save?

Step 1 — Convert accuracy to mispredict rate. Mispredict : so and . Why the flip? Penalties come from the branches we get wrong, not right.

Step 2 — CPI at 50% accuracy.

Step 3 — CPI at 90% accuracy.

Step 4 — Improvement.

Verify: throughput ratio → a throughput gain. ✓


Example 6 — Cells H & I: degenerate and extreme inputs

Forecast: for (a), is there any speedup at all?

Step 1 — (a) . Total cycles , so CPI but there is no overlap — this is the single-cycle machine. Why the degenerate result? With one stage there is nothing to pipeline; speedup over single-cycle .

Step 2 — (b) balanced, no overhead. Why exactly ? Perfect balance and zero overhead is the ideal limit — speedup reaches the stage count.

Step 3 — (c) zero-hazard floor. CPI can never dip below for a scalar pipeline (one finish per cycle max) — that changes only in Example 7.

Step 4 — (d) all-hazard worst case. Why ? "Every" instruction hazards → hazard rate . This is the ceiling for a -cycle-stall world.

Verify: (a) speedup if that single stage summed the same ps — pipelining nothing changes nothing ✓. (b) ✓. (d) ✓.


Example 7 — Cell J: superscalar, CPI below 1 (real-world)

Forecast: can a single instruction really take a quarter of a cycle?

Step 1 — IPC is the reciprocal of CPI. Why reciprocal? CPI is cycles-per-instruction; flip it to get instructions-per-cycle.

Step 2 — Throughput.

Step 3 — Why CPI < 1? No single instruction is faster — the core simply issues 4–6 instructions in the same cycle using multiple execution units. Averaged, each instruction shares a cycle, so the per-instruction cycle count drops below .

Verify: IPC ✓; and CPI ✓.


Example 8 — Cell K: the exam trap "which is faster?"

Forecast: the flashy GHz chip — winner or bait?

Step 1 — Performance clock rate ÷ CPI. Why divide by CPI? Raw GHz counts cycles; only dividing by cycles-per-instruction turns it into work done.

Step 2 — Compare. delivers vs 's — Q is faster.

Step 3 — By how much.

Verify: time for instructions on P s; on Q s. Ratio ✓ — the "slower-clocked" chip wins by . This is the iron law in one punch.


Recall Self-test

CPI in the limit of many instructions for an ideal k-stage pipe ::: 1 Pipeline clock period formula ::: Why superscalar can give CPI < 1 ::: it issues multiple instructions per cycle (IPC > 1) Faster: 5 GHz CPI=4 or 3 GHz CPI=1 ::: the 3 GHz one (performance = rate ÷ CPI) Cycles saved per instruction by forwarding when 30% hazard, 2-cycle stall ::: 0.60