File: bogomips.c

package info (click to toggle)
linuxlogo 2.07-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 296 kB
  • ctags: 73
  • sloc: ansic: 982; sh: 125; makefile: 60
file content (49 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef linux
/*
 *                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)
 *
 * Modified for inclusion with Linux_Logo -- Vince Weaver
 */

#include <stdio.h>
#include <time.h>

/* portable version */
static void delay(int loops)
{
  long i;
  for (i = loops; i >= 0 ; i--)
    ;
}

int external_bogomips(char *bogomips_total)
{
  unsigned long loops_per_sec = 1;
  unsigned long ticks;
  
  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;
      sprintf(bogomips_total,"%lu.%02lu",
 	     loops_per_sec/500000,
	     (loops_per_sec/5000) % 100
	     );
         return 0;
    }
  }
  return -1;
}

#endif