I'm trying to figure out how to access the TSC on ARM, i.e similar to using RDTSC on x86. There are multiple examples on SO, but none of them seem to do what I wanted. I copy pasted the following code from another question:
uint64_t ReadTSC() {
uint64_t tsc;
asm volatile("isb; mrs %0, PMCCNTR_EL0" : "=r" (tsc));
return tsc;
}
I then tried the following code:
int main() {
uint64_t before = ReadTSC();
std::cout << "foo\n";
uint64_t after = ReadTSC();
std::cout << "Print took: " << after - before << std::endl;
}
However, the value I get is 18446744069338982144 for how long the print took. This seems completely nonsensical. The CPU I'm using is an Apple M2. What is the issue here?
What I'd like to measure is the actual precise number of clock cycles, i.e. avoid having to do conversions from wallclock time.