-
Notifications
You must be signed in to change notification settings - Fork 243
WASIp3 Cooperative Threading #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
421005c
Restructure thread impls
TartanLlama fd62b0b
Cmake fixes
TartanLlama 974fc8a
Common files
TartanLlama 2789d8f
Rename folder
TartanLlama 8bf9a00
First pass
TartanLlama 9f4cb70
Merge branch 'main' into sy/coop-threading
TartanLlama ed7f5d2
Merge in WASIP3
TartanLlama bd108e2
Linking fixes
TartanLlama 5f6f5ae
Various clocks and build fixes
TartanLlama 6bc21e1
Lock fixes
TartanLlama 2f613cc
Sysconf changes
TartanLlama 8f2a99c
sem_destroy fixes
TartanLlama 16d406a
Link and test updates
TartanLlama 5b95b09
Merge branch 'main' into sy/coop-threading
TartanLlama 72ac6f8
WASIp3 bump
TartanLlama 36d2c17
crt1 bump
TartanLlama aba8568
Fix bad lock initializations
TartanLlama 3647168
Ifdef lock
TartanLlama e055edf
typedef locks with no threading
TartanLlama c10da06
Unused variable warnings
TartanLlama 7b431f1
More lock nonsense
TartanLlama 787c289
Redo lock changes
TartanLlama 1000351
Move lock_ptc
TartanLlama 1fc2a40
OFL lock fix
TartanLlama c37f771
Add wasi-threads sem_destroy
TartanLlama 0ef525a
wasi-threads fixes
TartanLlama cfec5f1
wasi-threads fixes
TartanLlama c78d35c
wasi-threads fixes
TartanLlama 73dff1a
wasi-threads fixes
TartanLlama df6a4da
Pointer shenanigans
TartanLlama 35b1ed9
Pointer shenanigans
TartanLlama d8fb9a6
Pointer shenanigans
TartanLlama cb5f6a4
More lock changes
TartanLlama cce6bc0
Defined symbol changes
TartanLlama 53be6e5
Bump test suite
TartanLlama 6e3518a
Call compiler-rt
TartanLlama ffdf6b0
Merge branch 'main' into sy/coop-threading
TartanLlama fd5840e
Correct mtx cmake
TartanLlama ddd75e1
Update
TartanLlama e02f07d
Merge branch 'main' into sy/coop-threading
TartanLlama 4d2e463
Rename coop threads macro
TartanLlama d7961f8
Lock name fixes
TartanLlama 8fe99d7
Fix macro name
TartanLlama 84383bb
Fix lock issue
TartanLlama 5d1f328
Remove stale files
TartanLlama d249f32
Merge branch 'main' into sy/coop-threading
TartanLlama 3c017ff
Move thread index retrieval
TartanLlama 112e662
Move TLS allocation to C
TartanLlama 7c413fa
Add configuration option
TartanLlama f753690
Update expected symbols on wasip1-threads
alexcrichton 686e708
Adjust wasip3 coop threads build
alexcrichton 8a922b1
Run clang-format
alexcrichton 9b7bedc
Add comment for new version.h define
alexcrichton 413ed50
Avoid `FetchContent`
alexcrichton 4df0e1d
Add missing #define
alexcrichton f4c4149
Include `__libcall_thread_context.s` on all clang 23+ builds
alexcrichton ab97506
Don't test a link
alexcrichton f47e879
Adjust libcall_thread_context.S
alexcrichton f198075
More adjustments for wasip3
alexcrichton 285ad52
Don't initialize TLS on each task
alexcrichton 3103216
Add pthread dep since clang seems to want it
alexcrichton 80bf71d
Move configuring V8 tests into CMake
alexcrichton a56a46d
Use a published version of wasmtime
alexcrichton 8db2fce
Merge remote-tracking branch 'origin/main' into wat
alexcrichton 9016dd8
Update wasm-component-ld to support `--cooperative-threading`
alexcrichton b8360a0
Remove a debug printf
alexcrichton 8dd056e
Add a missing header for the wasi defines
alexcrichton 4ef1350
Prevent a double-free when detaching a joined thread
alexcrichton 0248c96
Run clang-format over coop-threads
alexcrichton 7a4f451
Remove THREADS from CMake
alexcrichton dad2471
Trim flags for coop threads
alexcrichton 1a3cc4d
Remove stray file
alexcrichton 7147fb2
Enable adding unit tests for coop threads
alexcrichton e22446e
Fix sem_wait wakeup with multiple waiters
alexcrichton 29ac9cb
Fix losing wakeups in pthread_cond_signal
alexcrichton c8d7402
Fix dropping locked files on thread exit
alexcrichton b86cddd
Fix a deadlock issue with the cwd lock
alexcrichton 0af5aca
Fix an issue in `__waitlist_wake_all`
alexcrichton f5c7666
Fix a UAF in `pthread_detach`
alexcrichton 6a6d4b6
Handle allocation failure in `__allocate_tls`
alexcrichton 0132240
Adjust waiters in pthread_once
alexcrichton 5f65090
Don't set map_base to NULL, it's ub
alexcrichton 8770137
Don't yield to joiners when exiting a thread
alexcrichton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # LLVM emits calls to the following functions when the libcall-thread-context feature is enabled (default on WASIp3) | ||
|
|
||
| #include <wasi/version.h> | ||
|
|
||
| .globl __wasm_get_stack_pointer | ||
| .type __wasm_get_stack_pointer,@function | ||
| .globl __wasm_set_stack_pointer | ||
| .type __wasm_set_stack_pointer,@function | ||
|
|
||
| .functype __wasm_component_model_builtin_context_get_0 () -> (i32) | ||
| .import_module __wasm_component_model_builtin_context_get_0, "$root" | ||
| .import_name __wasm_component_model_builtin_context_get_0, "[context-get-0]" | ||
| .functype __wasm_component_model_builtin_context_set_0 (i32) -> () | ||
| .import_module __wasm_component_model_builtin_context_set_0, "$root" | ||
| .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" | ||
|
|
||
| __wasm_get_stack_pointer: | ||
| .functype __wasm_get_stack_pointer () -> (i32) | ||
| call __wasm_component_model_builtin_context_get_0 | ||
| end_function | ||
|
|
||
| __wasm_set_stack_pointer: | ||
| .functype __wasm_set_stack_pointer (i32) -> () | ||
| local.get 0 | ||
| call __wasm_component_model_builtin_context_set_0 | ||
| end_function | ||
|
|
||
| .globl __wasm_get_tls_base | ||
| .type __wasm_get_tls_base,@function | ||
| .globl __wasm_set_tls_base | ||
| .type __wasm_set_tls_base,@function | ||
|
|
||
| #ifdef __wasi_cooperative_threads__ | ||
| # When coop threads are enabled the tls base lives in this async tasks's | ||
| # context slot index as 1. Note that this slot isn't valid when the | ||
| # component-model-threading feature is disabled, however, so it can't be | ||
| # used. | ||
| .functype __wasm_component_model_builtin_context_get_1 () -> (i32) | ||
| .import_module __wasm_component_model_builtin_context_get_1, "$root" | ||
| .import_name __wasm_component_model_builtin_context_get_1, "[context-get-1]" | ||
| .functype __wasm_component_model_builtin_context_set_1 (i32) -> () | ||
| .import_module __wasm_component_model_builtin_context_set_1, "$root" | ||
| .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" | ||
|
|
||
| __wasm_get_tls_base: | ||
| .functype __wasm_get_tls_base () -> (i32) | ||
| call __wasm_component_model_builtin_context_get_1 | ||
| end_function | ||
|
|
||
| __wasm_set_tls_base: | ||
| .functype __wasm_set_tls_base (i32) -> () | ||
| local.get 0 | ||
| call __wasm_component_model_builtin_context_set_1 | ||
| end_function | ||
| #else | ||
| # When coop threads are disabled do something similar to the basic output | ||
| # which is to have a global that stores the TLS base. | ||
| .globaltype __wasilibc_tls_base, i32 | ||
|
|
||
| __wasm_get_tls_base: | ||
| .functype __wasm_get_tls_base () -> (i32) | ||
| global.get __wasilibc_tls_base | ||
| end_function | ||
|
|
||
| __wasm_set_tls_base: | ||
| .functype __wasm_set_tls_base (i32) -> () | ||
| local.get 0 | ||
| global.set __wasilibc_tls_base | ||
| end_function | ||
|
|
||
| .section .wasm.__wasilibc_tls_base,"",@ | ||
| __wasilibc_tls_base: | ||
| #endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This I think is ok for an initial implementation, but I think we're going to want to eventually ensure that calls to
__wasm_get_stack_pointergo directly to the builtin intrinsic without needing a wrapper in the middle. Otherwise there's basically no way to create a module that directly performs the call because even with LTO these won't get inlined.