# 2021q1 Homework3 (fibdrv) contributed by < `ccs100203` > ###### tags: `linux2021` > [fibdrv](https://hackmd.io/@sysprog/linux2021-fibdrv) ## 根據 Linux 效能分析的提示 - 未經任何修改直接進行 `make check` 的測試 測試的結果非常不穩定,幾乎每一次的測試都有明顯差距,放兩張圖比較 ![](https://i.imgur.com/VOP8u4s.png) ![](https://i.imgur.com/oaOZQzi.png) - 透過 `sudo taskset -c 7 ./client` 指定使用的 CPU,還是有著不穩定的結果 ![](https://i.imgur.com/fyn6dUn.png) - 參考[限制 cpu 核心給指定程式使用](https://hackmd.io/@KYWeng/rkGdultSU#%E9%99%90%E5%AE%9A-CPU-%E7%B5%A6%E7%89%B9%E5%AE%9A%E7%9A%84%E7%A8%8B%E5%BC%8F%E4%BD%BF%E7%94%A8) 將 /etc/default/grub 內的 GRUB_CMDLINE_LINUX_DEFAULT 加入 `isolcpus=7`,並做 `sudo update-grub` 更新設定,接著重開機。 確認 cpu 7 已經保留給程式使用了 ``` $ taskset -cp 1 pid 1's current affinity list: 0-6 ``` 也可從這裡去確認 ``` $ cat /sys/devices/system/cpu/isolated 7 ``` 此時已經相對穩定不少 ![](https://i.imgur.com/Du7jCZU.png) - 抑制 [address space layout randomization](https://en.wikipedia.org/wiki/Address_space_layout_randomization) (ASLR),將 cpu mode 調整成 performance,以及關閉 intel 的 turbo mode ``` sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space" sudo sh -c "echo performance > /sys/devices/system/cpu/cpu$CPUID/cpufreq/scaling_governor" sudo sh -c "echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo" ``` ![](https://i.imgur.com/QypALrj.png) ## 實作 Fast doubling ```cpp static long long fast_doubling(long long k) { long long a = 0, b = 1; for (long long i = 1 << (63 - __builtin_clzll(k)); i > 0; i >>= 1) { long long t1 = a * (2 * b - a); long long t2 = (b * b) + (a * a); a = t1; b = t2; if (i & k) { t1 = a + b; a = b; b = t1; } } return a; } ``` - 與原先 sequence 的比較 在一開始數字小的時候 sequence 效率甚至會比較好,但數字越大兩者的差距越明顯。 (尚未釐清為什麼圖表有明顯波動) ![](https://i.imgur.com/ASjgbET.png) ## 大數運算 TODO
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up