Skip to content

Commit

Permalink
add aarch64 cntvct counter support
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bates authored and batesj committed Jan 5, 2022
1 parent 8af1898 commit 4f8a922
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/percetto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 4f8a922

Please sign in to comment.