-
Notifications
You must be signed in to change notification settings - Fork 628
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
Document how to use WASI threads in AOT mode #1905
Document how to use WASI threads in AOT mode #1905
Conversation
Following the discussion here. |
9bcbc4f
to
920a193
Compare
wamr-compiler/main.c
Outdated
@@ -231,6 +231,7 @@ main(int argc, char *argv[]) | |||
option.enable_bulk_memory = true; | |||
option.enable_thread_mgr = true; | |||
option.enable_ref_types = false; | |||
option.enable_aux_stack_check = false; |
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.
Should not disable aux stack check for multi-thread, it is enabled for lib-pthread mode, which divides aux stack area into many regions and assign each region to a thread, the bottom and boundary of a region are pre-known and are set to thread exec_env's aux_stack_bottom and aux_stack_boundary fields.
The wasi-threads mode allocates the aux stack from the libc heap of wasm app, the bottom and boundary of the the aux stack are also known when the aux stack is allocated (seems bottom = addr_allocated + size, boundary = addr_allocated), I think we should set them to exec_env's aux_stack_bottom and aux_stack_boundary, but not change code here.
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.
For wasi-threads the aux stack boundaries are not known for the runtime though. There were some discussions here WebAssembly/wasi-threads#12 and here WebAssembly/wasi-libc#380; there's no final conclusion although I'm leaning towards having this part of C ABI and not runtime ABI, so all the stack check work will most likely be done in the user space code.
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.
If so, could you set exec_env->aux_stack_bottom
to UINT32_MAX and exec_env->aux_stack_boundary
to 0? So the aux stack boundary checks will always succeed and no need to change code here.
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 guess that'd work too.
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.
Yes, it should work, refer to the checks in interpreter:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/interpreter/wasm_interp_classic.c#L1783-L1791
And the LLVM AOT compilation:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/compilation/aot_emit_variable.c#L215-L237
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.
Right, I tried it and it works with AOT.
I kept wasm_exec_env_is_aux_stack_managed_by_runtime()
to use it in free_aux_stack()
.
1ab7858
to
70be561
Compare
70be561
to
4943ca9
Compare
Describe how to use WASI threads in AOT mode, following the discussion below: bytecodealliance#1867 (comment) Make aux stack boundary checks of wasi-threads always successful by setting `exec_env->aux_stack_bottom` to UINT32_MAX and `exec_env->aux_stack_boundary` to 0
Describe how to use WASI threads in AOT mode (aux stack must be disabled).