Skip to content

Commit

Permalink
Set thread information earlier in exec_env creation
Browse files Browse the repository at this point in the history
For boundary checking, WAMR calls `pthread_attr_np`, which is
unfortunately quite slow on Linux when not called on the main thread
(see bytecodealliance#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`.
  • Loading branch information
sjamesr committed Dec 20, 2024
1 parent 9563909 commit e39e97d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/shared/platform/common/posix/posix_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e39e97d

Please sign in to comment.