Presentation is loading. Please wait.

Presentation is loading. Please wait.

제 10 장 Cache Memory. kuic.kyonggi.ac.kr/~dssung 10.0 Cache = Cache Memory Cache 는 Fast Memory 이며 CPU 와 Memory 사이에 위치 Memory 내 일부 정보를 가지고 있다 CPU Cache.

Similar presentations


Presentation on theme: "제 10 장 Cache Memory. kuic.kyonggi.ac.kr/~dssung 10.0 Cache = Cache Memory Cache 는 Fast Memory 이며 CPU 와 Memory 사이에 위치 Memory 내 일부 정보를 가지고 있다 CPU Cache."— Presentation transcript:

1 제 10 장 Cache Memory

2 kuic.kyonggi.ac.kr/~dssung 10.0 Cache = Cache Memory Cache 는 Fast Memory 이며 CPU 와 Memory 사이에 위치 Memory 내 일부 정보를 가지고 있다 CPU Cache Memory CPU Memory DRAM SRAM

3 kuic.kyonggi.ac.kr/~dssung CPU Memory Fast Slow 왜, Cache 를 이용하는가 ? 첫 번째, CPU 의 속도가 Memory 의 속도보다 빠르기 때문에 CPU 가 wait 상태에 있는 비율이 높아지게 되며 따라서 CPU 의 사용 효율이 낮아지게 된다. Cache 를 두어 CPU 의 사용 효율을 높이는 것이 목적 CPU 의 사용 효율이 높아지게 되면 프로그램의 수행속도가 빨라진다. CPU Cache Memory Slow Fast

4 kuic.kyonggi.ac.kr/~dssung 왜, Cache 를 이용하는가 ? 두 번째, DMA controller 가 Memory 를 이용하고 있는 동안에 CPU 는 idle 상태에 있게 되며 이로 인하여 CPU 의 사용 효율이 낮아지게 될 수 있다. 이 경우 Cache 를 두면 DMA controller 가 Memory 를 사용하는 동안 CPU 는 Cache 를 이용할 수 있기 때문에 CPU 의 사용 효율이 높아질 수 있다. CPU Cache MemoryI/O : DMA bus

5 kuic.kyonggi.ac.kr/~dssung 왜, Cache 를 이용하는가 ? 세 번째, CPU 가 여러 개 있는 병렬처리 컴퓨터에서 하나의 CPU 가 Memory 를 이용 할 때, 다른 CPU 는 idle 상태에 있게 되며 이로 인하여 CPU 의 사용 효율이 낮아지게 될 수 있다. 이 경우 Cache 를 두면 하나의 CPU 가 Memory 를 사용하는 동안 다른 CPU 는 Cache 를 이용할 수 있기 때문에 CPU 의 사용 효율이 높아질 수 있다. CPU Cache Memory bus Cache CPU

6 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory 왜, Cache 를 사용하면 프로그램의 속도가 빨라 지는가 ? -> 늦어지는 경우도 있다. Memory Access Time = 100 nsec Cache Access Time = 25 nsec 라 가정하면, CPU Memory Access Time = 100 nsec Access Time = 100 nsec + 25 nsec = 125 nsec

7 kuic.kyonggi.ac.kr/~dssung 왜, Cache 를 사용하면 프로그램의 속도가 일반적으로 빨라 지는가 ? -> Locality (Temporal Locality, Spatial Locality) -> 대부분의 프로그램은 지역성 (locality) 의 특징을 가진다. -> locality 의 특징을 가지지 않게 프로그램 하는 것은 비 효율적 일뿐만 아니라, 더 어렵다. -> locality 의 특징을 가지는 거의 대부분의 프로그램은 Cache 를 이용할 경우, 프로그램의 수행속도가 빨라지게 된다.

8 kuic.kyonggi.ac.kr/~dssung 10.1 Principle of Locality (1). Temporal Locality (Locality in Time) -> If an item is referenced, it will tend to be referenced again soon -> ex) main(){ int i, sum, mul; sum = 0; mul = 0; for(i=1; i<=10; i++){ sum = sum + i; mul = mul * i; } printf(“sum is %d \n”, sum); printf(“mul is %d \n”, mul); }

