如何在linux内核中计算出bogomips?究竟做了什么来获得这个价值?
答案 0 :(得分:2)
/*
* 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 (Jeff_Tranter@Mitel.COM)
*/
#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;
}
答案 1 :(得分:0)
太糟糕了,给出了这些
CFLAGS =“ - Wall -O2 -fomit-frame-pointer -finline-functions -s -std = gnu99”
独立的bogomips程序总是失败。从-O2更改为-O0使其实际工作,尽管报告的值远低于/ proc / cpuinfo报告的值。有趣的是,我已经尝试了gcc(4.4.6)手册页中列出的所有-f优化器标志(对于-O1,-O2和偶数-O3),但结果不会改变。添加-O1后失败。我想知道什么是严格的优化器标志集,应该为延迟循环启用/禁用以不转换为单个标量表达式(导致经过的滴答始终保持为0)。为什么-O1会让它失败?
答案 2 :(得分:0)
我没有定义任何延迟版本,只是提供了这个原型:
外部无效延迟(int循环);
并从QNX版本中获取提示,将以下内容与“ nasm -felf64 delay.asm”组合在一起
section .text
;原型外部无效延迟(int循环);
全局延迟
延迟:
dec edi; rdi是64位C程序中传递的第一个参数
jnz延迟
退出
最后
gcc -s -O2 -Wall bogomips.c delay.o -o bogomips
这是在64位Linux中。顺便说一句,结果比/ proc / cpuinfo中的值快,并且更改gcc选项中的-O(n)值几乎没有区别