From 1ee4ab2d12b0788d0c03315e33252d97dc04f5f7 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Fri, 18 Aug 2023 13:56:41 +0800 Subject: [PATCH] aarch64 cycle count with frequency Signed-off-by: Coldwings --- thread/thread.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thread/thread.cpp b/thread/thread.cpp index 04b65171..b82b5ec2 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -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;