|
4 | 4 | #include "Python.h" |
5 | 5 | #include "pycore_abstract.h" // _PyIndex_Check() |
6 | 6 | #include "pycore_audit.h" // _Py_AuditHookEntry |
| 7 | +#include "pycore_backoff.h" // JUMP_BACKWARD_INITIAL_VALUE, SIDE_EXIT_INITIAL_VALUE |
7 | 8 | #include "pycore_ceval.h" // _PyEval_AcquireLock() |
8 | 9 | #include "pycore_codecs.h" // _PyCodec_Fini() |
9 | 10 | #include "pycore_critical_section.h" // _PyCriticalSection_Resume() |
@@ -1438,6 +1439,20 @@ decref_threadstate(_PyThreadStateImpl *tstate) |
1438 | 1439 | } |
1439 | 1440 | } |
1440 | 1441 |
|
| 1442 | +static inline void |
| 1443 | +init_policy(uint16_t *target, const char *env_name, uint16_t default_value, |
| 1444 | + long min_value, long max_value) |
| 1445 | +{ |
| 1446 | + *target = default_value; |
| 1447 | + char *env = Py_GETENV(env_name); |
| 1448 | + if (env && *env != '\0') { |
| 1449 | + long value = atol(env); |
| 1450 | + if (value >= min_value && value <= max_value) { |
| 1451 | + *target = (uint16_t)value; |
| 1452 | + } |
| 1453 | + } |
| 1454 | +} |
| 1455 | + |
1441 | 1456 | /* Get the thread state to a minimal consistent state. |
1442 | 1457 | Further init happens in pylifecycle.c before it can be used. |
1443 | 1458 | All fields not initialized here are expected to be zeroed out, |
@@ -1523,8 +1538,21 @@ init_threadstate(_PyThreadStateImpl *_tstate, |
1523 | 1538 |
|
1524 | 1539 | _tstate->asyncio_running_loop = NULL; |
1525 | 1540 | _tstate->asyncio_running_task = NULL; |
1526 | | - |
| 1541 | + // Initialize interpreter policy from environment variables |
| 1542 | + init_policy(&_tstate->policy.interp.jump_backward_initial_value, |
| 1543 | + "PYTHON_JIT_JUMP_BACKWARD_INITIAL_VALUE", |
| 1544 | + JUMP_BACKWARD_INITIAL_VALUE, 1, MAX_VALUE); |
| 1545 | + init_policy(&_tstate->policy.interp.jump_backward_initial_backoff, |
| 1546 | + "PYTHON_JIT_JUMP_BACKWARD_INITIAL_BACKOFF", |
| 1547 | + JUMP_BACKWARD_INITIAL_BACKOFF, 0, MAX_BACKOFF); |
1527 | 1548 | #ifdef _Py_TIER2 |
| 1549 | + // Initialize JIT policy from environment variables |
| 1550 | + init_policy(&_tstate->policy.jit.side_exit_initial_value, |
| 1551 | + "PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE", |
| 1552 | + SIDE_EXIT_INITIAL_VALUE, 1, MAX_VALUE); |
| 1553 | + init_policy(&_tstate->policy.jit.side_exit_initial_backoff, |
| 1554 | + "PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF", |
| 1555 | + SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF); |
1528 | 1556 | _tstate->jit_tracer_state.code_buffer = NULL; |
1529 | 1557 | #endif |
1530 | 1558 | tstate->delete_later = NULL; |
|
0 commit comments