Skip to content

Check the PC sampling gap before synchronizing the context - #55

Merged
gnurizen merged 1 commit into
mainfrom
fix/pc-gap-before-sync
Nov 23, 2026
Merged

gnurizen merged 1 commit into
mainfrom
fix/pc-gap-before-sync

Conversation

@gnurizen

Copy link
Copy Markdown
Contributor

Under parca-agent, the launch callback calls PCSampling::start() every 30 ms for each thread that launches kernels (kPCSamplingIntervalNs). start() called cuCtxSynchronize first. Only after that, under pcSamplingMutex, did it find it was still inside the gap and return false. So every check drained the GPU: about 33 full context synchronizations a second per launching thread, whatever window and gap the agent set.

start() now checks the gap before the synchronize. The check under the lock stays, for a window that closes in between.

What we measured

CoreWeave, 8x RTX PRO 6000 node, vLLM and SGLang serving a decode-heavy load, agent window 30 ms / gap 10 s, release shim:

  • perf on the engine thread: PCSampling::start → libcuda (spinning in the synchronize) accounted for 64% of samples on vLLM and 37% on SGLang.
  • Throughput at C=8 fell from about 570 tok/s to 264, then 192, then 144 over three 4-minute reps. It got worse the longer PC sampling stayed on.
  • The cost did not follow the duty cycle. 10 ms / 10 s, 30 ms / 3 s, 100 ms / 10 s and the agent default 30 ms / 270 ms all cost far more than their windows could explain.
  • TRT-LLM was mostly spared: its context never finishes PC sampling setup (PC sampling enable failure always blamed on permissions; TRT-LLM fails with CUPTI_ERROR_OUT_OF_MEMORY #54), so start() returns before the synchronize.

A GPU A/B of this fix on the same node is running now. I'll add the numbers here.

Testing

  • The identical hunk builds on the experiment branch it was first written on, and that build is what's deployed in the GPU run.
  • No mock test: the mock cuCtxSynchronize is a no-op. A test would have to count synchronizations across launches inside a gap. I can add that if you'd like it.

Under parca-agent, the launch callback calls PCSampling::start() every
30 ms per launching thread. start() synchronized the context first and
only then, under the lock, found it was still inside the gap and
returned. So every check drained the GPU: about 33 full context
synchronizations a second per thread, whatever window and gap the agent
set.

start() now returns before the synchronize while the gap since the last
window has not passed. The check under the lock stays, for a window
that closes in between.

On an 8x RTX PRO 6000 node (vLLM and SGLang, decode-heavy load, agent
window 30 ms / gap 10 s) the synchronize took 37-64% of the engine
thread's CPU samples and throughput fell 50-75%, getting worse the
longer it ran. The same loss showed with the agent's 10 ms / 10 s and
its defaults, which is why measured cost did not follow the duty cycle.
@gnurizen
gnurizen marked this pull request as draft November 23, 2026 14:44
@gnurizen
gnurizen marked this pull request as ready for review November 23, 2026 17:24
@gnurizen
gnurizen merged commit 99aa64d into main Nov 23, 2026
2 checks passed
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.

1 participant