-
Notifications
You must be signed in to change notification settings - Fork 646
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
Disable aux stack allocations for threads spawned by wasi_thread_start #1867
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1783,14 +1783,18 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, | |||||||||||||||||||||||||||||||||||||
global = globals + global_idx; | ||||||||||||||||||||||||||||||||||||||
global_addr = get_global_addr(global_data, global); | ||||||||||||||||||||||||||||||||||||||
aux_stack_top = *(uint32 *)(frame_sp - 1); | ||||||||||||||||||||||||||||||||||||||
if (aux_stack_top <= exec_env->aux_stack_boundary.boundary) { | ||||||||||||||||||||||||||||||||||||||
wasm_set_exception(module, "wasm auxiliary stack overflow"); | ||||||||||||||||||||||||||||||||||||||
goto got_exception; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) { | ||||||||||||||||||||||||||||||||||||||
wasm_set_exception(module, | ||||||||||||||||||||||||||||||||||||||
"wasm auxiliary stack underflow"); | ||||||||||||||||||||||||||||||||||||||
goto got_exception; | ||||||||||||||||||||||||||||||||||||||
if (wasm_exec_env_is_aux_stack_managed_by_runtime(exec_env)) { | ||||||||||||||||||||||||||||||||||||||
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. Do we need to apply similar changes for LLVM AOT/JIT and Fast JIT, refer to: 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. Yes we do; however, for now we focus on the interpreter and we'll work on JIT/AOT next. 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. OK, so let's merge this PR first? 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. Yes, we can merge this one and next we'll continue working on AOT and JIT 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. @wenyongh @yamt for AOT, should we disable the aux stack globally when WASI threads are enabled? by replacing this
with something like
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. i guess it can be a workaround. 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. at this point, should we just specify in the documentation to compile with wasm-micro-runtime/core/iwasm/fast-jit/fe/jit_emit_variable.c Lines 264 to 280 in 622cdbe
|
||||||||||||||||||||||||||||||||||||||
if (aux_stack_top | ||||||||||||||||||||||||||||||||||||||
<= exec_env->aux_stack_boundary.boundary) { | ||||||||||||||||||||||||||||||||||||||
wasm_set_exception(module, | ||||||||||||||||||||||||||||||||||||||
"wasm auxiliary stack overflow"); | ||||||||||||||||||||||||||||||||||||||
goto got_exception; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
if (aux_stack_top > exec_env->aux_stack_bottom.bottom) { | ||||||||||||||||||||||||||||||||||||||
wasm_set_exception(module, | ||||||||||||||||||||||||||||||||||||||
"wasm auxiliary stack underflow"); | ||||||||||||||||||||||||||||||||||||||
goto got_exception; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
*(int32 *)global_addr = aux_stack_top; | ||||||||||||||||||||||||||||||||||||||
frame_sp--; | ||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# A slightly modified copy of the wasi-libc implementation | ||
# https://github.com/WebAssembly/wasi-libc/pull/376/ | ||
.globaltype __stack_pointer, i32 | ||
.functype __wasi_thread_start_C (i32, i32) -> () | ||
|
||
.globl wasi_thread_start | ||
|
||
wasi_thread_start: | ||
loganek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.functype wasi_thread_start (i32, i32) -> () | ||
|
||
# Set up the minimum C environment. | ||
# Note: offsetof(start_arg, stack) == 0 | ||
local.get 1 # start_arg | ||
i32.load 0 # stack | ||
global.set __stack_pointer | ||
|
||
# Make the C function do the rest of work. | ||
local.get 0 # tid | ||
local.get 1 # start_arg | ||
call __wasi_thread_start_C | ||
|
||
end_function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2022 Amazon.com Inc. or its affiliates. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
#ifndef WASI_THREAD_START_H | ||
#define WASI_THREAD_START_H | ||
|
||
#define STACK_SIZE 1024 | ||
|
||
typedef struct { | ||
void *stack; | ||
} start_args_t; | ||
|
||
static inline int | ||
start_args_init(start_args_t *start_args) | ||
{ | ||
start_args->stack = malloc(STACK_SIZE); | ||
if (!start_args->stack) { | ||
return 0; | ||
} | ||
|
||
start_args->stack += STACK_SIZE; | ||
return 1; | ||
} | ||
|
||
static inline void | ||
start_args_deinit(start_args_t *start_args) | ||
{ | ||
free(start_args->stack - STACK_SIZE); | ||
} | ||
|
||
#endif |
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 feel it's simpler to use a dedicated flag as 0 is a valid address in wasm. how do you think?
also, i guess aot needs an equivalent around create_aux_stack_info.
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.
Yeah, I did think about it. But I noticed that WAMR actually doesn't always respect 0 as a valid address; for example, it considers
wasm_runtime_malloc()
returning0
as a failure. Flag was another option but didn't want to increase the size of the object unnecessarily if there was a way to achieve the same without it (if my assumption about WAMR not respecting 0 as a correct value holds).That's correct. At the moment we're not testing AOT though so I was planning to do that (and other necessary things) in the follow-up PR. Does it make sense?
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.
ok.
ok.