How BogoMips is calculated in linux kernel?[通俗易懂]

How BogoMips is calculated in linux kernel?[通俗易懂]HowBogoMipsiscalculatedinlinuxkernel?-StackOverflow/**StandaloneBogoMipsprogram**BasedoncodeLinuxkernelcodeininit/main.cand*

大家好,欢迎来到IT知识分享网。

How BogoMips is calculated in linux kernel? – Stack Overflow

How BogoMips is calculated in linux kernel?[通俗易懂]
How BogoMips is calculated in linux kernel?[通俗易懂]

/*
 *                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;
}

View Code

BogoMIPS – LinuxMIPS (linux-mips.org)

        .set    noreorder
  loop: bnez    $reg, loop
        subu    $reg, 1
        .set    reorder"

怪不得BogoMIPS上不去,100发射也没用啊。:-) 所以我之前把人看扁了,说错了,放厥词了。二十年Architecture之长进

However, 就FritzChess而言,单核性能提升不明显啊,所以我也不能算是大错特错。

.set noreorder prevents the assembler from juggling the code sequence to move useful instructions into the branch delay slot. 还明确规定不许乱序执行。

我觉得我完全看懂了Stack Overflow的那个帖子并做了改进:

#include <stdio.h>
#include <time.h>
#define INSTRUCTIONS_PER_LOOP 4.0
int main() {
  for (unsigned loops = 1; loops <<= 1;) { // 溢出后loops为0,循环退出
    unsigned ticks = clock();
    extern int k;
    for (unsigned i = 0; i < loops; i++) k += i;
    ticks = clock() - ticks;
    if (ticks >= CLOCKS_PER_SEC) { // delay不够1秒太不精确
      printf("loops=%u ticks=%d CLOCKS_PER_SEC=%d\n", loops, ticks, CLOCKS_PER_SEC);
      float mips = INSTRUCTIONS_PER_LOOP * loops / 1E6 * CLOCKS_PER_SEC / ticks;
      printf("BogoMips=%.2f\n", mips);
      break; // 超过1秒后不再折腾
    }
  }
}
int k;
/*
gcc -O3 t.c; a
loops=2147483648 ticks=1803 CLOCKS_PER_SEC=1000
BogoMips=4764.25
https://openbenchmarking.org/s/Intel%20Core%20i3%20370M
bogomips    : 4787.64
-----------------------------
gcc -O3 -S t.c; t.s的部分代码
    call    _clock
    movl    _k, %ecx
    xorl    %edx, %edx
    movl    %eax, %edi
    .p2align 4,,10
    .p2align 3
L2:
    addl    %edx, %ecx    1
    addl    $1, %edx      2
    cmpl    %esi, %edx    3
    jb      L2            4 所以#define INSTRUCTIONS_PER_LOOP 4.0
    movl    %ecx, _k
4.0而不是4避免算mips时溢出。除以50万就是乘2再除以100万。Linux kernel不用C运行库和浮点数。
i3-370m没有做到4发射。:-)
*/

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/29231.html

(0)
上一篇 2023-09-28 21:15
下一篇 2023-09-29 11:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信