Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in#124086
Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in#124086
Conversation
…inux Cherry-picked from jkotas@7518cab This change adds compile-time diagnostics to ensure that on Linux platforms, the HAVE_CLOCK_MONOTONIC and HAVE_PTHREAD_CONDATTR_SETCLOCK flags are properly set. This helps investigate the root cause of Task.Delay freezing when the system time is adjusted backwards, which should be using monotonic clocks instead of real-time clocks. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
|
@copilot Apply jkotas@224e4bd to see whether it fixes the issue |
The CMake configuration was successfully detecting HAVE_CLOCK_MONOTONIC support, but the config.h.in template was missing the #cmakedefine01 directive, causing the macro to be undefined in the generated config.h. This resulted in the runtime falling back to wall-clock time (CLOCK_REALTIME) instead of monotonic clocks, causing Task.Delay to freeze when the system time was adjusted backwards. This change adds the missing #cmakedefine01 HAVE_CLOCK_MONOTONIC line to src/coreclr/pal/src/config.h.in, ensuring the CMake-detected value is properly propagated to the C/C++ code. Applies jkotas@224e4bd Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Applied in f009787. The missing |
Found and fixed additional missing #cmakedefine directives across multiple config.h.in files: 1. src/coreclr/pal/src/config.h.in: Added HAVE_STRERRORNAME_NP - Checked in configure.cmake line 144 - Used in src/coreclr/pal/src/misc/utils.cpp for friendly error messages 2. src/mono/cmake/config.h.in: Added HAVE_SYSSIGNAME - Checked in configure.cmake line 117 - Used in src/mono/mono/utils/mono-signal-handler.c for signal name lookup These were the same type of issue as HAVE_CLOCK_MONOTONIC - CMake was successfully detecting these features, but the configuration values were not being propagated to the generated config.h headers due to missing #cmakedefine directives. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
As requested, keeping only the one-line fix for HAVE_CLOCK_MONOTONIC in src/coreclr/pal/src/config.h.in and reverting all other changes: - Reverted diagnostic checks in synchmanager.cpp and pal_threading.c - Reverted HAVE_STRERRORNAME_NP addition - Reverted HAVE_SYSSIGNAME addition to mono config This PR now contains only the minimal fix for issue #123950. Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a CoreCLR PAL build-configuration regression where CMake detected monotonic clock support, but the result was not propagated into the generated config.h, causing PAL timing code to fall back to CLOCK_REALTIME and making waits susceptible to backward system time jumps (issue #123950).
Changes:
- Add
#cmakedefine01 HAVE_CLOCK_MONOTONICtosrc/coreclr/pal/src/config.h.inso the generatedconfig.hreflects the CMake probe result. - Re-enables the
CLOCK_MONOTONIC-based code paths guarded byHAVE_CLOCK_MONOTONIC(e.g., in SynchManager) when supported.
|
Are we considering this one for backport since it can impact all wait calls and their accuracy? |
|
Yes, I plan to submit backport request |
|
/ba-g known issues |
|
/backport to release/10.0 |
|
Started backporting to |
|
@jkotas backporting to git am output$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Creating an empty commit: Initial plan
Applying: Investigating #123950: Add diagnostic checks for monotonic clock on Linux
.git/rebase-apply/patch:19: trailing whitespace.
#if !HAVE_CLOCK_MONOTONIC
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M src/coreclr/pal/src/synchmgr/synchmanager.cpp
M src/native/libs/System.Native/pal_threading.c
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/pal/src/synchmgr/synchmanager.cpp
Auto-merging src/native/libs/System.Native/pal_threading.c
Applying: Fix #123950: Add missing HAVE_CLOCK_MONOTONIC to config.h.in
Applying: Add missing CMake feature definitions to config.h.in files
Applying: Revert extra changes, keep only HAVE_CLOCK_MONOTONIC fix
error: sha1 information is lacking or useless (src/coreclr/pal/src/config.h.in).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0005 Revert extra changes, keep only HAVE_CLOCK_MONOTONIC fix
Error: The process '/usr/bin/git' failed with exit code 128 |
Fixes issue #123950 where Task.Delay freezes when system time jumps backwards on .NET 10 Linux - a regression from .NET 8 and 9. The root cause was a missing `#cmakedefine01 HAVE_CLOCK_MONOTONIC` directive in `src/coreclr/pal/src/config.h.in`. While CMake was successfully detecting monotonic clock support, the configuration value was never propagated to the generated config.h header. This caused the runtime to fall back to wall-clock time (CLOCK_REALTIME) instead of monotonic clocks (CLOCK_MONOTONIC), making timing operations vulnerable to system time adjustments. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
Description
Fixes issue #123950 where Task.Delay freezes when system time jumps backwards on .NET 10 Linux - a regression from .NET 8 and 9.
The root cause was a missing
#cmakedefine01 HAVE_CLOCK_MONOTONICdirective insrc/coreclr/pal/src/config.h.in. While CMake was successfully detecting monotonic clock support, the configuration value was never propagated to the generated config.h header. This caused the runtime to fall back to wall-clock time (CLOCK_REALTIME) instead of monotonic clocks (CLOCK_MONOTONIC), making timing operations vulnerable to system time adjustments.Changes
Fix applied:
#cmakedefine01 HAVE_CLOCK_MONOTONIC- Enables monotonic clock support, fixing the Task.Delay freeze when system time is adjusted backwardsThis is a minimal one-line change that ensures the CMake-detected monotonic clock support is properly propagated to the C/C++ code.
Impact
The runtime will correctly use monotonic clocks on Linux for synchronization primitives and timing operations, making them immune to system time adjustments. This resolves the Task.Delay freeze behavior and restores .NET 8/9 behavior.
Original fix commit: jkotas@224e4bd
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.