Pipelining introduces structural hazards when the hardware lacks sufficient resources to support simultaneous access by multiple pipeline stages. These hazards occur when instructions in different stages require the same hardware resource at the same time, and the resource cannot handle concurrent requests.
Example: Memory Access in a Von Neumann Architecture
Consider a simple 5-stage pipeline (fetch, decode, execute, memory, writeback) in a von Neumann architecture (where instructions and data share the same memory):
- Fetch Stage: Fetches the next instruction from memory.
- Memory Stage: Executes a
LOAD or STORE instruction, accessing memory for data.
If these two stages require memory access in the same clock cycle, the single memory port becomes a bottleneck. The processor cannot service both requests simultaneously, leading to a structural hazard.
Scenario:
- Cycle 1: Instruction A is fetched (fetch stage).
- Cycle 2: Instruction A enters decode; Instruction B is fetched.
- Cycle 3: Instruction A enters execute; Instruction B enters decode; Instruction C is fetched.
- Cycle 4: Instruction A enters memory stage (accessing data); Instruction B enters execute; Instruction C enters decode; Instruction D is fetched.
At Cycle 4, the fetch stage (accessing Instruction D) and memory stage (accessing data for Instruction A) both need memory. If the memory is single-ported, only one operation can proceed, causing a stall.
Why Pipelining Causes This:
Without pipelining, sequential execution would naturally avoid overlapping memory accesses. Pipelining overlaps stages, creating scenarios where resource conflicts arise if hardware is not replicated (e.g., single memory port).
Mitigation:
- Use a Harvard architecture (separate instruction/data memories).
- Add more ports or duplicate resources (e.g., multi-ported memory).
This example highlights how pipelining’s overlap of stages can expose resource limitations, leading to structural hazards.