Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions Include/internal/pycore_backoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ initial_jump_backoff_counter(_PyOptimizationConfig *opt_config)
opt_config->jump_backward_initial_backoff);
}

// This needs to be around 2-4x of JUMP_BACKWARD_INITIAL_VALUE
// The reasoning is that we always want loop traces to form and inline
// functions before functions themselves warm up and link to them instead
// of inlining.
#define RESUME_INITIAL_VALUE 8190
#define RESUME_INITIAL_BACKOFF 6
static inline _Py_BackoffCounter
initial_resume_backoff_counter(_PyOptimizationConfig *opt_config)
{
return make_backoff_counter(
opt_config->resume_initial_value,
opt_config->resume_initial_backoff);
}

/* Initial exit temperature.
* Must be larger than ADAPTIVE_COOLDOWN_VALUE,
* otherwise when a side exit warms up we may construct
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ PyAPI_FUNC(void) _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
PyAPI_FUNC(void) _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
PyAPI_FUNC(void) _Py_GatherStats_GetIter(_PyStackRef iterable);
PyAPI_FUNC(void) _Py_Specialize_CallFunctionEx(_PyStackRef func_st, _Py_CODEUNIT *instr);
PyAPI_FUNC(void) _Py_Specialize_Resume(_Py_CODEUNIT *instr, PyThreadState *tstate, _PyInterpreterFrame *frame);

// Utility functions for reading/writing 32/64-bit values in the inline caches.
// Great care should be taken to ensure that these functions remain correct and
Expand Down
9 changes: 8 additions & 1 deletion Include/internal/pycore_interp_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern "C" {
#include "pycore_structs.h" // PyHamtObject
#include "pycore_tstate.h" // _PyThreadStateImpl
#include "pycore_typedefs.h" // _PyRuntimeState
#include "pycore_uop.h" // _PyBloomFilter

#define CODE_MAX_WATCHERS 8
#define CONTEXT_MAX_WATCHERS 8
Expand Down Expand Up @@ -413,6 +414,9 @@ typedef struct _PyOptimizationConfig {
uint16_t jump_backward_initial_value;
uint16_t jump_backward_initial_backoff;

uint16_t resume_initial_value;
uint16_t resume_initial_backoff;

// JIT optimization thresholds
uint16_t side_exit_initial_value;
uint16_t side_exit_initial_backoff;
Expand Down Expand Up @@ -972,7 +976,10 @@ struct _is {

// Optimization configuration (thresholds and flags for JIT and interpreter)
_PyOptimizationConfig opt_config;
struct _PyExecutorObject *executor_list_head;
_PyBloomFilter *executor_blooms; // Contiguous bloom filter array
struct _PyExecutorObject **executor_ptrs; // Corresponding executor pointer array
size_t executor_count; // Number of valid executors
size_t executor_capacity; // Array capacity
struct _PyExecutorObject *executor_deletion_list_head;
struct _PyExecutorObject *cold_executor;
struct _PyExecutorObject *cold_dynamic_executor;
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Known values:
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
Python 3.15a4 3660 (Change generator preamble code)
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
Python 3.15a6 3662 (Add counter to RESUME)
Python 3.16 will start with 3700
Expand All @@ -305,7 +306,7 @@ PC/launcher.c must also be updated.
*/

#define PYC_MAGIC_NUMBER 3661
#define PYC_MAGIC_NUMBER 3662
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
22 changes: 14 additions & 8 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Include/internal/pycore_optimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ typedef struct {
bool cold;
uint8_t pending_deletion;
int32_t index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
_PyBloomFilter bloom;
_PyExecutorLinkListNode links;
int32_t bloom_array_idx; // Index in interp->executor_blooms/executor_ptrs.
_PyExecutorLinkListNode links; // Used by deletion list.
PyCodeObject *code; // Weak (NULL if no corresponding ENTER_EXECUTOR).
} _PyVMData;

Expand Down Expand Up @@ -157,7 +157,7 @@ typedef struct _PyExecutorObject {
// Export for '_opcode' shared extension (JIT compiler).
PyAPI_FUNC(_PyExecutorObject*) _Py_GetExecutor(PyCodeObject *code, int offset);

void _Py_ExecutorInit(_PyExecutorObject *, const _PyBloomFilter *);
int _Py_ExecutorInit(_PyExecutorObject *, const _PyBloomFilter *);
void _Py_ExecutorDetach(_PyExecutorObject *);
void _Py_BloomFilter_Init(_PyBloomFilter *);
void _Py_BloomFilter_Add(_PyBloomFilter *bloom, void *obj);
Expand Down Expand Up @@ -361,6 +361,8 @@ _PyJit_TryInitializeTracing(PyThreadState *tstate, _PyInterpreterFrame *frame,
int oparg, _PyExecutorObject *current_executor);

PyAPI_FUNC(void) _PyJit_FinalizeTracing(PyThreadState *tstate, int err);
PyAPI_FUNC(bool) _PyJit_EnterExecutorShouldStopTracing(int og_opcode);

void _PyPrintExecutor(_PyExecutorObject *executor, const _PyUOpInstruction *marker);
void _PyJit_TracerFree(_PyThreadStateImpl *_tstate);

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_uop.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef struct _PyUOpInstruction{
} _PyUOpInstruction;

// This is the length of the trace we translate initially.
#ifdef Py_DEBUG
#if defined(Py_DEBUG) && defined(_Py_JIT)
// With asserts, the stencils are a lot larger
#define UOP_MAX_TRACE_LENGTH 1000
#else
Expand Down
Loading
Loading