Try   HackMD

2021q1 Homework3 (fibdrv)

contributed by < ccs100203 >

tags: linux2021

fibdrv

根據 Linux 效能分析的提示

  • 未經任何修改直接進行 make check 的測試
    測試的結果非常不穩定,幾乎每一次的測試都有明顯差距,放兩張圖比較

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 透過 sudo taskset -c 7 ./client 指定使用的 CPU,還是有著不穩定的結果

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 參考限制 cpu 核心給指定程式使用
    將 /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
    

    此時已經相對穩定不少

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  • 抑制 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"
    

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

實作 Fast doubling

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 效率甚至會比較好,但數字越大兩者的差距越明顯。
    (尚未釐清為什麼圖表有明顯波動)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

大數運算

TODO