9 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory Temporal Locality 의 경우 average access time 이 빨라지는 예 -> 동일한 정보를 10 번 읽는 경우 Memory Access Time = 100 nsec Cache Access Time = 25 nsec 라 가정하면, CPU Memory Total Access Time = 100 nsec * 10 Average Access Time = 100 nsec Total Access Time = 100 nsec + 25 nsec*10 = 350 nsec Average Access Time = 35 nsec

10 kuic.kyonggi.ac.kr/~dssung (2). Spatial Locality (Locality in Space) -> If an item is referenced, nearby items will tend to be referenced soon -> ex) main(){ int i, sum, mul; sum = 0; mul = 0; for(i=1; i<=10; i++){ sum = sum + i; mul = mul * i; } printf(“sum is %d \n”, sum); printf(“mul is %d \n”, mul); }

11 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory Spatial Locality 의 경우 average access time 이 빨라지는 예 -> 이웃 정보를 4 개를 읽는 경우 (Memory->Cache: fast page mode) Memory Access Time = 100 nsec Cache Access Time = 25 nsec 라 가정하면, CPU Memory Total Access Time = 100 nsec * 4 Average Access Time = 100 nsec Total Access Time = 100 nsec + 50 nsec*3 + 25 nsec*4 = 350 nsec Average Access Time = 87.5 nsec

12 kuic.kyonggi.ac.kr/~dssung 10.2 Hit Ratio Hit is a memory access in cache, while miss means it is not found in cache. CPU Cache Memory CPU Cache Memory Hit Miss

13 kuic.kyonggi.ac.kr/~dssung Hit ratio is the fraction of memory accesses found in the cache. Hit ratio = {(Hit number)/(Try number)}*100 CPU Cache Memory CPU Memory CPU Cache Memory Hit ratio = 0 Hit ratio = 100 0 < Hit ratio < 100

14 kuic.kyonggi.ac.kr/~dssung 10.3 Block Size in Cache Block : miss 가 발생 시 memory 에서 cache 로 복사하는 정보 단위 Cache Memory Cache Memory Block 의 크기가 크면 cache 내 block 의 개수가 적어지며 block 의 크기가 작으면 cache 내 block 의 개수가 많아진다. ex) cache size = 256byte block size : 16byte -> cache 내 block 의 수 = 16 개 block size : 32byte -> cache 내 block 의 수 = 8 개

15 kuic.kyonggi.ac.kr/~dssung Block 의 size 는 hit ratio 를 높이는 방향으로 결정되어야 한다. 매우 어려운 문제 -> block 의 size 가 작아지면 block 의 개수가 많아지게 된다. Temporal Locality : good Spatial Locality : bad -> block 의 size 가 커지면 block 의 개수가 적어지게 된다. Temporal Locality : bad Spatial Locality : good

16 kuic.kyonggi.ac.kr/~dssung Cache = Set of Blocks Cache size is 256 byte If block size is 16 byte -> Cache = 16 blocks If block size is 32 byte -> Cache = 8 blocks Block = Set of Entries Block size is 16 byte If 8bit CPU -> Block = 16 entries If 16bit CPU -> Block = 8 entries Entry = Set of Bytes 8bit CPU -> Entry = 1 Byte 16bit CPU -> Entry = 2 Bytes 32bit CPU -> Entry = 4 Bytes

17 kuic.kyonggi.ac.kr/~dssung ex) 8 bit CPU, Cache size = 256 bytes, Block size = 16bytes Cache = 16 Blocks, Block = 16 Entries, Entry = 1 Bytes C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F)

18 kuic.kyonggi.ac.kr/~dssung 10.4 Block Placement CPU Cache Memory CPU Cache Memory miss 가 발생시 memory 에서 해당되는 block 을 cache 로 가지고 와야 하며, 이때, 어디에 둘 것인가 ?

19 kuic.kyonggi.ac.kr/~dssung A. Direct Mapped : = One-way set associative Each block has only one place it can appear in the cache Cache Memory Cache Memory

