summaryrefslogtreecommitdiff
path: root/nacl/cpucycles/sgi.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/cpucycles/sgi.c')
-rw-r--r--nacl/cpucycles/sgi.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/nacl/cpucycles/sgi.c b/nacl/cpucycles/sgi.c
new file mode 100644
index 00000000..c232af09
--- /dev/null
+++ b/nacl/cpucycles/sgi.c
@@ -0,0 +1,38 @@
1#include <time.h>
2#include <stdio.h>
3#include <unistd.h>
4#include <sys/time.h>
5#include <sys/types.h>
6#include <sys/sysctl.h>
7
8static double cpufrequency = 0;
9
10static void init(void)
11{
12 FILE *f;
13
14 f = popen("hinv -c processor | awk '{if ($3==\"MHZ\") print $2*1000000}'","r");
15 if (!f) return;
16 if (fscanf(f,"%lf",&cpufrequency) < 1) cpufrequency = 0;
17 pclose(f);
18 if (!cpufrequency) return;
19}
20
21long long cpucycles_sgi(void)
22{
23 double result;
24 struct timespec t;
25 if (!cpufrequency) init();
26 clock_gettime(CLOCK_SGI_CYCLE,&t);
27 result = t.tv_nsec;
28 result *= 0.000000001;
29 result += (double) t.tv_sec;
30 result *= cpufrequency;
31 return result;
32}
33
34long long cpucycles_sgi_persecond(void)
35{
36 if (!cpufrequency) init();
37 return cpufrequency;
38}