Chapter 2 The Role of Performance

advertisement
Chapter 2
The Role of Performance
1
Performance
Why is some hardware better than others for
different programs?
What factors of system performance are hardware
related?
(e.g., Do we need a new machine, or a new
operating system?)
How does the machine's instruction set affect
performance?
2
Which of these airplanes has the best performance?
Airplane
Passengers
Boeing 737-100
Boeing 747
BAC/Sud Concorde
Douglas DC-8-50
Range (mi)
101
470
132
146
Speed (mph)
630
4150
4000
8720
598
610
1350
544
• The plane with the highest cruising speed is the Concorde.
• The plane with the longest range is the DC-8.
• The plane with the largest capacity is the Boeing 747.
• How much faster is the Concorde compared to the 747?
• How much bigger is the 747 than the Douglas DC-8?
3
Airplanes Example (cont.)
Airplane
Passenger Throughput
(Passengers x m.p.h)
Boeing 737-100
228,750
Boeing 747
286,700
BAC/Sud Concorde
178,200
Douglas DC-8-50
79,424
If we define performance in terms of speed, this leaves two possible
definitions:
1. Define the fastest plane as the one with the highest speed, taking
a single passenger from one point to another in the least time. The
Concorde would clearly be the fastest.
2. Define the fastest plane as the one with the highest speed, taking
450 passengers from one point to another in the least time. The
Boeing 747 would clearly be the fastest. Check the above table.
4
Computer Performance: TIME, TIME, TIME
• Response Time (latency)
— How long does it take for my job to run?
— How long does it take to execute a job?
— How long must I wait for the database query?
— The time between the start and completion of a task.
• Throughput
— How many jobs can the machine run at once?
— What is the average execution rate?
— How much work is getting done?
— The total amount of work done in a given time.
5
Example
• If we upgrade a machine with a new processor what do
we increase?
• If we add a new machine to the lab what do we increase?
• Answer:
– Case 1: Both response time and throughput are
improved.
– Case 2: No one task gets work done faster, so only
throughput increases.
But by increasing the number of processors would
reduce the waiting time in the queue, therefore response
time could improve.
6
Execution Time
• Elapsed Time
– counts everything (disk and memory accesses,
I/O , etc.)
– a useful number, but often not good for
comparison purposes
• CPU time
– doesn't count I/O or time spent running other
programs
– can be broken up into system time, and user
time
• Our focus: user CPU time
– time spent executing the lines of code that are
"in" our program
7
Example: Unix time Command
90.7u
12.9s
2:39
65%
• 90.7u : User CPU Time (seconds)
• 12.9s : System CPU Time (seconds)
• 2:39 : Elapsed Time (159 seconds)
• 65% : Percentage of Elapsed Time that is CPU Time
is (90.7 + 12.9) / 159 = 0.65
• More than a third of the elapsed time in this
example was spent waiting for I/O, running other
programs, or both.
8
Book's Definition of Performance
• For some program running on machine X,
PerformanceX = 1 / Execution timeX
• “machine X is n times faster than machine Y"
PerformanceX / PerformanceY = n
• Problem:
– machine A runs a program in 10 seconds
– machine B runs the same program in 15
seconds, how much faster is A than B?
– Answer: A is 1.5 times faster than B.
9
Clock Cycles
• Instead of reporting execution time in seconds, we often use
cycles
seconds
cycles seconds
=
×
program program cycle
• A simple formula relates the most basic metrics (clock cycles
and clock cycle time) to CPU time:
CPU execution time = CPU clock cycles X Clock cycle time
for a program
for a program
• Or, because clock rate and clock cycle time are inverses:
CPU execution time = (CPU clock cycles ) / Clock rate
for a program
10
Clock Cycles (Cont.)
• Clock “ticks” indicate when to start activities
(one abstraction):
time
• cycle time = time between ticks = seconds per cycle
• clock rate (frequency) = cycles per second
(1 Hz.= 1 cycle/sec)
1
A 200 MHz. clock has a
cycle time
200 × 106
×109 = 5 nanoseconds
11
How to Improve Performance
seconds
cycles
seconds
=
×
program program
cycle
So, hardware designer can improve performance by
reducing either the length of the clock cycle or the
number of clock cycles required for a program.
12
Example
• Our favorite program runs in 10 seconds on computer A,
which has a 400 MHz. clock. We are trying to help a
computer designer build a new machine B, that will run
this program in 6 seconds. The designer can use new (or
perhaps more expensive) technology to substantially
increase the clock rate, but has informed us that this
increase will affect the rest of the CPU design, causing
machine B to require 1.2 times as many clock cycles as
machine A for the same program. What clock rate
should we tell the designer to target?"
13
Answer
• First find the number of clock cycles required for the program
on A:
CPU timeA = (CPU clock cyclesA) / Clock rateA
10 seconds = (CPU clock cyclesA) / 400 x 106 cycles/sec
CPU clock cyclesA = 10 sec X 400 X 106 cycles/sec
= 4000 X 106 cycles
• CPU time for B can be found using this equation:
CPU timeB = (1.2 X CPU clock cyclesA) / Clock rateB
6 seconds = (1.2 X 4000 X 106 cycles) / Clock rateB
Clock rateB = (1.2 X 4000 X 106 cycles) / 6 seconds
= (800 X 106 cycles) / second = 800 MHz
Machine B must therefore have twice the clock rate of A to run
the program in 6 seconds.
14
Cycles and Instructions
• Since the compiler clearly generated
instructions to execute, and the machine
had to execute the instructions to run the
program, the execution time must depend
on the number of instructions in a program.
15
How many cycles are required for a program?
This assumption is incorrect,
...
6th
5th
4th
3rd instruction
2nd instruction
1st instruction
• Could assume that # of cycles = # of instructions
time
different instructions take different amounts of time on
different machines.
Why? hint: remember that these are machine instructions,
not lines of C code
16
Different numbers of cycles for different instructions
time
• Multiplication takes more time than addition
• Floating point operations take longer than
integer ones
• Accessing memory takes more time than
accessing registers
•
Important point: changing the cycle time often
changes the number of cycles required for various
instructions (more later)
17
CPI (clock cycles per instruction)
• The number of clock cycles required for a program
can be written as:
CPU clock cycles = Instructions X Average clock cycles
for a program
per instruction
• The term clock cycles per instruction, which is the
average number of clock cycles each instruction
takes to execute, is called CPI.
• Since different instructions may take different
amounts of time depending on what they do, CPI is
an average of all instructions executed in the
program.
18
CPI Example
• Suppose we have two implementations of the same
instruction set architecture (ISA).
For some program,
Machine A has a clock cycle time of 1 ns. and a CPI of 2.0
Machine B has a clock cycle time of 2 ns. and a CPI of 1.2
What machine is faster for this program, and by how much?
• If two machines have the same ISA which of our quantities
(e.g., clock rate, CPI, execution time, # of instructions,
MIPS) will always be identical?
19
Answer
• We know that each machine executes the same number of
instructions for the same program;
let’s call this number I
• First find the number of processor clock cycles for each
machine:
CPU clock cyclesA = I x 2.0
CPU clock cyclesB = I x 1.2
• Now we can compute the CPU time for each machine:
CPU timeA = CPU clock cyclesA x Clock cycle timeA
= I x 2.0 x 1 ns = 2 x I ns
CPU timeB = I x 1.2 x 2 ns = 2.4 x I ns
• Clearly, machine A is faster. The amount faster is given by the
ratio of the execution times:
CPU PerformanceA = Execution timeB = 2.4 x I ns = 1.2
CPU PerformanceB Execution timeA 2 x I ns
• Machine A is 1.2 times faster than machine B for this program
20
Instruction Count
• Basic Performance Equation in terms of instruction count
(the number of instructions executed by the program), CPI,
and clock cycle time:
or
CPU time = Instruction count x CPI x Clock cycle time
CPU time = (Instruction count x CPI) / Clock rate
• Execution Time = Instructions x Clock cycles x Seconds
Program
Instruction
Clock cycle
• How to find the above performance parameters?
• CPU clock cycles = Summation (CPIi x Ci)
i = 1 to n
Where Ci is the count of the number of instructions of classi
executed, CPIi is the average number of cycles per
instruction for that instruction class, and n is the number of
instruction classes.
21
Number of Instructions Example
• A compiler designer is trying to decide between
two code sequences for a particular machine.
Based on the hardware implementation, there are
three different classes of instructions: Class A,
Class B, and Class C, and they require one, two,
and three cycles (respectively).
The first code sequence has 5 instructions: 2 of A,
1 of B, and 2 of C
The second sequence has 6 instructions: 4 of A, 1
of B, and 1 of C.
Which sequence will be faster?
What is the CPI for each sequence?
22
Answer
•
•
•
•
Sequence 1 executes 2 + 1 + 2 = 5 instructions.
Sequence 2 executes 4 + 1 + 1 = 6 instructions.
So, sequence 1 executes fewer instructions.
To find the total number of clock cycles for each sequence:
CPU clock cycles = Summation (CPIi x Ci)
i = 1 to n
CPU clock cycles1 = (2x1) + (1x2) + (2x3) = 10 cycles
CPU clock cycles2 = (4x1) + (1x2) + (1x3) = 9 cycles
• So code sequence 2 is faster, even though it actually
executes one extra instruction.
• Since code sequence 2 takes fewer overall clock cycles but
has more instructions, it must have a lower CPI.
23
Answer (Cont.)
• The CPI values can be computed by:
CPI = CPU clock cycles
Instruction count
CPI1 = CPU clock cycles1 = 10 = 2
Instruction count1 5
CPI2 = CPU clock cycles2 = 9 = 1.5
Instruction count2 6
• Note: When comparing two machines, you must
look at all three components (instruction count,
CPI, and clock cycle time), which combine to form
execution time.
24
Now that we understand cycles
• A given program will require
– some number of instructions (machine instructions)
– some number of cycles
– some number of seconds
• We have a vocabulary that relates these quantities:
– cycle time (seconds per cycle)
– clock rate (cycles per second)
– CPI (cycles per instruction)
a floating point intensive application might have a
higher CPI
25
Performance
• Performance is determined by execution time
• Do any of the other variables equal performance?
– number of cycles to execute program?
– number of instructions in program?
– number of cycles per second?
– average number of cycles per instruction?
– average number of instructions per second?
• Common pitfall: thinking one of the variables is
indicative of performance when it really isn’t.
26
Benchmarks
• Performance best determined by running a real application
– Use programs typical of expected workload
– Or, typical of expected class of applications
e.g., compilers/editors, scientific applications, graphics, etc.
• Small benchmarks
– nice for architects and designers
– easy to standardize
– can be abused
• SPEC (System Performance Evaluation Cooperative)
– companies have agreed on a set of real program and inputs
– can still be abused (Intel’s “other” bug)
– valuable indicator of performance (and compiler technology)
27
SPEC ‘89
• Compiler “enhancements” and performance
800
700
SPEC performance ratio
600
500
400
300
200
100
0
gcc
e s p re s s o
s p ic e
doduc
na sa 7
li
e q n to tt
m a tr i x 3 0 0
fp p p p
to m c a tv
B e n ch m a rk
C o m p i le r
E n h a n c e d c o m p il e r
28
SPEC ’95 (8 integer followed by 10 floating-point benchmarks)
Benchmark
go
m88ksim
gcc
compress
li
ijpeg
perl
vortex
tomcatv
swim
su2cor
hydro2d
mgrid
applu
trub3d
apsi
fpppp
wave5
Description
Artificial intelligence; plays the game of Go
Motorola 88k chip simulator; runs test program
The Gnu C compiler generating SPARC code
Compresses and decompresses file in memory
Lisp interpreter
Graphic compression and decompression
Manipulates strings and prime numbers in the special-purpose programming language Perl
A database program
A mesh generation program
Shallow water model with 513 x 513 grid
quantum physics; Monte Carlo simulation
Astrophysics; Hydrodynamic Naiver Stokes equations
Multigrid solver in 3-D potential field
Parabolic/elliptic partial differential equations
Simulates isotropic, homogeneous turbulence in a cube
Solves problems regarding temperature, wind velocity, and distribution of pollutant
Quantum chemistry
Plasma physics; electromagnetic particle simulation
29
SPECint ‘95
SPEC ratio: bigger numeric results indicate faster performance
10
9
8
SPECint
7
6
5
4
3
2
1
0
50
100
150
C lo c k r a te ( M H z )
200
250
P e n tiu m
P e n tiu m P r o
Pentium Pro is 1.4 to 1.5 times faster than Pentium
30
SPECfp ‘95
SPEC ratio: bigger numeric results indicate faster performance
10
9
8
SPECfp
7
6
5
4
3
2
1
0
50
100
150
C lo c k r a te ( M H z )
200
250
P e n tiu m
P e n tiu m P r o
Pentium Pro is 1.7 to 1.8 times faster than Pentium
31
Synthetic Benchmarks
• Synthetic benchmarks are artificial programs that
are constructed to try to match the characteristics
of a large set of programs.
• Whetstone and Dhrystone are the most popular
synthetic benchmarks.
• Whetstone was based on measurements of Algol
programs in a scientific and engineering
environment. It was later converted to Fortran and
became popular.
• Dhrystone was created as benchmark for systems
programming environments. It was originally
written in Ada and later converted in C, after which
it became popular.
32
Synthetic Benchmarks Drawbacks
• One major drawback of synthetic benchmarks is
that no user would ever run a synthetic benchmark
as an application because these programs do not
compute anything a user would find remotely
interesting.
• Synthetic benchmarks are not real programs, they
usually do not reflect program behavior, other than
the behavior considered when they were created.
33
CPU Performance
• Does doubling the clock rate double the performance?
• For a given instruction set architecture, increases
in CPU performance can come from three sources:
1. Increases in clock rate
2. Improvements in processor organization that
lower the CPI
3. Compiler enhancements that lower the
instruction count or generate instructions with
a lower average CPI (e.g., by using simpler
instructions)
34
Comparing and Summarizing Performance
• Example: Execution times of 2 programs on 2
different machines
Computer A
Computer B
Program 1 (seconds)
1
10
Program 2 (seconds)
1000
100
Total time (seconds)
1001
110
• Which is best answer?
1. A is 10 times faster than B for program 1.
2. B is 10 times faster than A for program 2.
3. B is 9.1 times faster than A for programs 1 & 2.
35
Comparing Performance (Cont.)
• Answer: Best answer is
PerformanceB = Execution timeA = 1001 = 9.1
PerformanceA Execution timeB 110
• The average of the execution times that is directly
proportional to total execution time is the
arithmetic mean (AM):
AM = 1/n x Summation Timei
i = 1 to n
where Timei is the execution time for the ith
program of a total of n in the workload.
• Since it is the mean of execution times, a smaller
mean indicates a smaller average execution time
and thus improved performance.
36
Amdahl's Law
• The performance enhancement possible with a given
improvement is limited by the amount that the improved
feature is used (Amdahl’s Law).
• Execution Time After Improvement =
Execution Time Unaffected +( Execution Time Affected
/ Amount of Improvement )
• Example:
"Suppose a program runs in 100 seconds on a machine,
with multiply responsible for 80 seconds of this time.
How much do we have to improve the speed of
multiplication if we want the program to run 5 times
faster?"
37
Amdahl's Law (Cont.)
• Answer:
Execution time after improvement =
(100 – 80 seconds) + (80 seconds / n)
Since we want the performance to be 5 times
faster, the new execution time should be 20
seconds, giving:
20 seconds = (20 seconds) + (80 seconds / n)
0 = (80 seconds / n)
That is, there is no amount by which we can
enhance multiply to achieve a fivefold increase in
performance, if multiply accounts for only 80% of
the workload.
38
Amdahl's Law (Cont.)
• Amdahl’s law is given in another form that yields
the speedup.
• Speedup is the measure of how a machine
performs after some enhancement relative to how it
performed previously.
• Speedup = Performance after improvement
Performance before improvement
= Execution time before improvement
Execution time after improvement
39
MIPS (million instructions per second)
• MIPS = Instruction count / (Execution time x 106)
• Faster machines have a higher MIPS rating.
• Three problems with using MIPS:
1. MIPS specifies the instruction execution rate
but does not take into account the capabilities
of the instructions. We cannot compare
computers with different instruction sets.
2. MIPS varies between programs on the same
computer; thus a machine cannot have a single
MIPS rating for all programs.
3. MIPS can vary inversely with performance.
40
MIPS Example
• Two different compilers are being tested for a 500 MHz. machine
with three different classes of instructions: Class A, Class B,
and Class C, which require one, two, and three cycles (CPI)
respectively. Both compilers are used to produce code for a
large piece of software.
The first compiler's code uses 5 billion Class A instructions, 1
billion Class B instructions, and 1 billion Class C instructions.
The second compiler's code uses 10 billion Class A
instructions, 1 billion Class B instructions, and 1 billion Class C
instructions.
• Which sequence will be faster according to MIPS?
• Which sequence will be faster according to execution time?
41
MIPS Example (Answer)
• First we find the execution time for the 2 different
compiles using the following equation:
Execution time = CPU clock cycles / Clock rate
where CPU clock cycles = Summation (CPIi x Ci)
i = 1 to n
CPU clock cycles1 = (5x1+1x2+1x3)x109 = 10 x 109
CPU clock cycles2 = (10x1+1x2+1x3)x109 = 15 x 109
Now, we find the execution time for the 2 compiles:
Execution time1 = (10 x 109) / (500 x 106) = 20 seconds
Execution time2 = (15 x 109) / (500 x 106) = 30 seconds
• So, we conclude that compiler 1 generates the faster
program, according to execution time.
42
MIPS Example (Answer Cont.)
• Now let’s compute the MIPS rate for each version
of the program, using:
MIPS = (Instruction count) / (Execution time x 106)
MIPS1 = ((5+1+1) x 109) / (20 x 106) = 350
MIPS2 = ((10+1+1) x 109) / (30 x 106) = 400
• So, the code from compiler 2 has a higher MIPS
rating, but the code from compiler 1 runs faster!
• From the above example, MIPS fails to give a true
picture of performance; even when comparing 2
versions of the same program from 2 different
compilers on the same machine
43
MFLOPS as a Performance Metric
• MFLOPS (megaFLOPS): million floating-point
operations per second.
• MFLOPS = Number of floating-point operations in a program
Execution time x 106
• A floating-point is an addition, subtraction, multiplication, or
division operation applied to a number in a single or double
precision floating-point representation (key words: float, real,
double…).
• MFLOPS rating is dependent on the program. That is, different
programs require the execution of different number of floatingpoint operations.
• Compilers have a MFLOPS rating near to zero no matter how fast
the machine is, because compilers rarely use floating-point
arithmetic.
44
Remember
• Performance is specific to a particular program/s
– Total execution time is a consistent summary of
performance
• For a given architecture performance increases come from:
– increases in clock rate
– improvements in processor organization that lower CPI
– compiler enhancements that lower CPI and/or
instruction count
• Pitfall: expecting improvement in one aspect of a
machine’s performance to affect the total performance
45
Performance versus Cost
• All computer designers must balance performance
and cost.
• Performance is the primary goal and cost is
secondary.
• The cost of a machine is affected not only by the
cost of the components, but by the costs of labor
to assemble the machine, of research and
development overhead, of sales and marketing,
and of the profit margin.
• Computer designs will always be measured by cost
and performance, and finding the best balance will
always be the art of computer design.
46
Download