###### tags: `homework` `sysprog2017`
2017q3 Homework1 (phonebook)
===
contributed by <`Jetudie`>
---
題目: [C02: phonebook](https://hackmd.io/s/HJJUmdXsZ)
## 開發環境
列出CPU資訊
`$ lscpu`
(要更詳細了解也可以用 `$ cat /proc/cpuinfo` )
```
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 60
Model name: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
Stepping: 3
CPU MHz: 799.865
CPU max MHz: 3100.0000
CPU min MHz: 800.0000
BogoMIPS: 4988.06
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
```
列出系統相關資訊
`$ uname -a`
```
Linux michael-Lenovo-IdeaPad-Z510 4.10.0-35-generic #39-Ubuntu SMP Wed Sep 13 07:46:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
```
清空 cache, 檢視一下資源 (只開 terminal 的情況)
`$ echo 1 | sudo tee /proc/sys/vm/drop_caches`
`$ free`
```
total used free shared buff/cache available
Mem: 8087436 281492 7619884 61484 186060 7543304
Swap: 10000380 0 10000380
```
---
## 效能
#### 一開始的效能
`$ make plot`

`$ make cache-test`
```
Performance counter stats for './phonebook_opt' (100 runs):
35,407 cache-misses # 46.277 % of all cache refs ( +- 0.28% )
76,511 cache-references ( +- 0.37% )
88,826,649 instructions # 1.53 insn per cycle ( +- 0.00% )
58,161,375 cycles ( +- 0.19% )
0.128115937 seconds time elapsed ( +- 0.72% )
```
## 參考資料
1. [2016 年春季系統課程 Homework 1 解說
](https://www.youtube.com/watch?v=ZICRLKf_bVw)
2. [cache 原理和實驗](https://hackmd.io/s/S14L26-_l)
3. [我的工具筆記](https://hackmd.io/s/SJluWzBhZ)