Skip to content

Commit e7b55f5

Browse files
authored
GH-136410: Faster side exits by using a cold exit stub (GH-136411)
1 parent 718e0c8 commit e7b55f5

15 files changed

+387
-267
lines changed

Include/cpython/pystate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ struct _ts {
198198

199199
PyObject *current_executor;
200200

201+
/* Internal to the JIT */
202+
struct _PyExitData *jit_exit;
203+
201204
uint64_t dict_global_version;
202205

203206
/* Used to store/retrieve `threading.local` keys/values for this thread */

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ struct _is {
943943
bool jit;
944944
struct _PyExecutorObject *executor_list_head;
945945
struct _PyExecutorObject *executor_deletion_list_head;
946+
struct _PyExecutorObject *cold_executor;
946947
int executor_deletion_list_remaining_capacity;
947948
size_t trace_run_counter;
948949
_rare_events rare_events;

Include/internal/pycore_optimizer.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ typedef struct {
6767
#endif
6868
} _PyUOpInstruction;
6969

70-
typedef struct {
70+
typedef struct _PyExitData {
7171
uint32_t target;
72+
uint16_t index;
7273
_Py_BackoffCounter temperature;
7374
struct _PyExecutorObject *executor;
7475
} _PyExitData;
@@ -354,6 +355,16 @@ PyAPI_FUNC(PyObject *) _Py_uop_symbols_test(PyObject *self, PyObject *ignored);
354355

355356
PyAPI_FUNC(int) _PyOptimizer_Optimize(_PyInterpreterFrame *frame, _Py_CODEUNIT *start, _PyExecutorObject **exec_ptr, int chain_depth);
356357

358+
static inline _PyExecutorObject *_PyExecutor_FromExit(_PyExitData *exit)
359+
{
360+
_PyExitData *exit0 = exit - exit->index;
361+
return (_PyExecutorObject *)(((char *)exit0) - offsetof(_PyExecutorObject, exits));
362+
}
363+
364+
extern _PyExecutorObject *_PyExecutor_GetColdExecutor(void);
365+
366+
PyAPI_FUNC(void) _PyExecutor_ClearExit(_PyExitData *exit);
367+
357368
static inline int is_terminator(const _PyUOpInstruction *uop)
358369
{
359370
int opcode = uop->opcode;
@@ -363,6 +374,8 @@ static inline int is_terminator(const _PyUOpInstruction *uop)
363374
);
364375
}
365376

377+
extern void _PyExecutor_Free(_PyExecutorObject *self);
378+
366379
PyAPI_FUNC(int) _PyDumpExecutors(FILE *out);
367380
#ifdef _Py_TIER2
368381
extern void _Py_ClearExecutorDeletionList(PyInterpreterState *interp);

0 commit comments

Comments
 (0)