5.2.9Processor Datapath & Pipelining

Pipeline throughput and CPI

2,906 words13 min readdifficulty · medium1 backlinks

Overview

Pipeline throughput measures how many instructions a pipelined processor completes per unit time, while CPI (Cycles Per Instruction) quantifies the average number of clock cycles needed to execute one instruction. These metrics reveal how efficiently our pipeline converts clock speed into actual work.

Fundamental Definitions

Why CPI and not just clock speed? Because a5 GHz processor with CPI=4 is slower than a 3 GHz processor with CPI=1. Real performance = Clock RateCPI\frac{\text{Clock Rate}}{\text{CPI}}.

Deriving Ideal Pipeline Performance

Let's build the performance equations from scratch.

Step 1: Single-Cycle Baseline

For a non-pipelined processor with clock period TsingleT_{single}:

  • Each instruction takes one full cycle
  • Time per instruction = TsingleT_{single}
  • Throughput = 1Tsingle\frac{1}{T_{single}} instructions/second
  • CPI = 1 (by definition)

But: TsingleT_{single} must be long enough for the slowest instruction stage. If we have5 stages taking 100ps, 120ps, 150ps, 110ps, 140 then Tsingle=150T_{single} = 150 ps (the longest stage dominates).

Step 2: Pipelined Clock Period

When we split execution into k stages, each stage has delay tit_i. The pipeline clock period must accommodate the slowest stage plus register overhead tregt_{reg}:

Tpipe=max(t1,t2,,tk)+tregT_{pipe} = \max(t_1, t_2, \ldots, t_k) + t_{reg}

Why the max? All stages advance on the same clock edge. The slowest stage is the bottleneck—like the slowest worker on an assembly line determines the line's speed.

Why add tregt_{reg}? Pipeline registers between stages need time to latch new data (setup time + clock-to-Q delay). Typical tregt_{reg} is 20-50 ps.

Step 1: Find the slowest stage. max(80,70,100,90,60)=100 ps (EX stage)\max(80, 70, 100, 90, 60) = 100 \text{ ps (EX stage)}

Step 2: Add register overhead. Tpipe=100+30=130 psT_{pipe} = 100 + 30 = 130 \text{ ps}

Why this step? The clock must be slow enough that EX completes and the register captures its output before the next cycle starts.

For comparison, single-cycle would need: Tsingle=80+70+100+90+60=400T_{single} = 80+70+100+90+60 = 400 ps (sum of all stages, no overlap).

Step 3: Ideal Throughput

In a k-stage pipeline, after an initial "fill-up" period, one instruction completes every cycle. This is the key insight:

Throughputideal=1Tpipe instructions/second\text{Throughput}_{ideal} = \frac{1}{T_{pipe}} \text{ instructions/second} CPIideal=1\text{CPI}_{ideal} = 1

Derivation: Consider executing nn instructions (where nkn \gg k):

  • First instruction takes kk cycles to flow through all stages
  • But while it's in stage2, instruction 2 enters stage 1
  • After kk cycles, instruction 1 finishes; after k+1k+1 cycles, instruction 2 finishes
  • Total time = k+(n1)k + (n-1) cycles ≈ nn cycles for large nn
  • Therefore: CPI = k+n1n1\frac{k + n - 1}{n} \approx 1 as nn \to \infty

In the best case (perfectly balanced stages, negligible tregt_{reg}), speedup ≈ k. In practice, speedup is 3-4× for a 5-stage pipeline due to stage imbalance and register delays.

Real Pipeline Performance: Hazards and Stalls

Real pipelines don't achieve CPI=1 because of hazards that force stalls (idle cycles).

Types of Stalls

  1. Data hazards: RAW (Read After Write) dependencies
  2. Control hazards: Branch mispredictions
  3. Structural hazards: Resource conflicts (rare in modern designs)

Actual CPI Formula

CPIactual=CPIideal+Stalls per Instruction\text{CPI}_{actual} = \text{CPI}_{ideal} + \text{Stalls per Instruction}

Since CPIideal=1\text{CPI}_{ideal} = 1 for pipelines:

CPIactual=1+Stalls per Instruction\text{CPI}_{actual} = 1 + \text{Stalls per Instruction}

