BogoMips 顧名思義是 Bogus 的 MIPS (Million Instructions Per Second). Bogus 表示 "偽".BogoMIPS 就是假的 MIPS.
一般常用的 DMIPS (Dhrystone MIPS) 主要是測量文書處理的表現. 如果要比較 CPU 是否夠快, 看主頻率 (clock) 也是不準的. 比方說 Intel i7 是 23.860 MIPS/MHz, ARM Cortex A8 僅有 2 MIPS/MHz [1], 所以 1GHz 的 i7 還是比 2GHz 的 A8 快很多!
為什麼 MIPS 也會有假的呢? 原因是 BogoMips 本來就不是用來比較 CPU 的計算能力的, 它是用來調校 Linux kernel 的計時單位.
假如我要 delay 1 mini-second (ms),那麼在不借助特殊硬體的情況之下, 我怎麼知道多久是 1 ms 呢? 最簡單的方法, 就是做一個簡單的迴圈,再看看繞完 X 圈後, 花掉多少時間, 然後反推繞幾圈是 1ms. 這個每秒繞幾圈就是 loops_per_jiffy.
因此在 [ref 2] 中, 我們可以看到它介紹 delay loop 怎麼做? loops_by_jiffy 怎麼做? 卻沒講到關鍵的 “為什麼?", 這部份只得去看[3]的說明, 配合 [4] 的程式. 總之, BogoMips 直接就對應到 loops_per_jiffy.
在 calibrate.c [4] 裡面有印出 BogoMips 的地方.
/* Round the value and print it */
printk("%lu.%02lu BogoMIPS (lpj=%lu)n", loops_per_jiffy/(500000/HZ), (loops_per_jiffy/(5000/HZ)) % 100, loops_per_jiffy);
那麼一個 jiffy 是多久呢? Linux 預設為 4ms,但其實可以調整為 1~10 ms, 這也是 Linux 一個 tick 所需要的時間.至於一圈 loop 是幾條指令? 這個也不一定, 在 Linux C code 裡面,會用一個迴圈取多次的值平均.
如果只看一次,可以簡化成:
pre_start = 0; read_current_timer(&start); start_jiffies = jiffies; while (jiffies <= (start_jiffies + 1)) { pre_start = start; read_current_timer(&start); } read_current_timer(&post_start); pre_end = 0; end = post_start; while (jiffies <= (start_jiffies + 1 + DELAY_CALIBRATION_TICKS)) { pre_end = end; read_current_timer(&end); } read_current_timer(&post_end); tsc_rate_max = (post_end - pre_start) / DELAY_CALIBRATION_TICKS; // loops per jiffy
至於為何 start 和 end 都要有 pre_ 和 post_, 是為了抓到剛好跨過 jiffy 進 1 的點.
[ref]
1. MIPS (計算機)
2. BogoMIPS
4. calibrate.c
5. Jiffies
還是沒搞懂Bogomips最主要的應用在哪呢?
它唯一的用途就是調校 timer interrupt 的時間而已. 為什麼要特別介紹它? 只是因為我以前看不懂 WIKI 寫的 “不科學的方法", “它不可在不同的CPU間進行比較演示" 是什麼意思. 後來才知道 “不科學" 是指它根本沒有精確地計算任何東西, 只是讀個 data, 減個 counter. “不能比較" 也是顯而易見, 它完全反映不出計算能力, 頂多只能反映數迴圈的能力, 所以也沒啥好比的.
同意bogomips僅作System Timer校調使用, 但antutu也會看bogomips來判斷系統效能,來估算CPU speed,所以有些中國Chip公司就利用這樣情況刻意調整bogomips以拉高Antutu分數…
感謝 CCC! Good point! 真是有趣.