When a machine is pipelined, the overlapped execution of instructions
requires pipelining of functional units and duplication of resources to
allow all posible combinations of instructions in the pipeline.
If some combination of instructions cannot be accommodated because
of a resource conflict, the machine is said
to have a structural hazard.
Common instances of structural hazards arise when
Example1:Some functional unit is not fully pipelined. Then a sequence of instructions using that unpipelined unit cannot proceed at the rate of one per clock cycle
Some resource has not been duplicated enough to allow all combinations of instructions in the pipeline to execute.
Example2:
a machine has shared a single-memory pipeline for data and instructions.
As a result, when an instruction contains a data-memory reference(load),
it
will conflict with the instruction reference for a later instruction (instr
3):
| Clock cycle number | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Instr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ||
| Load | IF | ID | EX | MEM | WB | |||||
| Instr 1 | IF | ID | EX | MEM | WB | |||||
| Instr 2 | IF | ID | EX | MEM | WB | |||||
| Instr 3 | IF | ID | EX | MEM | WB | |||||
| Clock cycle number | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Instr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
| Load | IF | ID | EX | MEM | WB | |||||
| Instr 1 | IF | ID | EX | MEM | WB | |||||
| Instr 2 | IF | ID | EX | MEM | WB | |||||
| Stall | bubble | bubble | bubble | bubble | bubble | |||||
| Instr 3 | IF | ID | EX | MEM | WB | |||||
To simplify the picture it is also commonly shown like this:
| Clock cycle number | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Instr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
| Load | IF | ID | EX | MEM | WB | |||||
| Instr 1 | IF | ID | EX | MEM | WB | |||||
| Instr 2 | IF | ID | EX | MEM | WB | |||||
| Instr 3 | stall | IF | ID | EX | MEM | WB | ||||
To reduce cost. For example, machines that support both an instruction and a cache access every cycle (to prevent the structural hazard of the above example) require at least twice as much total memory.
To reduce the latency of the unit. The shorter latency comes from the lack of pipeline registers that introduce overhead.