-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC 2: MT safe fiber context switch on ARM #15582
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
straight-shoota
merged 2 commits into
crystal-lang:master
from
ysbaddaden:feature/execution-context-arm-context-switch
Mar 31, 2025
Merged
RFC 2: MT safe fiber context switch on ARM #15582
straight-shoota
merged 2 commits into
crystal-lang:master
from
ysbaddaden:feature/execution-context-arm-context-switch
Mar 31, 2025
Conversation
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
It's actually a bit more subtle: we must check for |
@ysbaddaden This needs a conflict resolution. |
We need a store-store barrier between pushing the registers to the current stack and setting the resumable flag of the current fiber, otherwise the CPU is allowed to reorder the instructions at runtime and to store the resumable flag before or while storing the registers. This can happen for example: thread 1: enqueues current fiber A therad 1: swapcontext -> store resumable thread 1: is preempted thread 2: steals fiber A thread 2: resumes fiber A thread 2: loads registers => reads garbage => segfaults thread 1: stores registers (too late)
905e3e3
to
61e888c
Compare
@straight-shoota Rebased to drop the extracted first commit merged with #15585. No more conflicts. |
ysbaddaden
commented
Mar 28, 2025
straight-shoota
approved these changes
Mar 28, 2025
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind:bug
A bug in the code. Does not apply to documentation, specs, etc.
topic:multithreading
topic:stdlib:concurrency
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.
The ARM32 equivalent of #15581.
As stated in a comment the chosen assembly is compatible with armv6, but might not work on older architectures and it doesn't take advantage of armv7 supporting the
dmb ish
instruction.We might want to consider to integrate #14524 (comment) into the compiler, so we could add flags based on features, for example
armv7
when any feature matches/\+v7(ve|r|m|em|s|k|)/
.Note: I also reduced the duplicated assembly. Let's use the flags to wrap the FPU instructions intead of duplicating the assembly 4 times.Extracted as #15585 but the commit is still in this branch because I need it.