gh-149800: Generate the perf trampoline .eh_frame from the compiled assembly - #157246
gh-149800: Generate the perf trampoline .eh_frame from the compiled assembly#157246stratakis wants to merge 9 commits into
Conversation
Documentation build overview
23 files changed ·
|
|
Undrafting, this should be ready. The failed CI jobs must be flakiness as they passed on the previous commit, the last one just skips a specific test on BOLT builds. Did some extra verification here: A Fedora Rawhide RPM build of python3.15 with this on top of the split and the macOS fix (so basically a 3.15 backport), which contains the multitude of Fedora compiler flags. Tested on aarch64 and x86_64 the main, debug, free-threading and free-threading-debug interpreters . On all eight the trampoline is enabled, the jitdumps written by Also I've tested with adding ppc64le support and deployed it on the ppc64le Rawhide buildbot (source build not RPM). Granted the non-fp path is not exercised on ppc64le but nontheless it works if I add this patch on top: ppc64le patchbuilds, tests pass, perf back-chain and DWARF mode both unwind through the trampolines. Did also a s390x compilation (with the relevant code added similarly as the ppc64le one) on RHEL10 (no access to Fedora s390x for now), builds with and without So if that approach seems sound, it should be fairly easy to add s390x, ppc64le, RISC-V support. |
|
Thanks for the change, this is great. Two point of discussions, although very low priority:
The first skim of the PR looks OK to me, I might need a second look to it. Also please fix the errors in the CI. |
I would prefer to not depend on llvm for non-optional parts of CPython at least for now |
|
Will review this soon :) |
Re reading my message I realised that I didn't express well what I meant. I meant that we could reuse the work in this PR to drop the llvm-dwarfdump when building the JIT. |
Let the assembler emit an .eh_frame for the trampoline, matching the frame layout jit_unwind.c describes.
…iled assembly Extract the .eh_frame the assembler emits for the trampoline object at build time into trampoline_ehframe.h and patch only the FDE address fields at runtime. Building with the perf trampoline now needs a host Python, and configure disables the trampoline with a warning when none is usable.
Check the FDEs in jitdump files against their code load records, cover the generator's parsers, and validate the header structure from C.
99dbd73 to
0f6b805
Compare
|
Force pushed the get the latest changes from main, the commits are the same, I don't see how the CI could be failing so it might need something else, couldn't reproduce it. |
I'll take a jab on that, it certainly sounds like a better design. I could send another PR with it as alternative or do a followup, whatever works best.
Sharing would mean adding a CFA program interpreter in Python, which sounds great if it's gonna start reducing the llvm dependency area of the JIT. I'd be happy to take a look at it but since I deal with the JIT as adjacent to these Perf issues I don't have the best overview of the possible impact. |
|
The CI on Mac fails on the llvm installation phase |
A branch with some extra commits on top of this PR implementing that to see if it makes sense: main...stratakis:cpython:trampoline_bootstrap However it's mostly Fable generated with a small review by gpt6, haven't checked the code much or done any rigorous testing apart from a simple build and tests. If it makes sense I can expand on this. I'll check out the review comments the next days (or feel free to amend as you see fit :) ) |
|
I pushed a commit with some small cleanup for the main file to parse the debug info |
| if universal2.exists(): | ||
| return [universal2] | ||
| return sorted( | ||
| path for path in (builddir / "Python").glob("asm_trampoline_*.o") |
There was a problem hiding this comment.
Could we use the configured trampoline object here? The glob can pick up stale objects and fail the test.
| except FileNotFoundError: | ||
| # perf_map_jit_init() gives up silently when it cannot create | ||
| # the file (for example an unwritable /tmp). | ||
| self.skipTest("jitdump file was not created") |
There was a problem hiding this comment.
Could we check whether /tmp is usable before skipping? Missing output could also mean we broke jitdump generation.
|
|
||
| data: bytes | ||
| fde_pc_offset: int | ||
| fde_range_offset: int |
There was a problem hiding this comment.
Could we just derive this as fde_pc_offset + field_size?
The trampoline's unwind information has been a hand-maintained DWARF block per architecture in
Python/jit_unwind.c.Now all of this can be changed :)
The perf trampoline's unwind information is now produced by the assembler from
.cfidirectives in the trampoline assembly and extracted into a header at build time, so no architecture needs hand-written DWARF anymore.Building the perf trampoline now needs a host Python (
PYTHON_FOR_REGEN, 3.7 or newer. Wanted 3.9 for the stock Mac interpreter but 3.7 was compatible so why not). Without one,configuredisables the trampoline.Tested on Linux x86_64 (gcc, clang, CET, JIT, tail-call interpreter, free-threaded, LTO, PGO, BOLT, shared, debug, no frame pointers, out-of-tree)
Linux aarch64 (default, PAC, shared, debug, no frame pointers)
macOS arm64 (native, framework, universal2 on both slices), end to end with perf (fp and DWARF call graphs) and samply.
Plus the test suite ofc which was passing for me (let's see what the CI says though).
This can also be backported into 3.15 together with #149894 and #150364 if needed.
Fixes: #149800
THe PR and testing has been assisted by various frontier models, mainly by Fable 5.1 but also each each iteration reviewed in addition by the gpt 6 astra model.
Making it a draft for now, I believe it's ready but I'd also like to test an rpm build first, plus adding another architecture such as s390x or ppc64le to verify things work as intended.