Skip to content

Commit

Permalink
remove marco control from wamrc
Browse files Browse the repository at this point in the history
  • Loading branch information
lum1n0us committed Dec 30, 2023
1 parent e485d6e commit 672abfb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
52 changes: 29 additions & 23 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "../common/wasm_runtime_common.h"
#include "../common/wasm_native.h"
#include "../compilation/aot.h"
#include <stdint.h>

#if WASM_ENABLE_DEBUG_AOT != 0
#include "debug/elf_parser.h"
Expand Down Expand Up @@ -2766,46 +2765,52 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
}

#if WASM_ENABLE_LINUX_PERF != 0
static uintptr_t
get_func_addr(const AOTModule *module, void **sorted_func_ptrs, uint32 idx)
{
return (uintptr_t)sorted_func_ptrs[idx];
}
struct func_info {
uint32 idx;
void *ptr;
};

static uint32
get_func_size(const AOTModule *module, void **sorted_func_ptrs, uint32 idx)
get_func_size(const AOTModule *module, struct func_info *sorted_func_ptrs,
uint32 idx)
{
uint32 func_sz;

if (idx == module->func_count - 1)
func_sz = (uintptr_t)module->code + module->code_size
- (uintptr_t)sorted_func_ptrs[idx];
- (uintptr_t)(sorted_func_ptrs[idx].ptr);
else
func_sz = (uintptr_t)sorted_func_ptrs[idx + 1]
- (uintptr_t)sorted_func_ptrs[idx];
func_sz = (uintptr_t)(sorted_func_ptrs[idx + 1].ptr)
- (uintptr_t)(sorted_func_ptrs[idx].ptr);

return func_sz;
}

/* do a quick sort on func_ptrs in place*/
static int
compare_func_ptrs(const void *fp1, const void *fp2)
compare_func_ptrs(const void *f1, const void *f2)
{
return (intptr_t)(*(void **)fp1) - (intptr_t)(*(void **)fp2);
return (intptr_t)((struct func_info *)f1)->ptr
- (intptr_t)((struct func_info *)f2)->ptr;
}

