S4 · Lesson 1 · Performance and the iron law
Execution time from instruction count, CPI and clock rate, benchmarks, and the memory wall
Computer architecture is the art of spending a transistor and power budget to make programs run faster, and "faster" needs a precise meaning before any design choice can be judged. The only honest measure is the time a real program takes. That time factors into three terms (how many instructions run, how many cycles each takes on average, and how long a cycle is), and every architectural idea in this course attacks one of them, usually at some cost to another. This course builds on C8's processor and S3's hardware to the depth of a senior architecture course, using Hennessy and Patterson's quantitative approach: measure, model, then design.
- Average time per instruction against clock frequency for a core whose pipeline CPI is and which misses to main memory m times per instruction, each miss taking a fixed nanoseconds.
- The core's part, , shrinks as the clock rises, but the memory part, , doesn't, because DRAM's latency is fixed in nanoseconds.
- Raise m: past a point a faster clock barely helps. That's the memory wall, the reason a third of this course is about memory.
Predict
A core with a CPI of 1 also misses to a 100 ns memory once every 100 instructions. Its clock is raised from 1 GHz to 4 GHz. How much faster do programs run?
1.6 times. At 1 GHz each instruction averages 1 ns in the core plus 0.01 × 100 = 1 ns of memory stall: 2 ns. At 4 GHz the core part shrinks to 0.25 ns but the stall stays at 1 ns: 1.25 ns. The memory stall became 80% of the time. Architects attack it with caches, prefetching and out-of-order execution that overlaps misses with useful work.
Name it
The iron law
- Instruction count (IC): set by the program, the compiler and the ISA.
- Cycles per instruction (CPI): set by the microarchitecture and the memory system; a mix's CPI is . Its reciprocal is IPC.
- Clock period: set by the circuit design and the pipeline depth.
Improving one term often worsens another: a more powerful instruction lowers IC but may raise CPI or the period.
Memory stalls
With the miss penalty fixed in nanoseconds, its cost in cycles grows with the clock rate.
Comparing machines
- Speedup of B over A: .
- MIPS () ignores instruction count, so it can rank machines backwards.
- Benchmarks such as SPEC report each program's ratio to a reference machine, combined by the geometric mean, , the only mean whose ranking doesn't depend on which machine is the reference.
- Performance per watt matters as much as performance from phones to data centers (lesson 3).
Worked example
A program runs instructions at a CPI of 1.5 on a 2 GHz core. A new compiler cuts the instruction count by 20% but raises the CPI to 1.8. Which is faster, and which has the higher MIPS?
Show the solution
- Time with the old compiler.
- Time with the new compiler. so the new code is 4% faster.
- MIPS of each.
- Why MIPS gets it wrong. MIPS ranks them the wrong way, because it ignores the 20% fewer instructions.
Answer the new compiler's code is 4% faster (0.72 s against 0.75 s), yet the old code has the higher MIPS (1333 against 1111).
Worked example
A new machine's speed ratios on three benchmarks are 2, 1.5 and 4. What single number does SPEC report, and why not the arithmetic mean?
Show the solution
- The geometric mean. SPEC reports the geometric mean of the ratios:
- The arithmetic mean. It is 2.5, but it gives a different ranking depending on which machine the ratios are taken against.
- Why the geometric mean is consistent. In a geometric mean of ratios the reference machine's times cancel, so the ranking doesn't depend on the reference.
- Its weakness. The geometric mean no longer corresponds to the time of any real workload.
Answer SPEC reports the geometric mean, 2.29, because unlike the arithmetic mean (2.5) it ranks machines the same whichever machine the ratios are taken against.
Worked example
A core with a base CPI of 1.0 runs at 2 GHz; 2% of its instructions miss to a memory 100 ns away. What is its CPI, and how much faster is it at 4 GHz with the same memory?
Show the solution
- CPI at 2 GHz. A 100 ns miss costs 200 cycles: which is 2.5 ns per instruction.
- CPI at 4 GHz. The same 100 ns is now 400 cycles: which is 2.25 ns per instruction.
- Compare the times. Doubling the clock buys only 11%: that's the memory wall in one line.
Answer the CPI is 5.0 at 2 GHz; at 4 GHz it rises to 9.0, and the core is only 11% faster.
Check
A program runs 2 billion instructions at a CPI of 0.8 on a 3 GHz core. How long does it take?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
Check
A program is 0.5 ALU instructions at CPI 1.2, 0.25 loads and stores at CPI 3, and the rest branches at CPI 3. What's its CPI?
Check
Machine A runs a program as 1 billion instructions at CPI 1.2 and 3 GHz; machine B needs 1.3 billion instructions at CPI 1.5 and 2.5 GHz. What's B's speedup over A?
Check
A core with CPI 0.8 misses 0.005 times per instruction to a 120 ns memory. Its clock goes from 2 GHz to 2× that. What's the speedup?
Check
What's the MIPS rating of a 2 GHz core with a CPI of 1.25?
Check
A machine's speed ratios on three benchmarks are 1.5, 0.8 and 6. What's the geometric mean?
Check
A program executes 1 × 10⁹ instructions at a CPI of 0.8 on a 3 GHz core.
(a)
How long does it run?
Write units the way you normally would: 1.5 s and 1500 ms are the same answer.
(b)
What MIPS rating does it get?
Check
A core with a base CPI of 0.5 misses to memory on 0.005 of its instructions; memory takes 100 ns, and the clock is 4 GHz.
(a)
What is its CPI?
(b)
How long does each instruction take on average?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
Check
A machine's speed ratios against a reference on three benchmarks are a, b and c.
Step 1
What is their geometric mean?
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
What is their arithmetic mean?
Step 3
And their harmonic mean?
Explain why
Why is execution time on real programs the only trustworthy performance measure, when clock rate, MIPS and peak FLOPS are all easier to quote?
Each of the easy numbers measures one factor of execution time and assumes the others stay fixed. Clock rate ignores how many cycles each instruction takes and how many instructions the program needs; MIPS ignores how many instructions are needed, so a machine with simpler instructions can show higher MIPS while finishing later; peak FLOPS assumes every unit is busy every cycle, which memory stalls and dependences prevent. Two designs can trade these factors against each other, so only the product, the time the program actually takes, tells which is faster. That's why architects measure real benchmarks and use the iron law to explain each result in terms of its three factors.
Practice
Keep practicing
11 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.