Structural and Control Hazards in Pipelining: Worked Cycle Tables and CPI
Learn to recognise resource conflicts and wrong-path fetches, then count their cycles correctly through two complete five-stage pipeline examples.
KnowledgeGate Team
Exam prep & CS education

An ideal pipeline table looks regular until two stages demand one resource or a branch changes the next PC. Then one misplaced bubble spoils the cycle count. Structural and control hazards differ from data hazards in their causes, cycle effects, and CPI calculations. The equal-stage baseline and general speedup model are developed in pipelining in computer architecture; a single-memory structural stall and an EX-resolved taken-branch flush require separate cycle accounting.
Five-stage pipeline baseline: count ideal cycles before hazards
Our scalar, in-order pipeline has instruction fetch (IF), decode (ID), execute (EX), memory access (MEM), and write back (WB). Each stage takes one cycle, at most one instruction is issued per cycle, and the worked sequences contain no RAW, WAR, or WAW dependencies.
For n instructions and k stages, the first instruction needs k cycles to finish. Each of the remaining n - 1 instructions then finishes one cycle later. Therefore:
Total cycles = k + (n - 1) = k + n - 1
Five instructions and five stages take 5 + 5 - 1 = 9 ideal cycles. Latency is five cycles for one instruction, while ideal steady-state throughput is one completion per cycle after filling. The CS Fundamentals learning route provides wider context.
Hazard | What causes it? | What must be resolved? |
|---|---|---|
Structural | Two stages need one physical resource in the same cycle | Resource availability |
Control | The correct next PC is not yet known | Branch direction and target |
Data | Instructions have an operand relationship | Value availability and ordering |
Structural hazards: one resource, two requests
A structural hazard occurs when overlapping stages need one resource together. With single-ported unified memory, IF needs the port for each fetch while MEM needs it for a load or store.
Use this sequence:
I1: LW R1, 0(R2)I2: ADD R3, R4, R5I3: SUB R6, R7, R8I4: AND R9, R10, R11I5: OR R12, R13, R14
Cycles 1 to 3 fill normally. In cycle 4, I1 reaches MEM and needs the only memory port. I4 would normally use that same port for IF, so its fetch is blocked for one cycle.
Instruction | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
I1 | IF | ID | EX | MEM | WB | |||||
I2 | IF | ID | EX | MEM | WB | |||||
I3 | IF | ID | EX | MEM | WB | |||||
I4 | Blocked | IF | ID | EX | MEM | WB | ||||
I5 | IF | ID | EX | MEM | WB |
Ideal completion was 9 cycles. One blocked fetch makes it 9 + 1 = 10. Realised finite-sequence CPI is 10 / 5 = 2.0, against ideal CPI 9 / 5 = 1.8.
A non-pipelined implementation taking five equal stage-times per instruction needs 5 x 5 = 25 stage-cycles. Realised speedup is 25 / 10 = 2.5, not the rounded ideal 25 / 9 = 2.78.

Structural hazard remedies: stall, split paths or add ports
Three remedies are standard: stall through an interlock, use separate instruction and data paths, or use dual-ported memory. Stalling costs cycles; more hardware removes this conflict.
With separate paths, I1 uses data memory in cycle 4 while I4 uses instruction memory. I5 fetches in cycle 5, so completion returns to 9 cycles with unchanged results.
The remedy is resource-specific. Extra memory ports do not fix contention for a single multiplier. Cache mapping and hit ratio affect memory performance, but are not this hazard automatically.
Control hazards: fetching from an unconfirmed PC
A branch creates a control hazard because its direction and target determine the next PC. The processor can freeze fetch, predict, or later squash sequentially fetched work.
Here the decision and target arrive at the end of EX, with prediction not taken. If actually taken, the instructions in IF and ID are wrong-path work, giving a two-cycle penalty.
Earlier resolution needs ready operands and target. Prediction lowers average cost, but a miss flushes work. Delayed branching is a historical architecture-visible technique, not a modern default.
Control hazard worked example: two squashes and a new CPI
Use I1: ADD R1, R2, R3, I2: BEQ R4, R5, L, I3: SUB R6, R7, R8, I4: AND R9, R10, R11, and target L: I5: OR R12, R13, R14. Set R4 = 7 and R5 = 7, so I2 is taken. There are no operand dependencies.
Instruction | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
I1 | IF | ID | EX | MEM | WB | ||||
I2 | IF | ID | EX, taken | MEM | WB | ||||
I3 | IF | ID, squash | |||||||
I4 | IF, squash | ||||||||
I5 | IF | ID | EX | MEM | WB |
I2 resolves at the end of cycle 4. I3 and I4 are squashed, then target I5 is fetched in cycle 5. Only I1, I2, and I5 are useful. Their no-hazard completion is 3 + 5 - 1 = 7 cycles. The schedule needs 9, so penalty is 9 - 7 = 2 and finite-sequence CPI is 9 / 3 = 3.0.
For a long-run calculation, keep pipeline fill out of the base CPI. With base CPI 1, branch frequency 20%, prediction accuracy 90%, and a two-cycle penalty, the misprediction rate is 10%. Extra CPI is 0.20 x 0.10 x 2 = 0.04, so effective CPI is 1 + 0.04 = 1.04. If every branch instead forced a two-cycle wait, CPI would be 1 + 0.20 x 2 = 1.40.

Structural and control hazard questions: traps that lose marks
Questions ask you to identify conflicts, insert stalls, count flushes, calculate cycles, CPI, or speedup, or compare stalling with duplicated hardware. Assumptions control the answer.
Write the assumptions, mark the first conflict or resolution cell, add justified bubbles or squashes, count useful completions, then use the formula. Changed memory organisation or branch resolution changes the answer.
Avoid four common traps:
Do not call every delay a data hazard.
Do not count squashed instructions as completed instructions.
Do not assume branch penalty equals pipeline depth.
Do not mix finite-sequence
k + n - 1CPI with steady-state base CPI 1.
About 30 practice questions on COA Pipelining for Structural and Control Hazards are available. Use the Computer Organization MCQs guide for subject practice, then use the GATE Test Series for timed practice.
Structural and control hazards: the short version and next study action
Structural means a resource collision. Control means an unresolved next PC. A stall preserves an instruction but delays it. A squash discards wrong-path work.
For every numerical, write baseline cycles, stalls or flushes, useful instructions, and the requested metric. Redraw both grids. Separate instruction and data paths should give 9 cycles. Setting R5 = 9 makes the branch not taken, with no flush.
For a structured route through pipelining and the rest of computer organisation, continue with GATE Guidance by Sanchit Sir.
Keep learning
Pipelining Cross-Concept Problems: CPI, Hazards and Cache Stalls
Build one reliable cycle ledger for a five-stage pipeline, then use it to combine load-use stalls, branch penalties and cache misses without mixing units.
Structural and Control Hazards MCQs: 12 Solved Pipeline Questions with Explanations
Attempt 12 published MCQ, MSQ, and NAT problems on hazard classification, effective CPI, branch timing, prediction, and delayed branching. Each answer shows the reusable method.
Data Hazards in Pipelining: Types, Solutions and Worked Examples
Follow one three-instruction trace to see exactly when a load-use pair stalls and when ALU forwarding works. Then compare the same trace without forwarding.
Pipelining in COA: Speedup, Hazards, and Worked GATE Examples
Build a clear mental model of pipelining, then use it to solve clock-period, speedup, throughput, efficiency, and hazard questions step by step.





