8000 bpo-43760: Speed up check for tracing in interpreter dispatch by markshannon · Pull Request #25276 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43760: Speed up check for tracing in interpreter dispatch #25276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more comments strssing the importance satck discipline when deali…
…ng with CFrames.
  • Loading branch information
markshannon committed Apr 8, 2021
commit 2cf3c9858612ffc139d7223db1d1cdf07dd52599
15 changes: 13 additions & 2 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ typedef int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *);

typedef struct _cframe {
/* This struct will be threaded through the C stack
* allowing faster access to state that must can be modified
* outside of the interpreter must be accessed within it */
* allowing fast access to per-thread state that needs
* to be accessed quickly by the interpreter, but can
* be modified outside of the interpreter.
*
* WARNING: This makes data on the C stack accessible from
* heap objects. Care must be taken to maintain stack
* discipline and make sure that instances of this struct cannot
* accessed outside of their lifetime.
*/
int use_tracing;
struct _cframe *previous;
} CFrame;
Expand Down Expand Up @@ -69,6 +76,9 @@ struct _ts {
This is to prevent the actual trace/profile code from being recorded in
the trace/profile. */
int tracing;

/* Pointer to current CFrame in the C stack frame of the currently,
* or most recently, executing _PyEval_EvalFrameDefault. */
CFrame *cframe;

Py_tracefunc c_profilefunc;
Expand Down Expand Up @@ -136,6 +146,7 @@ struct _ts {

/* Unique thread state id. */
uint64_t id;

CFrame root_cframe;

/* XXX signal handlers should also be here */
Expand Down
6 changes: 5 additions & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
/* Mark trace_info as uninitialized */
trace_info.code = NULL;

/* WARNING: Because the CFrame lives on the C stack,
* but can be accessed from a heap allocated object (tstate)
* strict stack discipline must be maintained.
*/
CFrame *prev_cframe = tstate->cframe;
trace_info.cframe.use_tracing = prev_cframe->use_tracing;
trace_info.cframe.previous = prev_cframe;
Expand Down Expand Up @@ -4588,7 +4592,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)

/* pop frame */
exit_eval_frame:

/* Restore previous cframe */
tstate->cframe = trace_info.cframe.previous;
tstate->cframe->use_tracing = trace_info.cframe.use_tracing;

Expand Down
0