diff --git a/core/iwasm/interpreter/wasm.h b/core/iwasm/interpreter/wasm.h index e6d02c3f1..0797a018b 100644 --- a/core/iwasm/interpreter/wasm.h +++ b/core/iwasm/interpreter/wasm.h @@ -602,6 +602,9 @@ struct WASMModule { since no need to enable llvm jit compilation for Mode_Interp and Mode_Fast_JIT, so as to improve performance for them */ bool enable_llvm_jit_compilation; + /* The count of groups which finish compiling the fast jit + functions in that group */ + uint32 fast_jit_ready_groups; #endif }; diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 376152763..d3128dbd0 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -3182,6 +3182,11 @@ orcjit_thread_callback(void *arg) return NULL; } } +#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0 + os_mutex_lock(&module->tierup_wait_lock); + module->fast_jit_ready_groups++; + os_mutex_unlock(&module->tierup_wait_lock); +#endif #endif #if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \ @@ -3209,9 +3214,11 @@ orcjit_thread_callback(void *arg) } } - /* Wait until init_llvm_jit_functions_stage2 finishes */ + /* Wait until init_llvm_jit_functions_stage2 finishes and all + fast jit functions are compiled */ os_mutex_lock(&module->tierup_wait_lock); - while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation)) { + while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation + && module->fast_jit_ready_groups >= group_stride)) { os_cond_reltimedwait(&module->tierup_wait_cond, &module->tierup_wait_lock, 10000); if (module->orcjit_stop_compiling) { diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 92be851fa..3a983b293 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2025,6 +2025,11 @@ orcjit_thread_callback(void *arg) return NULL; } } +#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0 + os_mutex_lock(&module->tierup_wait_lock); + module->fast_jit_ready_groups++; + os_mutex_unlock(&module->tierup_wait_lock); +#endif #endif #if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \ @@ -2052,9 +2057,11 @@ orcjit_thread_callback(void *arg) } } - /* Wait until init_llvm_jit_functions_stage2 finishes */ + /* Wait until init_llvm_jit_functions_stage2 finishes and all + fast jit functions are compiled */ os_mutex_lock(&module->tierup_wait_lock); - while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation)) { + while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation + && module->fast_jit_ready_groups >= group_stride)) { os_cond_reltimedwait(&module->tierup_wait_cond, &module->tierup_wait_lock, 10000); if (module->orcjit_stop_compiling) { diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 5548fad5a..2338f90bf 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1489,7 +1489,7 @@ set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode, os_mutex_lock(&module->tierup_wait_lock); while (!module->llvm_jit_inited) { os_cond_reltimedwait(&module->tierup_wait_cond, - &module->tierup_wait_lock, 10); + &module->tierup_wait_lock, 10000); if (module->orcjit_stop_compiling) { /* init_llvm_jit_functions_stage2 failed */ os_mutex_unlock(&module->tierup_wait_lock);