Performance: CPU Time and Amdahl's Law
An architect compares designs before they exist. Two small equations do most of that work. One gives the time of a program, and one limits every speed-up.
You Will Be Able To
- Work out CPU time from the instruction count, the CPI and the clock period.
- Compare two designs by the time of one program, not by one number.
- Use Amdahl's law to find the worth of a speed-up, and its limit.
- Lesson
- S1.5
- Time
- 22 min
- Runs on
- Your browser
- Check
- 5 questions
A team makes one unit of its chip four times faster. The job that uses the unit finishes less than twice as fast. Nothing is broken.
Before You Start
You need the fetch, decode and execute loop from S0.6: a processor runs one instruction after another. You need the design flow of S1.4, where the architect decides first.
| Question | |
|---|---|
| 1 | Which three numbers give the time a program takes? |
| 2 | Why is a faster clock not always a faster chip? |
| 3 | What is a speed-up? |
| 4 | If one part of a job gets faster, how much faster is the whole job? |
| 5 | What is the most that any speed-up of one part can buy? |
The Idea: Time Is the Measure
The architect of S1.4 must choose between designs that are still on paper. Which processor? How fast a clock? Is a special block worth building? Each choice needs a number.
For speed, that number is time: how long the chip takes to finish a real job. Everything else is a part of that time, and a part can mislead.
Two equations carry most of the load. The first splits the time of a program into three factors. The second says what happens when you improve only a part of a job. Both fit on one line.
New Words
| Word | Meaning |
|---|---|
| CPU | Central processing unit: another name for the processor. |
| CPU time | The time the processor spends running one program. |
| Instruction count | The number of instructions the processor executes to finish the program. |
| CPI | Cycles per instruction: the clock cycles of a program, divided by the instructions it executes. |
| Nanosecond (ns) | One thousand-millionth of a second. |
| Megahertz (MHz) | One million clock cycles in each second. A clock of 100 MHz has a period of 10 ns. |
| Speed-up | The old time divided by the new time. A speed-up of 2 means half the time. |
| Amdahl's law | The rule that the untouched part of a job limits the speed-up of the whole job. |
One more name: the time of one clock cycle is the clock period, as in S1.2.
One Picture: Where the Time Goes
- Processor
- Memory
- Peripheral
- Before
The job takes 260 cycles. The sum is the larger part: 160 of them.
- After
The unit is 4 times faster, so the sum takes 40 cycles. The copy still takes 100.
- What is left
The part that did not change is now the larger part. More speed in the unit would buy little.
Read the diagram as text
- Before: 260 cycles: the whole job, with the slow unit
- Copy: 100: part 1, one word in each cycle
- Sum: 160: part 2, four cycles for each word
- After: 140 cycles: the whole job, with the fast unit
- Copy: 100: part 1, untouched
- Sum: 40: part 2, one cycle for each word
- Before: 260 cycles → Copy: 100: part 1
- Copy: 100 → Sum: 160: part 2
- After: 140 cycles → Copy: 100: part 1
- Copy: 100 → Sum: 40: part 2
Built from the recorded cycle counts of the lab.
Keep this picture in mind for the second half of the page. First comes the equation for one program.
The Smallest Example, Worked by Hand: Three Numbers
A program executes 1000 instructions. On this processor an instruction takes 1.5 clock cycles on average. The clock of ap_soc runs at 100 MHz, so its period is 10 ns.
| Step | Sum | Result |
|---|---|---|
| Clock cycles | 1000 instructions x 1.5 cycles each | 1500 cycles |
| CPU time | 1500 cycles x 10 ns | 15,000 ns |
Now a designer offers a change. The clock period falls to 8 ns. To reach that, some instructions need an extra cycle, and the CPI rises to 2.
| Design | Instructions | CPI | Period | CPU time |
|---|---|---|---|---|
| A | 1000 | 1.5 | 10 ns | 15,000 ns |
| B | 1000 | 2 | 8 ns | 16,000 ns |
Exercise numbers. The 100 MHz clock is the fast clock of ap_soc.
Design B has the faster clock, 125 MHz against 100 MHz. It is also the slower chip. Its extra cycles cost more than its shorter period saves.
The Rules
Rule 1: CPU time is instruction count, times CPI, times clock period.
The program sets the first factor. The processor design sets the second. The circuit sets the third.
Rule 2: Compare designs by the time of the same program.
One factor alone can mislead. A higher clock rate with a higher CPI can be slower.
Rule 3: Speed-up is the old time divided by the new time.
It is a ratio of whole times, measured on the whole job.
Rule 4: A faster part shrinks only its own share.
New time is the untouched time, plus the improved time divided by its factor. This is Amdahl's law.
Rule 5: The untouched part sets the limit.
Even an endlessly fast part leaves the untouched time. The speed-up can never pass the old time divided by it.
Sources for These Rules
The CPU time equation and its three factors: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 1.6.
Amdahl's law, and the mistake of expecting one improved part to speed up the whole: the same book, section 1.10.
The 100 MHz clock of ap_soc is a choice of this course. The other numbers of the worked example are exercise numbers.
Now Run It: Count the Cycles
The lab at the end of this page runs a job in two parts and counts clock cycles. Part 1 copies 100 words, one in each cycle. Part 2 adds up 40 words in a unit that needs four cycles for each.
part 1, copy: 100 cycles
part 2, sum: 160 cycles (40 words, 4 each)
sum=780
total: 260 cyclesNow the team makes the unit four times faster: one cycle for each word. Before running it, apply rule 4 by hand.
| Quantity | Sum | Result |
|---|---|---|
| Untouched part | the copy | 100 cycles |
| Improved part | 160 cycles / 4 | 40 cycles |
| New time | 100 + 40 | 140 cycles |
| Speed-up | 260 / 140 | about 1.86 |
| Limit | 260 / 100 | 2.6 |
part 1, copy: 100 cycles
part 2, sum: 40 cycles (40 words, 1 each)
sum=780
total: 140 cyclesRule 4 at work: the lab counts 140 cycles, as predicted. A unit that is 4 times faster made the job about 1.86 times faster.
Rule 5 at work: the copy alone takes 100 cycles. No unit, however fast, brings this job under 100. The best possible speed-up is 2.6.
In real time, 260 cycles of a 10 ns clock are 2600 ns, and 140 cycles are 1400 ns. Rule 1 turns cycles into time.
The lab leaves things out. Its two parts are test code, not a processor running instructions. The cycle counts are exact for this model only.
Why It Is Built This Way
| Habit | The alternative | What the habit buys, and costs |
|---|---|---|
| Measure whole jobs | Quote one factor, such as the clock rate | An honest comparison. You need a real program to measure. |
| Improve the largest part first | Improve the part that is easiest | The most speed-up for the work. The largest part is often the hardest. |
| Work out the limit before building | Build, then measure | A block that cannot pay back is never built. The estimate needs a measured split of the time. |
The Trap: "Four Times Faster"
Return to the opening. The team reported "the unit is four times faster", and that was true. The customer heard "the chip is four times faster". The job improved by 1.86.
After the change the split has moved. The copy is now 100 cycles of 140. Doubling the speed of the unit again would save only 20 cycles.
The cure is two questions before any speed-up. What share of the time does this part take? And what will the largest part be afterwards?
At Scale
This section looks ahead. The lab split a job into two parts by hand. On a real chip the split must be measured.
The CPI is measured, not guessed
Module S2 builds a processor and counts its cycles. S2.23 measures one program on three of them.
The period comes from the circuit
The longest path of logic sets the shortest clock period. S2.6 finds that path.
The split comes from counters
Chips carry counters that record where cycles go. S8.6 reads them.
Standard programs
Teams agree on a fixed set of programs to time, so that two chips can be compared fairly.
Try It
Run the lab. Check that the two parts add up to the total.
Set STEPS to 1. Work out the total with rule 4 before you run it.
Keep STEPS at 4 and change the copy to 20 words. Work out the new limit of the speed-up.
part 1, copy: 100 cycles part 2, sum: 160 cycles (40 words, 4 each) sum=780 total: 260 cyclesCheck Yourself
Common Mistakes
Wrong Call the chip with the higher clock rate the faster chip.
A shorter period can come with more cycles for each instruction.
Fix Multiply all three factors, for the same program.
Wrong Quote the speed-up of a part as the speed-up of the job.
The rest of the job takes as long as before.
Fix Add the untouched time, then divide old time by new time.
Wrong Keep speeding up the same part.
After each gain it is a smaller share, and the limit is near.
Fix Find the largest part again after every change.
Remember
- CPU time is instruction count, times CPI, times clock period.
- Compare designs by whole times for the same program.
- Speed-up is old time divided by new time.
- A faster part shrinks only its own share of the time.
- The untouched part limits every speed-up.