Enable AOT linux perf support (#2930)

And refactor the original perf support
- use WAMR_BUILD_LINUX_PERF as the cmake compilation control
- use WASM_ENABLE_LINUX_PERF as the compiler macro
- use `wamrc --enable-linux-perf` to generate aot file which contains fp operations
- use `iwasm --enable-linux-perf` to create perf map for `perf record`
This commit is contained in:
liang.he
2024-01-02 15:58:17 +08:00
committed by GitHub
parent 38019f273a
commit 5c3ad0279a
17 changed files with 208 additions and 36 deletions

View File

@ -330,7 +330,7 @@ wasm_config_set_linux_perf_opt(wasm_config_t *config, bool enable)
if (!config)
return NULL;
config->linux_perf_support = enable;
config->enable_linux_perf = enable;
return config;
}
@ -380,7 +380,8 @@ wasm_engine_new_internal(wasm_config_t *config)
init_args.mem_alloc_type = config->mem_alloc_type;
memcpy(&init_args.mem_alloc_option, &config->mem_alloc_option,
sizeof(MemAllocOption));
init_args.linux_perf_support = config->linux_perf_support;
init_args.enable_linux_perf = config->enable_linux_perf;
if (!wasm_runtime_full_init(&init_args)) {
LOG_DEBUG("wasm_runtime_full_init failed");

View File

@ -158,7 +158,7 @@ static JitCompOptions jit_options = { 0 };
#endif
#if WASM_ENABLE_JIT != 0
static LLVMJITOptions llvm_jit_options = { 3, 3, 0, false };
static LLVMJITOptions llvm_jit_options = { 3, 3, 0 };
#endif
static RunningMode runtime_running_mode = Mode_Default;
@ -662,14 +662,17 @@ wasm_runtime_full_init(RuntimeInitArgs *init_args)
#endif
#if WASM_ENABLE_JIT != 0
LOG_DEBUG("Start LLVM_JIT, opt_sz=%u, opt_lvl=%u, segue=%s, linux_perf=%s",
init_args->llvm_jit_size_level, init_args->llvm_jit_opt_level,
init_args->segue_flags ? "Yes" : "No",
init_args->linux_perf_support ? "Yes" : "No");
llvm_jit_options.size_level = init_args->llvm_jit_size_level;
llvm_jit_options.opt_level = init_args->llvm_jit_opt_level;
llvm_jit_options.segue_flags = init_args->segue_flags;
llvm_jit_options.linux_perf_support = init_args->linux_perf_support;
#endif
#if WASM_ENABLE_LINUX_PERF != 0
wasm_runtime_set_linux_perf(init_args->enable_linux_perf);
#else
if (init_args->enable_linux_perf)
LOG_WARNING("warning: to enable linux perf support, please recompile "
"with -DWAMR_BUILD_LINUX_PERF=1");
#endif
if (!wasm_runtime_env_init()) {
@ -6146,3 +6149,19 @@ wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key)
return wasm_native_get_context(inst, key);
}
#endif /* WASM_ENABLE_MODULE_INST_CONTEXT != 0 */
#if WASM_ENABLE_LINUX_PERF != 0
static bool enable_linux_perf = false;
bool
wasm_runtime_get_linux_perf(void)
{
return enable_linux_perf;
}
void
wasm_runtime_set_linux_perf(bool flag)
{
enable_linux_perf = flag;
}
#endif

View File

@ -443,7 +443,6 @@ typedef struct LLVMJITOptions {
uint32 opt_level;
uint32 size_level;
uint32 segue_flags;
bool linux_perf_support;
} LLVMJITOptions;
#endif
@ -1105,6 +1104,14 @@ wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
void
wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
#if WASM_ENABLE_LINUX_PERF != 0
bool
wasm_runtime_get_linux_perf(void);
void
wasm_runtime_set_linux_perf(bool flag);
#endif
#ifdef __cplusplus
}
#endif