Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instant + Duration produce wrong result on aarch64-apple-darwin #91417

Closed
wangrunji0408 opened this issue Dec 1, 2021 · 12 comments · Fixed by #103594
Closed

Instant + Duration produce wrong result on aarch64-apple-darwin #91417

wangrunji0408 opened this issue Dec 1, 2021 · 12 comments · Fixed by #103594
Labels
A-time Area: Time C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. O-AArch64 Armv8-A or later processors in AArch64 mode O-macos Operating system: macOS P-medium Medium priority T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@wangrunji0408
Copy link

I tried this code on M1 macOS:

use std::time::{Duration, Instant};
fn main() {
    let t0 = Instant::now();
    let t1 = t0 + Duration::from_nanos(50);
    let d = t1 - t0;
    dbg!(t0, t1, d);
    assert_eq!(t0 + d, t1);
}

It's expected to succeed.

Instead, this happened:

[src/main.rs:6] t0 = Instant {
    t: 147092181000,
}
[src/main.rs:6] t1 = Instant {
    t: 147092181001,
}
[src/main.rs:6] d = 41ns
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Instant { t: 147092181000 }`,
 right: `Instant { t: 147092181001 }`', src/main.rs:7:5

It seems that there is something wrong with the Duration -> Instant casting in Rust std:

fn checked_dur2intervals(dur: &Duration) -> Option<u64> {
let nanos =
dur.as_secs().checked_mul(NSEC_PER_SEC)?.checked_add(dur.subsec_nanos() as u64)?;
let info = info();
Some(mul_div_u64(nanos, info.denom as u64, info.numer as u64))
}

This problem does not exist on x86_64-apple-darwin, because info.denom = info.numer = 1.

Meta

rustc --version --verbose:

rustc 1.56.1 (59eed8a2a 2021-11-01)
binary: rustc
commit-hash: 59eed8a2aac0230a8b53e89d4e99d55912ba6b35
commit-date: 2021-11-01
host: aarch64-apple-darwin
release: 1.56.1
LLVM version: 13.0.0
@wangrunji0408 wangrunji0408 added the C-bug Category: This is a bug. label Dec 1, 2021
@hkratz
Copy link
Contributor

hkratz commented Dec 1, 2021

@rustbot label +T-libs +O-macos +O-arm

@rustbot rustbot added O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-macos Operating system: macOS T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 1, 2021
@csmoe
Copy link
Member

csmoe commented Dec 1, 2021

Seems related to the time resolution difference on Apple M1, cc https://eclecticlight.co/2020/09/08/changing-the-clock-in-apple-silicon-macs/

@hkratz
Copy link
Contributor

hkratz commented Dec 2, 2021

The reason for this behavior is that Instant uses platform-specific resolution while Duration uses nanosecond resolution. For Macos x86-64 and Linux this does not matter because on those platforms the resolution of Instant is also nanoseconds.

Instant resolution on my M1 is 125 / 3 ≈ 41.67 ns. So when you add 50 ns to t0 you are adding 1 to its internal representation (= ~41.67 ns). When the duration is calculated it gets rounded down to d = ⌊1 * 125 / 3⌋ = 41 ns. t0 + d = t0 because 41 ns is less than the minimum resolution.

@wangrunji0408
Copy link
Author

The reason for this behavior is that Instant uses platform-specific resolution while Duration uses nanosecond resolution. For Macos x86-64 and Linux this does not matter because on those platforms the resolution of Instant is also nanoseconds.

Instant resolution on my M1 is 125 / 3 ≈ 41.67 ns. So when you add 50 ns to t0 you are adding 1 to its internal representation (= ~41.67 ns). When the duration is calculated it gets rounded down to d = ⌊1 * 125 / 3⌋ = 41 ns. t0 + d = t0 because 41 ns is less than the minimum resolution.

So is it considered a bug? Should we round 41 ns up to 1?

@hkratz
Copy link
Contributor

hkratz commented Dec 12, 2021

Thought about this some more.

We allow those operations:

  • Duration = Instant - Instant
  • Instant = Instant + Duration
  • bool = Instant == Instant

That can't be changed, so simple arithmetic identities such as i0 + (i1 - i0) == i1 should hold if there is no overflow. In particular because the current behavior leads to real bugs.

The only way to achieve this is IMHO to change the internal representation for Instant on MacOS to nanosecond resolution because otherwise the resolution of the machine timer influences Instant/Duration arithmetic.

cc @thomcc What do you think?

@thomcc
Copy link
Member

thomcc commented Dec 13, 2021

We should do this, but I'm not sure we can do it everywhere — clock_gettime_nsec_np (and the other clock_gettime functions) is only available in Darwin 16 (macOS 10.12, iOS 10) and newer, which is newer than our supported versions.

We can certainly do it on macOS+aarch64 targets though, since those should always have it.

@BGR360
Copy link
Contributor

BGR360 commented Dec 26, 2021

This seems pretty severe. I'm a novice contributor, but I do have an M1 device if there's anything I can do to aid the development of a fix here.

Also, should this get some sort of I-prioritize doohickey?

@yaahc yaahc added A-time Area: Time E-help-wanted Call for participation: Help is requested to fix this issue. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 8, 2022
@the8472
Copy link
Member

the8472 commented Feb 8, 2022

The only way to achieve this is IMHO to change the internal representation for Instant on MacOS to nanosecond resolution because otherwise the resolution of the machine timer influences Instant/Duration arithmetic.

But the documentation says:

An Instant is a wrapper around system-specific types and it may behave differently depending on the underlying operating system. For example, the following snippet is fine on Linux but panics on macOS:

So the consequence would seem that we can any range and precision limitations from the underlying type and thus rounding errors are part of the API? I don't see the benefit of it, but it's documented.

@hkratz
Copy link
Contributor

hkratz commented Feb 8, 2022

It is documented for Instant, yes. But we do allow arithmetic operations (+/-) between Duration and Instant leading to those problems, that - at minimum - violate the principle of the least surprise. It is exacerbated by the fact that Linux, Windows and macOS x86-64 (de facto because numer and denom are both 1) Instants all use nanosecond resolution.

We should just use clock_gettime_nsec_np(CLOCK_UPTIME_RAW)1 on macOS aarch64 as @thomcc suggested, in particular because the use of mach_absolute_time() is already discouraged. We don't specify which version of iOS we support, so no idea if we could use it for ios as well.

Footnotes

  1. Which is currently implemented as (mach_absolute_time() * tb_info.numer) / tb_info.denom (source) apparently totally unconcerned about overflow, so I assume that numer will stay small.

@m-ou-se m-ou-se added the P-medium Medium priority label Feb 9, 2022
@m-ou-se m-ou-se removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 16, 2022
@lyinch
Copy link

lyinch commented Feb 17, 2022

It tried to use clock_gettime_nsec_np(CLOCK_UPTIME_RAW) but this didn't fix the issue. The changes:

https://github.com/lyinch/rust/blob/issue-91417-fix/library/std/src/sys/unix/time.rs#L154
https://github.com/lyinch/rust/blob/issue-91417-fix/library/std/src/time/tests.rs#L17

I also added a test which still fails:

failures:

---- time::tests::macos_resolution_regression stdout ----
[library/std/src/time/tests.rs:21] t0 = Instant {
    t: 511866740696750,
}
[library/std/src/time/tests.rs:21] t1 = Instant {
    t: 511866740696751,
}
[library/std/src/time/tests.rs:21] d = 41ns
thread 'time::tests::macos_resolution_regression' panicked at 'assertion failed: `(left == right)`
  left: `Instant { t: 511866740696750 }`,
 right: `Instant { t: 511866740696751 }`', library/std/src/time/tests.rs:22:5


failures:
    time::tests::macos_resolution_regression

I'm not sure how to correctly get CLOCK_UPTIME_RAW from Rust, so I looked the value up in my local time.h file and used 8 :

typedef enum {
_CLOCK_REALTIME __CLOCK_AVAILABILITY = 0,
#define CLOCK_REALTIME _CLOCK_REALTIME
_CLOCK_MONOTONIC __CLOCK_AVAILABILITY = 6,
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
#define CLOCK_MONOTONIC_RAW _CLOCK_MONOTONIC_RAW
_CLOCK_MONOTONIC_RAW_APPROX __CLOCK_AVAILABILITY = 5,
#define CLOCK_MONOTONIC_RAW_APPROX _CLOCK_MONOTONIC_RAW_APPROX
_CLOCK_UPTIME_RAW __CLOCK_AVAILABILITY = 8,
#define CLOCK_UPTIME_RAW _CLOCK_UPTIME_RAW
_CLOCK_UPTIME_RAW_APPROX __CLOCK_AVAILABILITY = 9,
#define CLOCK_UPTIME_RAW_APPROX _CLOCK_UPTIME_RAW_APPROX
#endif
_CLOCK_PROCESS_CPUTIME_ID __CLOCK_AVAILABILITY = 12,
#define CLOCK_PROCESS_CPUTIME_ID _CLOCK_PROCESS_CPUTIME_ID
_CLOCK_THREAD_CPUTIME_ID __CLOCK_AVAILABILITY = 16
#define CLOCK_THREAD_CPUTIME_ID _CLOCK_THREAD_CPUTIME_ID
} clockid_t;

Note that this enum uses

#if !defined(_DARWIN_FEATURE_CLOCK_GETTIME) || _DARWIN_FEATURE_CLOCK_GETTIME != 0
#if __DARWIN_C_LEVEL >= 199309L
#if __has_feature(enumerator_attributes)
#define __CLOCK_AVAILABILITY __OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0) __TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
#else
#define __CLOCK_AVAILABILITY
#endif

and possibly: https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html

@hkratz
Copy link
Contributor

hkratz commented Feb 17, 2022

@lyinch That can't work, because you are still adjusting the value returned by clock_gettime_nsec_np(CLOCK_UPTIME_RAW) with mach_timebase_info numerator and denominator in https://github.com/lyinch/rust/blob/issue-91417-fix/library/std/src/sys/unix/time.rs#L159-L172

Also this can only be done for macOS aarch64 where it is always available.

It just occurred to me that we don't even need to use clock_gettime_nsec_np, we can just use the standard UNIX implementation (https://github.com/lyinch/rust/blob/aebc9040ebf41d35b646e4ea9aedb86df09cacdb/library/std/src/sys/unix/time.rs#L268) for macOS aarch64 except that we need to use CLOCK_UPTIME_RAW. Defining a local const for CLOCK_UPTIME_RAW to 8 is fine is fine for testing, but it should become a PR to https://github.com/rust-lang/libc before merging.

@lyinch
Copy link

lyinch commented Feb 17, 2022

The test passes now with your proposed changes: lyinch@f9f0c97

bors added a commit to rust-lang/libc that referenced this issue Feb 18, 2022
Macos aarch64 clock uptime const

This will add the constant `CLOCK_UPTIME_RAW` from `time.h` on macos apple silicon. I don't know if the same constant also exists for other systems, so I put it into the most specific file. Background is this issue: rust-lang/rust#91417 which might need the constant.

On my machine, it is defined as:

```C
typedef enum {
_CLOCK_REALTIME __CLOCK_AVAILABILITY = 0,
#define CLOCK_REALTIME _CLOCK_REALTIME
_CLOCK_MONOTONIC __CLOCK_AVAILABILITY = 6,
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
#define CLOCK_MONOTONIC_RAW _CLOCK_MONOTONIC_RAW
_CLOCK_MONOTONIC_RAW_APPROX __CLOCK_AVAILABILITY = 5,
#define CLOCK_MONOTONIC_RAW_APPROX _CLOCK_MONOTONIC_RAW_APPROX
_CLOCK_UPTIME_RAW __CLOCK_AVAILABILITY = 8,
#define CLOCK_UPTIME_RAW _CLOCK_UPTIME_RAW
_CLOCK_UPTIME_RAW_APPROX __CLOCK_AVAILABILITY = 9,
#define CLOCK_UPTIME_RAW_APPROX _CLOCK_UPTIME_RAW_APPROX
#endif
_CLOCK_PROCESS_CPUTIME_ID __CLOCK_AVAILABILITY = 12,
#define CLOCK_PROCESS_CPUTIME_ID _CLOCK_PROCESS_CPUTIME_ID
_CLOCK_THREAD_CPUTIME_ID __CLOCK_AVAILABILITY = 16
#define CLOCK_THREAD_CPUTIME_ID _CLOCK_THREAD_CPUTIME_ID
} clockid_t;
```

I ran the tests in `libc-test` :
```
% cargo test
   Compiling libc v0.2.118 (/Users/backes/dev/libc)
   Compiling libc-test v0.2.118 (/Users/backes/dev/libc/libc-test)
    Finished test [unoptimized + debuginfo] target(s) in 10.40s
     Running test/cmsg.rs (/Users/backes/dev/libc/target/debug/deps/cmsg-1a9cf9acb3bfd606)

