-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-141504: Factor out tracing and optimization heuristics into a single object #143381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
0ebb67a
2b1cbbc
7fce731
d01f572
1942f72
a0e6965
196d204
f0ccb28
b3b608b
6a32b9a
f55ce78
03fe066
fe0d38a
304c70c
e6e3202
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,10 +127,9 @@ trigger_backoff_counter(void) | |
| #define JUMP_BACKWARD_INITIAL_VALUE 4000 | ||
| #define JUMP_BACKWARD_INITIAL_BACKOFF 6 | ||
| static inline _Py_BackoffCounter | ||
| initial_jump_backoff_counter(void) | ||
| initial_jump_backoff_counter(uint16_t initial_value, uint16_t initial_backoff) | ||
| { | ||
| return make_backoff_counter(JUMP_BACKWARD_INITIAL_VALUE, | ||
| JUMP_BACKWARD_INITIAL_BACKOFF); | ||
| return make_backoff_counter(initial_value, initial_backoff); | ||
| } | ||
|
|
||
| /* Initial exit temperature. | ||
|
|
@@ -141,10 +140,9 @@ initial_jump_backoff_counter(void) | |
| #define SIDE_EXIT_INITIAL_BACKOFF 6 | ||
|
|
||
| static inline _Py_BackoffCounter | ||
| initial_temperature_backoff_counter(void) | ||
| initial_temperature_backoff_counter(uint16_t initial_value, uint16_t initial_backoff) | ||
|
||
| { | ||
| return make_backoff_counter(SIDE_EXIT_INITIAL_VALUE, | ||
| SIDE_EXIT_INITIAL_BACKOFF); | ||
| return make_backoff_counter(initial_value, initial_backoff); | ||
| } | ||
|
|
||
| /* Unreachable backoff counter. */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Factor out tracing and optimization heuristics into a single object. | ||
| Patch by Donghee Na. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| #include "Python.h" | ||
| #include "pycore_abstract.h" // _PyIndex_Check() | ||
| #include "pycore_audit.h" // _Py_AuditHookEntry | ||
| #include "pycore_backoff.h" // JUMP_BACKWARD_INITIAL_VALUE, SIDE_EXIT_INITIAL_VALUE | ||
| #include "pycore_ceval.h" // _PyEval_AcquireLock() | ||
| #include "pycore_codecs.h" // _PyCodec_Fini() | ||
| #include "pycore_critical_section.h" // _PyCriticalSection_Resume() | ||
|
|
@@ -1438,6 +1439,20 @@ decref_threadstate(_PyThreadStateImpl *tstate) | |
| } | ||
| } | ||
|
|
||
| static inline void | ||
| init_jit_metric(uint16_t *target, const char *env_name, uint16_t default_value, | ||
|
||
| long min_value, long max_value) | ||
| { | ||
| *target = default_value; | ||
| char *env = Py_GETENV(env_name); | ||
| if (env && *env != '\0') { | ||
| long value = atol(env); | ||
| if (value >= min_value && value <= max_value) { | ||
| *target = (uint16_t)value; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* Get the thread state to a minimal consistent state. | ||
| Further init happens in pylifecycle.c before it can be used. | ||
| All fields not initialized here are expected to be zeroed out, | ||
|
|
@@ -1523,8 +1538,21 @@ init_threadstate(_PyThreadStateImpl *_tstate, | |
|
|
||
| _tstate->asyncio_running_loop = NULL; | ||
| _tstate->asyncio_running_task = NULL; | ||
|
|
||
| // Initialize interpreter policy from environment variables | ||
| init_jit_metric(&_tstate->policy.interp.jump_backward_initial_value, | ||
|
||
| "PYTHON_JIT_JUMP_BACKWARD_INITIAL_VALUE", | ||
| JUMP_BACKWARD_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_jit_metric(&_tstate->policy.interp.jump_backward_initial_backoff, | ||
| "PYTHON_JIT_JUMP_BACKWARD_INITIAL_BACKOFF", | ||
| JUMP_BACKWARD_INITIAL_BACKOFF, 0, MAX_BACKOFF); | ||
| #ifdef _Py_TIER2 | ||
| // Initialize JIT policy from environment variables | ||
| init_jit_metric(&_tstate->policy.jit.side_exit_initial_value, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE", | ||
| SIDE_EXIT_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_jit_metric(&_tstate->policy.jit.side_exit_initial_backoff, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF", | ||
| SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF); | ||
| _tstate->jit_tracer_state.code_buffer = NULL; | ||
| #endif | ||
| tstate->delete_later = NULL; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take a single value
_tstate/tstateand grab the jump backward values from it.