Skip to content

Add global worker statistics param (QUIC_PARAM_GLOBAL_WORKER_STATISTICS)#6115

Open
guhetier wants to merge 6 commits into
mainfrom
guhetier/worker_statistics_copilot
Open

Add global worker statistics param (QUIC_PARAM_GLOBAL_WORKER_STATISTICS)#6115
guhetier wants to merge 6 commits into
mainfrom
guhetier/worker_statistics_copilot

Conversation

@guhetier

@guhetier guhetier commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Description

Add per-worker statistics accessible via MsQuic->GetParam(NULL, QUIC_PARAM_GLOBAL_WORKER_STATISTICS, ...):

  • QUIC_WORKER_STATISTICS struct: IdealProcessor, CumulativeActiveTimeUs, CumulativeWallTimeUs per CXPLAT worker
  • QUIC_WORKER_STATISTICS_LIST header with WorkerCount and WorkerStatsSize for forward-compatible stride-based iteration

It tracks the amount of time a worker is active or idle. Note that a worker is considered active when it is preempted while processing a job: this isn't a measure of how much CPU time used by the worker and rather a measure of its work load.

Preview-guarded in public header (QUIC_API_ENABLE_PREVIEW_FEATURES).

Testing

Test added

Documentation

TBD

Comment thread src/core/library.c Fixed
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.78431% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.53%. Comparing base (4c67926) to head (58bb6d6).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
src/core/library.c 60.78% 20 Missing ⚠️

❌ Your patch check has failed because the patch coverage (60.78%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6115      +/-   ##
==========================================
+ Coverage   85.13%   85.53%   +0.39%     
==========================================
  Files          60       60              
  Lines       18929    19020      +91     
==========================================
+ Hits        16116    16268     +152     
+ Misses       2813     2752      -61     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new preview global parameter, QUIC_PARAM_GLOBAL_WORKER_STATISTICS, to expose per-worker timing statistics (active vs wall time) from the library’s worker pool via MsQuic->GetParam(NULL, ...). This fits into MsQuic’s diagnostics/observability surface alongside existing global perf counters and other global params.

Changes:

  • Introduces new preview public structs QUIC_WORKER_STATISTICS and QUIC_WORKER_STATISTICS_LIST, plus the new global param ID in msquic.h.
  • Tracks worker active time at idle points (event-queue waits and scheduler yields) and adds a platform worker-pool API to snapshot per-worker stats.
  • Adds parameter-validation tests (user + kernel test harness registration) for querying/validating the new statistics.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/test/MsQuicTests.h Adds new test declarations for worker statistics.
src/test/lib/ApiTest.cpp Implements new tests to query and validate worker statistics snapshots.
src/test/bin/winkernel/control.cpp Registers the new tests in the kernel-mode test driver dispatcher.
src/test/bin/quic_gtest.cpp Adds new gtest cases to invoke the new worker statistics tests.
src/platform/platform_worker.c Adds per-worker timing accumulation and implements CxPlatWorkerPoolGetStatistics.
src/inc/quic_platform.h Declares CxPlatWorkerPoolGetStatistics for worker-pool snapshots.
src/inc/msquic.h Adds preview structs and the new QUIC_PARAM_GLOBAL_WORKER_STATISTICS global param constant.
src/core/library.c Implements QUIC_PARAM_GLOBAL_WORKER_STATISTICS in global param dispatch.

Comment thread src/test/MsQuicTests.h
Comment thread src/test/lib/ApiTest.cpp
Comment thread src/inc/msquic.h Outdated
Comment thread src/platform/platform_worker.c Outdated
Comment thread src/platform/platform_worker.c Outdated
Comment thread src/core/library.c Outdated
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@guhetier
guhetier force-pushed the guhetier/worker_statistics_copilot branch from a9694eb to cbd435b Compare June 23, 2026 00:48
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@microsoft microsoft deleted a comment from github-actions Bot Jun 23, 2026
@guhetier
guhetier force-pushed the guhetier/worker_statistics_copilot branch 4 times, most recently from 96de8bf to 326c9b0 Compare June 30, 2026 22:40
Adds a preview global parameter to retrieve per-worker active and wall
time statistics. Active time is tracked via timestamps in the platform
worker loop. Kernel mode returns QUIC_STATUS_NOT_SUPPORTED.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@guhetier
guhetier force-pushed the guhetier/worker_statistics_copilot branch from 326c9b0 to c4af934 Compare July 8, 2026 22:48
…, UniquePtrArray

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@guhetier
guhetier marked this pull request as ready for review July 14, 2026 00:34
@guhetier
guhetier requested a review from a team as a code owner July 14, 2026 00:34
Comment thread src/core/library.c Outdated
guhetier and others added 2 commits July 13, 2026 19:49
Protect QUIC_PARAM_GLOBAL_WORKER_STATISTICS from concurrent teardown of
the platform worker pool. The query now captures MsQuicLib.WorkerPool and
takes a rundown reference (CXPLAT_WORKER_POOL_REF_STATS) under the library
lock, releasing the lock before doing work on the referenced pool. To keep
the pointer from being freed under a reader, MsQuicExecutionCreate and
MsQuicExecutionDelete now mutate MsQuicLib.WorkerPool under the same lock
and never leave it dangling (null under the lock, delete/create outside).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
{
if (Worker->Stats.ActiveStartTimeUs != 0) {
Worker->Stats.CumulativeActiveTimeUs +=
CxPlatTimeDiff64(Worker->Stats.ActiveStartTimeUs, CxPlatTimeUs64());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Generally, looks fine, but you need to be careful with all the CxPlatTimeUs64() calls, as they are quite expensive. Especially since I believe the processing call (once you dequeue an event) almost immediately calls it again.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The timestamp in the worker loop is snapped again only after the events have been processed. I considered re-ordering the loop so that Worker->TimeNow can be used as the ActiveStartTimeUs, that might be worth it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Looking at it again, we currently snap time:

  • right before running execution context (prior to this PR)
  • right before processing events (added by this PR)

Both are potentially time consuming, so it seems reasonable to me to snap the time again - at least because the ECs seems to need a pretty fresh timestamp (see the comment about solving a potential race, it isn't clear which race this is but I suspect it has something to do with timers being already expired).

Comment thread src/platform/platform_worker.c Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants