]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-138050: [WIP] JIT - Streamline MAKE_WARM - move coldness check to executor creatio...
authoralm <alonme@users.noreply.github.com>
Mon, 27 Oct 2025 16:37:37 +0000 (18:37 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 16:37:37 +0000 (16:37 +0000)
Include/internal/pycore_interp_structs.h
Include/internal/pycore_optimizer.h
Python/bytecodes.c
Python/ceval_gil.c
Python/executor_cases.c.h
Python/optimizer.c
Python/pystate.c

index badc97808c6132a871b96bd5f601f67ee21a81e0..9cdaa950e3479a8bf62f0632ccc2186616cb2485 100644 (file)
@@ -939,7 +939,7 @@ struct _is {
     struct _PyExecutorObject *executor_deletion_list_head;
     struct _PyExecutorObject *cold_executor;
     int executor_deletion_list_remaining_capacity;
-    size_t trace_run_counter;
+    size_t executor_creation_counter;
     _rare_events rare_events;
     PyDict_WatchCallback builtins_dict_watcher;
 
index 685c39dcd65fb9e81f849125c137501b43bf642b..8ed5436eb6838cd744df92463c346d0bff0bb164 100644 (file)
@@ -90,8 +90,9 @@ PyAPI_FUNC(void) _Py_Executors_InvalidateCold(PyInterpreterState *interp);
 #endif
 
 // Used as the threshold to trigger executor invalidation when
-// trace_run_counter is greater than this value.
-#define JIT_CLEANUP_THRESHOLD 100000
+// executor_creation_counter is greater than this value.
+// This value is arbitrary and was not optimized.
+#define JIT_CLEANUP_THRESHOLD 1000
 
 #define TRACE_STACK_SIZE 5
 
index f9f14322df0a5e6c134ea3ac21ec613130e6fc41..6ebd9ebdfce1bb4223223486eac6ea468aeaf307 100644 (file)
@@ -11,7 +11,6 @@
 #include "pycore_audit.h"         // _PySys_Audit()
 #include "pycore_backoff.h"
 #include "pycore_cell.h"          // PyCell_GetRef()
-#include "pycore_ceval.h"
 #include "pycore_code.h"
 #include "pycore_emscripten_signal.h"  // _Py_CHECK_EMSCRIPTEN_SIGNALS
 #include "pycore_function.h"
@@ -5362,10 +5361,6 @@ dummy_func(
 
         tier2 op(_MAKE_WARM, (--)) {
             current_executor->vm_data.warm = true;
-            // It's okay if this ends up going negative.
-            if (--tstate->interp->trace_run_counter == 0) {
-                _Py_set_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
-            }
         }
 
         tier2 op(_FATAL_ERROR, (--)) {
index 6bf64868cbb2d39c7a16e01ff0bb4e711837c4f1..9b6506ac3326b374bebf605bbf157b11f6a9b3d9 100644 (file)
@@ -1398,7 +1398,7 @@ _Py_HandlePending(PyThreadState *tstate)
     if ((breaker & _PY_EVAL_JIT_INVALIDATE_COLD_BIT) != 0) {
         _Py_unset_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
         _Py_Executors_InvalidateCold(tstate->interp);
-        tstate->interp->trace_run_counter = JIT_CLEANUP_THRESHOLD;
+        tstate->interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD;
     }
 
     /* GIL drop request */
index 0e4d86463761a0a8eee9bca8d5609a639a50cb19..9ce0a9f8a4d87b9f3f02e2194eea4bd79e9d9274 100644 (file)
 
         case _MAKE_WARM: {
             current_executor->vm_data.warm = true;
-            if (--tstate->interp->trace_run_counter == 0) {
-                _Py_set_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
-            }
             break;
         }
 
index 6ad9124744859a3dd75a88f61d8d23c00fc2b2e0..f44f8a9614b8467ff8d63a524abaf1225b87b575 100644 (file)
@@ -6,6 +6,7 @@
 #include "pycore_interp.h"
 #include "pycore_backoff.h"
 #include "pycore_bitutils.h"        // _Py_popcount32()
+#include "pycore_ceval.h"       // _Py_set_eval_breaker_bit
 #include "pycore_code.h"            // _Py_GetBaseCodeUnit
 #include "pycore_function.h"        // _PyFunction_LookupByVersion()
 #include "pycore_interpframe.h"
@@ -1343,6 +1344,14 @@ uop_optimize(
         return -1;
     }
     assert(length <= UOP_MAX_TRACE_LENGTH);
+
+    // Check executor coldness
+    PyThreadState *tstate = PyThreadState_Get();
+    // It's okay if this ends up going negative.
+    if (--tstate->interp->executor_creation_counter == 0) {
+        _Py_set_eval_breaker_bit(tstate, _PY_EVAL_JIT_INVALIDATE_COLD_BIT);
+    }
+
     *exec_ptr = executor;
     return 1;
 }
index 5d0927c6c081965aaeef74b10c8ff91cda517f1e..2141e842a37d2f36635612d3bcf26706ab1d7e94 100644 (file)
@@ -571,7 +571,7 @@ init_interpreter(PyInterpreterState *interp,
     interp->executor_list_head = NULL;
     interp->executor_deletion_list_head = NULL;
     interp->executor_deletion_list_remaining_capacity = 0;
-    interp->trace_run_counter = JIT_CLEANUP_THRESHOLD;
+    interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD;
     if (interp != &runtime->_main_interpreter) {
         /* Fix the self-referential, statically initialized fields. */
         interp->dtoa = (struct _dtoa_state)_dtoa_state_INIT(interp);