You are on page 1of 35

Lecture 3

CMPT215.3

Performance
Chapter 1 Computer Abstractions and Technology 4
Understanding Performance

Algorithm

Determines number of oerations e!ecuted

Programming language" comiler" architecture

Determine number of machine instructions e!ecuted er


oeration

Processor and memor# s#stem

Determine ho$ fast instructions are e!ecuted

%&' s#stem (including ')*

Determines ho$ fast %&' oerations are e!ecuted


Chapter 1 Computer Abstractions and Technology 5
+esonse Time and Throughut

+esonse time

,o$ long it ta-es to do a tas-

Throughut

Total $or- done er unit time

e.g." tas-s&transactions&. er hour

,o$ are resonse time and throughut affected b#

+elacing the rocessor $ith a faster /ersion0

Adding more rocessors0

1e2ll focus on resonse time for no$.


Chapter 1 Computer Abstractions and Technology 6
+elati/e Performance

Define Performance 3 1&4!ecution Time

56 is n time faster than 78


n = =
6 7
7 6
time 4!ecution time 4!ecution
e Performanc e Performanc

4!amle9 time ta-en to run a rogram

1:s on A" 15s on ;

4!ecution Time
;
& 4!ecution Time
A
3 15s & 1:s 3 1.5

)o A is 1.5 times faster than ;


Chapter 1 Computer Abstractions and Technology 7
Measuring 4!ecution Time

4lased time

Total resonse time" including all asects

Processing" %&'" ') o/erhead" idle time

Determines s#stem erformance

CPU time

Time sent rocessing a gi/en <ob

Discounts %&' time" other <obs2 shares

Comrises user CPU time and s#stem CPU time

Different rograms are affected differentl# b# CPU


and s#stem erformance
Chapter 1 Computer Abstractions and Technology 8
CPU Time

Performance imro/ed b#

+educing number of cloc- c#cles

%ncreasing cloc- rate

,ard$are designer must often trade off cloc- rate


against c#cle count
+ate Cloc-
C#cles Cloc- CPU
Time C#cle Cloc- C#cles Cloc- CPU Time CPU
=
=
Chapter 1 Computer Abstractions and Technology 9
CPU Cloc-ing

'eration of digital hard$are go/erned b# a


constant=rate cloc-
Cloc- (c#cles*
Data transfer
and comutation
Udate state
Cloc- eriod

Cloc- eriod9 duration of a cloc- c#cle

e.g." 25:s 3 :.25ns 3 25:>1:


?12
s

Cloc- fre@uenc# (rate*9 c#cles er second

e.g." A.:B,C 3 A:::M,C 3 A.:>1:


D
,C
Chapter 1 Computer Abstractions and Technology 10
CPU Time 4!amle

Comuter A9 2B,C cloc-" 1:s CPU time

Designing Comuter ;

Aim for Es CPU time

Can do faster cloc-" but causes 1.2 > cloc- c#cles

,o$ fast must Comuter ; cloc- be0


AB,C
Es
1: 2A
Es
1: 2: 1.2
+ate Cloc-
1: 2: 2B,C 1:s
+ate Cloc- Time CPU C#cles Cloc-
Es
C#cles Cloc- 1.2
Time CPU
C#cles Cloc-
+ate Cloc-
D D
;
D
A A A
A
;
;
;
=

=

=
= =
=

= =
Chapter 1 Computer Abstractions and Technology 11
%nstruction Count and CP%

%nstruction Count for a rogram

Determined b# rogram" %)A and comiler

A/erage c#cles er instruction

Determined b# CPU hard$are

%f different instructions ha/e different CP%

A/erage CP% affected b# instruction mi!


+ate Cloc-
CP% Count n %nstructio
Time C#cle Cloc- CP% Count n %nstructio Time CPU
n %nstructio er C#cles Count n %nstructio C#cles Cloc-

=
=
=
Chapter 1 Computer Abstractions and Technology 1
CP% 4!amle

Comuter A9 C#cle Time 3 25:s" CP% 3 2.:

Comuter ;9 C#cle Time 3 5::s" CP% 3 1.2

)ame %)A

1hich is faster" and b# ho$ much0


1.2
5::s %
E::s %
A
Time CPU
;
Time CPU
E::s % 5::s 1.2 %
;
Time C#cle
;
CP% Count n %nstructio
;
Time CPU
5::s % 25:s 2.: %
A
Time C#cle
A
CP% Count n %nstructio
A
Time CPU
=

=
= =
=
= =
=
A is faster.
.b# this much
Chapter 1 Computer Abstractions and Technology 1!
CP% in More Detail

%f different instruction classes ta-e different


numbers of c#cles