running 5 tests
test t::test_cmsg_firsthdr ... ok
test t::test_cmsg_data ... ok
test t::test_cmsg_space ... ok
test t::test_cmsg_len ... ok
test t::test_cmsg_nxthdr ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.32s

     Running test/errqueue.rs (/Users/backes/dev/libc/target/debug/deps/errqueue-34a57aa145f73969)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running test/linux_elf.rs (/Users/backes/dev/libc/target/debug/deps/linux_elf-0d81190c35086f0f)
PASSED 0 tests
     Running test/linux_fcntl.rs (/Users/backes/dev/libc/target/debug/deps/linux_fcntl-35043d47b0ba1ab8)
PASSED 0 tests
     Running test/linux_if_arp.rs (/Users/backes/dev/libc/target/debug/deps/linux_if_arp-7d13a47b02694998)
PASSED 0 tests
     Running test/linux_ipv6.rs (/Users/backes/dev/libc/target/debug/deps/linux_ipv6-019e5b7c295e467b)
PASSED 0 tests
     Running test/linux_strerror_r.rs (/Users/backes/dev/libc/target/debug/deps/linux_strerror_r-177f4ad6f4f31457)
PASSED 0 tests
     Running test/linux_termios.rs (/Users/backes/dev/libc/target/debug/deps/linux_termios-0ef27e1d55afb4db)
