S4 · Lesson 9 · Dynamic scheduling
Data hazards, register renaming, reservation stations, the common data bus, and the window Little's law demands
An in-order pipeline stops at the first instruction whose operands aren't ready, even when the next ten instructions are independent and could run. Dynamic scheduling lets those instructions go ahead: they wait in reservation stations until their operands arrive, then execute in whatever order their data allows. Robert Tomasulo's algorithm for the IBM 360/91 floating-point unit (1967) did this with three ideas that every out-of-order core still uses: renaming registers to tags so only true dependences remain, reservation stations that capture operands as they're produced, and a common data bus that broadcasts each result to everyone waiting for it.
- The IPC an out-of-order core can sustain against the size of its instruction window, W, when instructions take L cycles on average from entering the window to completing (long-latency loads included) and the core can issue w per cycle.
- By Little's law, the window holds instructions, so IPC can't exceed W/L. It also can't exceed the width w.
- The knee is at . Raise the average latency, as cache misses do, and the window needed to stay at full width grows in proportion.
Predict
A 4-wide out-of-order core sees an average of 30 cycles from dispatch to completion per instruction, counting cache misses. Its window holds 64 instructions. What IPC can it sustain at best?
2.13. Little's law says the number of instructions in flight equals throughput times latency, so 64 = IPC × 30 gives IPC = 2.13. To sustain all 4 per cycle it would need a 120-entry window. That's why windows grew from tens to hundreds of entries as memory latency grew in cycles.
Name it
Dependences and hazards
- RAW (read after write): a true dependence; the consumer needs the producer's value.
- WAR (write after read) and WAW (write after write): name dependences, caused only by reusing a register name. They disappear if each new value gets a fresh name.
Tomasulo's algorithm
- Issue: take the next instruction in order; if a reservation station is free, put it there. For each source register, copy the value if it's ready, or else the tag of the station that will produce it. Record this station as the register's future producer (renaming: later readers wait for this tag, and WAR and WAW vanish).
- Execute: when all operands are present, start on a functional unit, oldest first.
- Write result: broadcast the value and its tag on the common data bus (CDB). Every station and register waiting for that tag captures it.
Loads and stores use address buffers and must respect memory dependences: a load can't pass an earlier store to the same address.
Sizing the machine
- Little's law: instructions in flight = IPC × average latency. A window of W entries sustains at most IPC.
- Reservation stations per unit: about (issue rate to that unit) × (its latency + waiting time).
- Physical registers with renaming: the architectural ones plus one per in-flight instruction that writes a register.
- The CDB carries one result per bus per cycle: with c buses and a fraction of instructions producing a result, IPC ≤ .
Worked example
A 6-wide core averages 40 cycles of latency per instruction. How big must its window be for full width, and what IPC does a 224-entry window allow? How many physical registers does it need if 75% of instructions write one of 32 architectural registers?
Show the solution
- Window for full width.
- IPC with 224 entries.
- Physical registers. Machines add a few more so renaming never stalls.
Answer full width needs a 240-entry window; 224 entries allow an IPC of 5.6 and need about 200 physical registers.
Worked example
Two iterations of fld f0, 0(x1), fmul f4, f0, f2, fsd f4, 0(x1), addi x1, x1, 8: which hazards does Tomasulo remove?
Show the solution
- Within an iteration. fmul waits for fld (RAW on f0) and fsd waits for fmul (RAW on f4). Those are real dependences.
- Between iterations. The second fld writes f0 while the first fmul may still need the old f0 (WAR), and the second fmul writes f4 like the first (WAW).
- Renaming. Tomasulo gives each f0 and f4 its own station tag, so the second load can issue and execute while the first multiply is still running.
- The result. The loop overlaps itself, which in-order issue couldn't do.
Answer Tomasulo removes the WAR hazard on f0 and the WAW hazard on f4 between iterations; the RAW hazards on f0 and f4 within each iteration remain.
Worked example
A core has 2 common data buses, and 70% of its instructions produce a register result. Its floating-point multiplier takes 4 cycles, receives one instruction a cycle, and each waits about 2 cycles for operands. What IPC can the buses carry, and how many reservation stations does the multiplier need?
Show the solution
- Bus limit. Each bus carries one result a cycle, and 70% of instructions need one:
- Multiplier stations. Each station holds an instruction for its wait plus its latency, so by Little's law:
- Sizing. Too few stations stall issue; too many waste area and wake-up power.
Answer the buses carry an IPC of at most 2.86, and the multiplier needs about 6 reservation stations.
Check
A 4-wide core averages 15 cycles from dispatch to completion. What window does it need to sustain full width?
Check
An 8-wide core has a 128-entry window and averages 20 cycles of latency per instruction. What IPC can it sustain at most?
Check
A core with 32 architectural registers keeps 96 instructions in flight, 0.8 of which write a register. How many physical registers does renaming need?
Check
A Tomasulo machine has 2 common data bus(es), each carrying one result per cycle, and 0.6 of instructions produce a result. What IPC does the CDB allow at most?
Check
A multiplier receives 1 instructions per cycle on average. Each spends 4 cycles waiting for operands and 3 cycles executing. How many reservation stations does it need on average?
Check
A chain of 3 dependent multiplies each executes in 4 cycles and then takes 1 cycle to broadcast its result on the CDB before the next can start. How many cycles from the first starting to execute to the last result's broadcast?
Check
A 6-wide out-of-order core averages 20 cycles of latency per instruction; 0.8 of instructions write one of 32 architectural registers, and it has 3 common data buses.
(a)
How big must its window be to sustain full width?
(b)
How many physical registers does that window need?
(c)
What IPC can its result buses carry?
Check
An out-of-order window holds W instructions, each staying L cycles on average.
Step 1
What is the highest IPC it can sustain?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How big a window does an IPC of i need?
Explain why
Why does register renaming remove WAR and WAW hazards but not RAW hazards?
A RAW hazard is a real flow of data: the second instruction needs the value the first one computes, so it can't execute until that value exists, whatever the value is called. WAR and WAW hazards exist only because two different values happen to be assigned to the same register name: a later instruction wants to write the name while an earlier one still needs to read the old value, or two writes must land in order so the right one remains. If every new value gets its own storage, a reservation-station tag or a physical register, the two values no longer share a location, so neither can disturb the other, and only the true data dependences are left to order execution.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.