Skip to content
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

Add instruction metering #4122

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

AlixANNERAUD
Copy link

Resolve #3927 and #2163.

@AlixANNERAUD
Copy link
Author

Currently, there is no implementation on the AOT side since I'm not sure if this is really possible since we are dealing with compiled / native code.

Regarding the classic/fast interpreter, I'm note sure about the save/restore of the context. It seems that prev_frame is saved in exec_env and reused upon invocation. However, I'm unsure whether prev_frame alone is sufficient or if we also need to back up frame (and maybe more).

@AlixANNERAUD AlixANNERAUD changed the title feat: add instruction metering support with execution limit Add instruction metering Mar 2, 2025
#if WASM_INSTRUCTION_METERING != 0
#define CHECK_INSTRUCTION_LIMIT() \
if (instructions_left == 0) { \
goto return_func; \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing.

I totally agree with the concept of checking the meter in HANDLE_OP_END.

However, I have reservations about this part. Clearly, running out of meter should not be equated with a normal return. It's more akin to being suspended or interrupted. Additionally, unlike a normal return, there is no return value for subsequent processing. Perhaps a special exception is needed.

Another one, When instructions_left == -1, IIUC, this signifies unlimited instructions. We should bypass the calculation to minimize performance degradation, as this check occurs after every opcode execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Instruction metering
2 participants