Fix issue of Multi-tier JIT (#2056)

This commit is contained in:
Wenyong Huang 2023-03-25 11:15:05 +08:00 committed by GitHub
parent b0f614d77a
commit 605c8b07dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View File

@ -602,6 +602,9 @@ struct WASMModule {
since no need to enable llvm jit compilation for Mode_Interp and since no need to enable llvm jit compilation for Mode_Interp and
Mode_Fast_JIT, so as to improve performance for them */ Mode_Fast_JIT, so as to improve performance for them */
bool enable_llvm_jit_compilation; 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 #endif
}; };

View File

@ -3182,6 +3182,11 @@ orcjit_thread_callback(void *arg)
return NULL; 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 #endif
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \ #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); 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, os_cond_reltimedwait(&module->tierup_wait_cond,
&module->tierup_wait_lock, 10000); &module->tierup_wait_lock, 10000);
if (module->orcjit_stop_compiling) { if (module->orcjit_stop_compiling) {

View File

@ -2025,6 +2025,11 @@ orcjit_thread_callback(void *arg)
return NULL; 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 #endif
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \ #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); 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, os_cond_reltimedwait(&module->tierup_wait_cond,
&module->tierup_wait_lock, 10000); &module->tierup_wait_lock, 10000);
if (module->orcjit_stop_compiling) { if (module->orcjit_stop_compiling) {

View File

@ -1489,7 +1489,7 @@ set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode,
os_mutex_lock(&module->tierup_wait_lock); os_mutex_lock(&module->tierup_wait_lock);
while (!module->llvm_jit_inited) { while (!module->llvm_jit_inited) {
os_cond_reltimedwait(&module->tierup_wait_cond, os_cond_reltimedwait(&module->tierup_wait_cond,
&module->tierup_wait_lock, 10); &module->tierup_wait_lock, 10000);
if (module->orcjit_stop_compiling) { if (module->orcjit_stop_compiling) {
/* init_llvm_jit_functions_stage2 failed */ /* init_llvm_jit_functions_stage2 failed */
os_mutex_unlock(&module->tierup_wait_lock); os_mutex_unlock(&module->tierup_wait_lock);