Resolving Structural Hazards
What you'll learn: How to eliminate structural hazards using stalling, resource duplication, and separate memories.
The Core Problem
You've learned that structural hazards occur when multiple pipeline stages need the same hardware resource simultaneously. Now you need practical solutions to prevent these conflicts from breaking your pipeline.
Three Key Solutions
1. Stalling (Pipeline Bubble)
The simplest solution: when a conflict is detected, pause one instruction until the resource becomes available. This inserts a "bubble" or no-op cycle into the pipeline.
Analogy: Like waiting for someone to finish using the bathroom before you can enter—simple but slows everyone down.
Cost: Reduces throughput since the pipeline can't operate at full capacity during stalls.
2. Resource Duplication
Add more hardware! If two stages need the same resource, build two copies.
Example: Instead of one ALU shared between execute and memory stages, provide separate ALUs for each stage.
Analogy: Installing multiple bathrooms in a house—more expensive upfront, but no waiting.
Tradeoff: Costs more in chip area and power, but maintains maximum throughput.
3. Separate Instruction and Data Memories
One common structural hazard occurs when the fetch stage needs to read an instruction while the memory stage accesses data—both competing for the same memory port.
Solution: Use a Harvard architecture with physically separate instruction and data memories (or separate caches).
Benefit: Fetch and memory-access stages can proceed simultaneously without conflict.
Choosing the Right Approach
- Stalling: Used when conflicts are rare
- Duplication: Used for frequently-contested, small resources
- Separate memories: Standard in modern pipelined processors
Key Takeaway: Structural hazards are resolved through stalling (accepting performance loss), resource duplication (spending area/power), or architectural changes like split instruction/data memories—each solution balances cost against pipeline efficiency.