Professional Documents
Culture Documents
Semester 1
EMT 475/3
Computer Organization
& Architecture
Chapter 3 : Cache Memory
Outline
Computer Memory System Overview
Cache Memory Principles
Cache Design
Cache Organization
Outline
Computer Memory System Overview
Cache Memory Principles
Cache Design
Cache Organization
PC Program Counter
IR Instruction Register
10
11
12
13
14
Parts
Inboard Memory
Registers
Cache
Main memory
Outboard
Memory
Magnetic-disk
CD-ROM
CD-RW
DVD-RW
DVD-RAM
Off-line storage
Magnetic tape
MO
WORM
MO - Magneto-optical
WORM write once read many
15
16
17
18
19
20
21
Outline
Computer Memory System Overview
Cache Memory Principles
Cache Design
Cache Organization
22
Cache Principles
Small amount of fast memory
Sits between normal main memory and CPU
May be located on CPU chip or module
23
Cache Principles
24
Cache Principles
An intermediate buffer between CPU and main memory.
Use to reduce the CPU waiting time during the main
memory accesses.
Without cache memory, every main memory access results in
delay in instruction processing.
Implement due to higher main memory access time
compare to processor clock period.
Cause the high speed CPUs time wasted during memory
access (instruction fetch, operand fetch or result storing)
To minimize the waiting time for the CPU, a small but fast
memory is introduced as a cache buffer between main
memory and CPU.
School of Microelectronic Engineering
Universiti Malaysia Perlis
25
Cache Principles
A portion of program and data is brought into the cache memory in
advance.
The cache controller keeps track of locations of the main memory
which are copied In cache memory
When CPU needs for instruction or operand, it receives from the
cache memory (if available) instead of accessing the main
memory.
Thus the memory access is fast because the slow main memory
appears as a fast memory.
The cache memory capacity is very small compared to main
memory but the speed is several times better than main memory.
Transfer between the CPU and cache memory usually one word at
a time.
The cache memory usually can be physically with processor IC as
internal cache, also known as on-chip cache.
School of Microelectronic Engineering
Universiti Malaysia Perlis
26
Cache Principles
Cache Level
Level
Devices Cached
Level2 cache, system RAM, Hard Disk,
Level1
DC-ROM
Level2
System RAM, Hard Disk, CD-ROM
System RAM Hard Disk, CD-ROM
Hard Disk/
-CD-ROM
School of Microelectronic Engineering
Universiti Malaysia Perlis
27
Cache Principles
More about Cache.
Disk cache, peripheral cache (e.g.: CDs, very slow initial
access time), Internet cache (software).
A 512kb level 2 cache, caching 64MB of system memory,
can supply 90-95% of info. <=1% in size.
This is due to locality of reference (large programs with
several MBs of instructions, only small portions are
loaded at a time (e.g.: Opening a word document)).
SRAM 7-20 ns, DRAM50-70 ns
Level2 256-512KB, level18-64KB
School of Microelectronic Engineering
Universiti Malaysia Perlis
28
29
Cache Principles
Remember!
Unit
KB
MB
GB
TB
Value
210 Bytes = 1024 Bytes
220 Bytes = 1024 KB
230 Bytes = 1024 MB
240 Bytes = 1024 GB
30
Cache Principles
Example:
Cache Memory
Cache of 64KBytes
Cache block of 4 bytes each.
64K/4 = 64(1024)bytes/4bytes =16K = 214 lines
i.e. cache is 16K = (214) lines of 4 bytes each
Main Memory
16MBytes main memory
(24)(220)bytes = (224) =16MBytes
24bit address
School of Microelectronic Engineering
Universiti Malaysia Perlis
31
Cache Principles
Cache Operation: Overview
CPU requests contents of memory location
Check cache for this data
If present, get from cache (fast)
If not present, read required block from main memory to
cache
Then deliver from cache to CPU
Cache includes tags to identify which block of main
memory is in each cache slot
School of Microelectronic Engineering
Universiti Malaysia Perlis
32
Cache Principles
Cache Operation
Flowchart
Read operation
RA Read address
33
Outline
Computer Memory System Overview
Cache Memory Principles
Cache Design
Cache Organization
34
Cache Design
Size
Mapping Function
Replacement Algorithm
Write Policy
Block Size
Number of Caches
35
Cache Design
Size
Cost
More cache is expensive
Speed
More cache is faster (up to a point)
Checking cache for data takes time
36
Cache Design
37
Cache Design
Comparison of Cache Sizes
Processor
Type
Year of
Introduction
L1 cache
L2 cache
L3 cache
IBM 360/85
Mainframe
1968
16 -32 kB
PDP-11/70
Minicomputer
1975
1 kB
VAX 11/780
Minicomputer
1978
16 kB
IBM 3033
Mainframe
1978
64 kB
IBM 3090
Mainframe
1985
128 256 kB
Intel 80486
PC
1989
8 kB
Pentium
PC
1993
8 kB/8 kB
256 512 kB
PowerPC 601
PC
1993
32 kB
PowerPC 602
PC
1996
32 kB/32 kB
PowerPC G4
PC/Server
1999
32 kB/32 kB
256 kB to 1 MB
2 MB
IBM S/390 G6
Mainframe
1999
256 kB
8 MB
38
Cache Design
Comparison of Cache Sizes
Processor
Type
Year of
Introduction
L1 cache
L2 cache
L3 cache
Pentium 4
PC/Server
2000
8 kB/8 kB
256 kB
IBM SP
High-end server/supercomputer
2000
64 kB/32 kB
8M
CRAY MTA
Supercomputer
2000
8 kB
2 MB
Itanium
PC/Server
2001
16 kB/16 kB
96 kB
4 MB
Itanium 2
PC/Server
2002
32 kB
256 kB
6 MB
IBM POWER5
High-end server
2003
64 kB
1.9MB
36 MB
CRAY XD-1
Supercomputer
2004
64 kB/64 kB
1 MB
IBM POWER6
PC/Server
2007
64 kB/64 kB
4 MB
32 MB
IBM z10
Mainframe
2008
64 kB/128 kB
3 MB
24 48 MB
Workstation/server
2011
6 x 32 kB/32 kB
1.5 MB
12 MB
Mainframe/server
2011
24 x 64 kB/128 kB
24 x 1.5 MB
24 MB L3
192 MB L4
39
Cache Design
Mapping Function
Fewer cache lines than the main memory block.
Therefore, an algorithm is needed for mapping main memory
blocks into cache lines.
Needs for determining which memory block currently
occupies a cache line Mapping function
The choice of the mapping function, determines the how the
cache is organized.
Three techniques :Direct
Associative
Set associative
School of Microelectronic Engineering
Universiti Malaysia Perlis
40
Cache Design
Direct Mapping
Each block of main memory maps to only one cache line
i.e. if a block is in cache, it must be in one specific place
Address is in two parts
Least Significant w bits identify unique word
Most Significant s bits specify one memory block
The MSBs are split into a cache line field r and a tag of
s-r (most significant)
School of Microelectronic Engineering
Universiti Malaysia Perlis
41
Cache Design
Direct Mapping
42
Cache Design
Direct Mapping Address Structure
Tag s-r
Line or Slot r
Word w
8-bit
2-bit
14-bit
24 bit address
2 bit word identifier (4 byte block)
22 bit block identifier
8 bit tag (=22-14)
14 bit slot or line
No two blocks in the same line have the same Tag field
Check contents of cache by finding line and checking Tag
School of Microelectronic Engineering
Universiti Malaysia Perlis
43
Cache Design
Direct Mapping - Cache Line Table
Cache
line
0
0, m, 2m, 3m 2 -m
m-1
m-1, 2m-1,3m-1 2 -1
School of Microelectronic Engineering
Universiti Malaysia Perlis
44
Cache Design
Direct Mapping Cache Organization
45
Cache Design
Direct Mapping
Example
46
Cache Design
Direct Mapping
47
Cache Design
Direct Mapping - Summary
Address length = (s + w) bits
s+w
Number of addressable units = 2 words or bytes
w
Block size = line size = 2 words or bytes
s+w
w
s
Number of blocks in main memory = 2 /2 = 2
r
Number of lines in cache = m = 2
Size of tag = (s r) bits
48
Cache Design
Direct Mapping pros & cons
Simple
Inexpensive
Fixed location for given block
If a program accesses 2 blocks that map to the same
line repeatedly, cache misses are very high
49
Cache Design
Associative Mapping
A main memory block can load into any line of cache
Memory address is interpreted as tag and word
Tag uniquely identifies block of memory
Every lines tag is examined for a match
Cache searching gets expensive
50
Cache Design
Associative Mapping Address Structure
Tag
Word w
22bit
2bit
3FFFFF
24682468
3FFF
51
Cache Design
Associative Mapping
52
Cache Design
Fully Associative Cache Organization
53
Cache Design
Associative Mapping
Example
Address
Tag
Data
Cache line
FFFFFC
3FFFFF
24682468
3FFF
54
Cache Design
Associative
Mapping
55
Cache Design
Associative Mapping Summary
Address length = (s + w) bits
s+w
Number of addressable units = 2 words or bytes
w
Block size = line size = 2 words or bytes
s+w
w
s
Number of blocks in main memory = 2 / 2 = 2
Number of lines in cache = undetermined
Size of tag = s bits
56
Cache Design
Set Associative Mapping
Cache is divided into a number of sets
Each set contains a number of lines
A given block maps to any line in a given set
e.g. Block B can be in any line of set i
e.g. 2 lines per set
2 way associative mapping
A given block can be in one of 2 lines in only one set
School of Microelectronic Engineering
Universiti Malaysia Perlis
57
Cache Design
Set Associative
Mapping
58
Cache Design
Set Associative
Mapping
59
Cache Design
Set Associative Mapping Example
13 bit set number
Block number in main memory is modulo 213
000000, 00A000, 00B000, 00C000 map to same set
60
Cache Design
Set Associative Mapping Address Structure
Tag
Set
9bit
13bit
Use set field to determine cache set to look in
Compare tag field to see if we have a hit
e.g.
Address
167FFC
FFFFFC
Tag
02C
1FF
Data
12345678
11223344
Word
2bit
Set Number
1FFF
1FFF
61
Cache Design
Two Way
Set Associative
Cache
Organization
62
Cache Design
Two Way
Set Associative
Mapping Example
63
Cache Design
Set Associative
Mapping
64
Cache Design
Set Associative Mapping Summary
Address length = (s + w) bits
s+w
Number of addressable units = 2 words or bytes
w
Block size = line size = 2 words or bytes
d
Number of blocks in main memory = 2
Number of lines in set = k
d
Number of sets,v = 2
d
Number of lines in cache, m = k v = k 2
Size of tag = (s d) bits
School of Microelectronic Engineering
Universiti Malaysia Perlis
65
Cache Design
Comparison
Cache Type
Hit Ratio
Search Speed
Direct Mapping
Good
Best
Fully Associative
Mapping
Best
Moderate
Very Good,
k-way SetBetter as k
Associative Mapping
increases
Good, Worse as k
increases
66
Cache Design
Replacement Algorithms (1): Direct mapping
No choice
Each block only maps to one line
Replace that line
67
Cache Design
Replacement Algorithms (2): Associative & Set Associative
Hardware implemented algorithm (speed)
Least Recently used (LRU)
e.g. in 2 way set associative
Which of the 2 block is LRU?
First in first out (FIFO)
replace block that has been in cache longest
Least frequently used
replace block which has had fewest hits
Random
68
School of Microelectronic Engineering
Universiti Malaysia Perlis
Cache Design
Write Policy
Must not overwrite a cache block unless main memory is
up to date
Multiple CPUs may have individual caches
I/O may address main memory directly
69
Cache Design
Write through
All writes go to main memory as well as cache
Multiple CPUs can monitor main memory traffic to keep
local (to CPU) cache up to date
Lots of traffic
Slows down writes
70
Cache Design
Write back
Updates initially made in cache only
Update bit for cache slot is set when update occurs
If block is to be replaced, write to main memory only if
update bit is set
Other caches get out of sync
I/O must access main memory through cache
N.B. 15% of memory references are writes
School of Microelectronic Engineering
Universiti Malaysia Perlis
71
Outline
Computer Memory System Overview
Cache Memory Principles
Cache Design
Cache Organization
72
Cache Organization
Pentium 4 Cache
Pentium 4
L1 caches
80386 no on chip cache
8k bytes
80486 8k using 16 byte lines
64 byte lines
and four way set associative
organization
four way set associative
Pentium (all versions) two L2 cache
on chip L1 caches
Feeding both L1 caches
Data & instructions
256k
128 byte lines
Pentium III L3 cache added
off chip
8 way set associative
L3 cache on chip
School of Microelectronic Engineering
Universiti Malaysia Perlis
73
Cache Organization
Intel Cache Evolution
Problem
Solution
Processor on which
feature first appears
386
486
486
Create separate back-side bus that runs at higher speed than the
main (front-side) external bus. The BSB is dedicated to the L2 cache.
Pentium
Pentium Pro
Pentium II
Pentium III
Pentium 4
74
Cache Organization
Pentium 4 Block Diagram
75
Cache Organization
Pentium 4 Core Processor
dependence and resources
Fetch/Decode Unit
May speculatively execute
Fetches instructions from
L2 cache
Execution units
Decode into micro-ops
Execute micro-ops
Store micro-ops in L1 cache Data from L1 cache
Out of order execution logic
Results in registers
Schedules micro-ops
Memory subsystem
Based on data
L2 cache and systems bus
School of Microelectronic Engineering
Universiti Malaysia Perlis
76
Cache Organization
Pentium 4 Design Reasoning
Decodes instructions into RISC
like micro-ops before L1 cache
Micro-ops fixed length
Superscalar pipelining and
scheduling
Pentium instructions long &
complex
Performance improved by
separating decoding from
scheduling & pipelining
(More later ch14)
Data cache is write back
Can be configured to write
through
L1 cache controlled by 2 bits in
register
CD = cache disable
NW = not write through
2 instructions to invalidate
(flush) cache and write back
then invalidate
L2 and L3 8-way set-associative
Line size 128 bytes
77
Cache Organization
PowerPC Cache Organization
64kb L1 cache
601 single 32kb 8 way set
associative
8 way set associative
256k, 512k or 1M L2 cache
603 16kb (2 x 8kb) two way
set associative
two way set associative
604 32kb
G5
32kB instruction cache
620 64kb
64kB data cache
G3 & G4
78
Cache Organization
PowerPC G5 Block Diagram
79
Internet Sources
Manufacturer sites
Intel
IBM/Motorola
Search on cache
80
Finish!
Q&A
81