Skip to content

Commit

Permalink
aarch64 cycle count with frequency (#179)
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <coldwings@me.com>
  • Loading branch information
Coldwings committed Aug 22, 2023
1 parent 72c37b6 commit c5fb639
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 c5fb639

Please sign in to comment.