python / python/cpython

Make perf_trampoline thread safe.

未關閉
#152,330 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-free-threading type-feature
主要語言
Python
星號
77.2k
分支
36k
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Python/perf_trampoline.c 以及 compile_trampoline 和 code_arena_new_code 周圍回報的 TSan 堆疊追蹤開始。在進行變更之前,檢視連結的 PR gh-152331 和現有的 free-threading 行為。完成的標準是 perf_trampoline 支援所回報的並行 profiler 情境,且不存在所回報的 Races、Deadlocks 或生命週期失敗。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend, devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。