Performance ICS 233 Computer Architecture and Assembly Language

Performance ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals [Adapted from slides of Dr. M. Mudawar, ICS 233, KFUPM]

Outline v Response Time and Throughput v Performance and Execution Time v Clock Cycles Per Instruction (CPI) v Single- vs. Multi-cycle CPU Performance v Amdahl’s Law v Benchmarks Performance ICS 233 – KFUPM © Muhamed Mudawar slide 2

What is Performance? v How can we make intelligent choices about computers? v Why some computer hardware performs better at some programs, but performs less at other programs? v How do we measure the performance of a computer? v What factors are hardware related? software related? v How does machine’s instruction set affect performance? v Understanding performance is key to understanding underlying organizational motivation Performance ICS 233 – KFUPM © Muhamed Mudawar slide 3

Response Time and Throughput v Response Time ² Time between start and completion of a task, as observed by end user ² Response Time = CPU Time + Waiting Time (I/O, OS scheduling, etc. ) v Throughput ² Number of tasks the machine can run in a given period of time v Decreasing execution time improves throughput ² Example: using a faster version of a processor ² Less time to run a task more tasks can be executed v Increasing throughput can also improve response time ² Example: increasing number of processors in a multiprocessor ² More tasks can be executed in parallel ² Execution time of individual sequential tasks is not changed ² But less waiting time in scheduling queue reduces response time Performance ICS 233 – KFUPM © Muhamed Mudawar slide 4

Book’s Definition of Performance v For some program running on machine X Performance. X = 1 Execution time. X v X is n times faster than Y Performance. X Performance. Y Performance ICS 233 – KFUPM = Execution time. Y Execution time. X © Muhamed Mudawar slide 5 =n

What do we mean by Execution Time? v Real Elapsed Time ² Counts everything: § Waiting time, Input/output, disk access, OS scheduling, … etc. ² Useful number, but often not good for comparison purposes v Our Focus: CPU Execution Time ² Time spent while executing the program instructions ² Doesn't count the waiting time for I/O or OS scheduling ² Can be measured in seconds, or ² Can be related to number of CPU clock cycles Performance ICS 233 – KFUPM © Muhamed Mudawar slide 6

Clock Cycles v Clock cycle = Clock period = 1 / Clock rate Cycle 1 Cycle 2 Cycle 3 v Clock rate = Clock frequency = Cycles per second ² 1 Hz = 1 cycle/sec 1 KHz = 103 cycles/sec ² 1 MHz = 106 cycles/sec 1 GHz = 109 cycles/sec ² 2 GHz clock has a cycle time = 1/(2× 109) = 0. 5 nanosecond (ns) v We often use clock cycles to report CPU execution time CPU Execution Time = CPU cycles × cycle time = Performance ICS 233 – KFUPM © Muhamed Mudawar slide 7 CPU cycles Clock rate

Improving Performance v To improve performance, we need to ² Reduce number of clock cycles required by a program, or ² Reduce clock cycle time (increase the clock rate) v Example: ² ² ² A program runs in 10 seconds on computer X with 2 GHz clock What is the number of CPU cycles on computer X ? We want to design computer Y to run same program in 6 seconds But computer Y requires 10% more cycles to execute program What is the clock rate for computer Y ? v Solution: ² CPU cycles on computer X = 10 sec × 2 × 109 cycles/s = 20 × 109 ² CPU cycles on computer Y = 1. 1 × 20 × 109 = 22 × 109 cycles ² Clock rate for computer Y = 22 × 109 cycles / 6 sec = 3. 67 GHz Performance ICS 233 – KFUPM © Muhamed Mudawar slide 8

Clock Cycles Per Instruction (CPI) v Instructions take different number of cycles to execute ² Multiplication takes more time than addition ² Floating point operations take longer than integer ones ² Accessing memory takes more time than accessing registers v CPI is an average number of clock cycles per instruction I 1 1 I 2 2 3 I 3 4 5 6 I 4 I 5 7 8 9 I 6 CPI = 14/7 = 2 I 7 10 11 12 13 14 cycles v Important point Changing the cycle time often changes the number of cycles required for various instructions (more later) Performance ICS 233 – KFUPM © Muhamed Mudawar slide 9

Performance Equation v To execute, a given program will require … ² Some number of machine instructions ² Some number of clock cycles ² Some number of seconds v We can relate CPU clock cycles to instruction count CPU cycles = Instruction Count × CPI v Performance Equation: (related to instruction count) Time = Instruction Count × CPI × cycle time Performance ICS 233 – KFUPM © Muhamed Mudawar slide 10