=
=
n
1 i
i i
* Count n %nstructio (CP% C#cles Cloc-

1eighted a/erage CP%

= =
n
1 i
i
i
Count n %nstructio
Count n %nstructio
CP%
Count n %nstructio
C#cles Cloc-
CP%
+elati/e fre@uenc#
Chapter 1 Computer Abstractions and Technology 14
CP% 4!amle

Alternati/e comiled code se@uences using


instructions in classes A" ;" C
Class A ; C
CP% for class 1 2 3
%C in se@uence 1 2 1 2
%C in se@uence 2 A 1 1

)e@uence 19 %C 3 5

Cloc- C#cles
3 2>1 F 1>2 F 2>3
3 1:

A/g. CP% 3 1:&5 3 2.:

)e@uence 29 %C 3 E

Cloc- C#cles
3 A>1 F 1>2 F 1>3
3 D

A/g. CP% 3 D&E 3 1.5


Chapter 1 Computer Abstractions and Technology 15
Performance )ummar#

Performance deends on

Algorithm9 affects %C" ossibl# CP%

Programming language9 affects %C" CP%

Comiler9 affects %C" CP%

%nstruction set architecture9 affects %C" CP%" T


c
The BIG Picture
c#cle Cloc-
)econds
n %nstructio
c#cles Cloc-
Program
ns %nstructio
Time CPU =
Chapter 1 Computer Abstractions and Technology 16
Pitfall9 Amdahl2s La$

%mro/ing an asect of a comuter and e!ecting a


roortional imro/ement in o/erall erformance
G
1
.
H

I
a
l
l
a
c
i
e
s

a
n
d

P
i
t
f
a
l
l
s
2:
H:
2: + =
n

Can2t be doneJ
unaffected
affected
imro/ed
T
factor t imro/emen
T
T + =

4!amle9 multil# accounts for H:s&1::s

,o$ much imro/ement in multil# erformance to get 5>


o/erall0

Corollar#9 ma-e the common case fast


Chapter 1 Computer Abstractions and Technology 17
)P4C CPU ;enchmar-

Programs used to measure erformance

)uosedl# t#ical of actual $or-load

)tandard Performance 4/aluation Cor ()P4C*

De/elos benchmar-s for CPU" %&'" 1eb" .

)P4C CPU2::E

4lased time to e!ecute a selection of rograms

Kegligible %&'" so focuses on CPU erformance

KormaliCe relati/e to reference machine

)ummariCe as geometric mean of erformance ratios

C%KT2::E (integer* and CIP2::E (floating=oint*


n
n
1 i
i
ratio time 4!ecution

=
Chapter 1 Computer Abstractions and Technology 19
Iallac#9 Lo$ Po$er at %dle

Loo- bac- at 6A o$er benchmar-

At 1::L load9 2D51

At 5:L load9 2AE1 (H3L*

At 1:L load9 1H:1 (E1L*

Boogle data center

Mostl# oerates at 1:L ? 5:L load

At 1::L load less than 1L of the time

Consider designing rocessors to ma-e o$er


roortional to load
Chapter 1 Computer Abstractions and Technology 0
Pitfall9 M%P) as a Performance Metric

M%P)9 Millions of %nstructions Per )econd

Doesn2t account for

Differences in %)As bet$een comuters

Differences in comle!it# bet$een instructions


E
E
E
1: CP%
rate Cloc-
1:
rate Cloc-
CP% count n %nstructio
count n %nstructio
1: time 4!ecution
count n %nstructio
M%P)

CP% /aries bet$een rograms on a gi/en CPU


Definitions

Milob#te ? 2
1:
or 1":2A b#tes

Megab#te? 2
2:
or 1":AH"5NE b#tes

sometimes 5rounded8 to 1:
E
or 1":::"::: b#tes

Bigab#te ? 2
3:
or 1":N3"NA1"H2A b#tes

sometimes rounded to 1:
D
or 1":::":::"::: b#tes

Terab#te ? 2
A:
or 1":DD"511"E2N"NNE b#tes

sometimes rounded to 1:
12
or 1":::":::":::"::: b#tes

Petab#te ? 2
5:
or 1:2A terab#tes

sometimes rounded to 1:
15
or 1":::":::":::":::"::: b#tes

4!ab#te ? 2
E:
or 1:2A etab#tes

)ometimes rounded to 1:
1H
or 1":::":::":::":::":::"::: b#tes
Chapter 1 Computer Abstractions and Technology
Arithmetic
July 16, 2014 Chapter 3 Arithmetic for Computers 24
Arithmetic for Comuters

'erations on integers

Addition and subtraction

Multilication and di/ision

Dealing $ith o/erflo$

Iloating=oint real numbers

+eresentation and oerations


G
3
.
1

%
n
t
r
o
d
u
c
t
i
o
n
July 16, 2014 Chapter 3 Arithmetic for Computers 25
%nteger Addition

4!amle9 N F E
G
3
.
2

A
d
d
i
t
i
o
n

a
n
d

)
u
b
t
r
a
c
t
i
o
n

'/erflo$ if result out of range

