[PATCH v2 0/1] MR8916: ntdll: Switch to CLOCK_BOOTTIME for monotonic counters on Linux.
This now accounts for system suspend periods on Linux, similar to how native win32 ticks work. On macOS `mach_continuous_time` already does so. ~~On BSDs (and other POSIX compliant operating systems) `CLOCK_MONOTONIC` likewise includes suspend time. However they also provide a `CLOCK_BOOTTIME`, which does *not* include suspend time, hence the added `__linux__` check there.~~ See https://lkml.org/lkml/2020/5/8/1707 -- v2: ntdll: Switch to CLOCK_BOOTTIME for monotonic counters when available. https://gitlab.winehq.org/wine/wine/-/merge_requests/8916
From: Marc-Aurel Zent <mzent(a)codeweavers.com> This now accounts for system suspend periods. See https://lkml.org/lkml/2020/5/8/1707 --- dlls/ntdll/unix/sync.c | 4 ++-- server/request.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c index acdb7b3d9f8..a352e814fde 100644 --- a/dlls/ntdll/unix/sync.c +++ b/dlls/ntdll/unix/sync.c @@ -94,8 +94,8 @@ static inline ULONGLONG monotonic_counter(void) return mach_continuous_time() * timebase.numer / timebase.denom / 100; #elif defined(HAVE_CLOCK_GETTIME) struct timespec ts; -#ifdef CLOCK_MONOTONIC_RAW - if (!clock_gettime( CLOCK_MONOTONIC_RAW, &ts )) +#ifdef CLOCK_BOOTTIME + if (!clock_gettime( CLOCK_BOOTTIME, &ts )) return ts.tv_sec * (ULONGLONG)TICKSPERSEC + ts.tv_nsec / 100; #endif if (!clock_gettime( CLOCK_MONOTONIC, &ts )) diff --git a/server/request.c b/server/request.c index 835ea30cec3..432a5918892 100644 --- a/server/request.c +++ b/server/request.c @@ -515,8 +515,8 @@ timeout_t monotonic_counter(void) return mach_continuous_time() * timebase.numer / timebase.denom / 100; #elif defined(HAVE_CLOCK_GETTIME) struct timespec ts; -#ifdef CLOCK_MONOTONIC_RAW - if (!clock_gettime( CLOCK_MONOTONIC_RAW, &ts )) +#ifdef CLOCK_BOOTTIME + if (!clock_gettime( CLOCK_BOOTTIME, &ts )) return (timeout_t)ts.tv_sec * TICKS_PER_SEC + ts.tv_nsec / 100; #endif if (!clock_gettime( CLOCK_MONOTONIC, &ts )) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/8916
On Thu Sep 11 21:50:22 2025 +0000, Marc-Aurel Zent wrote:
Ah I was looking at https://man.freebsd.org/cgi/man.cgi?query=clock_gettime Well it seems they implemented things differently to what they intended to do, and given that previous versions did not include suspend and now `CLOCK_BOOTTIME` behaves identical to `CLOCK_MONOTONIC` (both including suspend) that `__linux__` check is really unnecessary there now. I couldn't find any other BSD with `CLOCK_BOOTTIME` so I will just remove it. If it helps, I found that commit that changed the `clock_gettime` man page: https://github.com/freebsd/freebsd-src/commit/de1e91339b17171e020029e1d49f36...
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/8916#note_115725
Is the current change now acceptable with ignoring the BSD case (since it is unnecessary) and given that `RtlQueryPerformanceCounter` and `GetTickCount` also include suspend time? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/8916#note_117771
participants (3)
-
Brendan Shanks (@bshanks) -
Marc-Aurel Zent -
Marc-Aurel Zent (@mzent)