From d5c3cfb11435f2c049f21a00607c798e625d2bc4 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Thu, 19 May 2022 09:30:45 +0800 Subject: [PATCH 1/4] Upgrade quanta to v0.10.0 --- Cargo.toml | 2 +- src/common/time.rs | 2 +- src/common/time/atomic_time.rs | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c777810..4c58d6a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ uuid = { version = "0.8", features = ["v4"] } triomphe = { version = "0.1", default-features = false } # Optional dependencies (quanta, enabled by default) -quanta = { version = "0.9.3", optional = true } +quanta = { version = "0.10.0", optional = true } # Optional dependencies (dashmap) dashmap = { version = "5.2", optional = true } diff --git a/src/common/time.rs b/src/common/time.rs index 20992b7b..e519f70f 100644 --- a/src/common/time.rs +++ b/src/common/time.rs @@ -26,7 +26,7 @@ pub(crate) use clock::Mock; /// a wrapper type over Instant to force checked additions and prevent /// unintentional overflow. The type preserve the Copy semantics for the wrapped #[derive(PartialEq, PartialOrd, Clone, Copy)] -pub(crate) struct Instant(pub clock::Instant); +pub(crate) struct Instant(clock::Instant); pub(crate) trait CheckedTimeOps { fn checked_add(&self, duration: Duration) -> Option diff --git a/src/common/time/atomic_time.rs b/src/common/time/atomic_time.rs index 56d07e85..1a41c666 100644 --- a/src/common/time/atomic_time.rs +++ b/src/common/time/atomic_time.rs @@ -1,6 +1,9 @@ use super::Instant; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::{ + any::TypeId, + sync::atomic::{AtomicU64, Ordering}, +}; pub(crate) struct AtomicInstant { instant: AtomicU64, @@ -14,6 +17,9 @@ impl Default for AtomicInstant { } } +// TODO: Need a safe way to convert between `quanta::Instant` and `u64`. +// quanta v0.10.0 no longer provides `quanta::Instant::as_u64` method. + impl AtomicInstant { pub(crate) fn reset(&self) { self.instant.store(std::u64::MAX, Ordering::Release); @@ -28,11 +34,20 @@ impl AtomicInstant { if ts == u64::MAX { None } else { - Some(unsafe { std::mem::transmute(ts) }) + debug_assert_eq!( + TypeId::of::(), + TypeId::of::() + ); + Some(Instant(unsafe { std::mem::transmute(ts) })) } } pub(crate) fn set_instant(&self, instant: Instant) { - self.instant.store(instant.0.as_u64(), Ordering::Release); + debug_assert_eq!( + TypeId::of::(), + TypeId::of::() + ); + let ts = unsafe { std::mem::transmute(instant.0) }; + self.instant.store(ts, Ordering::Release); } } From e5576f9230d219f7d98b310b972cb28895d7cd07 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Thu, 19 May 2022 10:13:12 +0800 Subject: [PATCH 2/4] Update the README and CHANGELOG for the issue in Quanta v0.9 --- CHANGELOG.md | 17 +++++++++++++++-- README.md | 23 ++++++++--------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b67e77..ed673385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ ## Version 0.8.4 +### Fixed + +- Fix the issue [#119][gh-issue-0119], which can occur on some x86_64 machines, by + upgrading Quanta crate to v0.10.0. ([#126][gh-pull-0126]) + - Quanta v0.9.3 or older may not work correctly on some x86_64 machines where + the Time Stamp Counter (TSC) is not synched across the processor cores. + - For more details about the issue, see [the relevant section][panic_in_quanta] + of the README. + + ### Added - Add `get_with_if` method to the following caches: ([#123][gh-issue-0123]) @@ -19,8 +29,10 @@ - Quanta v0.9.3 or older may not work correctly on some x86_64 machines where the Time Stamp Counter (TSC) is not synched across the processor cores. ([#119][gh-issue-0119]) - - You can avoid the issue by disabling the default features of Moka. - See [the relevant section][panic_in_quanta] of the README. + - This issue was fixed by Quanta v0.10.0. You can upgrade Moka to v0.8.4 or newer + to prevent the issue. + - For more details about the issue, see [the relevant section][panic_in_quanta] + of the README. ## Version 0.8.2 @@ -334,6 +346,7 @@ The minimum supported Rust version (MSRV) is now 1.51.0 (2021-03-25). [gh-issue-0038]: https://github.com/moka-rs/moka/issues/38/ [gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/ +[gh-pull-0126]: https://github.com/moka-rs/moka/pull/126/ [gh-pull-0121]: https://github.com/moka-rs/moka/pull/121/ [gh-pull-0117]: https://github.com/moka-rs/moka/pull/117/ [gh-pull-0116]: https://github.com/moka-rs/moka/pull/116/ diff --git a/README.md b/README.md index 0cdb97cb..8f7db556 100644 --- a/README.md +++ b/README.md @@ -437,13 +437,14 @@ change. ### Integer Overflow in Quanta Crate on Some x86_64 Machines -Quanta crate has a known issue on some specific x86_64-based machines. It will cause -intermittent panic due to integer overflow: +Quanta crate up to v0.9.3 has an issue on some specific x86_64-based machines. It +will cause intermittent panic due to integer overflow: -- metrics-rs/quanta — [Intermittent panic due to overflowing our source calibration denominator. #61](https://github.com/metrics-rs/quanta/issues/61) +- metrics-rs/quanta — [Intermittent panic due to overflowing our source calibration denominator. #61](https://github.com/metrics-rs/quanta/issues/61) + (Fixed by Quanta v0.10.0) The overflows have been reported by a couple of users who use AMD-based Lenovo -laptops or Circle CI. There is no fix available yet as of Quanta v0.9.3. +laptops or Circle CI. When this issue occurs, you will get a stacktrace containing the following lines: @@ -457,18 +458,10 @@ quanta::Clock::new::{{closure}} ... ``` -You can avoid the issue by disabling `qanta` feature, which is one of the default -features of Moka. Edit your Cargo.toml to add `default-features = false` to the -dependency declaration. +This issue was fixed by Quanta v0.10.0. -```toml:Cargo.toml -[dependencies] -moka = { version = "0.8", default-feautures = false } -# Or -moka = { version = "0.8", default-feautures = false, features = ["future"] } -``` - -This will make Moka to opt out Quanta and switch to a fall-back implementation. +You can prevent the issue by upgrading Moka to v0.8.4 or newer, which depends on +Quanta v0.10.0 or newer. ### Compile Errors on Some 32-bit Platforms From 9f88e65d9ecc5047eb59b6998e64283127ebfc7e Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Thu, 19 May 2022 10:13:29 +0800 Subject: [PATCH 3/4] Bump the Moka version to v0.8.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4c58d6a6..d27f9ef8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "moka" -version = "0.8.3" +version = "0.8.4" edition = "2018" rust-version = "1.51" From cc689c5d3c67207fc63c822766fb46c7f9858357 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Thu, 19 May 2022 10:19:16 +0800 Subject: [PATCH 4/4] Improve some wording in the CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed673385..53831ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### Fixed -- Fix the issue [#119][gh-issue-0119], which can occur on some x86_64 machines, by - upgrading Quanta crate to v0.10.0. ([#126][gh-pull-0126]) +- Fix the issue [#119][gh-issue-0119] by upgrading Quanta crate to v0.10.0. + ([#126][gh-pull-0126]) - Quanta v0.9.3 or older may not work correctly on some x86_64 machines where the Time Stamp Counter (TSC) is not synched across the processor cores. - For more details about the issue, see [the relevant section][panic_in_quanta]