EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design...

19
EECS 370 Discussion 1 xkcd.com

Transcript of EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design...

Page 1: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

1

EECS 370 Discussion

xkcd.com

Page 2: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

2

EECS 370 Discussion

Topics Today:

– Caches!!• Theory• Design• Examples

Page 3: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

3

EECS 370 Discussion

Memory Hierarchy

Cache

Main Memory (RAM)

Disk(Hard Drive)

Page 4: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

4

EECS 370 Discussion

Memory Hierarchy

Real World Example - Intel i7

Cache Level Size Access Time

L1 64 kB 4 cycles

L2 256 kB 10 cycles

L3 8192 kB 40 cycles

RAM 8388608 kB 200 cycles

Disk 1073741824 kB 20000000 cycles

Page 5: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

5

EECS 370 Discussion

Memory Hierarchy

Problem: Caches are very tiny, but memory is quite large If memory accesses are totally random, caches are useless

Solution: Memory accesses really aren’t random at all!

Page 6: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

6

EECS 370 Discussion

Memory Hierarchy

Temporal LocalityYou are likely to access memory locations multiple times

Spatial LocalityYou are likely to access memory locations near each other

Page 7: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

7

EECS 370 Discussion

Memory Hierarchy

Example:

int data[10];int sum = 0;…for (int i=0; i<10; i++) {

sum += data[i];}

Page 8: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

8

EECS 370 Discussion

Memory Hierarchy

Real World Example - Intel i7

Core0 Core1 Core2 Core3

Page 9: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

9

EECS 370 Discussion

Cache Design

Split Cache – portion your cache into two halves

I-Cache: Instruction CacheD-Cache: Data Cache

Why would we want to do this?

Page 10: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

10

EECS 370 Discussion

Types of CachesFully Associative

Blocks map to any cache line

CacheTag Data

Memory

0x1000 10

0x1004 20

0x1008 30

0x100C 40

0x1010 50

0x1014 60

0x1018 70

0x101C 80

0x1020 90

0x1024 100

0x1028 110

Page 11: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

11

EECS 370 Discussion

Types of CachesDirect Mapped

Blocks map to one cache line

CacheTag Data

Memory

0x1000 10

0x1004 20

0x1008 30

0x100C 40

0x1010 50

0x1014 60

0x1018 70

0x101C 80

0x1020 90

0x1024 100

0x1028 110

Page 12: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

12

EECS 370 Discussion

Types of CachesSet Associative

Blocks map to any line in a set

CacheTag Data

Memory

0x1000 10

0x1004 20

0x1008 30

0x100C 40

0x1010 50

0x1014 60

0x1018 70

0x101C 80

0x1020 90

0x1024 100

0x1028 110

Page 13: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

13

EECS 370 Discussion

Types of CachesSet Associative

Sets = Cache Lines / Ways

CacheTag Data

CacheTag Data

CacheTag Data

CacheTag Data

1-Way 2-Way 3-Way 6-Way

Page 14: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

14

EECS 370 Discussion

Three C’s

There are three reasons a cache miss occurs

1) Compulsory – never been loaded before

2) Capacity – evicted due to small cache size

3) Conflict – evicted due to overlap with another block

Page 15: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

15

EECS 370 Discussion

Cache Addressing

Addresses split into:

Tag Set Index Block Offset

log2(Block Size)

log2(Number of Sets)

Remaining Bits

Page 16: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

16

EECS 370 Discussion

Cache Writing Policy

For Writes Only On misses:

Write Allocate – add to cacheNo Write Allocate – don’t add to cache

On hits:Write Through – always write to memoryWrite Back – only write to cache

Page 17: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

17

EECS 370 Discussion

Caches

Cache Examples

Page 18: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

18

EECS 370 Discussion

Block size = 1 Word, Address = 16 bits2-way Set Associative

CacheTag Data

Memory

0x1000 10

0x1004 20

0x1008 30

0x100C 40

0x1010 50

0x1014 60

0x1018 70

0x101C 80

0x1020 90

0x1024 100

0x1028 110

0x102C 120

Page 19: EECS 370 Discussion 1 xkcd.com. EECS 370 Discussion Topics Today: – Caches!! Theory Design Examples 2.

19

EECS 370 Discussion

Caches

Cache Examples

Options:– Type of Cache– Cache Size– Block Size– Address Bits– Write Policy