Skip to main content

Computer Organization

Pipelining

Ideal speedup ≈ stages — then subtract reality with stalls, hazards, and branch penalties.

~4 hrs ~2–3 marks · Must-score 10 samples · 10 practice · 10 cards

GATE CSE instruction pipelining — ideal speedup, stalls, RAW/WAR/WAW, control hazards, forwarding, branch penalty, with samples and drills.

Learning outcomes

  • Compute ideal and stall-adjusted pipeline speedup and effective CPI
  • Classify structural, data (RAW/WAR/WAW), and control hazards with examples
  • Explain how forwarding reduces many RAW stalls and when a load-use stall remains
  • Account for branch penalties and pipeline fill/flush in numericals

Pipeline idea & ideal speedup

  • Instruction pipelining overlaps stages of successive instructions (classic 5-stage: IF, ID, EX, MEM, WB).
  • Balanced k-stage pipeline, no hazards, large N: speedup approaches k versus a non-pipelined design whose cycle equals the sum of the stage delays.
  • Throughput approaches 1 instruction per clock once the pipe is full. Latency of one instruction remains about k clocks — pipelining improves throughput, not single-instruction latency.
  • Pipeline registers sit between stages and hold intermediate results plus control. Clock period is set by the slowest stage (+ overhead).
  • Fill (startup) and flush overhead become negligible when N is large — GATE often says “large number of instructions”.

Formulas to remember

  • Ideal speedup ≈ k (balanced, no stalls, large N)
  • Speedup = T_nonpipe / T_pipe
  • Time_pipe ≈ (k + N − 1) × T_clk (no stalls)
  • CPI_pipe ≈ 1 + stalls_per_instruction
StageTypical workWrites / reads
IFFetch instructionI-mem / I-cache
IDDecode / read regsRegister file read
EXALU / EA / branchALU, flags
MEMLoad/storeD-mem / D-cache
WBWrite resultRegister file write

Worked example

Problem. 5-stage pipe, clock 2 ns. Non-pipe cycle 10 ns. Ideal speedup for large N?

Solution. Non-pipe ≈ 10 ns/instr; pipe ≈ 2 ns/instr ⇒ speedup ≈ 5.

Five-stage IF ID EX MEM WB pipeline with overlapping instruction timeline
Ideal speedup approaches k — throughput rises; single-instr latency stays ~k clocks.

Hazards, stalls & forwarding

  • Structural hazard: two instructions need the same hardware resource in the same cycle (e.g., a single memory port for IF and MEM).
  • Data hazards: RAW (read after write — true dependence), WAR (write after read), WAW (write after write). In a simple in-order 5-stage pipe, RAW is the main concern; WAR/WAW matter more with out-of-order / multi-issue.
  • Control hazard: next PC is unknown or wrong until a branch/jump resolves — may require stall, flush, or prediction.
  • Forwarding/bypassing routes an ALU/MEM result to a later instruction’s EX inputs before WB completes — eliminates many RAW stalls.
  • Load-use hazard: a load’s data is available only after MEM; an immediately following consumer often needs one stall even with forwarding.
  • Stall / bubble: insert a wait cycle (NOP-like slot) when the hazard cannot be resolved in time. Average stalls per instruction raise CPI above 1.
  • Branch penalty: number of wasted cycles on a taken/mispredicted branch (flush wrong-path instructions). Speedup numericals often give fraction of branches × penalty.

Formulas to remember

  • CPI ≈ 1 + stall_cycles_per_instruction
  • Speedup ≈ k / CPI (when non-pipe cycle ≈ k pipe clocks)
  • Extra branch stalls ≈ (branch fraction) × (penalty) × N

Worked example

Problem. Average 0.25 stall cycles per instruction. Effective CPI?

Solution. CPI ≈ 1 + 0.25 = 1.25.

RAW WAR WAW and control hazards with forwarding path note for load-use stall
Forwarding fixes many RAWs; load-use often still needs one bubble.

