add other architecture fallback

This commit is contained in:
quackerd 2022-12-14 10:59:17 +01:00
parent e524b6e0c8
commit 5e83406f81

View File

@ -1,6 +1,8 @@
#include <stdint.h>
#ifdef __amd64__
#include <immintrin.h>
#include <x86intrin.h>
#endif
#include <errno.h>
#include <sys/sysctl.h>
@ -19,6 +21,7 @@ tsc2ns(uint64_t tsc, uint64_t tsc_freq)
int
topo_ts_init(struct topo_desc * desc, int verbose)
{
#ifdef __amd64__
int rc;
size_t sz = sizeof(desc->tsc_freq);
@ -33,14 +36,23 @@ topo_ts_init(struct topo_desc * desc, int verbose)
}
return rc;
#else
return 0;
#endif
}
uint64_t
topo_desc_uptime_ns(struct topo_desc * desc)
{
#ifdef __amd64__
unsigned int dummy;
_mm_lfence();
uint64_t tsc = __rdtscp(&dummy);
_mm_lfence();
return tsc2ns(tsc, desc->tsc_freq);
#else
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
return ((uint64_t)tp.tv_sec * S2NS + (uint64_t)tp.tv_nsec);
#endif
}