20 kuic.kyonggi.ac.kr/~dssung B. Fully Associative : A block can be placed anywhere in the cache Cache Memory Cache Memory Cache Memory Cache Memory Cache Memory

21 kuic.kyonggi.ac.kr/~dssung C. Set Associative : A block can be placed in a restricted set of places in the cache Cache Memory Cache Memory Cache Memory

22 kuic.kyonggi.ac.kr/~dssung If there are n blocks in a set, the cache placement is called n-way set associative Cache 2-way set associative 4-way set associative = Fully associative 1-way set associative = Direct mapped for example) Cache 내에 4 개의 block 가 있는 경우

23 kuic.kyonggi.ac.kr/~dssung ex) Main Memory => 64 Kbyte (0x0000 - 0xFFFF) M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F)

24 kuic.kyonggi.ac.kr/~dssung Memory Block 01F A. Direct Mapped Method => Cache Block F 만 Placement M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F)

25 kuic.kyonggi.ac.kr/~dssung Memory Block 01F 0000 0001 1111 Cache Set 의 개수 = Cache Block 의 개수 16 개 = 4bit 로 표현 선택되는 Cache Set = Cache Block -> Memory Block 의 하위 4bit 에 의하여 선택 0000 0001 1111 -> Memory Block 01F 는 Cache Block F 로 Placement

26 kuic.kyonggi.ac.kr/~dssung CPU 가 Memory 01F8 번지 정보를 원하는 경우 이 정보가 Cache 에 없다면 (Miss) 이 정보가 속해 있는 Memory Block 을 해당되는 Cache Block 에 복사해야 한다. 01F8 번지가 속한 Memory Block 은 01F Direct Mapped Method 에 의하여 Cache Block F 에 Placement 했다면 -> Memory Block 01F 는 Cache Block F 에 복사 되었음을 의미

27 kuic.kyonggi.ac.kr/~dssung B. Full Associative Method => Cache Block 0 - F 어느 곳이나 Placement M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F)

28 kuic.kyonggi.ac.kr/~dssung C. 2-Way Set Associative Method C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Set 0 Set 1 Set 2 Set 3 Set 4 Set 5 Set 6 Set 7

29 kuic.kyonggi.ac.kr/~dssung 2-Way Set Associative Method M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Set 0 Set 1 Set 2 Set 3 Set 4 Set 5 Set 6 Set 7

30 kuic.kyonggi.ac.kr/~dssung Memory Block 01F 0000 0001 1111 Cache Set 의 개수 8 개 = 3bit 로 표현 선택되는 Cache Set -> Memory Block 의 하위 3bit 에 의하여 선택 0000 0001 1111 -> Memory Block 01F 는 Cache Set 7 로 Placement

31 kuic.kyonggi.ac.kr/~dssung D. 4-Way Set Associative Method C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Set 0 Set 1 Set 2 Set 3

32 kuic.kyonggi.ac.kr/~dssung 4-Way Set Associative Method M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Set 0 Set 1 Set 2 Set 3

33 kuic.kyonggi.ac.kr/~dssung Memory Block 01F 0000 0001 1111 Cache Set 의 개수 4 개 = 2bit 로 표현 선택되는 Cache Set -> Memory Block 의 하위 2bit 에 의하여 선택 0000 0001 1111 -> Memory Block 01F 는 Cache Set 3 으로 Placement

34 kuic.kyonggi.ac.kr/~dssung 10.5 Block Identification CPU 가 원하는 정보가 Cache 에 있는지를 어떠한 방법으로 확인할 것인가 ? CPU Cache Memory CPU Cache Memory Hit Miss

35 kuic.kyonggi.ac.kr/~dssung Full Associative Method => Cache Block 0 - F 어느 곳이나 Placement M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F)

36 kuic.kyonggi.ac.kr/~dssung M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) … … … … … … … … … … … 0x 01F … … … … Tag CPU 가 원하는 정보가 Cache 에 있는지를 어떠한 방법으로 확인할 것인가 ? Cache 내 Tag 를 이용 Cache Tag 를 통하여 Cache Block B 에 Memory Block 01F 가 있음을 알 수 있다.

