Skip to content

Commit 9185f57

Browse files
committed
Add support for Arm
1 parent 0a94c63 commit 9185f57

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/cpucounter.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdint.h>
22

3+
#if defined(__x86_64__) || defined(__amd64__)
34
uint64_t cpucounter(void)
45
{
56
uint64_t low, high;
@@ -9,3 +10,12 @@ uint64_t cpucounter(void)
910
: "%ecx");
1011
return (high << 32) | low;
1112
}
13+
#elif defined(__aarch64__)
14+
uint64_t cpucounter(void)
15+
{
16+
uint64_t virtual_timer_value;
17+
__asm__ __volatile__("mrs %0, cntvct_el0"
18+
: "=r"(virtual_timer_value));
19+
return virtual_timer_value;
20+
}
21+
#endif

src/cpucounter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,22 @@ pub(crate) struct CPUCounter;
44

55
#[cfg(asm)]
66
#[inline]
7+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
78
unsafe fn cpucounter() -> u64 {
89
let (low, high): (u64, u64);
910
asm!("rdtscp", out("eax") low, out("edx") high, out("ecx") _);
1011
(high << 32) | low
1112
}
1213

14+
#[cfg(asm)]
15+
#[inline]
16+
#[cfg(any(target_arch = "aarch64"))]
17+
unsafe fn cpucounter() -> u64 {
18+
let (vtm): (u64);
19+
asm!("mrs {}, cntvct_el0", out(reg) vtm);
20+
vtm
21+
}
22+
1323
#[cfg(not(asm))]
1424
extern "C" {
1525
fn cpucounter() -> u64;

0 commit comments

Comments
 (0)