summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorgsallam <123525874+gsallam@users.noreply.github.com>2023-10-27 03:57:29 (GMT)
committerGitHub <noreply@github.com>2023-10-27 03:57:29 (GMT)
commit21f068d80c6cc5de75f9df70fdd733d0ce9c70de (patch)
treedaceefb593efea137dd642df968075b24c6d52f8 /Modules
parent3d2f1f0b830d86f16f42c42b54d3ea4453dac318 (diff)
downloadcpython-21f068d80c6cc5de75f9df70fdd733d0ce9c70de.zip
cpython-21f068d80c6cc5de75f9df70fdd733d0ce9c70de.tar.gz
cpython-21f068d80c6cc5de75f9df70fdd733d0ce9c70de.tar.bz2
gh-109587: Allow "precompiled" perf-trampolines to largely mitigate the cost of enabling perf-trampolines (#109666)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testinternalcapi.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 4ead1b6..1869f48 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -1556,6 +1556,36 @@ _testinternalcapi_test_long_numbits_impl(PyObject *module)
Py_RETURN_NONE;
}
+static PyObject *
+compile_perf_trampoline_entry(PyObject *self, PyObject *args)
+{
+ PyObject *co;
+ if (!PyArg_ParseTuple(args, "O!", &PyCode_Type, &co)) {
+ return NULL;
+ }
+ int ret = PyUnstable_PerfTrampoline_CompileCode((PyCodeObject *)co);
+ if (ret != 0) {
+ PyErr_SetString(PyExc_AssertionError, "Failed to compile trampoline");
+ return NULL;
+ }
+ return PyLong_FromLong(ret);
+}
+
+static PyObject *
+perf_trampoline_set_persist_after_fork(PyObject *self, PyObject *args)
+{
+ int enable;
+ if (!PyArg_ParseTuple(args, "i", &enable)) {
+ return NULL;
+ }
+ int ret = PyUnstable_PerfTrampoline_SetPersistAfterFork(enable);
+ if (ret == 0) {
+ PyErr_SetString(PyExc_AssertionError, "Failed to set persist_after_fork");
+ return NULL;
+ }
+ return PyLong_FromLong(ret);
+}
+
static PyMethodDef module_functions[] = {
{"get_configs", get_configs, METH_NOARGS},
@@ -1613,6 +1643,8 @@ static PyMethodDef module_functions[] = {
{"run_in_subinterp_with_config",
_PyCFunction_CAST(run_in_subinterp_with_config),
METH_VARARGS | METH_KEYWORDS},
+ {"compile_perf_trampoline_entry", compile_perf_trampoline_entry, METH_VARARGS},
+ {"perf_trampoline_set_persist_after_fork", perf_trampoline_set_persist_after_fork, METH_VARARGS},
_TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
{NULL, NULL} /* sentinel */