Skip to content

Commit f79e7d1

Browse files
Move lltrace into the frame struct
1 parent e65a1eb commit f79e7d1

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

Include/internal/pycore_frame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ typedef struct _PyInterpreterFrame {
7676
uint16_t return_offset; /* Only relevant during a function call */
7777
char owner;
7878
char visited;
79+
#ifdef Py_DEBUG
80+
char lltrace;
81+
#endif
7982
/* Locals and stack */
8083
_PyStackRef localsplus[1];
8184
} _PyInterpreterFrame;

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4993,7 +4993,7 @@ dummy_func(
49934993
_Py_CODEUNIT *target = _PyFrame_GetBytecode(frame) + exit->target;
49944994
#if defined(Py_DEBUG) && !defined(_Py_JIT)
49954995
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
4996-
if (lltrace >= 2) {
4996+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 2) {
49974997
printf("SIDE EXIT: [UOp ");
49984998
_PyUOpPrint(&next_uop[-1]);
49994999
printf(", exit %u, temp %d, target %d -> %s]\n",
@@ -5111,7 +5111,7 @@ dummy_func(
51115111
_Py_CODEUNIT *target = frame->instr_ptr;
51125112
#if defined(Py_DEBUG) && !defined(_Py_JIT)
51135113
OPT_HIST(trace_uop_execution_counter, trace_run_length_hist);
5114-
if (lltrace >= 2) {
5114+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 2) {
51155115
printf("DYNAMIC EXIT: [UOp ");
51165116
_PyUOpPrint(&next_uop[-1]);
51175117
printf(", exit %u, temp %d, target %d -> %s]\n",

Python/ceval.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
799799
#endif
800800
uint8_t opcode; /* Current opcode */
801801
int oparg; /* Current opcode argument, if any */
802-
#ifdef LLTRACE
803-
int lltrace = 0;
804-
#endif
805802

806803
_PyInterpreterFrame entry_frame;
807804

@@ -821,6 +818,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
821818
entry_frame.owner = FRAME_OWNED_BY_CSTACK;
822819
entry_frame.visited = 0;
823820
entry_frame.return_offset = 0;
821+
#ifdef LLTRACE
822+
entry_frame.lltrace = 0;
823+
#endif
824824
/* Push frame */
825825
entry_frame.previous = tstate->current_frame;
826826
frame->previous = &entry_frame;
@@ -880,9 +880,13 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
880880
stack_pointer = _PyFrame_GetStackPointer(frame);
881881

882882
#ifdef LLTRACE
883-
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS());
884-
if (lltrace < 0) {
885-
goto exit_unwind;
883+
{
884+
int lltrace = maybe_lltrace_resume_frame(frame, &entry_frame,
885+
GLOBALS());
886+
FT_ATOMIC_STORE_UINT8_RELAXED(frame->lltrace, (uint8_t)lltrace);
887+
if (lltrace < 0) {
888+
goto exit_unwind;
889+
}
886890
}
887891
#endif
888892

@@ -1002,7 +1006,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10021006
}
10031007
/* Resume normal execution */
10041008
#ifdef LLTRACE
1005-
if (lltrace >= 5) {
1009+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 5) {
10061010
lltrace_resume_frame(frame);
10071011
}
10081012
#endif
@@ -1079,7 +1083,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10791083
for (;;) {
10801084
uopcode = next_uop->opcode;
10811085
#ifdef Py_DEBUG
1082-
if (lltrace >= 3) {
1086+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 3) {
10831087
dump_stack(frame, stack_pointer);
10841088
if (next_uop->opcode == _START_EXECUTOR) {
10851089
printf("%4d uop: ", 0);
@@ -1121,7 +1125,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11211125

11221126
jump_to_error_target:
11231127
#ifdef Py_DEBUG
1124-
if (lltrace >= 2) {
1128+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 2) {
11251129
printf("Error: [UOp ");
11261130
_PyUOpPrint(&next_uop[-1]);
11271131
printf(" @ %d -> %s]\n",
@@ -1157,7 +1161,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
11571161
next_instr = next_uop[-1].target + _PyFrame_GetBytecode(frame);
11581162
goto_to_tier1:
11591163
#ifdef Py_DEBUG
1160-
if (lltrace >= 2) {
1164+
if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 2) {
11611165
printf("DEOPT: [UOp ");
11621166
_PyUOpPrint(&next_uop[-1]);
11631167
printf(" -> %s]\n",

Python/ceval_macros.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
8282
#ifdef LLTRACE
83-
#define PRE_DISPATCH_GOTO() if (lltrace >= 5) { \
83+
#define PRE_DISPATCH_GOTO() if (FT_ATOMIC_LOAD_UINT8_RELAXED(frame->lltrace) >= 5) { \
8484
lltrace_instruction(frame, stack_pointer, next_instr, opcode, oparg); }
8585
#else
8686
#define PRE_DISPATCH_GOTO() ((void)0)
@@ -89,7 +89,8 @@
8989
#if LLTRACE
9090
#define LLTRACE_RESUME_FRAME() \
9191
do { \
92-
lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS()); \
92+
int lltrace = maybe_lltrace_resume_frame(frame, &entry_frame, GLOBALS()); \
93+
FT_ATOMIC_STORE_UINT8_RELAXED(frame->lltrace, (uint8_t)lltrace); \
9394
if (lltrace < 0) { \
9495
goto exit_unwind; \
9596
} \
@@ -153,7 +154,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
153154
/* The integer overflow is checked by an assertion below. */
154155
#define INSTR_OFFSET() ((int)(next_instr - _PyFrame_GetBytecode(frame)))
155156
#define NEXTOPARG() do { \
156-
_Py_CODEUNIT word = {.cache = FT_ATOMIC_LOAD_UINT16_RELAXED(*(uint16_t*)next_instr)}; \
157+
_Py_CODEUNIT word = {.cache = FT_ATOMIC_LOAD_UINT8_RELAXED(*(uint16_t*)next_instr)}; \
157158
opcode = word.op.code; \
158159
oparg = word.op.arg; \
159160
} while (0)

Python/executor_cases.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)