Skip to content

Commit a440042

Browse files
committed
delay: Implement aarch64 support
Signed-off-by: Akira Moroo <[email protected]>
1 parent e1323e7 commit a440042

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/delay.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const NSECS_PER_SEC: u64 = 1000000000;
1010
const CPU_KHZ_DEFAULT: u64 = 200;
1111
const PAUSE_THRESHOLD_TICKS: u64 = 150;
1212

13-
#[cfg(not(target_arch = "x86_64"))]
13+
#[cfg(target_arch = "aarch64")]
1414
#[inline]
1515
unsafe fn rdtsc() -> u64 {
16-
0
16+
let value: u64;
17+
asm!("mrs {}, cntvct_el0", out(reg) value);
18+
value
1719
}
1820

1921
#[cfg(target_arch = "x86_64")]
@@ -22,10 +24,10 @@ unsafe fn rdtsc() -> u64 {
2224
_rdtsc()
2325
}
2426

25-
#[cfg(target_arch = "x86_64")]
27+
#[cfg(target_arch = "aarch64")]
2628
#[inline]
2729
unsafe fn pause() {
28-
asm!("pause");
30+
asm!("yield");
2931
}
3032

3133
#[cfg(target_arch = "x86_64")]
@@ -34,10 +36,6 @@ unsafe fn pause() {
3436
asm!("pause");
3537
}
3638

37-
#[cfg(not(target_arch = "x86_64"))]
38-
#[inline]
39-
unsafe fn pause() {}
40-
4139
pub fn ndelay(ns: u64) {
4240
let delta = ns * CPU_KHZ_DEFAULT / NSECS_PER_SEC;
4341
let mut pause_delta = 0;

0 commit comments

Comments
 (0)