Make perf_trampoline thread safe.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
We are using an internal profiler that relies on perf_trampoline to associate Python frames with native samples. The current implementation is incompatible with free-threading, leading to data races and crashes when we enabled Tsan and used the profiler in highly concurrent environments. This proposal aims to bridge that gap and enable profiler support for free-threading builds by fixing data races, deadlocks, and memory lifecycle edge cases in perf_trampoline.c.
ThreadSanitizer (TSan) Data Race Report
The following data race was captured during concurrent execution under Free Threading and Tsan. Note that the following stack trace has been sanitized to remove internal organization details and the critical data race in perf_trampoline.c should remain represented:
==================
WARNING: ThreadSanitizer: data race (pid=6355)
Read of size 8 at 0x720c009e2428 by thread T2:
#0 compile_trampoline Python/perf_trampoline.c:413:27
#1 py_trampoline_evaluator Python/perf_trampoline.c:437:40
#2 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122:12
#3 _PyEval_Vector Python/ceval.c:2094:12
#4 _PyFunction_Vectorcall Objects/call.c:380:12
... [generic interpreter evaluation frames] ...
#10 thread_run Modules/_threadmodule.c:359:21
#11 pythread_wrapper Python/thread_pthread.h:242:5
Previous write of size 8 at 0x720c009e2428 by main thread:
#0 code_arena_new_code Python/perf_trampoline.c:403:27
#1 compile_trampoline Python/perf_trampoline.c:419:12
#2 py_trampoline_evaluator Python/perf_trampoline.c:437:40
#3 _PyEval_EvalFrame Include/internal/pycore_ceval.h:122:12
#4 _PyEval_Vector Python/ceval.c:2094:12
... [generic interpreter evaluation frames] ...
#15 _PyEval_EvalFrameDefault Python/generated_cases.c.h:1622:35
==================
I have searched the existing issues for similar reports but was unable to find any duplicates. Please let me know if this has already been reported!
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-152331
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Python/perf_trampoline.c と、compile_trampoline および code_arena_new_code 周辺で報告されている TSan のスタックトレースから始めてください。変更を加える前に、リンクされている PR gh-152331 と既存の free-threading の動作を確認してください。perf_trampoline が、報告されている Races、Deadlocks、またはライフサイクルの失敗なしに、報告された並行プロファイラーのシナリオをサポートできれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend, devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100