1 / 23

November 3 rd , 2008 Nael Abu-Ghazaleh nabughaz@qatar.cmu qatar.cmu/~msakr/15447-f08/

CS-447– Computer Architecture Lecture 21 Set Associative Cache. November 3 rd , 2008 Nael Abu-Ghazaleh nabughaz@qatar.cmu.edu www.qatar.cmu.edu/~msakr/15447-f08/. address: tag index offset. Valid. 000000000000000000 0000000001 1100. 0x4-7.

billier
Télécharger la présentation

November 3 rd , 2008 Nael Abu-Ghazaleh nabughaz@qatar.cmu qatar.cmu/~msakr/15447-f08/

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS-447– Computer Architecture Lecture 21Set Associative Cache November 3rd, 2008 Nael Abu-Ghazalehnabughaz@qatar.cmu.edu www.qatar.cmu.edu/~msakr/15447-f08/

  2. address:tag index offset Valid 00000000000000000000000000011100 0x4-7 0x8-b 0xc-f 0x0-3 Tag 0 1 1 0 a b c d 2 3 ... Review… • Mechanism for transparent movement of data among levels of a storage hierarchy • set of address/value mappings • address => index to set of candidate blocks • compare desired address with tag • service hit or miss • load new block and binding on miss

  3. Review… • Drawbacks of Larger Block Size • Larger block size means larger miss penalty • on a miss, takes longer time to load a new block from next level • If block size is too big relative to cache size, then there are too few blocks • Result: miss rate goes up • In general, minimize Average Access Time = Hit Time + Miss Penalty x Miss Rate

  4. Review… • Hit Time = time to find and retrieve data from current level cache • Miss Penalty = average time to retrieve data on a current level miss (includes the possibility of misses on successive levels of memory hierarchy) • Hit Rate = % of requests that are found in current level cache • Miss Rate = 1 - Hit Rate

  5. Example • L1 cache: 2 cycle access time, 128Kbytes direct mapped • L2 cache access time: 10 cycles, 2Mbytes, 4 way set associative • DRAM access time: 100 cycles • If the hit ratio at L1 and at L2 is 98%, what is the average memory access time? • If the cost of a page fault is 1 million cycles, what page fault frequency (DRAM miss rate) would cause the average memory access time to double?

  6. Types of Cache Misses (1/2) • “Three Cs” Model of Misses • 1st C: Compulsory Misses • occur when a program is first started • Also called “cold misses” • cache does not contain any of that program’s data yet, so misses are bound to occur • can’t be avoided easily, so won’t focus on these in this course

  7. Types of Cache Misses (2/2) • 2nd C: Conflict Misses • miss that occurs because two distinct memory addresses map to the same cache location • two blocks (which happen to map to the same location) can keep overwriting each other • big problem in direct-mapped caches • how do we lessen the effect of these? • Dealing with Conflict Misses • Solution 1: Make the cache size bigger • Fails at some point • Solution 2: Multiple distinct blocks can fit in the same cache Index?

  8. Fully Associative Cache (1/3) • Memory address fields: • Tag: same as before • Offset: same as before • Index: non-existant • What does this mean? • no “rows”: any block can go anywhere in the cache • must compare with all tags in entire cache to see if data is there

  9. 4 31 0 Byte Offset Cache Tag (27 bits long) Cache Data Valid Cache Tag : B 0 B 31 B 1 = = = = : : : : = Fully Associative Cache (2/3) • Fully Associative Cache (e.g., 32 B block) • compare tags in parallel

  10. Fully Associative Cache (3/3) • Benefit of Fully Assoc Cache • No Conflict Misses (since data can go anywhere) • Drawbacks of Fully Assoc Cache • Need hardware comparator for every single entry: if we have a 64KB of data in cache with 4B entries, we need 16K comparators: infeasible

  11. A couple of new terms • Cache placement policy: where in the cache should a new block go • Cache replacement policy: when I need to make room for a new block, what block is replaced? • What are these policies for a direct mapped cache? Fully associative cache? • What is the “optimal” replacement policy? • Need to balance performance and complexity • The answer is different depending on the level of the cache

  12. Third Type of Cache Miss • Capacity Misses • miss that occurs because the cache has a limited size • miss that would not occur if we increase the size of the cache • sketchy definition, so just get the general idea • This is the primary type of miss for Fully Associative caches.

  13. N-Way Set Associative Cache (1/4) • Memory address fields: • Tag: same as before • Offset: same as before • Index: points us to the correct “row” (called a set in this case) • So what’s the difference? • each set contains multiple blocks • once we’ve found correct set, must compare with all tags in that set to find our data

  14. N-Way Set Associative Cache (2/4) • Summary: • cache is direct-mapped w/respect to sets • each set is fully associative • basically N direct-mapped caches working in parallel: each has its own valid bit and data

  15. N-Way Set Associative Cache (3/4) • Given memory address: • Find correct set using Index value. • Compare Tag with all Tag values in the determined set. • If a match occurs, hit!, otherwise a miss. • Finally, use the offset field as usual to find the desired data within the block.

  16. N-Way Set Associative Cache (4/4) • What’s so great about this? • even a 2-way set assoc cache avoids a lot of conflict misses • hardware cost isn’t that bad: only need N comparators • In fact, for a cache with M blocks, • it’s Direct-Mapped if it’s 1-way set assoc • it’s Fully Assoc if it’s M-way set assoc • so these two are just special cases of the more general set associative design

  17. 4 Byte Direct Mapped Cache Cache Index Memory Address Memory 0 0 1 1 2 2 3 3 4 5 6 7 8 9 A B C D E F Associative Cache Example • Recall this is how a simple direct mapped cache looked. • This is also a 1-way set-associative cache!

  18. Cache Index Memory Address Memory 0 0 0 1 1 2 1 3 4 5 6 7 8 9 A B C D E F Associative Cache Example • Here’s a simple 2 way set associative cache.

  19. Set Associative Cache Implementation

  20. Cache Performance—SPEC92

  21. Revisiting cache replacement • If we have a fully associative cache (or a set associative cache), what should the cache replacement policy be? • What is the optimal cache replacement policy (if you had oracle knowledge)? • What is the next best thing (without oracle knowledge)? • Least Recently Used; the future looks like the past • But how do we implement LRU?

  22. Cache sizes and access time • What’s the difference between L1, L2, L3, etc… caches? • If they are all SRAM, why do they have different access times? • Why do we need different levels? • What’s the difference between caches and registers? • Lets play with some Cacti (http://www.ece.ubc.ca/~stevew/cacti/run_frame.html)

  23. Cache writes • How should writes be handled? Write to memory or also to the caches? • Recall write-through vs. write-back • Which do you think performs better? • Lets complicate things a little bit; what happens if we have an SMP (symmetric multi-processor)

More Related