Commit 8a969c4
fix(callgrind): seed every live thread at instrumentation start
Only the thread issuing CALLGRIND_START_INSTRUMENTATION had its shadow
call stack seeded from the native one. A thread parked in a syscall at
the transition has a non-empty native stack and an empty shadow stack
just the same, so its first ret underflows: handleUnderflow pushes the
returned-into frame as a fresh top-level context without consulting
fn->skip, and an obj-skipped frame becomes a visible root carrying
everything the thread runs afterwards.
Under pytest-codspeed this put a CPython interpreter frame at the root
of every thread-pool worker, holding ~100% of that thread's cost. With
CPython 3.14's tail-calling interpreter the leaked frame is a
_TAIL_CALL_<OPCODE> handler, named after whichever opcode was
mid-execution when the worker parked in queue.get().
Seed all live threads instead, each under its own switch_thread since
the call stack, context chain and fn stack live in globals belonging to
whichever thread is switched in. A thread other than the running one is
unwound from the register state saved when it was descheduled; if that
yields a single frame the unwinder never got past the syscall, and
seeding one entry with a fabricated entry SP would re-parent the
thread's later work under it, so leave it empty.
Threads created after the transition are deliberately not covered: they
start at their real entry point with a genuinely empty stack.
Closes COD-2349
Co-Authored-By: Claude <noreply@anthropic.com>1 parent b19e730 commit 8a969c4
1 file changed
Lines changed: 46 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
500 | 501 | | |
501 | 502 | | |
502 | 503 | | |
503 | | - | |
504 | | - | |
505 | | - | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
506 | 508 | | |
507 | 509 | | |
508 | 510 | | |
| |||
512 | 514 | | |
513 | 515 | | |
514 | 516 | | |
515 | | - | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
516 | 520 | | |
517 | 521 | | |
518 | 522 | | |
| |||
523 | 527 | | |
524 | 528 | | |
525 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
526 | 542 | | |
527 | 543 | | |
528 | 544 | | |
| |||
581 | 597 | | |
582 | 598 | | |
583 | 599 | | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
584 | 626 | | |
0 commit comments