diff options
Diffstat (limited to 'nacl/cpucycles/x86cpuspeed.c')
-rw-r--r-- | nacl/cpucycles/x86cpuspeed.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/nacl/cpucycles/x86cpuspeed.c b/nacl/cpucycles/x86cpuspeed.c new file mode 100644 index 00000000..34222565 --- /dev/null +++ b/nacl/cpucycles/x86cpuspeed.c | |||
@@ -0,0 +1,24 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <sys/types.h> | ||
3 | #include <sys/param.h> | ||
4 | #include <sys/sysctl.h> | ||
5 | |||
6 | long long cpucycles_x86cpuspeed(void) | ||
7 | { | ||
8 | long long result; | ||
9 | asm volatile(".byte 15;.byte 49" : "=A" (result)); | ||
10 | return result; | ||
11 | } | ||
12 | |||
13 | long long cpucycles_x86cpuspeed_persecond(void) | ||
14 | { | ||
15 | int oid[2]; | ||
16 | int val; | ||
17 | size_t size; | ||
18 | oid[0] = CTL_HW; | ||
19 | oid[1] = HW_CPUSPEED; | ||
20 | size = sizeof val; | ||
21 | if (sysctl(oid,2,&val,&size,0,0) == -1) return 0; | ||
22 | if (size != sizeof val) return 0; | ||
23 | return val * 1000000LL; | ||
24 | } | ||