Skip to content

Commit

Permalink
aarch64 cycle count with frequency
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <[email protected]>
  • Loading branch information
Coldwings committed Aug 18, 2023
1 parent 72c37b6 commit 1ee4ab2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,11 @@ R"(
return (hi << 12) | (low >> 20);
#elif defined(__aarch64__)
uint64_t val;
uint64_t freq;
asm volatile("mrs %0, cntvct_el0" : "=r" (val));
return (uint32_t)(val >> 20);
asm volatile("mrs %0, cntfrq_el0" : "=r" (freq));
// cycles * microsec_per_sec / frequency = microsec
return (val << 10) / freq;
#endif
}
static uint32_t last_tsc = 0;
Expand Down

0 comments on commit 1ee4ab2

Please sign in to comment.