GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-126910: Make `_Py_get_machine_stack_pointer` return the actual stack pointer by markshannon · Pull Request #149103 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Apr 28, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

(or something close it), but not the frame pointer

  • Make _Py_ReachedRecursionLimit inline again
  • Remove _Py_MakeRecCheck replacing its use with _Py_ReachedRecursionLimit
  • Move the check for C stack swtiching into _Py_CheckRecursiveCall

This is a rebase of #147945 which was reverted due to a non-reproducable buildbot failure.

  • Issue: Supporting stack unwinding in the JIT compiler #126910

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon
Make _Py_get_machine_stack_pointer return the stack pointer (or som…
0d04a59
…ething close it), but not the frame pointer

* Make _Py_ReachedRecursionLimit inline again
* Remove _Py_MakeRecCheck replacing its use with _Py_ReachedRecursionLimit
* Move the check for C stack swtiching into _Py_CheckRecursiveCall
@markshannon
markshannon requested review from FFY00, ZeroIntensity, brandtbucher, diegorusso, ericsnowcurrently and savannahostrowski as code owners April 28, 2026 16:08
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 28, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 28, 2026
Supporting stack unwinding in the JIT compiler #126910
Open
@markshannon
Use simpler #ifdefs for selecting architecture on Windows
a5765b4
@markshannon markshannon added the skip news label Apr 29, 2026
@read-the-docs-community

read-the-docs-community Bot commented Apr 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32742459 | 📁 Comparing c971274 against main (d4eee16)

  🔍 Preview build  

66 files changed · + 1 added · ± 65 modified

+ Added

  • c-api/slots.html

± Modified

  • glossary.html
  • c-api/concrete.html
  • c-api/extension-modules.html
  • c-api/index.html
  • c-api/lifecycle.html
  • c-api/module.html
  • c-api/perfmaps.html
  • c-api/stable.html
  • c-api/synchronization.html
  • c-api/type.html
  • and 55 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon
Get esp for stack pointer on 32 bit Windows x86
01fe604
@markshannon markshannon added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2026
@bedevere-bot

bedevere-bot commented Apr 29, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit 01fe604 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149103%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2026
@markshannon
Merge branch 'main' into use-real-stack-pointer
98073f5
@markshannon markshannon added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 6, 2026
@bedevere-bot

bedevere-bot commented May 6, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit 98073f5 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149103%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 6, 2026
@markshannon

markshannon commented May 6, 2026

Copy link
Copy Markdown
Member Author

@pablogsal
Can you tell what is going on with the buildbot/AMD64 CentOS9 NoGIL PR buildbot?
The test_python_calls_appear_in_the_stack_if_perf_activated test is failing.
Interstingly py_trampoline_evaluator appears 1000s of times in the test output.
Isn't that supposed to show as the Python function in perf?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented May 6, 2026

Copy link
Copy Markdown
Member

@pablogsal

Can you tell what is going on with the buildbot/AMD64 CentOS9 NoGIL PR buildbot?

The test_python_calls_appear_in_the_stack_if_perf_activated test is failing.

Interstingly py_trampoline_evaluator appears 1000s of times in the test output.

Isn't that supposed to show as the Python function in perf?

Perf should add the Python function below that one, yes. I need time to investigate I will try to do it this week but I am a bit overwhelmed with pending things. I will try to take a look as soon as possible.

markshannon reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented May 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@pablogsal
Can you tell what is going on with the buildbot/AMD64 CentOS9 NoGIL PR buildbot?
The test_python_calls_appear_in_the_stack_if_perf_activated test is failing.
Interstingly py_trampoline_evaluator appears 1000s of times in the test output.
Isn't that supposed to show as the Python function in perf?

I spent several hours digging into this one and was able to reproduce theCentOS9 NoGIL failure locally in a CentOS Stream 9 podman container with GCC 11.5 and perf 5.14.

The short version is: the PR itself did not break perf-map generation. The generated perf map still contains the py::foo, py::bar, and py::baz entries. What broke is perf's ability to unwind into those generated trampoline
frames on this builder.

On the failing build, perf script showed lots of py_trampoline_evaluator frames, but none of the generated py::foo/bar/baz symbols. That means the trampoline machinery was active, but perf could not walk the frame-pointer chain far enough to resolve the generated Python frames. The regression comes from the change in _Py_get_machine_stack_pointer(). Before this PR, it used:

__builtin_frame_address(0)

