1
0

amd64tscfreq.c 415 B

123456789101112131415161718
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. long long cpucycles_amd64tscfreq(void)
  4. {
  5. unsigned long long result;
  6. asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax"
  7. : "=a" (result) :: "%rdx");
  8. return result;
  9. }
  10. long long cpucycles_amd64tscfreq_persecond(void)
  11. {
  12. long result = 0;
  13. size_t resultlen = sizeof(long);
  14. sysctlbyname("machdep.tsc_freq",&result,&resultlen,0,0);
  15. return result;
  16. }