python / python/cpython

perf_jit activated from a subinterpreter publishes JIT executors with the trampoline's unwind info

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

還沒有人認領這個 Issue。

interpreter-core topic-JIT type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

sys.activate_stack_trampoline() refuses to run while the JIT is active, but it only checks the current interpreter, and the perf state is process-wide. A subinterpreter can activate perf_jit while the main interpreter keeps its JIT.

import sys
from concurrent import interpreters

interpreters.create().exec("import sys; sys.activate_stack_trampoline('perf_jit')")

def hot(n):
    t = 0
    for i in range(n):
        t += i & 3
    return t

for _ in range(50):
    hot(100000)

With PYTHON_JIT=1 ./python buggy_stuff.py on a --enable-experimental-jit build, the resulting /tmp/jit-.dump holds the JIT's executors (records named py::jit:executor), and every one of them is tagged with the unwind information of the 8-byte perf trampoline. Executor frames look different, so perf produces wrong stacks for samples inside JIT code.

Found while working on https://github.com/python/cpython/pull/157246

CPython versions tested on:

CPython main branch, 3.16

Operating systems tested on:

Linux

Linked PRs
  • gh-157258
  • gh-157324

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從 sys.activate_stack_trampoline()、perf_jit 選項以及 issue 中的 subinterpreter 重現開始;在設定 PYTHON_JIT=1 的 experimental-JIT Linux build 上執行,並檢查產生的 /tmp/jit-.dump。追蹤 JIT executor 如何接收 unwind 資訊,並在 executor frame 不再帶有 8-byte perf trampoline 的 unwind data 時,認為該 issue 已解決。

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

評估

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

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

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