RFC 2: MT safe fiber context switch on ARM#15582
Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom Mar 31, 2025
Merged
RFC 2: MT safe fiber context switch on ARM#15582straight-shoota merged 2 commits intocrystal-lang:masterfrom
straight-shoota merged 2 commits intocrystal-lang:masterfrom
Conversation
Collaborator
Author
|
It's actually a bit more subtle: we must check for |
Member
|
@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
Collaborator
Author
|
@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
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ishinstruction.We might want to consider to integrate #14524 (comment) into the compiler, so we could add flags based on features, for example
armv7when 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.