From 4f8a9229c72b1a5e1ee6d4bf463ac022280d15f3 Mon Sep 17 00:00:00 2001 From: John Bates Date: Fri, 10 Dec 2021 11:42:46 -0800 Subject: [PATCH] add aarch64 cntvct counter support --- src/percetto.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/percetto.cc b/src/percetto.cc index d2b12a8..ed092f3 100644 --- a/src/percetto.cc +++ b/src/percetto.cc @@ -23,9 +23,8 @@ defined(_M_AMD64) #define HAS_RDTSC #endif -#if defined(_M_ARM) || defined(_M_ARMT) || defined(__arm__) || \ - defined(__thumb__) || defined(__aarch64__) - // TODO(jbates): support ARM CPU counter +#if defined(__aarch64__) + #define HAS_CNTVCT #endif #include "percetto.h" @@ -225,11 +224,15 @@ static BuiltinClock GetBuiltinClockIdFrom(clockid_t clockid) { } static inline uint64_t GetCpuTicks() { - #ifdef HAS_RDTSC +#ifdef HAS_RDTSC return __rdtsc(); - #else +#elif defined(HAS_CNTVCT) + uint64_t vct; + asm volatile("mrs %0, cntvct_el0" : "=r"(vct)); + return vct; +#else return 0; - #endif +#endif } static inline uint64_t GetTimestampNs() {