Docsity

More About Caches - Computer Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download More About Caches - Computer Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

CSE 410Computer SystemsL

t^12

M^ Ab^ t C

h

Lecture 12 – More About Caches

How big is the cache?How^ big is the cache?Suppose we have a byte-addressable machine with 16-bitaddresses with a cache with the following characteristics:•^ It is direct-mapped•^ Each block holds one byte

y

•^ The cache index is the four least significant bitsTwo questions:Two questions:•^ How many blocks does the cache hold?•^ How many bits of storage are required to build the cache( e.g. , for the data array, tags, etc.)?

Memory System PerformanceMemory

System Performance

•^ To examine the performance of a memorysystem we need to focus on a couple of important

CPU

system, we need to focus on a couple of importantfactors.– How long does it take to send data from thecache to the CPU?

CPU

– How long does it take to copy data frommemory into the cache?– How often do we have to access main?

A little staticRAM (cache)

memory?• There are names for all of these variables.– The hit time is how long it takes data to be sentf^ th^ h^

t^ th^

Thi^ i^ ll

Lots ofdynamic RAM

from the cache to the processor. This is usuallyfast, on the order of 1-3 clock cycles.– The miss penalty is the time to copy data frommain memory to the cache This often requires

dynamic^ RAM^5

main^ memory to the cache. This often requiresdozens of clock cycles (at least).– The miss rate is the percentage of misses.

Average memory access timeAverage

memory access time

•^ The average memory access time, or AMAT, can then bet dcomputed.AMAT = Hit time + (Miss rate x Miss penalty)This is just averaging the amount of time for cache hitsand the amount of time for cache misses.•^ How can we improve the average memory access time ofa s stem?a system?– Obviously, a lower AMAT is better.– Miss penalties are usually much greater than hit times,so the best way to lower AMAT is to reduce the missso the best way to lower AMAT is to reduce the misspenalty^

or^ the miss rate.

•^ However, AMAT should only be used as a generalguideline. Remember that execution time is still the best

gu de^ e^ e

e^ be^ t at^

e ecut o^ t^

e^ s st^ t e best

performance metric.

Spatial localitySpatial locality •^ One-byte cache blocks don’t take advantage ofy^

g

spatial locality, which predicts that an access to oneaddress will be followed by an access to a nearbyaddressaddress.• What can we do?

Spatial localitySpatial locality •^ What we can do is make the cache block size larger than onebbyte. •^ Here we use two-b t^ bl^ k^

MemoryAddress^0

byte blocks, sowe can load thecache with twobytes at a time.

Index

y • If we read fromaddress 12, thedata in addresses 12 d^^13 ld

Index^012

12 and^^13 wouldboth be copied tocache block 2.

Docsity.com

Cache mappingCache mapping • Once you know the block address, you can map it to the cache asbefore: find the remainder when the block address is divided by thebefore: find the remainder when the block address is divided by thenumber of cache blocks.• In our example,memory block 6

ByteAddress 0

BlockAddress belongs in cacheblock 2, since6 mod 4 = 2.• This corresponds

Index 0 1 2

-^ This^ correspondsto placing datafrom memory^ byte^ addresses

Index^0123 2 3 4 12 and 13 intocache block 2.

Docsity.com

Data placement within a block •^ When we access one byte of data in memory, we’ll copy its entire

block

Data^ placement within a blockinto the cache, to hopefully take advantage of spatial locality.•^ In our example, if a program reads from byte address 12 we’ll load all ofmemory block 6 (both addresses 12 and 13) into cache block 2.N t^ b t^ dd

13

d^ t^ th^

bl^ k^ dd^!

-^ Note byte address 13 corresponds to the

same^ memory block address! So a read from address 13 will also cause memory block 6 (addresses12 and 13) to be loaded into cache block 2.• To make things simpler byte

i^ of a memory block is always stored in To make things simpler, byte

i^ of a memory block is always stored in byte^ i^ of the corresponding cache block.^ Byte^

Cache Address^1213

BlockByte 1^2 Byte 0

A^ picture (

-bit addresses!)

A picture (4 bit addresses!)

Add^ (4 bit )^

Bl^ k^ ff^ t Tag^ Index (2 bits)^1

Address (4 bits)

Block offset 1 10 2 Index^ Tag^01

Data Valid 2 3 8^ =

8 1010 Mux^8

Hit^ Data

An exerciseAn^ exercise

n Address (4 bits)^

Block offset Tag^ Index (2 bits)n^ nn^2 I d T^ DV lid

For the addresses below,what byte is read from the

Index^ Tag^012

Data Valid^10 0xCA^11101

0xFE0xDE 0xAD0xBE 0xEF0 FE 0 ED 0

cache (or is there a miss)? ƒ^1010

3^ =

1 0xFE^ 0xED^8 810 Mux 0

ƒ^1110 ƒ^0001 ƒ^1101

Mux 8

ƒ^1101

Hit^ Data

A diagram of a larger example cacheA^ diagram of a larger example cache• Here is a cache with 1,024blocks of 4 bytes each, and 32-

Address (32 bits)

2 bits

y bit memory addresses.^ I d^

T^

D t V lid

Index^ Tag^0123

Data Valid (^3) ... ... (^102210231023) Tag^ =

8 8 8 8 Mux

Hit^

(^8) Data

A larger example cache mappingA^ larger example cache mapping•^ Where would the byte from memory address 6146 bestored in this direct-mapped 2

10 -block cache with 2

2 -byte

blocks?• We can determine this with the binary force.– 6146 in binary is 00...01 1000 0000 00 10.– The lowest 2 bits, 10, mean this is the second byte in itsblock.– The next 10 bits, 1000000000, are the block numberitself (512).• Equivalently you could use arithmetic insteadEquivalently, you could use arithmetic instead.– The block offset is 6146 mod 4, which equals 2.– The block address is 6146/4 = 1536, so the index is1536 mod 1024 or 512

1536 mod 1024, or 512.

What goes in the rest of that cacheblock?•^ The other three bytes of that cache block come from the samememory block, whose addresses must all have the same index(1000000000) and the same tag (00...01).

Address (32 bits)

0000 .... 0001^100000000020

Index^ Tag^ ...^512 ...

Data Valid Tag^ =

8 8 8 8 Mux

Hit^

(^8) Data

The rest of that cache block •^ Again, byte^ i^

of a memory block is stored into byte

i^ of the

The rest of that cache blockcorresponding cache block.– In our example, memory block 1536 consists of byte addresses6144 to 6147. So bytes 0-3 of the cache block would contain datafrom address 6144 6145 6146 and 6147 respectivelyfrom address 6144, 6145, 6146 and 6147 respectively.– You can also look at the lowest 2 bits of the memory address to findthe block offsets.Block offset

Memory address

Decimal 00 00..01 1000000000 00

6144 01 00..01 1000000000 01

6145 10 00..01 1000000000 10

6146 11 00..01 1000000000 11

6147 Index^ Tag^

Data Valid