GATE exam tricks — pipeline

  • Speedup ≈ k only if hazard-free and stages are balanced — check for stalls in the stem.
  • Effective CPI = 1 + average stall cycles per instruction — not “stalls alone”.
  • RAW = read after write; don’t swap with WAR.
  • Forwarding does not fix everything — load-use often still stalls one cycle.
  • Deeper pipelines can raise clock rate but also raise branch penalty and forwarding complexity.
  • If non-pipe cycle time equals k × T_clk, ideal speedup is k; if the stem gives different times, use T_old/T_new directly.
  • Count pipeline bubbles on a sketch for short code sequences — GATE loves 4–6 instruction traces.

Worked example

Problem. 5-stage pipe, CPI=1.25 due to stalls, non-pipe cycle = 5 pipe clocks. Speedup?

Solution. Non-pipe CPI≈5 pipe clocks/instr; pipe effective 1.25 ⇒ speedup ≈ 5/1.25 = 4.

Pipeline CPI equals one plus average stall cycles per instruction
Speedup ~ k / CPI when the non-pipe cycle is about k pipe clocks.

Exam tips

  • State assumptions: forwarding? branch penalty?
  • CPI ≈ 1 + stalls/instr.
  • Ideal speedup ≠ always equal to stage count once stalls appear.
  • Sketch IF–ID–EX–MEM–WB for short dependency chains.
  • Separate throughput (instr/cycle) from per-instruction latency.
Exam pattern · 10 questions

GATE sample questions & answers

10 GATE-style MCQs for Pipelining with full explanations. Attempt each question before revealing the answer.

Q1 Ideal speedup

Ideal speedup of balanced 5-stage pipe (no hazards, large N) vs non-pipe cycle = 5 pipe clocks:

  • A) 1
  • B) 2.5
  • C) 5
  • D) 25
Show answer & explanation

Answer: C

Throughput 1/clock vs 1 per 5 clocks ⇒ ≈5.

Q2 RAW

RAW hazard means:

  • A) Resource conflict
  • B) Read before earlier write completes
  • C) Write after read (WAR)
  • D) Only branch mispredict
Show answer & explanation

Answer: B

Read After Write.

Q3 CPI

Average 0.25 stall cycles/instr ⇒ CPI about:

  • A) 0.25
  • B) 1.25
  • C) 5
  • D) 4.75
Show answer & explanation

Answer: B

1 + 0.25 = 1.25.

Q4 Forwarding

Forwarding primarily reduces:

  • A) Control hazards only
  • B) Many RAW hazards
  • C) Disk latency
  • D) Compulsory misses
Show answer & explanation

Answer: B

Bypass paths for data hazards.

Q5 Structural

Structural hazard example:

  • A) Branch flush
  • B) Two instrs need one memory port
  • C) RAW on a register
  • D) Cold cache miss
Show answer & explanation

Answer: B

Resource conflict.

Q6 Control

Control hazard relates to:

  • A) Only ALU add
  • B) Branches / changes of PC
  • C) Only DRAM refresh
  • D) Disk DMA
Show answer & explanation

Answer: B

Next PC uncertain.

Q7 Stall

Pipeline bubble means:

  • A) Extra cache line
  • B) Stall cycle with no useful work in a stage
  • C) Faster clock
  • D) DMA block
Show answer & explanation

Answer: B

Inserted wait / nop-like slot.

Q8 Latency vs throughput

Latency of one instruction in a 5-stage pipe (no stall) is about:

  • A) 1 clock
  • B) 5 clocks
  • C) 0 clocks
  • D) 25 clocks
Show answer & explanation

Answer: B

Still passes 5 stages.

Q9 Load-use

Load-use hazard often needs:

  • A) No action
  • B) A stall even with forwarding
  • C) Only disk wait
  • D) Larger PC
Show answer & explanation

Answer: B

Result not ready for immediate next use.

Q10 Real speedup

Speedup with stalls is generally:

  • A) Always = k
  • B) Less than ideal k
  • C) Infinite
  • D) Zero
