x86tscfreq.c 361 B

1234567891011121314151617
  1. #include <sys/types.h>
  2. #include <sys/sysctl.h>
  3. long long cpucycles_x86tscfreq(void)
  4. {
  5. long long result;
  6. asm volatile(".byte 15;.byte 49" : "=A" (result));
  7. return result;
  8. }
  9. long long cpucycles_x86tscfreq_persecond(void)
  10. {
  11. long result = 0;
  12. size_t resultlen = sizeof(long);
  13. sysctlbyname("machdep.tsc_freq",&result,&resultlen,0,0);
  14. return result;
  15. }