Adding F/e and ?/e oerands" no o/erflo$

Adding t$o F/e oerands

'/erflo$ if result sign is 1

Adding t$o ?/e oerands

'/erflo$ if result sign is :


July 16, 2014 Chapter 3 Arithmetic for Computers 26
%nteger )ubtraction

Add negation of second oerand

4!amle9 N ? E 3 N F (?E*
FN9 :::: :::: . :::: :111
?E9 1111 1111 . 1111 1:1:
F19 :::: :::: . :::: :::1

'/erflo$ if result out of range

)ubtracting t$o F/e or t$o ?/e oerands" no o/erflo$

)ubtracting F/e from ?/e oerand

'/erflo$ if result sign is :

)ubtracting ?/e from F/e oerand

'/erflo$ if result sign is 1


July 16, 2014 Chapter 3 Arithmetic for Computers 27
1=bit adder
July 16, 2014 Chapter 3 Arithmetic for Computers 28
Dealing $ith '/erflo$

)ome languages (e.g." C* ignore o/erflo$

Use M%P) addu" addui" subu instructions

'ther languages (e.g." Ada" Iortran* re@uire


raising an e!cetion

Use M%P) add" addi" sub instructions

'n o/erflo$" in/o-e e!cetion handler

)a/e PC in e!cetion rogram counter (4PC* register

Oum to redefined handler address

mfc0 (mo/e from corocessor reg* instruction can


retrie/e 4PC /alue" to return after correcti/e action
July 16, 2014 Chapter 3 Arithmetic for Computers 29
Arithmetic for Multimedia

Brahics and media rocessing oerates on


/ectors of H=bit and 1E=bit data

Use EA=bit adder" $ith artitioned carr# chain

'erate on H>H=bit" A>1E=bit" or 2>32=bit /ectors

)%MD (single=instruction" multile=data*

)aturating oerations

'n o/erflo$" result is largest reresentable /alue

c.f. 2s=comlement modulo arithmetic

4.g." cliing in audio" saturation in /ideo


July 16, 2014 Chapter 3 Arithmetic for Computers 30
Multilication

)tart $ith long=multilication aroach


1000
1001
1000
0000
0000
1000
1001000
Length of roduct is
the sum of oerand
lengths
multilicand
multilier
roduct
G
3
.
3

M
u
l
t
i

l
i
c
a
t
i
o
n
July 16, 2014 Chapter 3 Arithmetic for Computers 31
Multilication ,ard$are
Initially 0
July 16, 2014 Chapter 3 Arithmetic for Computers 32
'timiCed Multilier

Perform stes in arallel9 add&shift

'ne c#cle er artial=roduct addition

That2s o-" if fre@uenc# of multilications is lo$


July 16, 2014 Chapter 3 Arithmetic for Computers 33
Iaster Multilier

Uses multile adders

Cost&erformance tradeoff

Can be ielined

)e/eral multilication erformed in arallel


July 16, 2014 Chapter 3 Arithmetic for Computers 34
M%P) Multilication

T$o 32=bit registers for roduct

,%9 most=significant 32 bits

L'9 least=significant 32=bits

%nstructions

mult rs, rt / multu rs, rt

EA=bit roduct in ,%&L'

mfhi rd / mflo rd

Mo/e from ,%&L' to rd

Can test ,% /alue to see if roduct o/erflo$s 32 bits

mul rd, rs, rt

Least=significant 32 bits of roduct ?P rd


July 16, 2014 Chapter 3 Arithmetic for Computers 35
Di/ision

Chec- for : di/isor

Long di/ision aroach

%f di/isor Q di/idend bits

1 bit in @uotient" subtract

'ther$ise

: bit in @uotient" bring do$n ne!t di/idend


bit

+estoring di/ision

Do the subtract" and if remainder goes R


:" add di/isor bac-

)igned di/ision

Di/ide using absolute /alues

Ad<ust sign of @uotient and remainder as


re@uired
1001
1000 1001010
-1000
10
101
1010
-1000
10
n=bit oerands #ield n=bit
@uotient and remainder
@uotient
di/idend
remainder
di/isor
G
3
.
A

D
i
/
i
s
i
o
n
July 16, 2014 Chapter 3 Arithmetic for Computers 36
Di/ision ,ard$are
%nitiall# di/idend
%nitiall# di/isor in
left half
July 16, 2014 Chapter 3 Arithmetic for Computers 37
M%P) Di/ision

Use ,%&L' registers for result

,%9 32=bit remainder

L'9 32=bit @uotient

%nstructions

div rs, rt / divu rs, rt

Ko o/erflo$ or di/ide=b#=: chec-ing

)oft$are must erform chec-s if re@uired

Use mfhi" mflo to access result



+eferences

Patterson and ,enness# ? Comuter 'rganiCation and Design


The ,ard$are&)oft$are interface (fourth edition*

You might also like