37 kuic.kyonggi.ac.kr/~dssung Full Associative Method => Cache Block 0 - F 어느 곳이나 Placement CPU 는 원하는 정보가 Cache 에 있는지 확인하기 위하여 최악의 경우 모든 Tag 를 확인해야 한다.

38 kuic.kyonggi.ac.kr/~dssung Direct Mapped Method => Cache Block F 만 Placement M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) … … … … … … … … … … … … … … … 0x 01F Tag Cache Tag 를 통하여 Cache Block F 에 Memory Block 01F 가 있음을 알 수 있다.

39 kuic.kyonggi.ac.kr/~dssung Direct Mapped Method => Cache Block F 만 Placement CPU 는 원하는 정보가 Cache 에 있는지 확인하기 위하여 특정 Cache Block 의 Tag 만 검사하면 된다. ex) CPU 가 원하는 정보 0x01F8 번지의 정보 -> Memory Block 0x01F 이며 Cache Block F 에 만 placement 가능 따라서 Cache Block F 의 Tag 만 검사하면 된다. 이 방법의 경우, Tag 의 길이는 다음과 같이 줄어 들 수 있다.

40 kuic.kyonggi.ac.kr/~dssung M block FFF (FFF0-FFFF) M block FFE (FFE0-FFEF) … … … … … … M block 01F (01F0-01FF) … … … … M block 002 (0020-002F) M block 001 (0010-001F) M block 000 (0000-000F) C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) … … … … … … … … … … … … … … … 0x01

41 kuic.kyonggi.ac.kr/~dssung Memory Block 0x01F 0000 0001 1111 Cache Set 의 개수 = Cache Block 의 개수 16 개 = 4bit 로 표현 선택되는 Cache Set = Cache Block -> Memory Block 의 하위 4bit 에 의하여 선택 0000 0001 1111 (index field) -> Memory Block 0x01F 는 Cache Block F 로 Placement 이 경우, 하위 4bit 를 제외한 나머지 부분만 Tag 로 하면 된다. -> 0000 0001 1111 (Tag field)

42 kuic.kyonggi.ac.kr/~dssung CPU Address => [ Tag field ][ Index field ][ Block offset field ] = [ Memory block number ][ Block offset field ] ex) CPU Address = 0x01F8 Direct Mapped Method 에서 Memory block number = 0x01F 0x01F8 Block offset field = 0x8 0x01F8 Tag field = 0x01 0x01F8 Index field = 0xF 0x01F8 Block offset field = 0x8 0x01F8

43 kuic.kyonggi.ac.kr/~dssung [Tag field] => Comparison with the tag in the cache [Index field] => Select the set [Block offset field] => Select the desired data

44 kuic.kyonggi.ac.kr/~dssung A. Full Associative Method (m-way set associative) ex) CPU Address = 0x01F8 Tag field = 0x01F 0x01F8 Index field = Block offset field = 0x8 0x01F8 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 1 개 = 0bit 로 표현 => index field is null 따라서 Tag field = 0000 0001 1111 = 0x01F

45 kuic.kyonggi.ac.kr/~dssung B. Direct Mapped Method (1-way set associative) ex) CPU Address = 0x01F8 Tag field = 0x01 0x01F8 Index field = 0xF 0x01F8 Block offset field = 0x8 0x01F8 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 16 개 = 4bit 로 표현 => index field is 4 bit => 1111 = 0xF 따라서 Tag field = 0000 0001 = 0x01

46 kuic.kyonggi.ac.kr/~dssung C. 2-way set Associative Method ex) CPU Address = 0x01F8 = 0000 0001 1111 1000 Tag field = 0000 0001 1 0000 0001 1111 1000 Index field = 111 0000 0001 1111 1000 Block offset field = 1000 0000 0001 1111 1000 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 8 개 = 3bit 로 표현 => index field is 3 bit => 111 따라서 Tag field = 0000 0001 1

47 kuic.kyonggi.ac.kr/~dssung D. 4-way set Associative Method ex) CPU Address = 0x01F8 = 0000 0001 1111 1000 Tag field = 0000 0001 11 0000 0001 1111 1000 Index field = 11 0000 0001 1111 1000 Block offset field = 1000 0000 0001 1111 1000 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 4 개 = 2bit 로 표현 => index field is 2 bit => 11 따라서 Tag field = 0000 0001 11

