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

Document how to use WASI threads in AOT mode #1905

Merged

Conversation

eloparco
Copy link
Contributor

Describe how to use WASI threads in AOT mode (aux stack must be disabled).

@eloparco
Copy link
Contributor Author

Following the discussion here.

@@ -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;
Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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().

@eloparco eloparco force-pushed the eloparco/wasi-threads-aot branch 2 times, most recently from 1ab7858 to 70be561 Compare January 27, 2023 01:35
@wenyongh wenyongh merged commit 2eed50b into bytecodealliance:dev/wasi_threads Jan 27, 2023
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
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
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.

3 participants