Factors Impacting Performance Time = Instruction Count × CPI × cycle time I-Count CPI Program X X Compiler X X ISA X X X Organization Technology Performance ICS 233 – KFUPM Cycle X © Muhamed Mudawar slide 11

Using the Performance Equation v Suppose we have two implementations of the same ISA v For a given program ² Machine A has a clock cycle time of 250 ps and a CPI of 2. 2 ² Machine B has a clock cycle time of 500 ps and a CPI of 1. 0 ² Which machine is faster for this program, and by how much? v Solution: ² Both computers execute same count of instructions = I ² CPU execution time (A) = I × 2. 2 × 250 ps = 550 × I ps ² CPU execution time (B) = I × 1. 0 × 500 ps = 500 × I ps ² Computer B is faster than A by a factor = Performance ICS 233 – KFUPM © Muhamed Mudawar slide 12 550 × I 500 × I = 1. 1

Determining the CPI v Different types of instructions have different CPI Let CPIi = clocks per instruction for class i of instructions Let Ci = instruction count for class i of instructions n ∑ (CPI × C ) i n CPU cycles = ∑ (CPI × C ) i i i=1 CPI = i i=1 n ∑C i i=1 v Designers often obtain CPI by a detailed simulation v Hardware counters are also used for operational CPUs Performance ICS 233 – KFUPM © Muhamed Mudawar slide 13

Example on Determining the CPI v Problem 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 per instruction, 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 Compute the CPU cycles for each sequence. Which sequence is faster? What is the CPI for each sequence? v Solution CPU cycles (1 st sequence) = (2× 1) + (1× 2) + (2× 3) = 2+2+6 = 10 cycles CPU cycles (2 nd sequence) = (4× 1) + (1× 2) + (1× 3) = 4+2+3 = 9 cycles Second sequence is faster, even though it executes one extra instruction CPI (1 st sequence) = 10/5 = 2 Performance ICS 233 – KFUPM CPI (2 nd sequence) = 9/6 = 1. 5 © Muhamed Mudawar slide 14

Second Example on CPI Given: instruction mix of a program on a RISC processor What is average CPI? What is the percent of time used by each instruction class? Classi Freqi CPIi × Freqi %Time ALU 50% Load 20% Store 10% Branch 0. 5× 1 = 0. 5 0. 2× 5 = 1. 0 0. 1× 3 = 0. 3 0. 2× 2 = 0. 4 0. 5/2. 2 = 23% 1. 0/2. 2 = 45% 0. 3/2. 2 = 14% 0. 4/2. 2 = 18% 1 5 3 20% 2 Average CPI = 0. 5+1. 0+0. 3+0. 4 = 2. 2 How faster would the machine be if load time is 2 cycles? What if two ALU instructions could be executed at once? Performance ICS 233 – KFUPM © Muhamed Mudawar slide 15

Single- vs. Multi-cycle CPU v Drawbacks of Single Cycle Processor: Long cycle time ² All instructions take as much time as the slowest ALU Instruction Fetch Reg Read ALU Reg Write longest delay Load Instruction Fetch Reg Read ALU Memory Read Store Instruction Fetch Reg Read ALU Memory Write Branch Instruction Fetch Reg Read ALU Jump Instruction Fetch Decode v Alternative Solution: Multicycle implementation ² Break down instruction execution into multiple cycles Performance ICS 233 – KFUPM © Muhamed Mudawar slide 16 Reg Write

Single- vs. Multi-cycle CPU v Break instruction execution into five steps ² Instruction fetch ² Instruction decode and register read ² Execution, memory address calculation, or branch completion ² Memory access or ALU instruction completion ² Load instruction completion v One step = One clock cycle (clock cycle is reduced) ² First 2 steps are the same for all instructions Performance Instruction # cycles ALU & Store 4 Branch 3 Load 5 Jump 2 ICS 233 – KFUPM Instruction © Muhamed Mudawar slide 17 # cycles

Single- vs. Multi-cycle Performance v Assume the following operation times for components: ² Instruction and data memories: 200 ps ² ALU and adders: 180 ps ² Decode and Register file access (read or write): 150 ps ² Ignore the delays in PC, mux, extender, and wires v Which of the following would be faster and by how much? ² Single-cycle implementation for all instructions ² Multicycle implementation optimized for every class of instructions v Assume the following instruction mix: ² 40% ALU, 20% Loads, 10% stores, 20% branches, & 10% jumps Performance ICS 233 – KFUPM © Muhamed Mudawar slide 18

