-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-141504: Refactor policy object into a single opt_config #143644
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fc84a62
gh-141504: Refactor policy object into a single opt_config
corona10 3dbdd01
nit
corona10 c8e4b7f
Address code review
corona10 ed1a96f
fix ci
corona10 17f6184
Remove env set
corona10 0cb9c40
Revert "Remove env set"
corona10 4e64df6
Merge remote-tracking branch 'upstream/main' into gh-141504-opt
corona10 21c4003
fix
corona10 0c67334
Merge remote-tracking branch 'upstream/main' into gh-141504-opt
corona10 7894e18
fix
corona10 643b8a5
lint
corona10 8600747
Update test
corona10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -514,6 +514,21 @@ _Py_LazyJitShim( | |
| main interpreter. We fix those fields here, in addition | ||
| to the other dynamically initialized fields. | ||
| */ | ||
|
|
||
| static inline void | ||
| init_policy(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; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static PyStatus | ||
| init_interpreter(PyInterpreterState *interp, | ||
| _PyRuntimeState *runtime, int64_t id, | ||
|
|
@@ -572,6 +587,31 @@ init_interpreter(PyInterpreterState *interp, | |
| interp->executor_list_head = NULL; | ||
| interp->executor_deletion_list_head = NULL; | ||
| interp->executor_creation_counter = JIT_CLEANUP_THRESHOLD; | ||
|
|
||
| // Initialize optimization configuration from environment variables | ||
| init_policy(&interp->opt_config.jump_backward_initial_value, | ||
| "PYTHON_JIT_JUMP_BACKWARD_INITIAL_VALUE", | ||
| JUMP_BACKWARD_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_policy(&interp->opt_config.jump_backward_initial_backoff, | ||
| "PYTHON_JIT_JUMP_BACKWARD_INITIAL_BACKOFF", | ||
| JUMP_BACKWARD_INITIAL_BACKOFF, 0, MAX_BACKOFF); | ||
| #ifdef _Py_TIER2 | ||
| init_policy(&interp->opt_config.side_exit_initial_value, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE", | ||
| SIDE_EXIT_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_policy(&interp->opt_config.side_exit_initial_backoff, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF", | ||
| SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF); | ||
| #endif | ||
|
|
||
| // Check if specialization should be disabled | ||
| // If PYTHON_SPECIALIZATION_OFF is set to any non-empty value, disable specialization | ||
| char *spec_off_env = Py_GETENV("PYTHON_SPECIALIZATION_OFF"); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Fidget-Spinner We can define about |
||
| if (spec_off_env && *spec_off_env != '\0' && *spec_off_env != '0') { | ||
| interp->opt_config.specialization_enabled = false; | ||
| } else { | ||
| interp->opt_config.specialization_enabled = true; | ||
| } | ||
| if (interp != &runtime->_main_interpreter) { | ||
| /* Fix the self-referential, statically initialized fields. */ | ||
| interp->dtoa = (struct _dtoa_state)_dtoa_state_INIT(interp); | ||
|
|
@@ -1439,20 +1479,6 @@ decref_threadstate(_PyThreadStateImpl *tstate) | |
| } | ||
| } | ||
|
|
||
| static inline void | ||
| init_policy(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, | ||
|
|
@@ -1538,21 +1564,8 @@ init_threadstate(_PyThreadStateImpl *_tstate, | |
|
|
||
| _tstate->asyncio_running_loop = NULL; | ||
| _tstate->asyncio_running_task = NULL; | ||
| // Initialize interpreter policy from environment variables | ||
| init_policy(&_tstate->policy.interp.jump_backward_initial_value, | ||
| "PYTHON_JIT_JUMP_BACKWARD_INITIAL_VALUE", | ||
| JUMP_BACKWARD_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_policy(&_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_policy(&_tstate->policy.jit.side_exit_initial_value, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_VALUE", | ||
| SIDE_EXIT_INITIAL_VALUE, 1, MAX_VALUE); | ||
| init_policy(&_tstate->policy.jit.side_exit_initial_backoff, | ||
| "PYTHON_JIT_SIDE_EXIT_INITIAL_BACKOFF", | ||
| SIDE_EXIT_INITIAL_BACKOFF, 0, MAX_BACKOFF); | ||
| _tstate->jit_tracer_state = NULL; | ||
| #endif | ||
| tstate->delete_later = NULL; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think Mark wants these numbers to be automatic, and remove the current env variables.
So for example,
PYHTON_JIT_STRESSwould setPYTHON_JIT_JUMP_BACKWARD_INITIAL_VALUEto 63, andPYTHON_JIT_SIDE_EXIT_INITIAL_VALUEto 63 a well.