48 kuic.kyonggi.ac.kr/~dssung E. 8-way set Associative Method ex) CPU Address = 0x01F8 = 0000 0001 1111 1000 Tag field = 0000 0001 111 0000 0001 1111 1000 Index field = 1 0000 0001 1111 1000 Block offset field = 1000 0000 0001 1111 1000 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 2 개 = 1bit 로 표현 => index field is 1 bit => 1 따라서 Tag field = 0000 0001 111

49 kuic.kyonggi.ac.kr/~dssung - The tag/index boundary moves to the right with increasing associativity. Direct Mapped Method (1-way set associative) 0000 0001 1111 2-way set Associative Method 0000 0001 1111 4-way set Associative Method 0000 0001 1111 8-way set Associative Method 0000 0001 1111 Full Associative Method (m-way set associative) 0000 0001 1111

50 kuic.kyonggi.ac.kr/~dssung - Caches include an address tag on each block - Cache tag address is checked to see if it matches the tag field of CPU address - Because speed is of the essence, all possible tags are searched in parallel - Valid bit in the tag : Notify whether or not this entry contains a valid address

51 kuic.kyonggi.ac.kr/~dssung A. Full Associative Method (m-way set associative) ex) CPU Address = 0x01F8 Tag field = 0x01F 0x01F8 Index field = Block offset field = 0x8 0x01F8 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 1 개 = 0bit 로 표현 => index field is null 따라서 Tag field = 0000 0001 1111 = 0x01F

52 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Tag Full Associative Method CPU 0x01F8 Valid bit 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0x234 0x000 0x01C 0x01E 0x553 0x000 0x766 0x023 0x011 0x126 0x123 0x222 0x111 0x01F

53 kuic.kyonggi.ac.kr/~dssung B. Direct Mapped Method (1-way set associative) ex) CPU Address = 0x01F8 Tag field = 0x01 0x01F8 Index field = 0xF 0x01F8 Block offset field = 0x8 0x01F8 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 16 개 = 4bit 로 표현 => index field is 4 bit => 1111 = 0xF 따라서 Tag field = 0000 0001 = 0x01

54 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) Tag CPU 0x01F8 Valid bit 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0x01 0x00 0x01 0x55 0x00 0x76 0x02 0x01 0x12 0x22 0x11 0x01 Direct Mapped Method

55 kuic.kyonggi.ac.kr/~dssung C. 2-way set Associative Method ex) CPU Address = 0x01F8 = 0000 0001 1111 1000 Tag field = 0000 0001 1 0000 0001 1111 1000 Index field = 111 0000 0001 1111 1000 Block offset field = 1000 0000 0001 1111 1000 Memory Block Number = 0x01F 0000 0001 1111 Cache Set 의 개수 = 8 개 = 3bit 로 표현 => index field is 3 bit => 111 따라서 Tag field = 0000 0001 1

56 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) CPU 0x01F8 Valid bit 1 1 0 1 1 1 0 0 1 1 1 1 1 1 1 1 000000011 2-way set Associative Method 0000 0001 1111 1000 000000111 000000000 000000111 000010011 000000011 000000000 001000011 001100011 001110011 111000011 000010011 011100011 000011111 000000111 Tag

57 kuic.kyonggi.ac.kr/~dssung 10.6 Block Replacement CPU Cache Memory

58 kuic.kyonggi.ac.kr/~dssung Direct Mapped Placement => Simple CPU Cache Memory

59 kuic.kyonggi.ac.kr/~dssung Fully or Set Associative Placement a. Random b. LRU(Least Recently Used) CPU Cache Memory

60 kuic.kyonggi.ac.kr/~dssung 10.7 Read Strategy Parallel Tags Matching Parallel Reading of Cache and Memory

61 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) 0x01F 0x111 0x222 0x123 0x126 0x011 0x023 0x766 0x812 0x922 0x553 0x01E 0x01C 0xABC 0x987 0x234 Tag Full Associative Method CPU 0x01F8 Parallel Tags Matching

