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 #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 19, 2024
1 parent 9563909 commit 2f5ec3d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/iwasm/common/wasm_exec_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ wasm_exec_env_create_internal(struct WASMModuleInstanceCommon *module_inst,
#endif

#ifdef OS_ENABLE_HW_BOUND_CHECK
if (!os_thread_signal_inited()) {
goto fail5;
}

/* Set thread handle and stack boundary if they haven't been set */
wasm_exec_env_set_thread_info(exec_env);
wasm_runtime_set_exec_env_tls(exec_env);

if (!(exec_env->exce_check_guard_page =
os_mmap(NULL, os_getpagesize(), MMAP_PROT_NONE, MMAP_MAP_NONE,
os_get_invalid_handle())))
Expand Down

0 comments on commit 2f5ec3d

Please sign in to comment.