Show answer & explanation

Answer: B

Stalls reduce throughput.

Topic drill · 10 questions

10 practice questions — Pipelining

Extra page-specific practice beyond the GATE samples. Attempt all 10, then reveal answers to check your reasoning.

P1

4-stage ideal speedup (no hazards) ≈

  • A) 1
  • B) 2
  • C) 4
  • D) 16
Show answer & explanation

Answer: C) 4

Approaches stage count.

P2

0.2 stalls/instr ⇒ CPI ≈

  • A) 0.2
  • B) 1.2
  • C) 5
  • D) 0.8
Show answer & explanation

Answer: B) 1.2

1 + 0.2.

P3

WAR hazard is:

  • A) Write After Read
  • B) Read After Write
  • C) Only structural
  • D) Cache miss
Show answer & explanation

Answer: A) Write After Read

Name dependency ordering.

P4

Branch penalty of 2 cycles every 5 instrs adds stalls/instr:

  • A) 2
  • B) 0.4
  • C) 5
  • D) 10
Show answer & explanation

Answer: B) 0.4

2/5 = 0.4.

P5

Throughput of a full ideal pipe is about:

  • A) 1 instr / clock
  • B) k instr / clock
  • C) 0
  • D) 1 instr / k^2 clocks
Show answer & explanation

Answer: A) 1 instr / clock

One completion per clock when full.

P6

Flushing a pipe after mispredict discards:

  • A) Only cache
  • B) Wrong-path instructions in flight
  • C) Main memory
  • D) Disk
Show answer & explanation

Answer: B) Wrong-path instructions in flight

Control hazard recovery.

P7

Balanced stages matter because:

  • A) Clock set by slowest stage
  • B) Clock ignores stages
  • C) No clock needed
  • D) Only RAM speed
Show answer & explanation

Answer: A) Clock set by slowest stage

Critical stage limits clock.

P8

Data hazard not helped by forwarding alone when:

  • A) Result needed immediately after load
  • B) Independent adds
  • C) No registers
  • D) Only jumps far
Show answer & explanation

Answer: A) Result needed immediately after load

Classic load-use.

P9

Non-pipe time 10 ns/instr, pipe 2 ns/instr (ideal) ⇒ speedup:

  • A) 2
  • B) 5
  • C) 8
  • D) 12
Show answer & explanation

Answer: B) 5

10/2 = 5.

P10

Pipeline speedup compares:

  • A) Only cache sizes
  • B) Non-pipe latency/throughput vs pipelined
  • C) Disk RPM
  • D) Compiler versions only
Show answer & explanation

Answer: B) Non-pipe latency/throughput vs pipelined

T_nonpipe / T_pipe.

Topic FAQs

Does pipelining reduce instruction latency to 1 cycle?

No. Throughput rises toward 1 instr/cycle; each instruction still flows through multiple stages.

What does forwarding fix?

Many RAW data hazards by bypassing results before write-back completes.

What is a pipeline bubble?

A stall cycle in which a stage holds no useful instruction work (an inserted wait/NOP-like slot).

Why can a load-use pair still stall with forwarding?

Load data is ready only after the MEM stage, so the next instruction’s EX often cannot receive it in time without one stall.

Quick revision · 10 cards

10 flashcards — Pipelining

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 What is the ideal speedup of a balanced k-stage pipeline with no hazards and a large number of instructions?
Q2 How do you express effective CPI when a pipeline has stalls?
Q3 What does a RAW data hazard mean in a pipeline?
Q4 How does forwarding (bypassing) help with data hazards?
Q5 What is a structural hazard in an instruction pipeline?
Q6 What causes a control hazard in a pipeline?
Q7 What is a pipeline bubble (stall cycle)?
Q8 How does instruction latency differ from pipeline throughput in a k-stage pipe?
Q9 Why does a load-use hazard often need a stall even when forwarding is present?
Q10 What happens to pipeline speedup when stalls and branch penalties appear?