62 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) 0x01F 0x111 0x222 0x123 0x126 0x011 0x023 0x766 0x812 0x922 0x553 0x01E 0x01C 0xABC 0x987 0x234 Tag CPU 0x01F8 Memory Parallel Reading of Cache and Memory

63 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) 0x01F 0x111 0x222 0x123 0x126 0x011 0x023 0x766 0x812 0x922 0x553 0x01E 0x01C 0xABC 0x987 0x234 Tag CPU 0x01F8 Memory Parallel Reading of Cache and Memory hit

64 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) 0x01A 0x111 0x222 0x123 0x126 0x011 0x023 0x766 0x812 0x922 0x553 0x01E 0x01C 0xABC 0x987 0x234 Tag CPU 0x01F8 Memory Parallel Reading of Cache and Memory miss

65 kuic.kyonggi.ac.kr/~dssung C block F (F0-FF) C block E (E0-EF) C block D (D0-DF) C block C (C0-CF) C block B (B0-BF) C block A (A0-AF) C block 9 (90-9F) C block 8 (80-8F) C block 7 (70-7F) C block 6 (60-6F) C block 5 (50-5F) C block 4 (40-4F) C block 3 (30-3F) C block 2 (20-2F) C block 1 (10-1F) C block 0 (00-0F) 0x01A 0x111 0x222 0x123 0x126 0x011 0x023 0x01F 0x812 0x922 0x553 0x01E 0x01C 0xABC 0x987 0x234 CPU 0x01F8 Memory Parallel Reading of Cache and Memory miss

66 kuic.kyonggi.ac.kr/~dssung Program Instruction = Code Op code field + Operand field Read Only Data Operand Read/Write ex) INC $1000 <- Instruction $1000 번지 내용 <- Data

67 kuic.kyonggi.ac.kr/~dssung Cache Code Cache - Code 정보만 Cache - Read Only - Read Hit, Read Miss Data Cache - Data 정보만 Cache - Read/Write : - Read Hit, Read Miss, Write Hit, Write Miss Code/Data Cache - Code 와 Data 정보 모두 Cache - Read/Write - Read Hit, Read Miss, Write Hit, Write Miss

68 kuic.kyonggi.ac.kr/~dssung 10.8 Write Strategy (1). Write Hit -> Cache 와 Memory 내에 있는 정보가 달라 질 수 있다. CPU Cache Memory CPU Cache Memory

69 kuic.kyonggi.ac.kr/~dssung a. Write Through -> The information is written to both the block in the cache and the block in the lower level memory -> Advantage to keep the cache and memory consistent CPU Cache Memory CPU Cache Memory Write hit

70 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory CPU Cache Memory Write hit CPU Cache Memory

71 kuic.kyonggi.ac.kr/~dssung b. Write Back -> The information is written only to the block in the cache. The modified cache block is written to main memory only when it is replaced. -> Use less memory bandwidth (Multiple write in a block => One write to low level memory)

72 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory CPU Cache Memory CPU Cache Memory ReplacementWrite hit

73 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory CPU Cache Memory CPU Cache Memory Replacement Write hit CPU Cache Memory Write hit

74 kuic.kyonggi.ac.kr/~dssung (2). Write Miss a. Write allocate : Prefetch on write -> The block is loaded into cache b. No write allocate : Write around -> The block is not loaded into cache

75 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory miss CPU Cache Memory read CPU Cache write Write allocate

76 kuic.kyonggi.ac.kr/~dssung CPU Cache Memory miss No write allocate CPU Cache Memory

77 kuic.kyonggi.ac.kr/~dssung write-back caches generally use write allocate (hoping that subsequent writes to that block will be captured by the cache) write-through caches often use no-write allocate (since subsequent writes to that block will still have to go to memory)


Download ppt "제 10 장 Cache Memory. kuic.kyonggi.ac.kr/~dssung 10.0 Cache = Cache Memory Cache 는 Fast Memory 이며 CPU 와 Memory 사이에 위치 Memory 내 일부 정보를 가지고 있다 CPU Cache."

Similar presentations


Ads by Google