diff options
Diffstat (limited to 'nacl/cpucycles/amd64tscfreq.c')
-rw-r--r-- | nacl/cpucycles/amd64tscfreq.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/nacl/cpucycles/amd64tscfreq.c b/nacl/cpucycles/amd64tscfreq.c new file mode 100644 index 00000000..ef182c1b --- /dev/null +++ b/nacl/cpucycles/amd64tscfreq.c | |||
@@ -0,0 +1,18 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <sys/types.h> | ||
3 | |||
4 | long long cpucycles_amd64tscfreq(void) | ||
5 | { | ||
6 | unsigned long long result; | ||
7 | asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax" | ||
8 | : "=a" (result) :: "%rdx"); | ||
9 | return result; | ||
10 | } | ||
11 | |||
12 | long long cpucycles_amd64tscfreq_persecond(void) | ||
13 | { | ||
14 | long result = 0; | ||
15 | size_t resultlen = sizeof(long); | ||
16 | sysctlbyname("machdep.tsc_freq",&result,&resultlen,0,0); | ||
17 | return result; | ||
18 | } | ||