在Linux內核中如何計算bogomips?爲了得到這個值,究竟做了什麼?如何在Linux內核中計算BogoMips?
3
A
回答
1
/*
* Standalone BogoMips program
*
* Based on code Linux kernel code in init/main.c and
* include/linux/delay.h
*
* For more information on interpreting the results, see the BogoMIPS
* Mini-HOWTO document.
*
* version: 1.3
* author: Jeff Tranter ([email protected])
*/
#include <stdio.h>
#include <time.h>
#ifdef CLASSIC_BOGOMIPS
/* the original code from the Linux kernel */
static __inline__ void delay(int loops)
{
__asm__(".align 2,0x90\n1:\tdecl %0\n\tjns 1b": :"a" (loops):"ax");
}
#endif
#ifdef QNX_BOGOMIPS
/* version for QNX C compiler */
void delay(int loops);
#pragma aux delay = \
"l1:" \
"dec eax" \
"jns l1" \
parm nomemory [eax] modify exact nomemory [eax];
#endif
#ifdef PORTABLE_BOGOMIPS
/* portable version */
static void delay(int loops)
{
long i;
for (i = loops; i >= 0 ; i--)
;
}
#endif
int
main(void)
{
unsigned long loops_per_sec = 1;
unsigned long ticks;
printf("Calibrating delay loop.. ");
fflush(stdout);
while ((loops_per_sec <<= 1)) {
ticks = clock();
delay(loops_per_sec);
ticks = clock() - ticks;
if (ticks >= CLOCKS_PER_SEC) {
loops_per_sec = (loops_per_sec/ticks) * CLOCKS_PER_SEC;
printf("ok - %lu.%02lu BogoMips\n",
loops_per_sec/500000,
(loops_per_sec/5000) % 100
);
return 0;
}
}
printf("failed\n");
return -1;
}
0
太糟糕了,給定這些
CFLAGS = 「 - 牆-O2 -fomit幀指針-finline函數-s -std = gnu99」
獨立bogomips程序總是失敗。雖然報告的值比/ proc/cpuinfo報告的要低得多,但從-O2到-O0的變化實際上可以工作。有趣的是,我已經嘗試了gcc(4.4.6)手冊頁中列出的所有-f優化器標誌(對於-O1,-O2甚至-O3),但結果不會改變。加入-O1後失敗。我想知道什麼是嚴格的優化器標誌集應該啓用/禁用的延遲循環不變成單個標量表達式(導致經過的滴答總是保持0)。爲什麼-O1使它失敗?
相關問題
- 1. 如何計算linux內核中的fb_videomode參數?
- 2. 我如何用kprobe計算linux內核中的malloc
- 3. jiffies在Linux內核中計算的位置?
- 4. 在Linux內核3.x模塊中如何計算與Kprobe的系統調用?
- 5. 在Linux內核中
- 6. 如何在Linux內核中進行乘法運算?
- 7. 如何在Linux內核中使用RSA
- 8. 如何在Buildroot中配置Linux內核?
- 9. 如何在Linux內核中使用tpm
- 10. 如何在linux內核中使用scanf?
- 11. 如何在arch linux 3.12內核中啓用審計框架?
- 12. 如何在內核模塊中打印linux內核版本號
- 13. Linux中的指針計算內核分配實現
- 14. 計算linux中處理器內核的數量
- 15. Linux內核2.6中的計時
- 16. 如何修補Linux內核?
- 17. 如何入睡Linux內核?
- 18. 如何製作Linux內核
- 19. GPU中的內存綁定內核和計算綁定內核
- 20. Seaborn的ClusterMap,內核計算
- 21. 在Linux內核中搶佔
- 22. Linux內核 - 中斷
- 23. setscheduler()在Linux內核
- 24. asm__volatile()在Linux內核
- 25. 在cleanup_module linux內核
- 26. 如何在編譯Linux內核
- 27. 如何轉換__u32在Linux內核
- 28. 如何在Linux內核模塊
- 29. Linux是如何計算MemFree
- 30. 計算CUDA內核中的週期數