Commit Graph

1609 Commits

Author SHA1 Message Date
liang.he
5c8b8a17a6
Enhancements on wasm function execution time statistic (#2985)
Enhance the statistic of wasm function execution time, or the performance
profiling feature:
- Add os_time_thread_cputime_us() to get the cputime of a thread,
  and use it to calculate the execution time of a wasm function
- Support the statistic of the children execution time of a function,
  and dump it in wasm_runtime_dump_perf_profiling
- Expose two APIs:
  wasm_runtime_sum_wasm_exec_time
  wasm_runtime_get_wasm_func_exec_time

And rename os_time_get_boot_microsecond to os_time_get_boot_us.
2024-01-17 09:51:54 +08:00
Enrico Loparco
25ccc9f2d5
Avoid unused thread_id warning and recompile multi-module sample (#3033)
- Unused variable warning (when building in release mode):
```bash
wasm-micro-runtime/samples/wasi-threads/wasm-apps/no_pthread.c:44:9:
warning: variable 'thread_id' set but not used [-Wunused-but-set-variable]
    int thread_id;
```
- When using the multi-module example and changing the files in `wasm-apps`,
  they don't get recompiled when the sample is rebuilt. Adding `BUILD_ALWAYS`
  as it's done in other samples.
2024-01-17 08:06:02 +08:00
Maks Litskevich
7b6d0a5d45
Don't redefine D_INO if already defined (#3036) 2024-01-16 22:28:06 +08:00
Marcin Kolny
ffa131b5ac
Allow using mmap for shared memory if hw bound check is disabled (#3029)
For shared memory, the max memory size must be defined in advanced. Re-allocation
for growing memory can't be used as it might change the base address, therefore when
OS_ENABLE_HW_BOUND_CHECK is enabled the memory is mmaped, and if the flag is
disabled, the memory is allocated. This change introduces a flag that allows users to use
mmap for reserving memory address space even if the OS_ENABLE_HW_BOUND_CHECK
is disabled.
2024-01-16 22:15:55 +08:00
Wenyong Huang
b3aaf2abc0
Check passive mode in fast-jit table.init (#3031)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3021.
2024-01-16 21:55:10 +08:00
Enrico Loparco
bb053e3a2d
Do not use pagezero size option if osx version >= 13 (#3025)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/3009.
2024-01-16 12:14:43 +08:00
Wenyong Huang
705bf807b2
Remove deprecated tests in language-bindings python (#3018)
After PR #2922, the caller of wasm-c-api wasm_func_call should ensure
the params and results are correctly created, runtime doesn't check
their format again.
2024-01-16 10:15:56 +08:00
Enrico Loparco
c9fd44e8b8
Build samples in debug mode (#3019)
Follow-up on #3008. Compiling samples in Debug mode allows us to
take advantage of asserts and would have prevented the fix in #3008.
2024-01-16 09:36:05 +08:00
YAMAMOTO Takashi
685d55d2e7
nuttx: Use larger alignment for os_mmap and comment why (#3017)
Other platforms with malloc-based os_mmap might need similar changes
too, depending on their target cpu arch.
2024-01-16 09:17:58 +08:00
Huang Qi
915adc433d
Rename rwlock_init to avoid conflict (#3016)
This symbol is too simple to cause conflict with others, such as the RW
spinlock in Linux kernel and NuttX, so rename it to avoid the conflict.
2024-01-16 08:53:18 +08:00
Wenyong Huang
884c1abc11
Fix nightly-run CI failure (#3014)
Not know how to make `__attribute__((no_sanitize_address))` take effect
on gcc in Ubuntu-20.04, just disable quick AOT entry for wasm-c-api
sample in nightly-run CI.
2024-01-16 08:44:35 +08:00
Enrico Loparco
54bc9f2053
Increase default app thread stack size (#3010) 2024-01-15 19:05:23 +08:00
Enrico Loparco
892a94fd05
fix(wasm-c-api): Do not clone stack frames if there's no trap (#3008)
When running the wasi-threads no_pthread sample, the assert was failing
on `src->num_elems != 0` in debug mode, it is because that the exception
is `proc_exit`, there is no trap (the execution didn't fail, no stack frames):
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/samples/wasi-threads/wasm-apps/no_pthread.c
2024-01-15 18:18:37 +08:00
YAMAMOTO Takashi
837b9904f5
aot debug: Try to use a bit more appropriate file names (#3000)
When the original wasm contains multiple compilation units, the current
logic uses the first one for everything. This commit tries to use a bit more
appropriate ones.
2024-01-15 15:02:12 +08:00
Wenyong Huang
23d2e0627c
Clear compilation warning and dead code (#3002) 2024-01-13 08:56:39 +08:00
Maks Litskevich
63012f0222
Fix build errors when initializing wasm_val_t values with macros (#3007)
Errors were reported when initializing wasm_val_t values with WASM_I32_VAL like macros.
```
 error: missing initializer for member ‘wasm_val_t::__paddings’ [-Werror=missing-field-initializers]
   64 |     wasm_val_t res = {WASM_INIT_VAL};
```
And rename DEPRECATED to WASM_API_DEPRECATED to avoid using defines with generic names.
2024-01-13 08:35:49 +08:00
YAMAMOTO Takashi
08442458b1
aot debug: Update DW_AT_producer (#3001)
Currently we are using "ant compiler", which is a bit historical.
This commit changes it to use "WAMR AoT compiler" instead.
2024-01-12 13:43:18 +08:00
Wenyong Huang
17e3bf255c
Update version number to 1.3.1 and update release notes (#2999) 2024-01-12 11:31:01 +08:00
Wenyong Huang
3198018214
Fix linux-sgx build error when libc-wasi is disabled (#2997)
Compilation error was reported when `cmake -DWAMR_BUILD_LIBC_WASI=0`
on linux-sgx platform:
```
core/shared/platform/linux-sgx/sgx_socket.c:8:10:
fatal error: libc_errno.h: No such file or directory
    8 | #include "libc_errno.h"
      |          ^~~~~~~~~~~~~~
```
After fixing, both `cmake -DWAMR_BUILD_LIBC_WASI=1` and
`WAMR_BUILD_LIBC_WASI=0` work good.
2024-01-11 14:26:39 +08:00
liang.he
9121db5671
Fix a bug when emit the custom name section to aot file (#2987)
The content in custom name section is changed after loaded since the strings
are adjusted with '\0' appended, the emitted AOT file then cannot be loaded.
The PR disables changing the content for AOT compiler to resolve it.

And disable emitting custom name section for `wamrc --enable-dump-call-stack`,
instead, use `wamrc --emit-custom-sections=name` to emit it.
2024-01-11 13:14:54 +08:00
modest
03a2af5095
Fix compilation error on iOS due to macOS-specific API (#2995)
`pthread_jit_write_protect_np` is only available on macOS, and
`sys_icache_invalidate` is available on both iOS and macOS and
has no restrictions on ARM architecture.
2024-01-11 12:35:44 +08:00
Enrico Loparco
ff25110840
Return stack frames of crashed thread when using wasm-c-api (#2908)
When using the wasm-c-api and there's a trap, `wasm_func_call()` returns
a `wasm_trap_t *` object. No matter which thread crashes, the trap contains
the stack frames of the main thread.

With this PR, when there's an exception, the stack frames of the thread
where the exception occurs are stored into the thread cluster.
`wasm_func_call()` can then return those stack frames.
2024-01-11 12:13:05 +08:00
Wenyong Huang
b21f17dd6d
Refine AOT/JIT code call wasm-c-api import process (#2982)
Allow to invoke the quick call entry wasm_runtime_quick_invoke_c_api_import to
call the wasm-c-api import functions to speedup the calling process, which reduces
the data copying.

Use `wamrc --invoke-c-api-import` to generate the optimized AOT code, and set
`jit_options->quick_invoke_c_api_import` true in wasm_engine_new when LLVM JIT
is enabled.
2024-01-10 18:37:02 +08:00
Wenyong Huang
7c7684819d
Register quick call entries to speedup the aot/jit func call process (#2978)
In some scenarios there may be lots of callings to AOT/JIT functions from the
host embedder, which expects good performance for the calling process, while
in the current implementation, runtime calls the wasm_runtime_invoke_native
to prepare the array of registers and stacks for the invokeNative assemble code,
and the latter then puts the elements in the array to physical registers and
native stacks and calls the AOT/JIT function, there may be many data copying
and handlings which impact the performance.

This PR registers some quick AOT/JIT entries for some simple wasm signatures,
and let runtime call the entry to directly invoke the AOT/JIT function instead of
calling wasm_runtime_invoke_native, which speedups the calling process.

We may extend the mechanism next to allow the developer to register his quick
AOT/JIT entries to speedup the calling process of invoking the AOT/JIT functions
for some specific signatures.
2024-01-10 16:44:09 +08:00
YAMAMOTO Takashi
6fa6d6d9a5
Enable MAP_32BIT for macOS (#2992)
On macOS, by default, the first 4GB is occupied by the pagezero.
While it can be controlled with link time options, as we are
an library, we usually don't have a control on how to link an
executable.
2024-01-10 16:19:06 +08:00
YAMAMOTO Takashi
49ac1e0636
doc/build_wasm_app.md: Add a note about aot abi compatibility (#2993) 2024-01-10 12:10:40 +08:00
Wenyong Huang
0d4ade6b4c
Fix build failure on esp-idf platform (#2991)
Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2989.
2024-01-10 10:44:31 +08:00
YAMAMOTO Takashi
722381fcf2
aot compiler: Some updates for LLVM 18 (#2981)
Note: This commit includes copy-and-paste from LLVM and thus adds
the LLVM copyright notice.

cf. 0a1aa6cda2
cf. a1e9777b76
cf. 56c72c7f33
2024-01-08 10:15:31 +08:00
Wenyong Huang
c39214e8a5
Fix potential recursive lock in pthread_create_wrapper (#2980)
Potential recursive lock occurs in:
```
pthread_create_wrapper   (acquire exec_env->wait_lock)
  => wasm_cluster_create_thread
    => allocate_aux_stack
      => wasm_runtime_module_malloc_internal
        => wasm_call_function
          => wasm_exec_env_set_thread_info (acquire exec_env->wait_lock again)
```
Allocate aux stack before calling wasm_cluster_create_thread to resolve it.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/pull/2977.
2024-01-08 09:43:31 +08:00
tkernelcn
4a1ad9a160
freertos: Change ssp_config.h due to clock_nanosleep() not supported in freertos (#2979) 2024-01-04 20:01:54 +08:00
Xu Jun
f96257bade
Fix fast-interp polymorphic stack processing (#2974)
Fix issue #2951, #2952 and #2953.
2024-01-04 10:00:36 +08:00
tkernelcn
a2751903ff
freertos: Minor changes for freertos libc_wasi build adaption (#2973) 2024-01-04 09:49:24 +08:00
Wenyong Huang
1ee4767d97
Fix ref.func function declared check in wasm loader (#2972)
The forward-declare function reference in ref.func can be declared in table element segments,
no matter whether the segment mode is passive, active or declarative.

Reported in https://github.com/bytecodealliance/wasm-micro-runtime/issues/2944.
2024-01-03 11:43:03 +08:00
liutao
75a2b98eb4
simd-128: The input lanes of integer-to-integer narrowing ops should be interpreted as signed (#2850)
https://github.com/WebAssembly/spec/blob/main/proposals/simd/SIMD.md#integer-to-integer-narrowing
2024-01-03 09:51:58 +08:00
Wenyong Huang
c43e4505da
Allow to set segue flags for wasm-c-api JIT (#2926)
Add an API to set segue flags for wasm-c-api LLVM JIT mode:
```C
wasm_config_t *
wasm_config_set_segue_flags(wasm_config_t *config, uint32 segue_flags);
```
2024-01-02 19:34:18 +08:00
Wenyong Huang
aa4d68c2af
Refine AOT function call process (#2940)
Don't set exec_env's thread handle and stack boundary in the recursive
calling from host, since they have been initialized in the first time calling.
2024-01-02 19:10:31 +08:00
Wenyong Huang
3637f2df79
Refine LLVM JIT function call process (#2925)
- Don't allocate the implicit/unused frame when calling the LLVM JIT function
- Don't set exec_env's thread handle and stack boundary in the recursive
  calling from host, since they have been set in the first time calling
- Fix frame not freed in llvm_jit_call_func_bytecode
2024-01-02 18:46:02 +08:00
Xu Jun
d818672f62
Fix ref.is_null processing in fast-interp loader (#2971) 2024-01-02 18:10:01 +08:00
Wenyong Huang
2ee013faf3
fast-jit: Fix const shift and const i64 compare issues (#2969) 2024-01-02 17:56:34 +08:00
tkernelcn
286ea35508
fixed(freertos): Fix crash when wasm app call pthread_exit(NULL) (#2970)
before the change, only support wasm app exit like:
```c
void *thread_routine(void *arg)
{
    printf("Enter thread\n");
    return NULL;
}
```
if call pthread_exit, it will crash:
```c
void *thread_routine(void *arg)
{
    printf("Enter thread\n");
    pthread_exit(NULL);
    return NULL;
}
```
This commit lets both upstairs work correctly, test pass on stm32f103 mcu.
2024-01-02 17:32:09 +08:00
Haoxuan Xu
ef5e74fd8a
fix(sgx-ra): Fix building when enclave is built without librats ahead (#2968)
This PR addresses the issue with building the sgx-ra sample when the enclave under
the path product-mini/platforms/linux-sgx/enclave-sample is built beforehand.

When the enclave is built without librats ahead, an error occurs as the following
without the changes:
```bash
...
CP libvmlib.a  <=  /home/haoxuan/wasm-micro-runtime/samples/sgx-ra/build/libvmlib.a
/usr/local/bin/ld: libvmlib.a(lib_rats_wrapper.c.o): in function `librats_collect_wrapper':
lib_rats_wrapper.c:(.text.librats_collect_wrapper+0x4a): undefined reference to `wasm_runtime_get_module_hash'
collect2: error: ld returned 1 exit status
```
2024-01-02 16:32:16 +08:00
liang.he
5c3ad0279a
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`
2024-01-02 15:58:17 +08:00
liang.he
38019f273a
Append .aot to .wasm as a custom section named "aot" (#2933)
As a pre_compiled wasm plugin for Envoy:
https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/wasm/v3/wasm.proto
2024-01-02 10:30:41 +08:00
tkernelcn
92bf8547aa
freertos: Add os_cond_broadcast for pthread wrapper (#2937) 2023-12-28 22:57:19 +08:00
liang.he
22c5c90340
Fix a bug that appends '_precheck' to aot_func (#2936) 2023-12-28 22:38:12 +08:00
liang.he
6c839042d6
Allow to control built-in libraries for wamrc from command line options (#2928)
Allow to control built-in libraries for wamrc from command line options:
```bash
cmake -DWAMR_BUILD_LIBC_WASI=1/0
cmake -DWAMR_BUILD_LIBC_BUILTIN=1/0
cmake -DWAMR_BUILD_LIB_PTHREAD=1/0
cmake -DWAMR_BUILD_LIB_WASI_THREADS=1/0
```
And add some messages to show the status.
2023-12-28 22:20:55 +08:00
YAMAMOTO Takashi
5edd85d055
doc: Separate source_debugging.md into two files (#2932)
The original file was confusing as it contains both of
interpreter and aot debugging information intermixed.
2023-12-27 15:51:51 +08:00
YAMAMOTO Takashi
8318333304
nuttx: Add CONFIG_INTERPRETERS_WAMR_DEBUG_AOT (#2929)
At least it's sometimes useful for nuttx sim.

eg. (modified a bit to avoid github autolinks)
```
spacetanuki% lldb ./nuttx
(lldb) target create "./nuttx"
Current executable set to '/Users/yamamoto/git/nuttx/nuttx/nuttx' (x86_64).
(lldb) settings set plugin.jit-loader.gdb.enable on
(lldb) b foo
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 37011 launched: '/Users/yamamoto/git/nuttx/nuttx/nuttx' (x86_64)

NuttShell (NSH) NuttX-10.4.0
nsh> mount -t hostfs -o fs=/tmp/wasm /mnt
nsh> iwasm /mnt/test.aot
1 location added to breakpoint 1
Process 37011 stopped
* thread #_1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #_0: 0x0000000105800673 JIT(0x1058002d4)`foo(exenv=0x0000000101284280) at test.c:5
   2
   3    __attribute__((noinline))
   4    void foo()
-> 5    {
   6        printf("hello from %s\n", __func__);
   7    }
   8
Target 0: (nuttx) stopped.
(lldb) bt
* thread #_1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #_0: 0x0000000105800673 JIT(0x1058002d4)`foo(exenv=0x0000000101284280) at test.c:5
    frame #_1: 0x000000010580077a JIT(0x1058002d4)`bar(exenv=0x0000000101284280) at test.c:12:2
    frame #_2: 0x000000010580086a JIT(0x1058002d4)`baz(exenv=0x0000000101284280) at test.c:19:2
    frame #_3: 0x0000000105800972 JIT(0x1058002d4)`__main_argc_argv(exenv=<unavailable>, argc=<unavailable>, argv=<unavailable>) at test.c:26:3
    frame #_4: 0x00000001058061aa JIT(0x1058002d4)`aot_func#14 + 278
    ...
```
2023-12-26 16:56:34 +08:00
Wenyong Huang
4a7a66e900
Enable wasm_runtime_terminate for single-threading (#2924)
The host embedder may also want to terminate the wasm instance
for single-threading mode, and it should work by setting exception
to the wasm instance.
2023-12-26 16:05:44 +08:00
Wenyong Huang
5a75c31c38
Add VectorCombine pass for JIT and AOT (#2923)
It improves performance for some cases.
And add several vectorize related passes for JIT mode.
2023-12-26 11:27:20 +08:00