Read System Clock for Monotonic Time#1627
Merged
bakpakin merged 1 commit intojanet-lang:masterfrom Aug 18, 2025
Merged
Conversation
Contributor
Author
|
Disclaimer: I tested the new Normal implementation with Implementation with the Ideally, this would be tested on an OS X system <10.12 (but I don't have access to one). |
This was referenced Aug 18, 2025
This PR changes the `janet_gettime` implementation for OSX <10.12 to read the system clock for `(os/clock :monotonic)`. As far as I was able to find online this is _a_ monotonic clock, although it produces different values from `clock_gettime(CLOCK_MONOTONIC, ...)` on the same system. I can speculate that this is related to `SYSTEM_CLOCK` monotonic time being implemented with `mach_absolute_time` which is documented to _not advance during sleep_, and I suspect that `clock_gettime(CLOCK_MONOTONIC, ...)` does. **Resources**: - `clock_get_time` implementation for the `SYSTEM_CLOCK`: <https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/osfmk/kern/clock_oldops.c#L284-L296> <https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/arm/rtclock.c#L248-L260> - `mach_absolute_time` and `mach_continuous_time` definitions: <https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/osfmk/mach/mach_time.h#L55-L68> - Stack overflow post for implementing `clock_gettime` on OS X before 10.12: <https://stackoverflow.com/questions/11680461/monotonic-clock-on-osx>
8a1559b to
ad8a5cb
Compare
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes the
janet_gettimeimplementation for OSX <10.12 to read the system clock for(os/clock :monotonic). As far as I was able to find online this is a monotonic clock, although it produces different values fromclock_gettime(CLOCK_MONOTONIC, ...)on the same system. I can speculate that this is related toSYSTEM_CLOCKmonotonic time being implemented withmach_absolute_timewhich is documented to not advance during sleep, and I suspect thatclock_gettime(CLOCK_MONOTONIC, ...)does.Resources:
clock_get_timeimplementation for theSYSTEM_CLOCK: https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/osfmk/kern/clock_oldops.c#L284-L296 and https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/arm/rtclock.c#L248-L260mach_absolute_timeandmach_continuous_timedefinitions: https://github.com/apple-oss-distributions/xnu/blob/e3723e1f17661b24996789d8afc084c0c3303b26/osfmk/mach/mach_time.h#L55-L68clock_gettimeon OS X before 10.12: https://stackoverflow.com/questions/11680461/monotonic-clock-on-osx