Performance Tuning by Dijesh P

40
Faculty Development Programme on Performance Tuning Dijesh P 27 July 2012

description

 

Transcript of Performance Tuning by Dijesh P

Page 1: Performance Tuning by Dijesh P

Faculty Development Programme

on

Performance Tuning

Dijesh P

27 July 2012

Page 2: Performance Tuning by Dijesh P

Quantitative Principles of Computer Design

• The most important principle of computer design is to make the common case fast.

• That is Favor the frequent case over the infrequent case.

• Improving the frequent event over the infrequent event will help improving performance.

• Amdahl’s law can be used to quantify this principle.

Page 3: Performance Tuning by Dijesh P

Amdahl’s Law

• States that “the performance improvement to be gained from using some faster mode of execution is limited by the time the faster mode can be used”.

• Amdahl’s law defines “Speedup” that can be gained by using a particular feature.

• We can make an enhancement to a machine that will improve the performance when it is used.

Page 4: Performance Tuning by Dijesh P

• Speedup = – Performance for entire task using enhancement when

possible

– Performance for entire task without using enhancement

– Alternatively,– Speedup =

• Execution time for entire task without using enhancement

• Execution time for entire task using enhancement when possible

• Speedup tells us how much faster a task will run using the m/c with the enhancement, as opposed by the original m/c.

Page 5: Performance Tuning by Dijesh P

• Amdahl’s law gives a quick way to find the speedup from some enhancement, which depends on two factors.

• The fraction of computation time in the original machine that can be converted to take advantage of the enhancement. (Fraction will always be less than or equal to 1).

• The improvement gained by the enhanced mode of execution; that is how much faster the task would run if the enhanced mode were used for the entire program.

Page 6: Performance Tuning by Dijesh P

• Execution timenew =Execution timeold X

• (1 – Fractionenhanced) + Fractionenhanced

• Speedupenhanced

Page 7: Performance Tuning by Dijesh P

• The overall speedup is the ratio of the execution times.

• Speedupoverall = Execution timeold

Execution timenew

= 1

(1 - Fractionenhanced) + Fractionenhanced

Speedupenhanced

Page 8: Performance Tuning by Dijesh P

The CPU performance Equation

• All computers are constructed using a clock running at a constant rate.

• These time events are called ticks, clock ticks, clock periods, clocks, cycles, or clock cycles.

• Designers refer to the time of a clock period by its duration (Eg. 1 ns) or by its rate (Eg. 1 GHz).

Page 9: Performance Tuning by Dijesh P

• CPU time for a program can be expressed in two ways.– CPU time = ( CPU clock cycles for a program )

X ( Clock cycle time ) .

– OR

– CPU time = CPU clock cycles for a program

Clock rate

Page 10: Performance Tuning by Dijesh P

• We can also count the number of instruction executed – Instruction count (IC)

• IF we know the number of clock cycles and the instruction count, we can calculate the average number of clock cycles per instructions (CPI).

• CPI = CPU clock cycles for a program

Instruction Count

Page 11: Performance Tuning by Dijesh P

• CPU time = Instrn Count X Clock cycle time X Cycles per instrn.

• CPU time is dependent on three characteristics:– Clock Cycles (Clock rate) H/W technology

and organization– Clock cycles per instrn Organization and

ISA.– Instrn Count ISA and Compiler technology.

Page 12: Performance Tuning by Dijesh P

Principle of Locality

• Programs tend to reuse data and instructions they have used recently.– Temporal Locality Recently accessed items

are likely to be accessed in the near future.– Spatial Locality Items whose addresses are

near one another tend to be referenced close together in time.

• We can predict what instructions and data a program will use in the near future based on its accesses in the recent past.

Page 13: Performance Tuning by Dijesh P

Instruction Set Architecture

• The type of internal storage in a processor is the basic difference.

• The major choices are: Stack, Accumulator (AC) or a set of registers.

• The operands in a stack architecture are implicitly on the top of the stack.

• In an AC architecture, one operand is implicitly the AC.

Page 14: Performance Tuning by Dijesh P

TOS

Page 15: Performance Tuning by Dijesh P

• The General purpose register architecture have only explicit operands – either registers or memory locations.

• Consider the instruction C = A + B.• Stack Accumulator Register Register