PASSED 0 tests
     Running test/main.rs (/Users/backes/dev/libc/target/debug/deps/main-112b28ce12de7d4b)
RUNNING ALL TESTS
PASSED 13288 tests
     Running test/semver.rs (/Users/backes/dev/libc/target/debug/deps/semver-e9e1e170582c8b37)
PASSED 1 tests
     Running test/sigrt.rs (/Users/backes/dev/libc/target/debug/deps/sigrt-13dc29f6aa83ea4c)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
```
bors added a commit to rust-lang/libc that referenced this issue Feb 18, 2022
Macos aarch64 clock uptime const

This will add the constant `CLOCK_UPTIME_RAW` from `time.h` on macos apple silicon. I don't know if the same constant also exists for other systems, so I put it into the most specific file. Background is this issue: rust-lang/rust#91417 which might need the constant.

On my machine, it is defined as:

```C
typedef enum {
_CLOCK_REALTIME __CLOCK_AVAILABILITY = 0,
#define CLOCK_REALTIME _CLOCK_REALTIME
_CLOCK_MONOTONIC __CLOCK_AVAILABILITY = 6,
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
_CLOCK_MONOTONIC_RAW __CLOCK_AVAILABILITY = 4,
#define CLOCK_MONOTONIC_RAW _CLOCK_MONOTONIC_RAW
_CLOCK_MONOTONIC_RAW_APPROX __CLOCK_AVAILABILITY = 5,
#define CLOCK_MONOTONIC_RAW_APPROX _CLOCK_MONOTONIC_RAW_APPROX
_CLOCK_UPTIME_RAW __CLOCK_AVAILABILITY = 8,
#define CLOCK_UPTIME_RAW _CLOCK_UPTIME_RAW
_CLOCK_UPTIME_RAW_APPROX __CLOCK_AVAILABILITY = 9,
#define CLOCK_UPTIME_RAW_APPROX _CLOCK_UPTIME_RAW_APPROX
#endif
_CLOCK_PROCESS_CPUTIME_ID __CLOCK_AVAILABILITY = 12,
#define CLOCK_PROCESS_CPUTIME_ID _CLOCK_PROCESS_CPUTIME_ID
_CLOCK_THREAD_CPUTIME_ID __CLOCK_AVAILABILITY = 16
#define CLOCK_THREAD_CPUTIME_ID _CLOCK_THREAD_CPUTIME_ID
} clockid_t;
```

I ran the tests in `libc-test` :
```
% cargo test
   Compiling libc v0.2.118 (/Users/backes/dev/libc)
   Compiling libc-test v0.2.118 (/Users/backes/dev/libc/libc-test)
    Finished test [unoptimized + debuginfo] target(s) in 10.40s
     Running test/cmsg.rs (/Users/backes/dev/libc/target/debug/deps/cmsg-1a9cf9acb3bfd606)

