Skip to content

Commit 1d6f242

Browse files
committed
Auto merge of #88652 - AGSaidi:linux-aarch64-should-be-actually-monotonic, r=yaahc
linux/aarch64 Now() should be actually_monotonic() While issues have been seen on arm64 platforms the Arm architecture requires that the counter monotonically increases and that it must provide a uniform view of system time (e.g. it must not be possible for a core to receive a message from another core with a time stamp and observe time going backwards (ARM DDI 0487G.b D11.1.2). While there have been a few 64bit SoCs that have bugs (#49281, #56940) which cause time to not monotonically increase, these have been fixed in the Linux kernel and we shouldn't penalize all Arm SoCs for those who refuse to update their kernels: SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1 FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10 HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11 ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12 255a3f3 std: Force `Instant::now()` to be monotonic added a Mutex to work around this problem and a small test program using glommio shows the majority of time spent acquiring and releasing this Mutex. 3914a7b tries to improve this, but actually makes it worse on big systems as for 128b atomics a ldxp/stxp pair (and successful loop) for v8.4 systems that don't support FEAT_LSE2 is required which is expensive as a lock and because of how the load/store-exclusives scale on large Arm systems is both unfair to threads and tends to go backwards in performance. A small sample program using glommio improves by 70x on a 32 core Graviton2 system with this change.
2 parents 12b5bce + a333b91 commit 1d6f242

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

library/std/src/sys/unix/time.rs

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ mod inner {
303303
pub fn actually_monotonic() -> bool {
304304
(cfg!(target_os = "linux") && cfg!(target_arch = "x86_64"))
305305
|| (cfg!(target_os = "linux") && cfg!(target_arch = "x86"))
306+
|| (cfg!(target_os = "linux") && cfg!(target_arch = "aarch64"))
306307
|| cfg!(target_os = "fuchsia")
307308
}
308309

library/std/src/time.rs

+14
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ impl Instant {
268268
//
269269
// To hopefully mitigate the impact of this, a few platforms are
270270
// excluded as "these at least haven't gone backwards yet".
271+
//
272+
// While issues have been seen on arm64 platforms the Arm architecture
273+
// requires that the counter monotonically increases and that it must
274+
// provide a uniform view of system time (e.g. it must not be possible
275+
// for a core to recieve a message from another core with a time stamp
276+
// and observe time going backwards (ARM DDI 0487G.b D11.1.2). While
277+
// there have been a few 64bit SoCs that have bugs which cause time to
278+
// not monoticially increase, these have been fixed in the Linux kernel
279+
// and we shouldn't penalize all Arm SoCs for those who refuse to
280+
// update their kernels:
281+
// SUN50I_ERRATUM_UNKNOWN1 - Allwinner A64 / Pine A64 - fixed in 5.1
282+
// FSL_ERRATUM_A008585 - Freescale LS2080A/LS1043A - fixed in 4.10
283+
// HISILICON_ERRATUM_161010101 - Hisilicon 1610 - fixed in 4.11
284+
// ARM64_ERRATUM_858921 - Cortex A73 - fixed in 4.12
271285
if time::Instant::actually_monotonic() {
272286
return Instant(os_now);
273287
}

0 commit comments

Comments
 (0)