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 摘要。