Breaking down stalls: Stalls per Instruction=(Data Hazard Rate×Avg Data Stalls)+(Branch Rate×Branch Mispredict Rate×Branch Penalty)\text{Stalls per Instruction} = (\text{Data Hazard Rate} \times \text{Avg Data Stalls}) + (\text{Branch Rate} \times \text{Branch Mispredict Rate} \times \text{Branch Penalty})

Calculate stalls from branches: Branch Stalls/Instr=0.25×0.10×3=0.075 cycles/instr\text{Branch Stalls/Instr} = 0.25 \times 0.10 \times 3 = 0.075 \text{ cycles/instr} Why? 25% are branches, 10% of those mispredict, each costs 3 cycles.

Calculate data hazard stalls: Data Stalls/Instr=0.15×2=0.30 cycles/instr\text{Data Stalls/Instr} = 0.15 \times 2 = 0.30 \text{ cycles/instr}

Total CPI: CPI=1+0.075+0.30=1.375\text{CPI} = 1 + 0.075 + 0.30 = 1.375

Actual throughput (if clock = 2GHz): Throughput=2×1091.375=1.45 billion instructions/second\text{Throughput} = \frac{2 \times 10^9}{1.375} = 1.45 \text{ billion instructions/second}

Why does CPI > 1 hurt? Every 0.1 increase in CPI reduces throughput by ~9% (for CPI near 1). That0.375 overhead means we're only getting 73% of ideal throughput.

Optimizing Pipeline Performance

1. Balance Stage Delays

Problem: If one stage takes 150ps and others take 80ps, the entire pipeline runs at 150ps.

Solution: Subdivide the slow stage. If EX takes 150ps, split it into EX1 (75ps) and EX2 (75ps). Now clock period drops from 150ps to 80ps (if ID is next slowest), improving throughput by 1.875×.

Trade-off: More stages = more register overhead. Diminishing returns beyond 10-15 stages.

2. Reduce Stalls via Forwarding

Forwarding (bypassing) passes results directly from one stage to another without waiting for writeback.

Example:

ADD R1, R2, R3  # R1 = R2 + R3 (EX stage produces result)
SUB R4, R1, R5  # Needs R1 (ID stage reads it)

Without forwarding: 2-cycle stall (wait for ADD to reach WB). With forwarding: 0 stalls (EX→EX bypass path).

Impact on CPI: If30% of instructions have RAW hazards, forwarding reduces CPI from 1.60 to 1.00(saves 0.6cycles/instr).

3. Improve Branch Prediction

Static prediction (always predict not-taken): ~60% accuracy. Dynamic prediction (branch history table): ~90-95% accuracy.

Impact: If 20% instructions are branches with 3-cycle penalty:

  • 50% mispredict: CPI = 1 + 0.20×0.50×3 = 1.30
  • 10% mispredict: CPI = 1 + 0.20×0.10×3 = 1.06

Improving prediction from 50% to 90% reduces CPI by 0.24 (18% throughput gain).

Effective IPC = 1/0.25 = 4 instructions per cycle.

Throughput: Throughput=4.0×109×4=16 billion instructions/second\text{Throughput} = 4.0 \times 10^9 \times 4 = 16 \text{ billion instructions/second}

How CPI < 1? Superscalar execution: processor has multiple execution units and issues4-6 instructions per cycle. This is beyond simple pipelining—it's instruction-level parallelism.

Common Mistakes

The reality: Each instruction still takes k cycles (latency unchanged). What improves is throughput—instructions complete more frequently, not faster individually.

Example: A 5-stage pipeline with 1ns per stage:

  • Latency per instruction = 5ns (same as non-pipelined if Tsingle=5T_{single}=5 ns)
  • But throughput = 1 instruction per ns (vs. 1 per 5ns non-pipelined)

Fix: Think "assembly line." A car still takes hours to build, but one rolls off every minute.

The reality: CPI measures cycles per instruction completed, not per stage. In an ideal pipeline, one instruction completes every cycle, so CPI=1 regardless of k.

Correct formulas:

  • Latency (cycles for one instruction) = k
  • CPI (cycles per completed instruction) = 1 (ideal)

Fix: Don't confuse latency with throughput. CPI measures steady-state throughput, not first-instruction delay.

The reality: Speedup=TsingleTpipe=timax(ti)+treg\text{Speedup} = \frac{T_{single}}{T_{pipe}} = \frac{\sum t_i}{\max(t_i) + t_{reg}}

