# Ubuntu 18.04 LTS
###### tags: `祭祖`
:::success
:::spoiler 目錄
[TOC]
:::
## *問題集*
- GEM5 + NVMAIN BUILD-UP (40%)
- Enable L3 last level cache in GEM5 + NVMAIN (15%)
- Config last level cache to 2-way and full-way associative cache and test performance (15%)
- Modify last level cache policy based on RRIP (15%)
- Test the performance of write back and write through policy based on 4-way associative cache with isscc_pcm(15%)
- Bonus (20%)
- Design last level cache policy to reduce the energy consumption of pcm_based main memory
- Baseline:LRU
## GEM5 + NVMAIN BUILD-UP (40%)
- [name=JCxYIS]
- Ubuntu 18.04.5 LTS 順利可行。
- 目前可以不需 GUI。
- 「Nvmain project 說明與教學」簡報
- 更正
> 簡報第十六頁:
>
> *可以由gem5/m5out中的==stat.txt==查看cache hit 的次數*
>
> 應更正為:
>
> *可以由gem5/m5out中的==stats.txt==查看cache hit 的次數*
- [name=wasabi-neko]
- 成功使用 docker 以 ubuntu:18.04 image 下順利運行
- 編譯效率也不錯
- 有空可以嘗試弄一個 gem5+NVmain 得 docker image 出來
## Enable L3 last level cache in GEM5 + NVMAIN (15%)
- [name=JCxYIS]
- 參考 [Enable L3](https://blog.csdn.net/tristan_tian/article/details/79851063)
- 更正
> *./config/common/==Caches.py== 這個是設置連接*
>
> 應更正為:
>
> *./config/common/==CacheConfig.py== 這個是設置連接*
- 這裡面的一些程式碼修改部分有一些位置指稱不明,可以嘗試尋找檔案中相似的部分。
- cache.py內的L3 cache的內容可能要更改(照著L2改)
- 在更改 Gem5 中的檔案之後要記得**編譯**。
- 即「Nvmain project 說明與教學」簡報第十四頁之命令:
(記得在 Gem5 目錄下執行)
```bash
scons EXTRAS=../NVmain build/X86/gem5.opt
```
- 以 Gem5 測試執行檔時要記得加上 `--l3cache` 以啟用 L3。
- 以「Nvmain project 說明與教學」簡報第十四頁之執行命令為例:
```bash!
./build/X86/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/x86/linux/hello --cpu-type=TimingSimpleCPU --caches --l2cache --l3cache --mem-type=NVMainMemory --nvmain-config=../NVmain/Config/PCM_ISSCC_2012_4GB.config
```
- 可以在 Gem5 中的 `./m5out/stats.txt` 中查詢 `l3` 關鍵字以查看是否成功。
- [name=Mibudin]
- (Optional)另外也可參考 [gem5 adding cache](https://www.gem5.org/documentation/learning_gem5/part1/cache_config/)
- [name=助教]
- 
## Config last level cache to 2-way and full-way associative cache and test performance (15%)
- [name=Mibudin]
- 可以用 `--<cache>_size=<size>` 來設定指定快取大小,如:
```bash
--l1i_size=32kB
--l1d_size=32kB
--l2_size=128kB
--l3_size=1MB
```
- 可以用 `--<cache>_assoc=<way>` 來設定指定 n-way associative,如:
```bash
--l1i_assoc=2
--l1d_assoc=2
--l2_assoc=8
--l3_assoc=16
```
- 如果 `--<cache>_assoc=1`,為 Full-way associative。
- [參考](http://www.m5sim.org/Coherence-Protocol-Independent_Memory_Components)
- 推薦在 `<GEM5>/m5out/config.ini` 來查看最終設定結果,很有用。
- 給 JSON 愛好者:`<GEM5>/m5out/config.json`
- [name=Soda]
- Config last level cache to 2-way associative cache and test performance command
```sh
./build/X86/gem5.opt configs/example/se.py -c ./quicksort --cpu-type=TimingSimpleCPU --caches --l2cache --l3cache --l3_assoc=2 --l1i_size=32kB --l1d_size=32kB --l2_size=128kB --l3_size=1MB --mem-type=NVMainMemory --nvmain-config=../NVmain/Config/PCM_ISSCC_2012_4GB.config
```
- Config last level cache to full associative cache and test performance command
```sh
./build/X86/gem5.opt configs/example/se.py -c ./quicksort --cpu-type=TimingSimpleCPU --caches --l2cache --l3cache --l3_assoc=1 --l1i_size=32kB --l1d_size=32kB --l2_size=128kB --l3_size=1MB --mem-type=NVMainMemory --nvmain-config=../NVmain/Config/PCM_ISSCC_2012_4GB.config
```
- [name=Mibudin]
- RESEARCH cache->tags->findVictim()
- http://doxygen.gem5.org/develop/classBaseSetAssoc.html
- http://doxygen.gem5.org/develop/classFALRU.html
- `tags = Param.BaseTags(FALRU(), "Tag store")`
## Modify last level cache policy based on RRIP (15%)
- [name=Soda]
- 在cache.py中加入
```python=
class L3Cache(Cache):
# 前面的code
...
# 加這一行
replacement_policy = Param.BaseReplacementPolicy(RRIPRP(),"Replacement policy")
```
- [name=Mibudin]
- 主要 Replacement Policy 宣告大全:
`<GEM5>/src/mem/cache/replacement_policies/ReplacementPolicies.py`
- RRIP 的 type 會設定成 `BRRIPRP` 而非 `RRIPRP`。
- 因為兩者共用相同的 C++ 類別。
- 不過可以透過 `<rp>.btp = 0` 來看出設定成功。
- [RPs](http://www.m5sim.org/Replacement_policy)
- 照此講法,**`btp = 0` 的 BRRIP 即為 RRIP**。
## Test the performance of write back and write through policy based on 4-way associative cache with isscc_pcm(15%)
- [name=Mibudin]
- IDK IDK IDK IDK IDK IDK IDK IDK
- [RESEARCH `cache.cc`](https://gem5.googlesource.com/arm/gem5/+/1ecc7a8c776bacd04c109cc286e569d434497229/src/mem/cache/cache.cc)
- [RESEARCH `cache.hh`](https://gem5.googlesource.com/arm/gem5/+/1ecc7a8c776bacd04c109cc286e569d434497229/src/mem/cache/cache.hh)
- [RESEARCH DOC](http://doxygen.gem5.org/release/current/index.html)
- pkt->setWriteThrough()
- http://doxygen.gem5.org/develop/mem_2cache_2base_8cc_source.html#l01132
- [name=JCxYIS]
- [參考](https://github.com/cyjseagull/gem5-nvmain-hybrid-simulator/blob/master/nvmain/Config/Hybrid_NVM_channel.config)
> 啊我就只是把 tRP 從 1 改成 0。
> 
- 20210628改
- 
- [name=助教]
- 
- [name=wasabi-neko]
- [MSHR](https://blog.csdn.net/baidu_35679960/article/details/77527782)
- [dataCacheObject](https://www.gem5.org/documentation/general_docs/memory_system/gem5_memory_system/)
- [learning gem5 very boring](https://youtu.be/fD3hhNnfL6k?t=3421)
- Debug option (stdout 輸出會多出很多東西)
- `build/x86/gem5.opt --debug-flags=Cache 略/se.py 略`
- [name=wasabi-neko-紀錄]
- 如果 `!blk == true` 代表 cache miss
- `wrtiebackVisitor()` 會製造 packet 送給 mem
- 在呼叫 `Base::access()` 後都會在呼叫一次 `Cache::doWrtiebacks`
- `Cache::doWritebacks()` 會將 writebacks 都 pop 出來做 `allocateWriteBuffer`
- `writeBuffer` 為 `Base` 中的 class member
- `writeclean` 在 writeback 下不會產生
## Bonus (20%)
### Design last level cache policy to reduce the energy consumption of pcm_based main memory
- Nope
> 我要去搞演算法了
> 
> [name=JCxYIS]
### Baseline:LRU