Skip to content

[runtime-async] Fix timestamp instrumentation#127662

Open
rcj1 wants to merge 3 commits intodotnet:mainfrom
rcj1:fix-timestamps
Open

[runtime-async] Fix timestamp instrumentation#127662
rcj1 wants to merge 3 commits intodotnet:mainfrom
rcj1:fix-timestamps

Conversation

@rcj1
Copy link
Copy Markdown
Contributor

@rcj1 rcj1 commented May 1, 2026

  1. We need to ensure that new continuations are timestamped at suspension time. In an app with an async chain starting with, say, Main, curContinuation and newContinuation will both belong to Main upon resuming Main in DispatchContinuations. The async chain in t_runtimeAsyncAwaitState.SentinelContinuation!.Next has been built by the JIT via AsyncSuspend and contains newly allocated continuations for the methods above Main in the stack. These should receive a new timestamp, not that of Main.

  2. I don't think we need to add timestamps in QueueContinuationFollowUpActionIfNecessary; they have already been added in HandleSuspended.

Fixes the issue of all the timestamps being the same.
Benchmark #123727 (comment):
New: 403.8 ms
Old: 407 ms

@rcj1 rcj1 requested review from Copilot, jakobbotsch and lateralusX May 1, 2026 20:13
@rcj1 rcj1 changed the title Fix timestamp instrumentation [runtime-async] Fix timestamp instrumentation May 1, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the runtime-async async-debugger instrumentation so that newly-created continuation chains get fresh timestamps at suspension time (instead of inheriting the timestamp of the currently-running continuation), and removes now-unneeded timestamp propagation logic tied to follow-up scheduling.

Changes:

  • Removed the Task.TryAddRuntimeAsyncContinuationChainTimestamps(Continuation chain, Continuation timestampSource) overload to avoid propagating an “old” timestamp to newly allocated continuation nodes.
  • Simplified AsyncDebugger.HandleSuspended / InstrumentedHandleSuspended to always timestamp based on the suspended chain head (sentinel’s Next) without a separate timestamp source.
  • Removed the SuspendRuntimeAsyncContext(ref AsyncDispatcherInfo, ...) / SuspendAsyncContext(ref AsyncDispatcherInfo, ...) path that previously timestamped the remaining chain when a follow-up continuation was queued.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs Removes the timestamp-source-based chain timestamping helper, leaving chain timestamping to use a fresh suspension-time timestamp.
src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs Updates runtime-async instrumentation to timestamp suspended chains without using a “source continuation”, and removes the follow-up-action timestamping/suspend helper calls.

Copilot AI review requested due to automatic review settings May 1, 2026 20:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +1317 to 1322
public static void HandleSuspended(Continuation? nextContinuation)
{
if (nextContinuation != null)
{
if (newContinuation != null)
{
Task.TryAddRuntimeAsyncContinuationChainTimestamps(nextContinuation, newContinuation);
}
else
{
Task.TryAddRuntimeAsyncContinuationChainTimestamps(nextContinuation);
}
Task.TryAddRuntimeAsyncContinuationChainTimestamps(nextContinuation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants