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