Skip to content

Commit 605c8b0

Browse files
authored
Fix issue of Multi-tier JIT (#2056)
1 parent b0f614d commit 605c8b0

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

core/iwasm/interpreter/wasm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,9 @@ struct WASMModule {
602602
since no need to enable llvm jit compilation for Mode_Interp and
603603
Mode_Fast_JIT, so as to improve performance for them */
604604
bool enable_llvm_jit_compilation;
605+
/* The count of groups which finish compiling the fast jit
606+
functions in that group */
607+
uint32 fast_jit_ready_groups;
605608
#endif
606609
};
607610

core/iwasm/interpreter/wasm_loader.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,11 @@ orcjit_thread_callback(void *arg)
31823182
return NULL;
31833183
}
31843184
}
3185+
#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
3186+
os_mutex_lock(&module->tierup_wait_lock);
3187+
module->fast_jit_ready_groups++;
3188+
os_mutex_unlock(&module->tierup_wait_lock);
3189+
#endif
31853190
#endif
31863191

31873192
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
@@ -3209,9 +3214,11 @@ orcjit_thread_callback(void *arg)
32093214
}
32103215
}
32113216

3212-
/* Wait until init_llvm_jit_functions_stage2 finishes */
3217+
/* Wait until init_llvm_jit_functions_stage2 finishes and all
3218+
fast jit functions are compiled */
32133219
os_mutex_lock(&module->tierup_wait_lock);
3214-
while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation)) {
3220+
while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation
3221+
&& module->fast_jit_ready_groups >= group_stride)) {
32153222
os_cond_reltimedwait(&module->tierup_wait_cond,
32163223
&module->tierup_wait_lock, 10000);
32173224
if (module->orcjit_stop_compiling) {

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,11 @@ orcjit_thread_callback(void *arg)
20252025
return NULL;
20262026
}
20272027
}
2028+
#if WASM_ENABLE_JIT != 0 && WASM_ENABLE_LAZY_JIT != 0
2029+
os_mutex_lock(&module->tierup_wait_lock);
2030+
module->fast_jit_ready_groups++;
2031+
os_mutex_unlock(&module->tierup_wait_lock);
2032+
#endif
20282033
#endif
20292034

20302035
#if WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
@@ -2052,9 +2057,11 @@ orcjit_thread_callback(void *arg)
20522057
}
20532058
}
20542059

2055-
/* Wait until init_llvm_jit_functions_stage2 finishes */
2060+
/* Wait until init_llvm_jit_functions_stage2 finishes and all
2061+
fast jit functions are compiled */
20562062
os_mutex_lock(&module->tierup_wait_lock);
2057-
while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation)) {
2063+
while (!(module->llvm_jit_inited && module->enable_llvm_jit_compilation
2064+
&& module->fast_jit_ready_groups >= group_stride)) {
20582065
os_cond_reltimedwait(&module->tierup_wait_cond,
20592066
&module->tierup_wait_lock, 10000);
20602067
if (module->orcjit_stop_compiling) {

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ set_running_mode(WASMModuleInstance *module_inst, RunningMode running_mode,
14891489
os_mutex_lock(&module->tierup_wait_lock);
14901490
while (!module->llvm_jit_inited) {
14911491
os_cond_reltimedwait(&module->tierup_wait_cond,
1492-
&module->tierup_wait_lock, 10);
1492+
&module->tierup_wait_lock, 10000);
14931493
if (module->orcjit_stop_compiling) {
14941494
/* init_llvm_jit_functions_stage2 failed */
14951495
os_mutex_unlock(&module->tierup_wait_lock);

0 commit comments

Comments
 (0)