Implement Cache Simulator

Implement Cache Simulator

I. Purpose

  • (1) enhance the basic concept of the Cache, understand the basic organizational structure and basic working principles.
  • (2) Cache control capacity, associativity, the block size of the Cache impact performance.
  • (3) master the various methods of reducing Cache miss rate and the benefits of these methods to improve the performance of the Cache.
  • (4) the random LRU understood that the basic idea of ​​the method and their impact on the performance of the Cache.

Second, the experimental details and steps

1 , start CacheSim.
2 , according to the relevant textbook knowledge, become more familiar with the concept and mechanism of Cache.
3 , sequentially enter the following parameters: Cache capacity, block size, the mapping mode, and write strategy replacement policy.
Cache block replacement policy capacity capacity mapping mode write strategy
Here Insert Picture Description
4 , read in the trace file cache-traces.zip.
5 , run the program, observe the number of visits cache, the read / write cycles, the average hit rate, read / write hit rate.
Reflections :
1. What is the relationship Cache hit rate to its capacity size?
2, Cache block size does not impact on the hit rate?
3, replacement algorithm and associated impact on the size of the miss rate?

III. Analysis of experimental results

The question: What is the relationship Cache hit rate to its capacity size?
Here Insert Picture Description

The average cache hit ratio average cache hit rate
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Conclusion: Cache larger capacity, higher hit rate CPU which, of course excessive capacity, an increase in cost, and when the cache capacity reaches a certain value, the hit rate is not due to increased capacity but significantly improved;

问题二:Cache块大小对不命中率的影响
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
结论:增大块长,由于局部性原理,起初命中率会提高,局部性原理指出,在被访问字的附近,近期也可能被访问,因此,增大块长,最初可将更多有用字存入缓存,提高命中率; 但是继续增大块长,命中率可能下降,因为所装入缓存的有用数据反而少于被替换掉的有用数据,由于块长增大,块数减少,装入新的块要覆盖旧块,很可能出现少数块刚装入就被覆盖,故命中率可能下降
问题三:替换算法对命中率影响数据分析
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
结论:替换算法中:LRU算法的平均命中率比FIFO的高
LRU算法比较好地利用访存局部性原理,替换出近期用得最少的字块,它需要随时记录cache 各个字块使用情况。FIFO不需要记录各个字块的使用情况,比较容易实现开销小,但是没有根据访存的局部性原理,最早调入的信息可能以后还要用到,或经常用到例如循环程序;

问题四:相关度大小对命中率影响数据分析

Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
结论:Cache 容量一定时,随着相联度的不断增加,命中率渐渐升高,但是当相连度增加到一定程度时,命中率保持不变;

四.知识点总结

  • (1)加深对 Cache的基本概念、基本组织结构以及基本工作原理的理解。
  • (2)掌握 Cache容量、相联度、块大小对Cache性能的影响。
  • (3)掌握降低 Cache不命中率的各种方法以及这些方法对提高Cache性能的好处。
  • (4)理解LRU与随机法的基本思想以及它们对Cache性能的影响。

一.为什么会出现Cache?

答:I/o设备向主存请求的级别高于cpu访存,出现了cpu等待I/o设备访存的现象,致使cpu空等一段时间,降低了工作效率;cache的出现让cpu可以不直接访问主存,而与高速cache交换信息

二.程序访问的局部性是什么?

答:cpu从主存中存取指令的数据,只对主存局部区域地址访问,这是由于指令和数据在主存内都是连续存放的,使得cpu在执行程序中,访存具有相对局部性,这就称为程序访问的局部性;

三.cache的基本组织结构

缓存是由2n 个可编址的字组成,每个字有唯一的n位地址,缓存分成了若干块,每块内包含了若干个字,块内字数相同,缓存的地址分为两端,高c位表示缓存块号,低b位表示块内地址,块长有2b

四.cache的基本工作原理?

任何时刻都有一些主存块处在缓存块中,cpu想要读取主存某字时,有两种可能:1.所需要的字已经在缓存中2.所需要的字不在缓存中,此时需要将该字所在的主存字块调入cache中,此时主存与缓存建立关系

五.Cache的替换机构

CPU欲想要访存的主存块与cache块未建立对应关系,此时cpu访问主存,将该字所在的主存块调入Cache,如果Cache已经被装满,需要采用替换策略。

六.替换策略

1.先进先出(FIFO)算法
举例:小明有一个书柜(相当于主存),书柜里的书相当于主存中的块,卧室还有一个床头柜(缓存),床头柜放书的数量有限,最在小明拿了一本工具书看,紧接着几天又拿了其他书,床头柜满了,需要拿走书,按照(FIFO)算法,把最早放入的那本工具书拿走了,但是这本工具书经常用到,所以这种方法,不可行,不能提高cache命中率
2.近期最少使用(LRU)算法
长期不被使用的数据,在未来被用到的几率也不大。因此,当数据所占内存达到一定阈值时,要移除掉最近最少使用的数据。Cache命中率提高

3.随机法
采用随机数产生器,产生一个随机被替换的块,没有根据访存的局部性原理,不能提高Cache命中率

Published 58 original articles · won praise 20 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_40709110/article/details/103026731