Skip to content

Commit f04a916

Browse files
committed
Use CLOCK_BOOTTIME for Instant
Discussion is ongoing upstream at rust-lang/rust#87906 about how exactly to make a change like this, but most of the concerns (backwards compatibility, legacy kernels prior to 2.6.39, non-Linux OSes) are not applicable to us. If upstream decideds to keep `Instant` as `CLOCK_MONOTONIC`, we should figure out an alternate solution for our use of `quiche` before backing this out. Bug: 200694560 Change-Id: I188ad48bbaccd2fb0196e8273b307a7bbfc737f1
1 parent 05d1dfd commit f04a916

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 267585dccb068a609c424ffd564abbb0d8a948b9 Mon Sep 17 00:00:00 2001
2+
From: Matthew Maurer <[email protected]>
3+
Date: Mon, 9 Aug 2021 19:01:45 -0700
4+
Subject: [PATCH] Switch Instant to use CLOCK_BOOTTIME
5+
6+
For Linux-like platforms, use CLOCK_BOOTTIME which continues ticking
7+
during suspend. Without this change, `Duration` between two `Instant`s
8+
can bear little relation to reality if a suspend took place in between.
9+
10+
Fixes rust-lang#87906
11+
---
12+
library/std/src/sys/unix/time.rs | 2 +-
13+
1 file changed, 1 insertion(+), 1 deletion(-)
14+
15+
diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs
16+
index 7dc09add27f..b8e00a8f2de 100644
17+
--- a/library/std/src/sys/unix/time.rs
18+
+++ b/library/std/src/sys/unix/time.rs
19+
@@ -293,7 +293,7 @@ pub struct SystemTime {
20+
21+
impl Instant {
22+
pub fn now() -> Instant {
23+
- Instant { t: now(libc::CLOCK_MONOTONIC) }
24+
+ Instant { t: now(libc::CLOCK_BOOTTIME) }
25+
}
26+
27+
pub const fn zero() -> Instant {
28+
--
29+
2.33.0.464.g1972c5931b-goog
30+

0 commit comments

Comments
 (0)