running 5 tests
test t::test_cmsg_firsthdr ... ok
test t::test_cmsg_data ... ok
test t::test_cmsg_space ... ok
test t::test_cmsg_len ... ok
test t::test_cmsg_nxthdr ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.32s

     Running test/errqueue.rs (/Users/backes/dev/libc/target/debug/deps/errqueue-34a57aa145f73969)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running test/linux_elf.rs (/Users/backes/dev/libc/target/debug/deps/linux_elf-0d81190c35086f0f)
PASSED 0 tests
     Running test/linux_fcntl.rs (/Users/backes/dev/libc/target/debug/deps/linux_fcntl-35043d47b0ba1ab8)
PASSED 0 tests
     Running test/linux_if_arp.rs (/Users/backes/dev/libc/target/debug/deps/linux_if_arp-7d13a47b02694998)
PASSED 0 tests
     Running test/linux_ipv6.rs (/Users/backes/dev/libc/target/debug/deps/linux_ipv6-019e5b7c295e467b)
PASSED 0 tests
     Running test/linux_strerror_r.rs (/Users/backes/dev/libc/target/debug/deps/linux_strerror_r-177f4ad6f4f31457)
PASSED 0 tests
     Running test/linux_termios.rs (/Users/backes/dev/libc/target/debug/deps/linux_termios-0ef27e1d55afb4db)
