Skip to content

Commit 8ac0649

Browse files
authored
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 #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`.
1 parent 040e776 commit 8ac0649

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

core/shared/platform/common/posix/posix_thread.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,13 @@ os_thread_signal_init(os_signal_handler handler)
712712
#if WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
713713
sigalt_stack_base_addr = map_addr;
714714
#endif
715+
716+
#if defined(os_thread_local_attribute)
717+
// calculate and cache the new stack boundary.
718+
// see https://github.com/bytecodealliance/wasm-micro-runtime/issues/3966
719+
(void)os_thread_get_stack_boundary();
720+
#endif
721+
715722
signal_handler = handler;
716723
thread_signal_inited = true;
717724
return 0;

0 commit comments

Comments
 (0)