Single- vs. Multi-cycle Performance Instruction Class Instruction Memory Register Read ALU Operation Data Memory Register Write Total ALU 200 150 180 150 680 ps Load 200 150 180 200 150 880 ps Store 200 150 180 200 Branch 200 150 180 530 ps Jump 200 150 decode and update PC 350 ps 730 ps v For fixed single-cycle implementation: ² Clock cycle = 880 ps determined by longest delay (load instruction) v For multi-cycle implementation: ² Clock cycle = max (200, 150, 180) = 200 ps (maximum delay at any step) ² Average CPI = 0. 4× 4 + 0. 2× 5 + 0. 1× 4+ 0. 2× 3 + 0. 1× 2 = 3. 8 v Speedup = 880 ps / (3. 8 × 200 ps) = 880 / 760 = 1. 16 Performance ICS 233 – KFUPM © Muhamed Mudawar slide 19

Amdahl’s Law v Amdahl's Law is a measure of Speedup ² How a computer performs after an enhancement E ² Relative to how it performed previously Performance with E Speedup(E) = = Performance before Ex. Time with E v Enhancement improves a fraction f of execution time by a factor s and the remaining time is unaffected Ex. Time with E = Ex. Time before × (f /s + (1 – f )) Speedup(E) = Performance ICS 233 – KFUPM 1 (f /s + (1 – f )) © Muhamed Mudawar slide 20

Example on Amdahl's Law v Suppose a program runs in 100 seconds on a machine, with multiply instruction 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 4 times faster? v Solution: suppose we improve multiplication by a factor s 25 sec (4 times faster) = 80 sec / s + 20 sec s = 80 / (25 – 20) = 80 / 5 = 16 Improve the speed of multiplication by s = 16 times v How about making the program 5 times faster? 20 sec ( 5 times faster) = 80 sec / s + 20 sec s = 80 / (20 – 20) = ∞ Impossible to make 5 times faster! Performance ICS 233 – KFUPM © Muhamed Mudawar slide 21

Benchmarks v Performance best obtained by running a real application ² Use programs typical of expected workload ² Representatives of expected classes of applications ² Examples: compilers, editors, scientific applications, graphics, . . . v SPEC (System Performance Evaluation Corporation) ² Funded and supported by a number of computer vendors ² Companies have agreed on a set of real programs and inputs ² Various benchmarks for … CPU performance, graphics, high-performance computing, clientserver models, file systems, Web servers, etc. ² Valuable indicator of performance (and compiler technology) Performance ICS 233 – KFUPM © Muhamed Mudawar slide 22

The SPEC CPU 2000 Benchmarks 12 Integer benchmarks (C and C++) 14 FP benchmarks (Fortran 77, 90, and C) Name Description gzip vpr gcc mcf crafty parser eon perlbmk gap vortex bzip 2 twolf Compression FPGA placement and routing GNU C compiler Combinatorial optimization Chess program Word processing program Computer visualization Perl application Group theory, interpreter Object-oriented database Compression Place and route simulator wupwise swim mgrid applu mesa galgel art equake facerec ammp lucas fma 3 d sixtrack apsi Quantum chromodynamics Shallow water model Multigrid solver in 3 D potential field Partial differential equation Three-dimensional graphics library Computational fluid dynamics Neural networks image recognition Seismic wave propagation simulation Image recognition of faces Computational chemistry Primality testing Crash simulation using finite elements High-energy nuclear physics Meteorology: pollutant distribution v Wall clock time is used as metric v Benchmarks measure CPU time, because of little I/O Performance ICS 233 – KFUPM © Muhamed Mudawar slide 23

SPEC ratio = Execution time is normalized relative to Sun Ultra 5 (300 MHz) SPEC rating = Geometric mean of SPEC ratios SPEC 2000 Ratings (Pentium III & 4) Performance 1400 Note the relative positions of the CINT and CFP 2000 curves for the Pentium III & 4 1200 Pentium 4 CFP 2000 1000 Pentium 4 CINT 2000 800 600 Pe ntium III CINT 2000 400 Pentium III CFP 2000 200 Pentium III does better at the integer benchmarks, while Pentium 4 does better at the floating-point benchmarks due to its advanced SSE 2 instructions 0 500 1000 1500 2000 Clock rate in MHz ICS 233 – KFUPM © Muhamed Mudawar slide 24 2500 3000 3500

Things to Remember v Performance is specific to a particular program ² Any measure of performance should reflect execution time ² Total execution time is a consistent summary of performance v For a given ISA, performance improvements come from ² Increases in clock rate (without increasing the CPI) ² Improvements in processor organization that lower CPI ² Compiler enhancements that lower CPI and/or instruction count ² Algorithm/Language choices that affect instruction count v Pitfalls (things you should avoid) ² Using a subset of the performance equation as a metric ² Expecting improvement of one aspect of a computer to increase performance proportional to the size of improvement Performance ICS 233 – KFUPM © Muhamed Mudawar slide 25
- Slides: 25