Set thread information earlier in exec_env creation (#3967)
For boundary checking, WAMR calls `pthread_attr_np`, which is unfortunately quite slow on Linux when not called on the main thread (see https://github.com/bytecodealliance/wasm-micro-runtime/issues/3966 for discussion). This change moves the cost of stack bounds checking earlier in the wasm_exec_env creation process. The idea is that it's perhaps better to pay the price when creating the execution environment rather than in the first function call. The original code is left in place inside `call_wasm_with_hw_bound_check` in case the `wasm_exec_env` is created via `wasm_runtime_spawn_exec_env`.
This commit is contained in:
@ -712,6 +712,13 @@ os_thread_signal_init(os_signal_handler handler)
|
||||
#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
|
||||
sigalt_stack_base_addr = map_addr;
|
||||
#endif
|
||||
|
||||
#if defined(os_thread_local_attribute)
|
||||
// calculate and cache the new stack boundary.
|
||||
// see https://github.com/bytecodealliance/wasm-micro-runtime/issues/3966
|
||||
(void)os_thread_get_stack_boundary();
|
||||
#endif
|
||||
|
||||
signal_handler = handler;
|
||||
thread_signal_inited = true;
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user