Skip to content

gh-159312: Avoid CPU attribution to suspended thread states - #159328

Draft
pablogsal wants to merge 2 commits into
python:mainfrom
pablogsal:fix-159312-cpu-tstate
Draft

pablogsal wants to merge 2 commits into
python:mainfrom
pablogsal:fix-159312-cpu-tstate

Conversation

@pablogsal

@pablogsal pablogsal commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

CPU mode can attribute samples to a suspended stack when another thread state uses the same native thread. For an unbound state, check whether a bound state on that native thread has Python frames before marking it on CPU. Preserve attribution when no bound stack is found, including native work after a callback deletes or empties its temporary state. Bound the lookup and keep the sample if remote reads fail.

The normal path adds one flag check, with no new allocation or remote read. The regression uses the existing test helper. External-inspection and profiling tests pass on regular and free-threaded debug builds, with 547 tests on each. A small Linux debug benchmark of ordinary sampling showed median changes of -1.9% for one thread and +0.6% for eight, within the observed run-to-run variation.

@pablogsal pablogsal changed the title gh-159312: Prefer bound stacks for CPU sample attribution gh-159312: Avoid CPU attribution to suspended thread states Oct 13, 2026
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