Skip to content

Commit 1753ccb

Browse files
authored
gh-138050: [WIP] JIT - Streamline MAKE_WARM - move coldness check to executor creation (GH-138240)
1 parent e03d8e4 commit 1753ccb

File tree

7 files changed

+15
-13
lines changed

7 files changed

+15
-13
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ struct _is {
939939
struct _PyExecutorObject *executor_deletion_list_head;
940940
struct _PyExecutorObject *cold_executor;
941941
int executor_deletion_list_remaining_capacity;
942-
size_t trace_run_counter;
942+
size_t executor_creation_counter;
943943
_rare_events rare_events;
944944
PyDict_WatchCallback builtins_dict_watcher;
945945

Include/internal/pycore_optimizer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
9090
#endif
9191

9292
// Used as the threshold to trigger executor invalidation when
93-
// trace_run_counter is greater than this value.
94-
#define JIT_CLEANUP_THRESHOLD 100000
93+
// executor_creation_counter is greater than this value.
94+
// This value is arbitrary and was not optimized.
95+
#define JIT_CLEANUP_THRESHOLD 1000
9596

9697
#define TRACE_STACK_SIZE 5
9798

Python/bytecodes.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "pycore_audit.h" // _PySys_Audit()
1212
#include "pycore_backoff.h"
1313
#include "pycore_cell.h" // PyCell_GetRef()
14-
#include "pycore_ceval.h"
1514
#include "pycore_code.h"
1615
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
1716
#include "pycore_function.h"
@@ -5362,10 +5361,6 @@ dummy_func(
53625361

53635362
tier2 op(_MAKE_WARM, (--)) {
53645363
current_executor->vm_data.warm = true;
5365-
// It's okay if this ends up going negative.
5366-
if (--tstate->interp->trace_run_counter == 0) {
5367-
_Py_set_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
5368-
}
53695364
}
53705365

53715366
tier2 op(_FATAL_ERROR, (--)) {

Python/ceval_gil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ _Py_HandlePending(PyThreadState *tstate)
13981398
if ((breaker & _PY_EVAL_JIT_INVALIDATE_COLD_BIT) != 0) {
13991399
_Py_unset_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
14001400
_Py_Executors_InvalidateCold(tstate->interp);
1401-
tstate->interp->trace_run_counter = JIT_CLEANUP_THRESHOLD;
1401+
tstate->interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD;
14021402
}
14031403

14041404
/* GIL drop request */

Python/executor_cases.c.h

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

Python/optimizer.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pycore_interp.h"
77
#include "pycore_backoff.h"
88
#include "pycore_bitutils.h" // _Py_popcount32()
9+
#include "pycore_ceval.h" // _Py_set_eval_breaker_bit
910
#include "pycore_code.h" // _Py_GetBaseCodeUnit
1011
#include "pycore_function.h" // _PyFunction_LookupByVersion()
1112
#include "pycore_interpframe.h"
@@ -1343,6 +1344,14 @@ uop_optimize(
13431344
return -1;
13441345
}
13451346
assert(length <= UOP_MAX_TRACE_LENGTH);
1347+
1348+
// Check executor coldness
1349+
PyThreadState *tstate = PyThreadState_Get();
1350+
// It's okay if this ends up going negative.
1351+
if (--tstate->interp->executor_creation_counter == 0) {
1352+
_Py_set_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
1353+
}
1354+
13461355
*exec_ptr = executor;
13471356
return 1;
13481357
}

Python/pystate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ init_interpreter(PyInterpreterState *interp,
571571
interp->executor_list_head = NULL;
572572
interp->executor_deletion_list_head = NULL;
573573
interp->executor_deletion_list_remaining_capacity = 0;
574-
interp->trace_run_counter = JIT_CLEANUP_THRESHOLD;
574+
interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD;
575575
if (interp != &runtime->_main_interpreter) {
576576
/* Fix the self-referential, statically initialized fields. */
577577
interp->dtoa = (struct _dtoa_state)_dtoa_state_INIT(interp);

0 commit comments

Comments
 (0)