Skip to content

Commit

Permalink
fix: fix time on x86_64 macos (#189)
Browse files Browse the repository at this point in the history
* fix time on x86_64 macos

Signed-off-by: Runji Wang <[email protected]>

* add path to madsim deps

Signed-off-by: Runji Wang <[email protected]>

* update deps for madsim

Signed-off-by: Runji Wang <[email protected]>

---------

Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 authored Jan 5, 2024
1 parent fdb1d56 commit 4d77c98
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## madsim [0.2.24] - 2024-01-05

### Fixed

- Fix intercepting time on x86_64 macOS, Rust 1.75.0.

## rdkafka [0.3.1] - 2024-01-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion madsim-aws-sdk-s3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ license = "Apache-2.0"
aws-sdk-s3 = "1"

[target.'cfg(madsim)'.dependencies]
madsim = "0.2.15"
madsim = { version = "0.2.15", path = "../madsim" }
aws-smithy-http = "0.60"
aws-smithy-runtime-api = "1"
aws-smithy-types = "1"
Expand Down
2 changes: 1 addition & 1 deletion madsim-rdkafka/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async-channel = "1"
async-trait = "0.1"
futures-channel = "0.3.0"
futures-util = "0.3"
madsim = { version = "0.2.8" }
madsim = { version = "0.2.8", path = "../madsim" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
spin = "0.9"
Expand Down
10 changes: 5 additions & 5 deletions madsim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim"
version = "0.2.23"
version = "0.2.24"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "Deterministic Simulator for distributed systems."
Expand Down Expand Up @@ -32,8 +32,8 @@ tracing = "0.1"
tracing-subscriber = "0.3"

[target.'cfg(madsim)'.dependencies]
ahash = "0.7"
async-channel = "1.6"
ahash = "0.8"
async-channel = "2"
async-stream = "0.3"
async-task = "4.4"
downcast-rs = "1.2"
Expand All @@ -43,7 +43,7 @@ panic-message = "0.3"
rand_xoshiro = "0.6"
rustversion = "1"
tokio = { version = "1", features = ["rt", "sync"] }
toml = "0.7"
toml = "0.8"

[target.'cfg(not(madsim))'.dependencies]
async-ucx = { version = "0.1", features = ["event"], optional = true }
Expand All @@ -60,7 +60,7 @@ tokio-util = { version = "0.7", features = ["codec"] }
# mad_rpc = { git = "https://github.com/madsys-dev/madrpc", rev = "2be4b02", optional = true }

[dev-dependencies]
criterion = "0.4"
criterion = "0.5"
structopt = "0.3"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }

Expand Down
10 changes: 2 additions & 8 deletions madsim/src/sim/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! Simulation configuration.

use std::{
hash::{Hash, Hasher},
str::FromStr,
};
use std::{hash::Hash, str::FromStr};

use crate::net::{self, tcp};
use ahash::AHasher;
use serde::{Deserialize, Serialize};

/// Simulation configuration.
Expand All @@ -25,9 +21,7 @@ pub struct Config {
impl Config {
/// Returns the hash value of this config.
pub fn hash(&self) -> u64 {
let mut hasher = AHasher::new_with_keys(0, 0);
Hash::hash(self, &mut hasher);
hasher.finish()
ahash::RandomState::with_seed(0).hash_one(self)
}
}

Expand Down
7 changes: 5 additions & 2 deletions madsim/src/sim/time/system_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ unsafe extern "C" fn gettimeofday(tp: *mut libc::timeval, tz: *mut libc::c_void)
}
}

/// Override the libc `clock_gettime` function. For Linux and ARM64 macOS.
/// Override the libc `clock_gettime` function.
/// For Linux, ARM64 macOS (since 1.67) and x86_64 macOS (since 1.75).
#[no_mangle]
#[inline(never)]
unsafe extern "C" fn clock_gettime(
Expand Down Expand Up @@ -86,12 +87,14 @@ unsafe extern "C" fn clock_gettime(
}
}

/// Override the `mach_absolute_time` function. For `Instant` on x86_64 macOS.
/// Override the `mach_absolute_time` function. For `Instant` on macOS before Rust 1.75.
#[no_mangle]
#[inline(never)]
#[cfg(target_os = "macos")]
// not used on ARM64 macOS after https://github.com/rust-lang/rust/pull/103594
#[rustversion::attr(since(1.67), cfg(not(target_arch = "aarch64")))]
// not used on x86_64 macOS after https://github.com/rust-lang/rust/pull/116238
#[rustversion::attr(since(1.75), cfg(not(target_arch = "x86_64")))]
extern "C" fn mach_absolute_time() -> u64 {
if let Some(time) = super::TimeHandle::try_current() {
// inside a madsim context, use the simulated time.
Expand Down

0 comments on commit 4d77c98

Please sign in to comment.