ch4a- 2 ee/cs/cpe 3760 - computer organization seattle pacific university performance what...
TRANSCRIPT
Ch4a- 2EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Performance
• What differences do we see in performance?
• Almost all computers operate correctly (within reason)
• Most computers implement useful operations• This is a matter of taste...
• Computers all operate at different speeds
• Speed is the most important performance metric
• The entire point of computer hardware is to “perform”
• Operate correctly
• Implement useful operations
• Do so as fast as possible
Ch4a- 3EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Measuring speed
• Raw speed
• Ferrari wins
• Which is faster?
• School Bus: 57 MPH, 40 people
• Ferrari: 170 MPH, 2 people
• Throughput
• Ferrari: 340 passenger-MPH
• School Bus: 2280 passenger-MPH
• Other issues...
• Range, reliability, cost
Ch4a- 4EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Performance of computers
• How long does it take to run my favorite program?
• To compare two computers, we compare the execution time of the same program on the two computers
• Faster one wins
• Lower execution time is better
• Batch throughput• Response time
Ch4a- 5EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
A little background...
• The compiler converts this code into machine-language instructions
• Computer programs are (usually) written in a high-level language (e.g. C)
• The performance of a program depends on:• The number and types of instructions executed• How fast the CPU can execute those instructions
• The CPU interprets machine-language instructions and executes them
Ch4a- 6EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Tick-tock• Almost all modern computers are based on a clock
Period
• All events are controlled by and synchronized to a regular clock
• Clocks are just regular periodic waveforms
• Cycle time: time for the waveform to repeat itself
• Also known as the clock period
• Frequency: 1/Period
• Example:• 10ns clock cycle --> period = 10-8 s• Frequency 1/10ns = 1/10-8 s = 108 cycles/sec
Ch4a- 7EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Execution time
• Performance can be improved by:
• Decreasing the cycle time• Hardware solution: Use faster technology
• Decreasing the number of cycles for the program• Software: Write a better program• Hardware: Re-design CPU
• Time = cycles * cycle time
• Time = cycles / clock frequency
• Since the cycle time of a computer is constant, we can express time in terms of CPU cycles
Ch4a- 8EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Instruction execution time• Every instruction takes time to execute
• Some instructions may take more or less time than others
• The time for an instruction is expressed in terms of clock cycles
Instruction CyclesADD 1MULT 4CMP 1SUB 2
Example:
• The time to run a program depends on:
• How many instructions
• What type of instructions
• 30 ADDs and 4 MULTs --> 46 cycles
Ch4a- 9EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Average CPI
• The Cycles-Per-Instruction (CPI) varies depending on what instructions are used
• Take an Average CPI
• Cycles = Number of Instructions * Average CPI
• Average CPI should reflect the mix of instructions in the program
• A large proportion of 4-cycle MULTs should raise the CPI, a large proportion of 1-cycle ADDs should lower it
• The average should be the weighted average
Ch4a- 10
EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Weighting the average
Instruction Cycles %ADD 1 40MULT 4 10CMP 1 20SUB 2 30
Average CPI = 1 * 40% + 4 * 10% + 1 * 20% + 2 * 30% = .4 + .4 + .2 + .6 = 1.6
Average CPI = 1 * 40% + 4 * 10% + 1 * 20% + 2 * 30% = .4 + .4 + .2 + .6 = 1.6
Notice: The average CPI depends on the code we’re executing!Notice: The average CPI depends on the code we’re executing!
Example mix of instructions
Example mix of instructions
Ch4a- 11
EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
How long?
• Remember, lower is better
• Reducing any one of the three components reduces execution time
• Execution time = Cycles * Cycle Time
• Cycles = Average CPI * Instruction Count
• Execution time = Instruction Count * CPI * Cycle Time
• Cycle time - Reduced through technology change, change in CPU design
• CPI - Reduced through better code, better compiler, change in CPU design
• Instruction count - Reduced through better code, better compiler, change in CPU design
Ch4a- 12
EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
Examples
Time = CPI x Period x Instructions = 1.10 x 22ns x 4 x 108 = 9.68s
System A: 400,000,000 instr., 22ns clock and a CPI of 1.10.How long does it take to run the program on system A?
System B: 10s to run a program, 20ns clock, 400,000,000 instr.What is the CPI? CPI = Time / (Period x InstrC) = 10s / (20 x 10-9 x 4 x 108) = 1.25
System C: 3,000,000,000 instr., 2GHz clock and a CPI of 1.25.How long does it take to run the program on system C?
Period = 1/Frequency = 1/2GHz = 0.5ns = 0.5 x 10-9
Time = CPI x Period x Instructions = 1.25 x 0.5 x 10-9 x 3 x 109 = 1.875s
Ch4a- 13
EE/CS/CPE 3760 - Computer OrganizationSeattle Pacific University
ExamplesAssume an add takes 1 cycle, a mult 4 cycles, and a sub 2 cycles
Two different compilers produce the following loops for the same code:
addaddmultsubaddadd
multaddmultsub
A: B:
loop1000000times
loop1000000times
What’s the CPI?CPIA = (4 + 1 + 4 + 2)/4 = 2.75
CPIB = (1 + 1 + 4 + 2 + 1 + 1)/6 = 1.667How long does it take to run each program on a 200MHz CPU?
TimeA = CPIA x PeriodA x InstructionsA = 2.75 x 5ns x 4000000 = .0055sTimeB = CPIB x PeriodB x InstructionsB = 1.667 x 5ns x 6000000 = .0050s