A64: Only clear icache when writing out new code#442
Merged
k0kubun merged 1 commit intoyjit_backend_irfrom Aug 26, 2022
Merged
Conversation
Previously we cleared the cache for all the code in the system when we flip memory protection, which was prohibitively expensive since the operation is not constant time. Instead, only clear the cache for the memory region of newly written code when we write out new code. This brings the runtime for the 30k_if_else test down to about 6 seconds from the previous 45 seconds on my laptop.
Member
|
The time spent on Arm CI seems to be shortened a lot too. Great work 👏👏👏 |
k0kubun
pushed a commit
that referenced
this pull request
Aug 26, 2022
Previously we cleared the cache for all the code in the system when we flip memory protection, which was prohibitively expensive since the operation is not constant time. Instead, only clear the cache for the memory region of newly written code when we write out new code. This brings the runtime for the 30k_if_else test down to about 6 seconds from the previous 45 seconds on my laptop.
maximecb
reviewed
Aug 26, 2022
Comment on lines
+964
to
+972
| // Invalidate icache for newly written out region so we don't run | ||
| // stale code. | ||
| { | ||
| let start = cb.get_ptr(start_write_pos).raw_ptr(); | ||
| let write_ptr = cb.get_write_ptr().raw_ptr(); | ||
| let codeblock_end = cb.get_ptr(cb.get_mem_size()).raw_ptr(); | ||
| let end = std::cmp::min(write_ptr, codeblock_end); | ||
| unsafe { rb_yjit_icache_invalidate(start as _, end as _) }; | ||
| } |
There was a problem hiding this comment.
Thanks for putting this together Alan!
Do you know if __builtin___clear_cache(start, end); uses a syscall underneath, or just a machine loop? Asking because if it uses a syscall, we might be able to batch multiple calls together in a future PR to improve speed further.
k0kubun
pushed a commit
that referenced
this pull request
Aug 29, 2022
Previously we cleared the cache for all the code in the system when we flip memory protection, which was prohibitively expensive since the operation is not constant time. Instead, only clear the cache for the memory region of newly written code when we write out new code. This brings the runtime for the 30k_if_else test down to about 6 seconds from the previous 45 seconds on my laptop.
k0kubun
pushed a commit
that referenced
this pull request
Aug 29, 2022
Previously we cleared the cache for all the code in the system when we flip memory protection, which was prohibitively expensive since the operation is not constant time. Instead, only clear the cache for the memory region of newly written code when we write out new code. This brings the runtime for the 30k_if_else test down to about 6 seconds from the previous 45 seconds on my laptop.
k0kubun
pushed a commit
to ruby/ruby
that referenced
this pull request
Aug 29, 2022
Previously we cleared the cache for all the code in the system when we flip memory protection, which was prohibitively expensive since the operation is not constant time. Instead, only clear the cache for the memory region of newly written code when we write out new code. This brings the runtime for the 30k_if_else test down to about 6 seconds from the previous 45 seconds on my laptop.
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.
Previously we cleared the cache for all the code in the system when we
flip memory protection, which was prohibitively expensive since the
operation is not constant time. Instead, only clear the cache for the
memory region of newly written code when we write out new code.
This brings the runtime for the 30k_if_else test down to about 6 seconds
from the previous 45 seconds on my laptop.