Computer Science and Engineering Copyright by Hesham El-Rewini Advanced Computer Architecture CSE 8383 January Session 2
Computer Science and Engineering Copyright by Hesham El-Rewini Contents (Memory) Memory Hierarchy Cache Memory Placement Policies n Direct Mapping n Fully Associative n Set Associative Replacement Policies
Computer Science and Engineering Copyright by Hesham El-Rewini Memory Hierarchy CPU Registers Cache Main Memory Secondary Storage Latency Bandwidth Speed Cost per bit
Computer Science and Engineering Copyright by Hesham El-Rewini Sequence of events 1.Processor makes a request for X 2.X is sought in the cache 3.If it exists hit (hit ratio h) 4.Otherwise miss (miss ratio m = 1-h) 5.If miss X is sought in main memory 6.It can be generalized to more levels
Computer Science and Engineering Copyright by Hesham El-Rewini Cache Memory The idea is to keep the information expected to be used more frequently in the cache. Locality of Reference n Temporal Locality n Spatial Locality Placement Policies Replacement Policies
Computer Science and Engineering Copyright by Hesham El-Rewini Placement Policies How to Map memory blocks (lines) to Cache block frames (line frames) Blocks (lines) Block Frames (Line Frames) Memory Cache
Computer Science and Engineering Copyright by Hesham El-Rewini Placement Policies n Direct Mapping n Fully Associative n Set Associative
Computer Science and Engineering Copyright by Hesham El-Rewini Direct Mapping Simplest A memory block is mapped to a fixed cache block frame (many to one mapping) J = I mod N n J Cache block frame number n I Memory block number n N number of cache block frames
Computer Science and Engineering Copyright by Hesham El-Rewini Address Format Memory M blocks Block size B words Cache N blocks Address size log 2 (M * B) TagBlock frameWord log 2 Blog 2 NRemaining bits log 2 M/N
Computer Science and Engineering Copyright by Hesham El-Rewini Example Memory 4K blocks Block size 16 words Address size log 2 (4K * 16) = 16 Cache 128 blocks TagBlock frameWord 475
Computer Science and Engineering Copyright by Hesham El-Rewini Example (cont.) MemoryTagcache bits
Computer Science and Engineering Copyright by Hesham El-Rewini Fully Associative Most flexible A memory block is mapped to any available cache block frame (many to many mapping) Associative Search
Computer Science and Engineering Copyright by Hesham El-Rewini Address Format Memory M blocks Block size B words Cache N blocks Address size log 2 (M * B) TagWord log 2 BRemaining bits log 2 M
Computer Science and Engineering Copyright by Hesham El-Rewini Example Memory 4K blocks Block size 16 words Address size log 2 (4K * 16) = 16 Cache 128 blocks TagWord 412
Computer Science and Engineering Copyright by Hesham El-Rewini Example (cont.) Memory Tagcache 12 bits
Computer Science and Engineering Copyright by Hesham El-Rewini Set Associative Compromise between the other two Cache number of sets Set number of blocks A memory block is mapped to any available cache block frame within a specific set Associative Search within a set
Computer Science and Engineering Copyright by Hesham El-Rewini Address Format Memory M blocks Block size B words Cache N blocks Number of sets S N/num of blocks per set Address size log 2 (M * B) log 2 B TagSetWord log 2 S Remaining bits log 2 M/S
Computer Science and Engineering Copyright by Hesham El-Rewini Example Memory 4K blocks Block size 16 words Address size log 2 (4K * 16) = 16 Cache 128 blocks Num of blocks per set = 4 Number of sets = 32 4 TagSetWord 57
Computer Science and Engineering Copyright by Hesham El-Rewini Example (cont.) Set 0 Tag cache 7 bits Set Memory
Computer Science and Engineering Copyright by Hesham El-Rewini Comparison Simplicity Associative Search Cache Utilization Replacement
Computer Science and Engineering Copyright by Hesham El-Rewini Group Exercise The instruction set for your architecture has 40-bit addresses, with each addressable item being a byte. You elect to design a four-way set-associative cache with each of the four blocks in a set containing 64 bytes. Assume that you have 256 sets in the cache. Show the Format of the address
Computer Science and Engineering Copyright by Hesham El-Rewini Group Exercise (Cont.) Consider the following sequence of addresses. (All are hex numbers) 0E1B01AA05 0E1B01AA07 0E1B2FE305 0E1B4FFD8F 0E1B01AA0E In your cache, what will be the tags in the sets(s) that contain these references at the end of the sequence? Assume that the cache is initially flushed (empty).
Computer Science and Engineering Copyright by Hesham El-Rewini Replacement Techniques FIFO LRU MRU Random Optimal