From 6b3584a5b913ba16bd5b909a0787298eb35a77d1 Mon Sep 17 00:00:00 2001 From: Matt Page Date: Fri, 1 Nov 2024 09:45:50 -0700 Subject: [PATCH 1/6] Ignore warning about JIT being deactivated when perf support is active in test_initconfig_api This is a temporary measure to get JIT tests passing again. This should be reverted once a more comprehensive fix lands. --- Lib/test/test_embed.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 4ea43edccda63e..88d4d3f25f0c27 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1,5 +1,6 @@ # Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs) from test import support +from test.libregrtest.utils import get_build_info from test.support import import_helper, os_helper, threading_helper, MS_WINDOWS import unittest @@ -1780,8 +1781,13 @@ def test_initconfig_api(self): 'perf_profiling': 2, } config_dev_mode(preconfig, config) + using_jit = any(x.startswith("JIT") for x in get_build_info()) + if using_jit: + stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" + else: + stderr = "" self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED) + api=API_ISOLATED, stderr=stderr) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") From 47a81dab4a3c65af8a785b6754920440829fe5ad Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Fri, 1 Nov 2024 19:29:54 +0200 Subject: [PATCH 2/6] Add a newline to optimizer.c to trigger JIT workflow --- Python/optimizer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/optimizer.c b/Python/optimizer.c index b876b6c2bd72fd..c0ed8198a46dbf 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1699,4 +1699,5 @@ _Py_Executors_InvalidateCold(PyInterpreterState *interp) _Py_Executors_InvalidateAll(interp, 0); } + #endif /* _Py_TIER2 */ From 8d80f449584f1ec5e83e0d7dbc7fa52ae515a06f Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Fri, 1 Nov 2024 19:56:26 +0200 Subject: [PATCH 3/6] Necessary changes made by Pablo and Ken Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Co-authored-by: Pablo Galindo --- Lib/test/test_perf_profiler.py | 6 +++--- Python/pylifecycle.c | 5 ++++- Python/sysmodule.c | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_perf_profiler.py b/Lib/test/test_perf_profiler.py index b55d441759eb69..1e74990878007a 100644 --- a/Lib/test/test_perf_profiler.py +++ b/Lib/test/test_perf_profiler.py @@ -210,14 +210,14 @@ def test_sys_api_with_existing_trampoline(self): sys.activate_stack_trampoline("perf") sys.activate_stack_trampoline("perf") """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def test_sys_api_with_invalid_trampoline(self): code = """if 1: import sys sys.activate_stack_trampoline("invalid") """ - rc, out, err = assert_python_failure("-c", code) + rc, out, err = assert_python_failure("-c", code, PYTHON_JIT="0") self.assertIn("invalid backend: invalid", err.decode()) def test_sys_api_get_status(self): @@ -228,7 +228,7 @@ def test_sys_api_get_status(self): sys.deactivate_stack_trampoline() assert sys.is_stack_trampoline_active() is False """ - assert_python_ok("-c", code) + assert_python_ok("-c", code, PYTHON_JIT="0") def is_unwinding_reliable_with_frame_pointers(): diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 2efaa9db7d7d58..4d1eeafb6ddc94 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1310,12 +1310,15 @@ init_interp_main(PyThreadState *tstate) enabled = *env != '0'; } if (enabled) { +#ifdef _Py_JIT if (config->perf_profiling > 0) { (void)PyErr_WarnEx( PyExc_RuntimeWarning, "JIT deactivated as perf profiling support is active", 0); - } else { + } else +#endif + { PyObject *opt = _PyOptimizer_NewUOpOptimizer(); if (opt == NULL) { return _PyStatus_ERR("can't initialize optimizer"); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index cbb73977e1aae6..a4abd7c3c45709 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2290,6 +2290,7 @@ sys_activate_stack_trampoline_impl(PyObject *module, const char *backend) #ifdef _Py_JIT _PyOptimizerObject* optimizer = _Py_GetOptimizer(); if (optimizer != NULL) { + Py_DECREF(optimizer); PyErr_SetString(PyExc_ValueError, "Cannot activate the perf trampoline if the JIT is active"); return NULL; } From cb19fc20ac136d3e9305e445736328d2b100c990 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Fri, 1 Nov 2024 20:02:39 +0200 Subject: [PATCH 4/6] Fix linting issue --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 4d1eeafb6ddc94..31ccd0db768e1e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1316,7 +1316,7 @@ init_interp_main(PyThreadState *tstate) PyExc_RuntimeWarning, "JIT deactivated as perf profiling support is active", 0); - } else + } else #endif { PyObject *opt = _PyOptimizer_NewUOpOptimizer(); From 79c966c13db86f7d10e49b5b1581592552284ed7 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Fri, 1 Nov 2024 20:34:05 +0200 Subject: [PATCH 5/6] Ignore stderr --- Lib/test/test_embed.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 88d4d3f25f0c27..5e886b6c8c38ec 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -1781,13 +1781,10 @@ def test_initconfig_api(self): 'perf_profiling': 2, } config_dev_mode(preconfig, config) - using_jit = any(x.startswith("JIT") for x in get_build_info()) - if using_jit: - stderr = ":0: RuntimeWarning: JIT deactivated as perf profiling support is active" - else: - stderr = "" + # Temporarily enable ignore_stderr=True to ignore warnings on JIT builds + # See gh-126255 for more information self.check_all_configs("test_initconfig_api", config, preconfig, - api=API_ISOLATED, stderr=stderr) + api=API_ISOLATED, ignore_stderr=True) def test_initconfig_get_api(self): self.run_embedded_interpreter("test_initconfig_get_api") From c6462c4d0ac16cb487ff14f26941d4a70913f406 Mon Sep 17 00:00:00 2001 From: Kirill Podoprigora Date: Sat, 2 Nov 2024 00:46:59 +0200 Subject: [PATCH 6/6] Add a comment about tier 2 interpreter --- Python/optimizer.c | 1 - Python/pylifecycle.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/optimizer.c b/Python/optimizer.c index c0ed8198a46dbf..b876b6c2bd72fd 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -1699,5 +1699,4 @@ _Py_Executors_InvalidateCold(PyInterpreterState *interp) _Py_Executors_InvalidateAll(interp, 0); } - #endif /* _Py_TIER2 */ diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 31ccd0db768e1e..23882d083844ac 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1311,6 +1311,8 @@ init_interp_main(PyThreadState *tstate) } if (enabled) { #ifdef _Py_JIT + // perf profiler works fine with tier 2 interpreter, so + // only checking for a "real JIT". if (config->perf_profiling > 0) { (void)PyErr_WarnEx( PyExc_RuntimeWarning,