PASSED 0 tests
     Running test/main.rs (/Users/backes/dev/libc/target/debug/deps/main-112b28ce12de7d4b)
RUNNING ALL TESTS
PASSED 13288 tests
     Running test/semver.rs (/Users/backes/dev/libc/target/debug/deps/semver-e9e1e170582c8b37)
PASSED 1 tests
     Running test/sigrt.rs (/Users/backes/dev/libc/target/debug/deps/sigrt-13dc29f6aa83ea4c)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
```
@workingjubilee workingjubilee added O-AArch64 Armv8-A or later processors in AArch64 mode and removed O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state labels Mar 18, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 18, 2022
Issue rust-lang#91417 fix

This is a regression test and a fixes rust-lang#91417
It also bumps the libc version to 0.2.119 because it requires the constant introduced here: rust-lang/libc#2689
@bors bors closed this as completed in 6419151 Nov 18, 2022
tamird added a commit to tamird/rust that referenced this issue Sep 28, 2023
Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Note that this change was made for aarch64 in
5008a31 which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang#91417 and in particular
rust-lang#91417 (comment)
and
rust-lang#91417 (comment)
are relevant. It's not clear from reading that thread why
CLOCK_UPTIME_RAW was used rather than CLOCK_MONOTONIC. The latter is now
used.
tamird added a commit to tamird/rust that referenced this issue Sep 28, 2023
Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Note that this change was made for aarch64 in
5008a31 which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang#91417 and in particular
rust-lang#91417 (comment)
and
rust-lang#91417 (comment)
are relevant. It's not clear from reading that thread why
`CLOCK_UPTIME_RAW` was used rather than `CLOCK_MONOTONIC`. The latter is
now used.
tamird added a commit to tamird/rust that referenced this issue Sep 28, 2023
Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Note that this change was made for aarch64 in
5008a31 which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang#91417 and in particular
rust-lang#91417 (comment)
and
rust-lang#91417 (comment)
are relevant. It's not clear from reading that thread why
`CLOCK_UPTIME_RAW` was used rather than `CLOCK_MONOTONIC`. The latter is
now used.
tamird added a commit to tamird/rust that referenced this issue Sep 28, 2023
Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Note that this change was made for aarch64 in
5008a31 which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang#91417 and in particular
rust-lang#91417 (comment)
and
rust-lang#91417 (comment)
are relevant.
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 24, 2023
time: use clock_gettime on macos

Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`gettimeofday` was first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca9.

Note that this change was made for aarch64 in
5008a31 which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang#91417 and in particular
rust-lang#91417 (comment)
and
rust-lang#91417 (comment)
are relevant.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Oct 25, 2023
time: use clock_gettime on macos

Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`gettimeofday` was first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Note that this change was made for aarch64 in
5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang/rust#91417 and in particular
rust-lang/rust#91417 (comment)
and
rust-lang/rust#91417 (comment)
are relevant.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
time: use clock_gettime on macos

Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`gettimeofday` was first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Note that this change was made for aarch64 in
5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang/rust#91417 and in particular
rust-lang/rust#91417 (comment)
and
rust-lang/rust#91417 (comment)
are relevant.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
time: use clock_gettime on macos

Replace `gettimeofday` with `clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`gettimeofday` was first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Replace `mach_{absolute_time,timebase_info}` with
`clock_gettime(CLOCK_REALTIME)` on:

```
all(target_os = "macos", not(target_arch = "aarch64")),
    target_os = "ios",
    target_os = "watchos",
    target_os = "tvos"
))]
```

`mach_{absolute_time,timebase_info}` were first used in
time-rs/time@cc367ed
which predated the introduction of `clock_gettime` support in macOS
10.12 Sierra which became the minimum supported version in
58bbca958d917a89124da248735926f86c59a149.

Note that this change was made for aarch64 in
5008a317ce8e508c390ed12bff281f307313376e which predated 10.12 becoming
the minimum supported version. The discussion took place in
rust-lang/rust#91417 and in particular
rust-lang/rust#91417 (comment)
and
rust-lang/rust#91417 (comment)
are relevant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-time Area: Time C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. O-AArch64 Armv8-A or later processors in AArch64 mode O-macos Operating system: macOS P-medium Medium priority T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet