+ All Categories
Home > Documents > 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of...

1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of...

Date post: 18-Jan-2016
Category:
Upload: raymond-melton
View: 212 times
Download: 0 times
Share this document with a friend
28
1 Chapter Seven
Transcript
Page 1: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

1

Chapter Seven

Page 2: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

2

• Users want large and fast memories!

SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte.DRAM access times are 60-120ns at cost of $5 to $10 per Mbyte.Disk access times are 10 to 20 million ns at cost of $.10 to $.20 per Mbyte.

• Try and give it to them anyway

– build a memory hierarchy

Exploiting Memory Hierarchy

1997

CPU

Level n

Level 2

Level 1

Levels in thememory hierarchy

Increasing distance from the CPU in

access time

Size of the memory at each level

Page 3: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

3

Locality

• A principle that makes having a memory hierarchy a good idea

• If an item is referenced,

temporal locality: it will tend to be referenced again soonspatial locality: nearby items will tend to be referenced soon.

Why does code have locality?

• Our initial focus: two levels (upper, lower)– block: minimum unit of data moved to cache. – hit: data requested is in the upper level– miss: data requested is not in the upper level

Page 4: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

4

Page 5: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

5

• Two issues:

– How do we know if a data item is in the cache?

– If it is, how do we find it?

• Our first example:

– block size is one word of data

– "direct mapped"

For each item of data at the lower level, there is exactly one location in the cache where it might be.

e.g., lots of items at the lower level share locations in the upper level

Cache

Page 6: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

6

Cache memory

Level of memory hierarchy between main memory and the CPU. Cache is constructed from very fast memory. It would be too expensive to construct main memory from this very fast memory. Cache memory is quite common.Note: For Cache line is often used instead of block.Address is broken into Tag, index and byte offset.The index is used to select the block in cache.The tag is compared with the value of the tag field in the cache blocked indexed.The offset is used to select a particular word in the cache.

Page 7: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

7

Direct Mapped cache

Page 8: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

8

• Mapping: address is modulo the number of blocks in the cache

Direct Mapped Cache

00001 00101 01001 01101 10001 10101 11001 11101

000

Cache

Memory

001

01

001

11

001

011

101

11

Page 9: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

9

• Taking advantage of spatial locality:

Direct Mapped Cache

Address (showing bit positions)

16 12 Byteoffset

V Tag Data

Hit Data

16 32

4Kentries

16 bits 128 bits

Mux

32 32 32

2

32

Block offsetIndex

Tag

31 16 15 4 32 1 0

(a). The instruction cache is direct mapped cache, and contains 64 lines. Each line contains 8 instructions. How many address bits are required for the tag?Answer: 64 lines require 6 bits for the index (26 = 64). 4 X 8 = 25 bytes in a line requires 5 bits for the offset. The number of bits for the tag = 32 – 6 – 5 = 21 bits.

Page 10: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

10

Page 11: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

11

Page 12: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

12

Page 13: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

13

Page 14: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

14

Page 15: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

15

Page 16: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

16

Page 17: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

17

Page 18: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

18

Page 19: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

19

Homework

A certain MIPS computer has a separate cache for instructions and data.

(a). The instruction cache is direct mapped cache, and contains 64 lines. Each line contains 8 instructions. How many address bits are required for the tag?

(b). The data cache is four way set associative and can hold a maximum or 4096 bytes of data. If four address bits are required for the index, how many bits are used for the tag?

(c). Would it be possible to build the instruction cache such that the most significant bits of the address are used for the index instead of being used for the tag?

(d). Explain either why this cannot be done, or if it can be done why it is not done.

Page 20: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

20

• Read hits

– this is what we want!

• Read misses

– stall the CPU, fetch block from memory, deliver to cache, restart

• Write hits:

– can replace data in cache and memory (write-through)

– write the data only into the cache (write-back the cache later)

• Write misses:

– read the entire block into the cache, then write the word

Hits vs. Misses

Page 21: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

21

• Make reading multiple words easier by using banks of memory

• It can get a lot more complicated...

Hardware Issues

CPU

Cache

Bus

Memory

a. One-word-wide memory organization

CPU

Bus

b. Wide memory organization

Memory

Multiplexor

Cache

CPU

Cache

Bus

Memorybank 1

Memorybank 2

Memorybank 3

Memorybank 0

c. Interleaved memory organization

Page 22: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

22

• Increasing the block size tends to decrease miss rate:

• Use split caches because there is more spatial locality in code:

Performance

1 KB

8 KB

16 KB

64 KB

256 KB

256

40%

35%

30%

25%

20%

15%

10%

5%

0%

Mis

s ra

te

64164

Block size (bytes)

ProgramBlock size in

wordsInstruction miss rate

Data miss rate

Effective combined miss rate

gcc 1 6.1% 2.1% 5.4%4 2.0% 1.7% 1.9%

spice 1 1.2% 1.3% 1.2%4 0.3% 0.6% 0.4%

Page 23: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

23

Performance

• Simplified model:

execution time = (execution cycles + stall cycles) cycle timestall cycles = # of instructions miss ratio miss penalty(in cycles)

• Two ways of improving performance:

– decreasing the miss ratio

– decreasing the miss penalty

What happens if we increase block size?

Page 24: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

24

Compared to direct mapped, give a series of references that:

– results in a lower miss ratio using a 2-way set associative cache

– results in a higher miss ratio using a 2-way set associative cache

assuming we use the “least recently used” replacement strategy

Decreasing miss ratio with associativity

Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data Tag Data

Eight-way set associative (fully associative)

Tag Data Tag Data Tag Data Tag Data

Four-way set associative

Set

0

1

Tag Data

One-way set associative(direct mapped)

Block

0

7

1

2

3

4

5

6

Tag Data

Two-way set associative

Set

0

1

2

3

Tag Data

Page 25: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

25

An implementationAddress

22 8

V TagIndex

0

12

253

254255

Data V Tag Data V Tag Data V Tag Data

3222

4-to-1 multiplexor

Hit Data

123891011123031 0

(b). The data cache is four way set associative and can hold a maximum or 4096 bytes of data. If four address bits are required for the index, how many bits are used for the tag?Answer: Each set contains 4096/4 = 1024 = 210 bytes of data. 4 index bits implies 24 lines in each set. Thus, there are 210/24 = 26 bytes in each line requiring 6 bits for the offset. The number of tag bits = 32 – 4 – 6 = 22.

Page 26: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

26

Performance

0%

3%

6%

9%

12%

15%

Eight-wayFour-wayTwo-wayOne-way

1 KB

2 KB

4 KB

8 KB

Mis

s ra

te

Associativity 16 KB

32 KB

64 KB

128 KB

Page 27: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

27

Decreasing miss penalty with multilevel caches

• Add a second level cache:

– often primary cache is on the same chip as the processor

– use SRAMs to add another cache above primary memory (DRAM)

– miss penalty goes down if data is in 2nd level cache

• Example:– CPI of 1.0 on a 500Mhz machine with a 5% miss rate, 200ns DRAM access– Adding 2nd level cache with 20ns access time decreases miss rate to 2%

• Using multilevel caches:

– try and optimize the hit time on the 1st level cache

– try and optimize the miss rate on the 2nd level cache

Page 28: 1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are 2 - 25ns at cost of $100 to $250 per Mbyte. DRAM access times are 60-120ns.

28

Cache Summary

• Processor performance has increased faster than memory performance. Cache memory helps resolve this problem.

• When a word is not found in cache multiple words (called a block or line) are moved form main memory to cache memory.

• Each cache line contains a tag to identify the main memory address of the line.

• Set associative memories a use to approximate a fully associative cache memory.

• Average memory access time = Hit time + Miss rate X Miss penalty

– Modern processors may execute other instructions when a miss occurs to reduce the effect of the miss.


Recommended