Implement instruction metering resume#4902
Open
AlixANNERAUD wants to merge 2 commits intobytecodealliance:mainfrom
Open
Implement instruction metering resume#4902AlixANNERAUD wants to merge 2 commits intobytecodealliance:mainfrom
AlixANNERAUD wants to merge 2 commits intobytecodealliance:mainfrom
Conversation
…ctionality and add tests
…ty in interpreter files
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request adds robust support for resuming execution after instruction metering suspension in both the classic and fast interpreter modes. When a wasm module exceeds its instruction budget, execution now suspends with state preserved, allowing the host to set a new budget and resume from where it left off. The PR also introduces new tests and documentation updates to cover this behavior.
Interpreter and Metering Suspension Enhancements:
Added
metering_suspendedandmetering_suspend_framefields toWASMExecEnv, and logic to preserve and restore interpreter state on instruction limit suspension in both classic and fast interpreter modes (wasm_exec_env.h,wasm_exec_env_create_internal,wasm_interp_call_func_bytecode,wasm_interp_call_wasm,wasm_interp_fast.c) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19].Ensured that resuming is only possible when re-entering the same function, with checks and exception handling for invalid or mismatched resume attempts (
wasm_interp_call_wasm) [1] [2].Instruction Metering Behavior and Documentation:
Updated the documentation to clarify that, in interpreter modes, exceeding the instruction budget suspends execution and allows resumption from the preserved state after budget reset (
doc/build_wamr.md).Improved instruction metering checks to properly roll back the instruction pointer when the budget is exceeded, ensuring correct resume behavior (
wasm_interp_fast.c).Testing:
tests/unit/instruction-metering/,tests/unit/CMakeLists.txt) [1] [2].These changes make instruction metering more robust and user-friendly, especially for hosts that need to pause and resume long-running wasm computations.