After this PR, on x86-64 it reads the real stack pointer with inline asm:

__asm__("{movq %%rsp, %0" : "=r" (result));

The new behavior is the right semantic direction for the stack-pointer work, but the old __builtin_frame_address(0) had an accidental side effect: it forced GCC to materialize an rbp frame pointer in _PyEval_EvalFrameDefault().

That matters because the perf trampoline test depends on frame-pointer unwinding.

On the failing CentOS9/GCC 11.5 build, _PyEval_EvalFrameDefault() also has this function-specific optimization attribute:

__attribute__((optimize ("no-tree-slp-vectorize")))

With the new %rsp helper, GCC generated _PyEval_EvalFrameDefault() without the normal frame-pointer prologue:

_PyEval_EvalFrameDefault:
    push   %r15
    push   %r14
    push   %r13
    push   %r12
    push   %rbx
    sub    $0x180,%rsp
    ...
    mov    %rsp,%rax

With the old __builtin_frame_address(0) helper, the same build generated:

_PyEval_EvalFrameDefault:
    push   %rbp
    mov    %rsp,%rbp
    push   %r15
    ...

So before this PR, the test passed because __builtin_frame_address(0) was preserving the frame-pointer chain. After this PR, that accidental protection disappeared, and perf's frame-pointer unwinder could no longer walk through _PyEval_EvalFrameDefault() into the generated trampoline frame.

The fix is to keep the new real stack-pointer behavior, but make the eval-loop optimization attribute explicitly preserve frame pointers too:

#define DONT_SLP_VECTORIZE \
    __attribute__((optimize ("no-tree-slp-vectorize", "no-omit-frame-pointer")))

I verified this in the CentOS Stream 9 reproduction:

  1. New %rsp helper plus the old DONT_SLP_VECTORIZE: reproduces the buildbot failure.
  2. Reverting only _Py_get_machine_stack_pointer() to__builtin_frame_address(0): test passes.
  3. New %rsp helper plus optimize("no-tree-slp-vectorize", "no-omit-frame-pointer"): test passes.
  4. Disassembly after the fix again shows _PyEval_EvalFrameDefault() starting with:
push   %rbp
mov    %rsp,%rbp
gpshead and chris-eibl reacted with heart emoji
All reactions
  • ❤️ 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented May 18, 2026

Copy link
Copy Markdown
Member Author

I spent several hours digging into this one and was able to reproduce theCentOS9 NoGIL

Thanks a lot for digging into this. Much appreciated

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon
Make sure frame pointer is used in PyEval_EvalDefault()
c971274
@markshannon markshannon added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 18, 2026
@bedevere-bot

bedevere-bot commented May 18, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit c971274 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149103%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 18, 2026
@markshannon
Merge branch 'main' into use-real-stack-pointer
0d3a7fb
@markshannon

markshannon commented May 21, 2026

Copy link
Copy Markdown
Member Author

!buildbot Alpine

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented May 21, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @markshannon for commit 0d3a7fb 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F149103%2Fmerge

The command will test the builders whose names match following regular expression: Alpine

The builders matched are:

  • AMD64 Alpine Linux PR
  • AMD64 Alpine Linux NoGIL PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon

markshannon commented May 21, 2026

Copy link
Copy Markdown
Member Author

The three buildobot failures were preexisting failures or time outs.
The Alpine buildots work now thanks to #149993

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

diegorusso
diegorusso approved these changes May 21, 2026
View reviewed changes

@diegorusso diegorusso left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nit comments, it looks good. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Include/internal/pycore_ceval.h Outdated
// Overflow if stack pointer is between soft limit and the base of the hardware stack.
// If it is below the hardware stack base, assume that we have the wrong stack limits, and do nothing.
// We could have the wrong stack limits because of limited platform support, or user-space threads.
// Possible overflow if stack pointer is beyond the soft limit.

@diegorusso diegorusso May 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/jit.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 21, 2026
@markshannon
Fix whitespace
5418bf1
@markshannon
markshannon merged commit a679366 into python:main May 26, 2026
175 of 181 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label May 26, 2026
@encukou encukou mentioned this pull request Aug 17, 2026
Increase the size of the test document in test_deeply_nested_content_model #149627
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@diegorusso diegorusso diegorusso approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner
@brandtbucher brandtbucher Awaiting requested review from brandtbucher brandtbucher is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@markshannon @bedevere-bot @pablogsal @diegorusso
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.