enable fsgsbase
instructions on Linux 5.9+ for EOS VM OC
#1129
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.
EOS VM OC uses the GS segment register for the base of its WASM memory. Prior to Linux 5.9 the only way to adjust the base address is via a syscall. For 5.9+, combined with modern CPUs (Intel Ivy Bridge+, 2012; AMD Bulldozer+, 2011), it's possible to instead use the
fsgsbase
instructions from userspace without needing to make a syscall. Switching to these instructions eliminates at least one syscall per action, and oftentimes more for something like EVM.I ran a replay test over blocks 96328736-96627942 on an i7-12700K (Alder Lake, 2021). I saw a surprising ~3.5% improvement. This far exceeds my expectations (should have done this years ago). I was anticipating that only older CPUs subject to Meltdown would incur such heavy overhead on this seemingly simplistic syscall. What might explain this is that Alder Lake is subject to the swapgs spectre variant, but I have not confirmed that is the source of the slow down.
I had planed to dig out an 8th gen Core CPU (with Meltdown) to benchmark with but now I'm not sure I'll go through the trouble since the gains are so impressive on modern gen.
I have created,
https://github.com/AntelopeIO/spring/wiki/Environment-Variables-Controlling-CPU-Features
to track the various environment variables controlling CPU instruction usage.