Results (
Thai) 1:
[Copy]Copied!
For cache to be functional, it must store useful data. However, this data becomesuseless if the CPU can’t find it. When accessing data or instructions, the CPUfirst generates a main memory address. If the data has been copied to cache, theaddress of the data in cache is not the same as the main memory address. Forexample, data located at main memory address 2E3 could be located in the veryfirst location in cache. How, then, does the CPU locate data when it has beencopied into cache? The CPU uses a specific mapping scheme that “converts” themain memory address into a cache location.This address conversion is done by giving special significance to the bits inthe main memory address. We first divide the bits into distinct groups we callfields. Depending on the mapping scheme, we may have two or three fields. Howwe use these fields depends on the particular mapping scheme being used. Themapping scheme determines where the data is placed when it is originally copiedinto cache and also provides a method for the CPU to find previously copied datawhen searching cache.Before we discuss these mapping schemes, it is important to understand howdata is copied into cache. Main memory and cache are both divided into the samesize blocks (the size of these blocks varies). When a memory address is generated,cache is searched first to see if the required word exists there. When therequested word is not found in cache, the entire main memory block in which theword resides is loaded into cache. As previously mentioned, this scheme is successfulbecause of the principle of locality—if a word was just referenced, thereis a good chance words in the same general vicinity will soon be referenced aswell. Therefore, one missed word often results in several found words. For example,when you are in the basement and you first need tools, you have a “miss” andmust go to the garage. If you gather up a set of tools that you might need andreturn to the basement, you hope that you’ll have several “hits” while working onyour home improvement project and don’t have to make many more trips to thegarage. Because accessing a cache word (a tool already in the basement) is fasterthan accessing a main memory word (going to the garage yet again!), cache memoryspeeds up the overall access time.So, how do we use fields in the main memory address? One field of themain memory address points us to a location in cache in which the data residesif it is resident in cache (this is called a cache hit), or where it is to be placed ifit is not resident (which is called a cache miss). (This is slightly different forassociative mapped cache, which we discuss shortly.) The cache block referencedis then checked to see if it is valid. This is done by associating a valid bitwith each cache block. A valid bit of 0 means the cache block is not valid (wehave a cache miss) and we must access main memory. A valid bit of 1 means itis valid (we may have a cache hit but we need to complete one more step beforewe know for sure). We then compare the tag in the cache block to the tag fieldof our address. (The tag is a special group of bits derived from the main memoryaddress that is stored with its corresponding block in cache.) If the tags arethe same, then we have found the desired cache block (we have a cache hit). Atthis point we need to locate the desired word in the block; this can be doneusing a different portion of the main memory address called the word field. Allcache mapping schemes require a word field; however, the remaining fields aredetermined by the mapping scheme. We discuss the three main cache mappingschemes on the next page.Direct Mapped CacheDirect mapped cache assigns cache mappings using a modular approach. Becausethere are more main memory blocks than there are cache blocks, it should beclear that main memory blocks compete for cache locations. Direct mappingmaps block X of main memory to block Y of cache, mod N, where N is the totalnumber of blocks in cache. For example, if cache contains 10 blocks, then mainmemory block 0 maps to cache block 0, main memory block 1 maps to cacheblock 1, . . . , main memory block 9 maps to cache block 9, and main memoryblock 10 maps to cache block 0. This is illustrated in Figure 6.2. Thus, mainmemory blocks 0 and 10 (and 20, 30, and so on) all compete for cache block 0.You may be wondering, if main memory blocks 0 and 10 both map to cacheblock 0, how does the CPU know which block actually resides in cache block 0 atany given time? The answer is that each block is copied to cache and identified
Being translated, please wait..