If stages are unbalanced (e.g., one takes 50% of total time), speedup is much less than k. Plus, register overhead erodes gains.

Example: 5 stages (100, 50, 50, 50 ps), treg=20t_{reg}=20 ps:

  • Tsingle=300T_{single} = 300 ps
  • Tpipe=100+20=120T_{pipe} = 100 + 20 = 120 ps
  • Speedup = 300/120 = 2.5× (not 5×)

Fix: Speedup depends on balance. Perfectly balanced stages with no overhead approaches k×, but real designs get60-80% of k.

Advanced Considerations

Superscalar and CPI < 1

Modern processors issue multiple instructions per cycle. A 4-way superscalar with perfect conditions can achieve CPI = 0.25 (IPC = 4).

How?

  • Multiple execution units (e.g., 2 ALUs, 1 FPU, 2 load/store units)
  • Issue logic finds independent instructions in the instruction window
  • Each "cycle" completes 4 instructions in parallel

Limitation: Instruction-level parallelism (ILP). Real code has dependencies limiting how many instructions can execute simultaneously. Typical IPC = 2-3even with 6-way superscalar hardware.

Amdahl's Law and Pipeline Efficiency

Even with perfect pipelining, overall speedup is limited by non-pipelined parts (Amdahl's Law). If 20% of execution time is in pipeline fill/drain (prologue/epilogue), maximum speedup is 5×.

Recall Feynman Explanation

Imagine you're doing laundry with four stages: wash, dry, fold, put away. Each takes 30 minutes.

Without pipelining: You wash one load, wait for it to dry, fold it, put it away. Then start the next load. Time for4 loads = 4 × (30×4) = 480 minutes (8 hours).

With pipelining: While load 1 is drying, you start washing load 2. While load 1 is being folded, load 2 dries and load 3 washes. After the first2 hours (4 stages), you finish one load every 30 minutes.

Time for 4 loads = 120 (first load) + 3×30 (remaining loads) = 210 minutes (3.5 hours). Speedup = 480/210 = 2.3×.

CPI: In steady state, you complete one load per "cycle" (30 min), so CPI = 1.

Why not 4× speedup? The first load still takes full120 minutes (latency), and we only have 4 loads (small n). With 100loads, speedup approaches 4×.

Stalls: If you forgot to buy detergent (data hazard), washing stops. Now loads2, 3, 4 are delayed. CPI increases because you're not completing one load every30 minutes anymore.

Connections

  • 5.2.01-Pipelining-basics: Foundation of how pipelining works
  • 5.2.03-Data-hazards: Main cause of CPI > 1
  • 5.2.05-Control-hazards: Branch penalties reduce throughput
  • 5.2.07-Forwarding-and-bypassing: Key technique to improve CPI
  • 5.3.02-Superscalar-architecture: Achieving CPI < 1
  • 5.1.05-CPU-performancemetrics: CPI fits into overall performance equation

#flashcards/hardware

What is pipeline throughput? :: The rate at which instructions complete, measured instructions per second. For an ideal pipeline, throughput = 1/T_pipe instructions/second.

What is CPI (Cycles Per Instruction)?
The average number of clock cycles required to complete one instruction. CPI = Total Cycles / Instructions Executed. The reciprocal of IPC.
Why is CPI more important than clock frequency for performance?
Because actual = Clock Rate / CPI. A 5 GHz processor with CPI=4 is slower than a 3 GHz processor with CPI=1. CPI reveals how efficiently the processor converts cycles into completed instructions.
What determines the clock period in a pipelined processor?
T_pipe = max(t_1, t_2, ..., t_k) + t_reg. The slowest stage sets the pace (bottleneck), plus register overhead for latching data between stages.
What is the ideal CPI for a k-stage pipeline?
CPI_ideal = 1. After initial fill-up, one instruction completes every cycle regardless of the number of stages k.
Why doesn't pipelining reduce per-instruction latency?
Each instruction still passes through all k stages, taking k cycles total. Pipelining improves throughput (completions per cycle), not latency (time for one instruction).
How do pipeline stalls affect CPI?
CPI_actual = CPI_ideal + Stalls per Instruction. Each stall cycle inserts a bubble where no instruction completes, increasing the average cycles needed per instruction.
What is the actual CPI formula including hazards?
CPI = 1 + (Data Hazard Rate × Avg Data Stalls) + (Branch Rate × Mispredict Rate × Branch Penalty). Each hazard type contributes stall cycles.
What is the theoretical speedup of a k-stage pipeline?
Speedup = T_single / T_pipe ≈ (sum of stage delays) / (max stage delay + register overhead). Perfect balance gives k×, but real designs achieve 60-80% of k.
Why is stage balance critical for pipeline performance?
The slowest stage sets the clock period for all stages. If one stage is 2× slower than others, the entire pipeline runs at the slow rate, wasting time in faster stages.
How does forwarding improve pipeline CPI?
Forwarding bypasses results directly from one stage to another without waiting for writeback, eliminating many data hazard stalls. Can reduce CPI from ~1.6 to 1.0 by removing 2-cycle RAW stalls.
How does branch prediction affect pipeline throughput?
Better prediction reduces branch misprediction stalls. Improving from 50% to 90% accuracy (20% branch rate, 3-cycle penalty) reduces CPI by ~0.24, an 18% throughput gain.

What is IPC and how does it relate to CPI? :: IPC (Instructions Per Cycle) = 1/CPI. IPC measures throughput directly (higher is better), while CPI measures cycle cost per instruction (lower is better).

How can CPI be less than 1?
In superscalar processors that issue multiple instructions per cycle. A 4-way superscalar can achieve CPI=0.25 (IPC=4) by completing 4 instructions per cycle using multiple execution units.
What limits pipeline speedup according to Amdahl's Law?
Non-pipelined portions like pipeline fill/drain limit overall speedup. If 20% of execution is non-pipelined, maximum speedup is 5× regardless of pipeline depth.

Concept Map

reciprocal of

divided by CPI

divides clock in

split into

dominates

added to

inverse gives

increases

has CPI=1

longest stage sets period

measured in IPS or IPC

Clock Rate

Throughput

CPI

IPC

Real Performance

k Stages

Slowest Stage max

Register Overhead

Pipeline Clock Period

Single-Cycle Baseline

Instruction Overlap

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Pipeline throughput aur CPI ka concept bahut straightforward hai lekin bohot powerful. Socho ek assembly line jisme cars ban rahi hain - har workerek specific kaam karta hai (paint, engine, wheels). Agar tum ek car ko shuru se end takek hi worker se banwao, toh bahut time lagega. Lekin agar har worker apna kaam karke next worker ko pass karde, toh simultaneously kai cars progress kar rahi hain. Yahi hai pipelining ka magic!

Ab throughput ka matlab hai kitni jaldi output mil raha hai. Ek assembly line pe har10 minute mein ek car ready ho rahi hai - yeh hai throughput. Lekin ek individual car ko complete hone mein ab bhi 50 minutes lagte hain (5 workers × 10 min each) - yeh hai latency. Pipeline latency ko change nahi karta, sirf throughput ko improve karta hai. Real processor mein bhi same concept: har instruction5 stages (IF, ID, EX, MEM, WB) se guzarti hai, lekin kyunki sab overlap ho rahe hain, har cyclek instruction complete ho jati hai steady state mein.

CPI (Cycles Per Instruction) bata hai kitne cycles lagte hain average mein ek instruction ko complete karne ke liye. Ideal pipeline mein CPI = 1 hota hai, matlab har cyclek instruction finish hoti hai. Lekin real life mein hazards ate hain - data dependencies (ek instruction ko dusri ke result ka wait karna), branch mispredictions (galat direction mein chale gaye). Har hazard "stall" dalta hai pipeline mein, jisme kuch cycles waste hote hain without any instruction completing. Is wajah se CPI badhta hai 1.5, 2.0 tak, aur throughput gir jata hai proportionally.

Modern superscalar processors mein CPI 1 se kam bhi ho sakta hai! Kaise? Kyunki woh ek cycle mein multiple instructions execute karte hain - jaise 4 different assembly lines parallel mein chal rahi hain. Agar CPI = 0.25 hai (matlab IPC = 4), toh processor har cycle 4 instructions complete kar raha hai. Yeh tab possible hai jab instructions independent hain aur processor ke pas multiple execution units hain. Performance optimization ka pora game yahi hai - CPI ko minimize karo forwarding se, branch prediction se, aur architecture ko efficiently design karke.

Go deeper — visual, from zero

Test yourself — Processor Datapath & Pipelining

Connections