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.
If Cr4.PCID is set and the 63rd bit is clear when moving into Cr3, the processor flushes all TLB entries for the given PCID (Intel SDM, Volume 3, 4.10.4.1 and AMD APM, Volume 2, 5.5.1). This is similar to the operation without PCID in which the processor also flushes all TLB entries every time a new value is moved into Cr3. Given that the entire idea behind PCIDs is to not flush all entries when Cr3 is changed, we should also provide a write method that sets the 63rd bit when moving into Cr3. This PR adds
write_pcid_no_flush
to do just that.A very quick and dirty comparison between
write_pcid
andwrite_pcid_no_flush
showed a10%25+% performance improvement.It could be argued that setting the 63rd bit should be the default, however, I'm a bit concerned that users rely on the flushing behavior (either intentionally or unintentionally) and so suddenly changing to non-flushing behavior could break code (This seems to be the case for a codebase I'm working on). In a future breaking release, we may want to change
write_pcid
to take an additional parameter specifying whether flushing behavior is intended.