2011-06-30 59 views

回答

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使它失敗?