Skip to content

Commit 3d0824a

Browse files
gh-127958: Trace from RESUME in the JIT (GH-145905)
1 parent 81ef1b7 commit 3d0824a

34 files changed

+909
-591
lines changed

Include/internal/pycore_backoff.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)
135135
opt_config->jump_backward_initial_backoff);
136136
}
137137

138+
// This needs to be around 2-4x of JUMP_BACKWARD_INITIAL_VALUE
139+
// The reasoning is that we always want loop traces to form and inline
140+
// functions before functions themselves warm up and link to them instead
141+
// of inlining.
142+
#define RESUME_INITIAL_VALUE 8190
143+
#define RESUME_INITIAL_BACKOFF 6
144+
static inline _Py_BackoffCounter
145+
initial_resume_backoff_counter(_PyOptimizationConfig *opt_config)
146+
{
147+
return make_backoff_counter(
148+
opt_config->resume_initial_value,
149+
opt_config->resume_initial_backoff);
150+
}
151+
138152
/* Initial exit temperature.
139153
* Must be larger than ADAPTIVE_COOLDOWN_VALUE,
140154
* otherwise when a side exit warms up we may construct

Include/internal/pycore_code.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ PyAPI_FUNC(void) _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
323323
PyAPI_FUNC(void) _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
324324
PyAPI_FUNC(void) _Py_GatherStats_GetIter(_PyStackRef iterable);
325325
PyAPI_FUNC(void) _Py_Specialize_CallFunctionEx(_PyStackRef func_st, _Py_CODEUNIT *instr);
326+
PyAPI_FUNC(void) _Py_Specialize_Resume(_Py_CODEUNIT *instr, PyThreadState *tstate, _PyInterpreterFrame *frame);
326327

327328
// Utility functions for reading/writing 32/64-bit values in the inline caches.
328329
// Great care should be taken to ensure that these functions remain correct and

Include/internal/pycore_interp_structs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ typedef struct _PyOptimizationConfig {
414414
uint16_t jump_backward_initial_value;
415415
uint16_t jump_backward_initial_backoff;
416416

417+
uint16_t resume_initial_value;
418+
uint16_t resume_initial_backoff;
419+
417420
// JIT optimization thresholds
418421
uint16_t side_exit_initial_value;
419422
uint16_t side_exit_initial_backoff;

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ Known values:
292292
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
293293
Python 3.15a4 3660 (Change generator preamble code)
294294
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
295+
Python 3.15a6 3662 (Add counter to RESUME)
295296
296297
297298
Python 3.16 will start with 3700
@@ -305,7 +306,7 @@ PC/launcher.c must also be updated.
305306
306307
*/
307308

308-
#define PYC_MAGIC_NUMBER 3661
309+
#define PYC_MAGIC_NUMBER 3662
309310
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
310311
(little-endian) and then appending b'\r\n'. */
311312
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

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

Include/internal/pycore_optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
361361
int oparg, _PyExecutorObject *current_executor);
362362

363363
PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err);
364+
PyAPI_FUNC(bool) _PyJit_EnterExecutorShouldStopTracing(int og_opcode);
365+
364366
void _PyPrintExecutor(_PyExecutorObject *executor, const _PyUOpInstruction *marker);
365367
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);
366368

Include/internal/pycore_uop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef struct _PyUOpInstruction{
3636
} _PyUOpInstruction;
3737

3838
// This is the length of the trace we translate initially.
39-
#ifdef Py_DEBUG
39+
#if defined(Py_DEBUG) && defined(_Py_JIT)
4040
// With asserts, the stencils are a lot larger
4141
#define UOP_MAX_TRACE_LENGTH 1000
4242
#else

0 commit comments

Comments
 (0)