Skip to content

[runtime-async] Fix timestamp instrumentation#127662

Merged
rcj1 merged 6 commits into
dotnet:mainfrom
rcj1:fix-timestamps
May 12, 2026
Merged

[runtime-async] Fix timestamp instrumentation#127662
rcj1 merged 6 commits into
dotnet: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: 387.4 ms
Old: 404.2 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.

@lateralusX
Copy link
Copy Markdown
Member

You will need to rebase and test this on top of #127238.

@lateralusX
Copy link
Copy Markdown
Member

We should probably also add some test to see if we could guard this specific scenario as well.

Copilot AI review requested due to automatic review settings May 5, 2026 19:20
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 3 out of 3 changed files in this pull request and generated 1 comment.

Copy link
Copy Markdown
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

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

LGTM!

@rcj1
Copy link
Copy Markdown
Contributor Author

rcj1 commented May 12, 2026

/ba-g timeouts

@rcj1 rcj1 merged commit 408f6a0 into dotnet:main May 12, 2026
150 of 153 checks passed
@rcj1 rcj1 deleted the fix-timestamps branch May 12, 2026 17:14
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.

3 participants