Skip to content
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

enable fsgsbase instructions on Linux 5.9+ for EOS VM OC #1129

Merged
merged 1 commit into from
Jan 27, 2025
Merged

Conversation

spoonincode
Copy link
Member

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.

const char disable_str[] = "SPRING_DISABLE_FSGSBASE";
if(strncmp(*my_environ++, disable_str, strlen(disable_str)) == 0)
return 0;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same mess as I used in bls,
AntelopeIO/bls12-381#4 (comment)
Don't really know what to do here. Disabling optimizations via environment variable is nice. Seems hard to believe _dl_argv would ever deviate.

@spoonincode spoonincode linked an issue Jan 27, 2025 that may be closed by this pull request
@spoonincode spoonincode merged commit 5d8954b into main Jan 27, 2025
36 checks passed
@spoonincode spoonincode deleted the fsgsbase branch January 27, 2025 15:49
@ericpassmore
Copy link
Contributor

Note:start
category: Other
component: OC
summary: Utilize modern CPU instructions to speed up system and contract execution.
Note:end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use fsgsbase instructions in OC
4 participants