static void *
static struct func_info *
sort_func_ptrs(const AOTModule *module, char *error_buf, uint32 error_buf_size)
{
size_t content_len = sizeof(void *) * module->func_count;
void *sorted_func_ptrs =
loader_malloc(content_len, error_buf, error_buf_size);
uint64 content_len;
struct func_info *sorted_func_ptrs;
unsigned i;

content_len = (uint64)sizeof(struct func_info) * module->func_count;
sorted_func_ptrs = loader_malloc(content_len, error_buf, error_buf_size);
if (!sorted_func_ptrs)
return NULL;

b_memcpy_s(sorted_func_ptrs, content_len, module->func_ptrs, content_len);
for (i = 0; i < module->func_count; i++) {
sorted_func_ptrs[i].idx = i;
sorted_func_ptrs[i].ptr = module->func_ptrs[i];
}

qsort(sorted_func_ptrs, module->func_count, sizeof(void *),
qsort(sorted_func_ptrs, module->func_count, sizeof(struct func_info),
compare_func_ptrs);

return sorted_func_ptrs;
Expand All @@ -2814,7 +2819,7 @@ sort_func_ptrs(const AOTModule *module, char *error_buf, uint32 error_buf_size)
static bool
create_perf_map(const AOTModule *module, char *error_buf, uint32 error_buf_size)
{
void **sorted_func_ptrs = NULL;
struct func_info *sorted_func_ptrs = NULL;
char perf_map_info[128] = { 0 };
FILE *perf_map = NULL;
uint32 i;
Expand All @@ -2828,16 +2833,17 @@ create_perf_map(const AOTModule *module, char *error_buf, uint32 error_buf_size)
snprintf(perf_map_info, 128, "/tmp/perf-%d.map", pid);
perf_map = fopen(perf_map_info, "w");
if (!perf_map) {
LOG_WARNING("can't create /tmp/perf-%d.map, because %s", pid,
LOG_WARNING("warning: can't create /tmp/perf-%d.map, because %s", pid,
strerror(errno));
goto quit;
}

for (i = 0; i < module->func_count; i++) {
memset(perf_map_info, 0, 128);
snprintf(perf_map_info, 128, "%lx %x aot_func#%u\n",
get_func_addr(module, sorted_func_ptrs, i),
get_func_size(module, sorted_func_ptrs, i), i);
(uintptr_t)sorted_func_ptrs[i].ptr,
get_func_size(module, sorted_func_ptrs, i),
sorted_func_ptrs[i].idx);

fwrite(perf_map_info, 1, strlen(perf_map_info), perf_map);
}
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ wasm_runtime_full_init(RuntimeInitArgs *init_args)
wasm_runtime_set_linux_perf(init_args->enable_linux_perf);
#else
if (init_args->enable_linux_perf)
LOG_WARNING("in order to enable linux perf support, need to recompile "
LOG_WARNING("warning: to enable linux perf support, please recompile "
"with -DWAMR_BUILD_LINUX_PERF=1");
#endif

Expand Down
6 changes: 3 additions & 3 deletions product-mini/platforms/posix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ main(int argc, char *argv[])
uint32 segue_flags = 0;
#endif
#if WASM_ENABLE_LINUX_PERF != 0
bool enable_enable_linux_perf = false;
bool enable_linux_perf = false;
#endif
wasm_module_t wasm_module = NULL;
wasm_module_inst_t wasm_module_inst = NULL;
Expand Down Expand Up @@ -721,7 +721,7 @@ main(int argc, char *argv[])
#endif
#if WASM_ENABLE_LINUX_PERF != 0
else if (!strncmp(argv[0], "--enable-linux-perf", 19)) {
enable_enable_linux_perf = true;
enable_linux_perf = true;
}
#endif
#if WASM_ENABLE_MULTI_MODULE != 0
Expand Down Expand Up @@ -827,7 +827,7 @@ main(int argc, char *argv[])
init_args.segue_flags = segue_flags;
#endif
#if WASM_ENABLE_LINUX_PERF != 0
init_args.enable_linux_perf = enable_enable_linux_perf;
init_args.enable_linux_perf = enable_linux_perf;
#endif

#if WASM_ENABLE_DEBUG_INTERP != 0
Expand Down
3 changes: 1 addition & 2 deletions wamr-compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ if (WAMR_BUILD_LLVM_LEGACY_PM EQUAL 1)
add_definitions(-DWASM_ENABLE_LLVM_LEGACY_PM=1)
endif ()

if (WAMR_BUILD_LINUX_PERF EQUAL 1)
message ("-- Enable linux perf support")
if (LINUX)
add_definitions(-DWASM_ENABLE_LINUX_PERF=1)
endif ()

Expand Down
6 changes: 3 additions & 3 deletions wamr-compiler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ main(int argc, char *argv[])
uint32 native_handle_count = 0;
#endif
#if WASM_ENABLE_LINUX_PERF != 0
bool enable_enable_linux_perf = false;
bool enable_linux_perf = false;
#endif

option.opt_level = 3;
Expand Down Expand Up @@ -534,7 +534,7 @@ main(int argc, char *argv[])
#endif
#if WASM_ENABLE_LINUX_PERF != 0
else if (!strncmp(argv[0], "--enable-linux-perf", 19)) {
enable_enable_linux_perf = true;
enable_linux_perf = true;
}
#endif
else if (!strncmp(argv[0], "--version", 9)) {
Expand Down Expand Up @@ -591,7 +591,7 @@ main(int argc, char *argv[])
init_args.mem_alloc_option.allocator.realloc_func = realloc;
init_args.mem_alloc_option.allocator.free_func = free;
#if WASM_ENABLE_LINUX_PERF != 0
init_args.enable_linux_perf = enable_enable_linux_perf;
init_args.enable_linux_perf = enable_linux_perf;
#endif

/* initialize runtime environment */
Expand Down

0 comments on commit 672abfb

Please sign in to comment.