• (Reg – Mem) (Load-store)

• PUSH A LOAD A LOAD R1, A LOAD R1,A

• PUSH B ADD B ADD R3,R1,B LOAD R2,B

• Add STORE C STORE R3,C ADD R3,R1,R2

• POP C STORE R3,C

Page 16: Performance Tuning by Dijesh P

• There are two classes of register computers :Register – Memory architecture and Register- Register architecture.

• Reg-mem architecture can access memory as part of any instruction, and the other can access memory only with load and store instruction.

• A third class is also there, not used now a days – Memory-Memory architecture. (Keeps all the operands in memory)

Page 17: Performance Tuning by Dijesh P

• Some ISA have more registers than a single accumulator, but places restriction on uses of these special purpose registers.

• Such an architecture is called extended accumulator or special – purpose register computer.

• Almost all the computers now a days are based on load-store register based. There are two reasons for this. (Registers are very fast and Compilers can efficiently use registers).

Page 18: Performance Tuning by Dijesh P

• Registers can be used to hold variables.

• When variables are allocated to registers, the memory traffic reduces, and the program speeds up.

• Two major concern in the ISA are:– Whether an ALU instruction has two or three

operands.– How many of the operands may be memory

addressed in ALU instruction.

• This divides the GPR architecture into different sub-categories.

Page 19: Performance Tuning by Dijesh P

No. of Mem Max no of Architecture Eg.Addresses operands

0 3 Reg-Mem MIPS, ARM, PowerPC

1 2 Reg-Mem IBM 360/370 Intel 80x86

2 2 Mem-Mem VAX

3 3 Mem-Mem VAXVAX is a 32-bit computing architecture that supports

virtual addressing. It was developed in the mid-1970s by Digital Equipment Corporation (DEC). DEC was later purchased by Compaq, which in turn was purchased by Hewlett-Packard.

Page 20: Performance Tuning by Dijesh P

Register- Register

• Advantages:– Simple, fixed length instructions.– Simple Code generation model– Instructions take similar number of clock

cycles.

• Disadvantages:– Higher instruction count than memory ref.– More instructions leads to larger programs.

Page 21: Performance Tuning by Dijesh P

Register - Memory

• Advantages:– Data can be accessed without a separate load

instruction first.– Instruction format can be easily encoded.

• Disadvantages:– Operands are not equal.– Restriction on the number of registers. (Due to

encoding a register number and a memory address in each instruction)

– Clocks per instruction vary.

Page 22: Performance Tuning by Dijesh P

Memory – Memory(2,2) or (3,3)

• Advantages:– Most compact.– Doesn’t waste registers for temporary data.

• Disadvantages:– Large variation in instruction size (three

operand instruction)– Large variation in work per instruction.– Memory access creates memory bottleneck.

Page 23: Performance Tuning by Dijesh P

Memory Addressing

• An architecture should specify, how memory addresses are interpreted, irrespective of whether the architecture is register-register.

• The measurement presented here are largely computer independent.

• In some cases the measurements are affected by the compiler technology.

Page 24: Performance Tuning by Dijesh P

Interpreting Memory Addresses

• All instruction sets are assumed to be byte addressed and provide access for bytes (8 bits), half words (16 bits), words (32 bits), and most computers provide access for double words (64 bits).

• There are two conventions for ordering the bytes within a large object: Little endian and Big endian.

Page 25: Performance Tuning by Dijesh P

• Little endian byte order put the byte whose address is “x….x000” at the least-significant position in the double word.

• The bytes are numbered

• Big endian byte order puts the byte whose address is “x….x000” at the most-significant position in the double word.

• The bytes are numbered

7 6 5 4 3 2 1 0

0 1 2 3 4 5 6 7

Page 26: Performance Tuning by Dijesh P

• Little endian ordering fails to match normal ordering of words when strings are compared.

• Strings appear “SDRAWKCAB” in the reg.

• Access to objects larger than a byte must be aligned.

• An access to an object of size s bytes at byte address A is aligned if A mod s = 0.

Issues in memory interpreting

Page 27: Performance Tuning by Dijesh P

• Misalignment causes hardware complications, since memory is usually aligned on a multiple of word or double word boundary.

• A misaligned memory access may take multiple aligned memory references.

