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

Use sleep-aware monotonic clock if available #1189

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion source/posix/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

static const uint64_t NS_PER_SEC = 1000000000;

#if defined(CLOCK_MONOTONIC_RAW)
#if defined(CLOCK_BOOTTIME)
# define HIGH_RES_CLOCK CLOCK_BOOTTIME
#elif defined(CLOCK_MONOTONIC_RAW)
# define HIGH_RES_CLOCK CLOCK_MONOTONIC_RAW
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we preferred CLOCK_MONOTONIC_RAW:
docs say:

Similar to CLOCK_MONOTONIC, but provides access to a raw hardware-based time that is not subject to NTP adjustments or the incremental adjustments performed by adjtime.

but with this change we'd prefer CLOCK_BOOTTIME, which days say:

Identical to CLOCK_MONOTONIC, except it also includes any time that the system is suspended.

So we'd be subject again to "NTP adjustments or the incremental adjustments performed by adjtime"

Just pointing it out. I don't know enough about this off the top of my head to gauge the full repercussions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I just did some more reading on all this. BOOTTIME seems fine for our purposes.

#else
# define HIGH_RES_CLOCK CLOCK_MONOTONIC
Expand Down