• In computers that allow misaligned access, programs with aligned access run faster.

Page 28: Performance Tuning by Dijesh P

Addressing modes

• If an address is given, memory can be accessed.

• Addressing modes specify constants and registers in additions to locations in memory.

• When a memory location is used, the actual memory address specified by the addressing mode is called effective address.

Page 29: Performance Tuning by Dijesh P

Categories

• Addressing Mode Eg. Instrn Meaning• Register Add R4, R3 Reg[R4]

Reg[R4]+Reg[R3]

• Immediate Add R4, #3 R4 R4+3

• Displacement Add R4, 100(R1) R4 R4+Mem [100+Reg [R1]]

• Register Indirect Add R4, (R1) Reg [R4] Reg [R4] +Mem [Reg [R1]]

Page 30: Performance Tuning by Dijesh P

• Indexed Add R3, (R1+R2) Reg [R3] Reg [R3]+Mem [ Reg [R1] + Reg

[ R2]]

• Direct Add R1, (1001) Reg [ R1] Reg [ R1] + Mem [1001]

• Mem Indirect Add R1, (R3) Reg [R1] Reg [R1]+ Mem [ Mem [ Reg [ R3]]]

• Autoincrement Add R1, (R2)+ Reg[R1] Reg[R1]

+Mem[Reg[R2]]

Reg[R2] Reg[R2] + d

Page 31: Performance Tuning by Dijesh P

• Autodecrement Add R1,-(R2) Reg[R2] Reg[R2] – d

Reg[R1] Reg[R1] +

Mem[Reg[R2]]• Scaled Add R1,100(R2)[R3]

Reg[R1] Reg[R1]+Mem[100+Reg[R2] + Reg[R3] *d]

Page 32: Performance Tuning by Dijesh P

Usage of different addressing modes

• Register When a value is in register.

• Immediate For Constants

• Displacement Accessing Local variables.

• Reg Indirect Accessing using a pointer or an address.

• Indexed Array addressing. (R1= base of array and R2=index amount)

Page 33: Performance Tuning by Dijesh P

• Direct Sometimes useful for accessing static data.

• Mem Indirect If R3 is the address of a pointer p, then mode yields *p;

• Autoincrement Stepping through arrays within a loop. R2 points to start of an array; each reference increment R2 by size of an element d.

Page 34: Performance Tuning by Dijesh P

Operations in the Instruction Set

• Operator Type Example• Arithmetic and logical add, subtract, and, or• Data transfer Loads – stores• Control Branch, jump, procedure call• System OS call, VM mgt instructions• Floating point add, multiply, divide, compare• Decimal add, multiply, dec–char

conversion• String move, search, compare• Graphics pixel and vertex operations,

compression, decompression

Page 35: Performance Tuning by Dijesh P

Instructions for control flow

• Four different types of control flow changes:

– Conditional branches– Jumps– Procedure calls– Procedure returns

Page 36: Performance Tuning by Dijesh P

Encoding an instruction set

• Different factors affect how the instructions are encoded into a binary representation.

• The representation affects the size of the compiled program and the implementation of the processor (which decode the rep to quickly find the operations and operands).

• Operation is specified in one field called opcode.• Important is how to encode the addressing

modes with the operations.

Page 37: Performance Tuning by Dijesh P

• This depends on the range of addressing modes.

• Some older computers have one to five operands with 10 addressing modes for each operand.

• For such large number of combinations, a separate address specifier is needed for each operand.

• When encoding an instruction, the no of registers and no of addressing modes both have an impact on the size of instruction.

Page 38: Performance Tuning by Dijesh P

Competing forces – instruction encoding

1. Desire to have as many registers and addressing modes as possible.

2. Impact of size of the register and addressing mode fields on the average instruction size. (!!! Hence the average of program size)

3. Desire to have instructions encoded into lengths that will be easy to handle in a pipelined implementation.

Page 39: Performance Tuning by Dijesh P

• Three choices for encoding an instruction set are:– Fixed Combines the operation and the

addressing mode into the opcode. Have only a single size for all instructions.

– Variable Allows all addressing modes to be with all operations. This style is best when there are many addressing modes and operations.

– Hybrid Has multiple formats.

Page 40: Performance Tuning by Dijesh P

Thank You