-
Notifications
You must be signed in to change notification settings - Fork 18k
x/build: add builders with different GODEBUG=cpu capabilities #12805
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
Comments
The main problem is that a lot of packages issue their own
CPUID instruction. We can't override that without refactor
them to use a centralized cpu feature detection facility.
I'm wondering if we could have a runtime/cpu package that
provide a public interface to query CPU capabilities?
we can't just have an internal package because some of
the code in sub-repo also needs CPU feature detection.
If we have a standard interface, then 3rdparty code will also
benefit from this kind of testing without forcing to test on
a large variety of machines.
If you think this standard interface is reasonable, I can write
a proposal.
Basically, the runtime/cpu package will provide overridable
runtime cpu feature detection.
|
For the runtime at least, I don't think we can use a separate package. The That said, runtime will always be special. This proposal sounds reasonable On Tue, Oct 6, 2015 at 5:07 PM, Minux Ma notifications@github.com wrote:
|
On 7 October 2015 at 11:22, Keith Randall notifications@github.com wrote:
I'd imagine the runtime/cpu package would depend on internal functions from |
Presumably there's no way to configure GCE to "select" a (virtually) different CPU other than Haswell? (It would seem that this might be an issue for other clients as well, not just for us.) |
No, you just get the processor type of the host machine. IIUC some GCE instances might have different kinds of processors, but you On 7 October 2015 at 11:44, Robert Griesemer notifications@github.com
|
We could run in different zones with different processors, but that is a very limited selection compared to what Go aims to support. For testing, I'd really like to cover many more paths. |
Yeah, the proposed runtime/cpu package will just expose
the functionality implemented in runtime in a way suitable
for other packages to use.
Overriding the cpu feature will only be supported through
environment variables specified before the program starts.
(Or we can document dynamic override of cpu feature only
affect programs that don't cache result by themselves and
the runtime package does cache the result.)
|
Now that for go1.9 the std lib cpuid usage has been unified to use internal/cpu i will work on a proposal and implementation for go1.10 to extend the cpu package such that we can set cpu flags for the std lib. If we use a standardized set of environment variables we could also augment other copies of the cpu feature detection code (e.g. in x/crypto which partly is vendored into std lib) to take these into account too and leaving internal/cpu still internal. For the runtime we would still need build infrastructure with virtual machines where we can set the cpuid mask with the hypervisor for the virtual machine. |
Keep in mind what happened with ARM - we did this with ARM and invalid instructions slipped in because the processor still supported them even though the environment variable said to not use them. The best way to test this really is machines with the old instruction sets. Or I suppose we could run inside bochs, but that would probably be horrifically slow. AFAICT qemu doesn't support controlling CPU feature flags. |
Thanks for the hint. Indeed it wont prevent using instructions that are not guarded by feature detection. It however would support testing output of code paths with the builders that are otherwise not tested since e.g. all amd64 builders support AVX and there are SSE41 code paths. |
Now that gvisor is open source (https://github.com/google/gvisor), we can run some build configurations under gvisor and its emulated CPUID instructions to mask away certain CPU features and get more test coverage of our code paths selected at runtime. |
Change https://golang.org/cl/91737 mentions this issue: |
Needs the go compiler to be build with GOEXPERIMENT=debugcpu to be active. The GODEBUGCPU environment variable can be used to disable usage of specific processor features in the Go standard library. This is useful for testing and benchmarking different code paths that are guarded by internal/cpu variable checks. Use of processor features can not be enabled through GODEBUGCPU. To disable usage of AVX and SSE41 cpu features on GOARCH amd64 use: GODEBUGCPU=avx=0,sse41=0 The special "all" option can be used to disable all options: GODEBUGCPU=all=0 Updates #12805 Updates #15403 Change-Id: I699c2e6f74d98472b6fb4b1e5ffbf29b15697aab Reviewed-on: https://go-review.googlesource.com/91737 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
With @martisch's GODEBUGCPU, this bug is now trivial. We just have to decide what a good set of new builders would be, disabling which CPU features. We could probably also skip most packages' tests and only test ones with assembly. |
Sounds great, exactly what it was made for. We changed to using GODEBUG for CPU feature masking at runtime for go1.12. For amd64 I would like to see:
The later corresponds to a Sandy Bridge era Pentium without AVX/AVX2/POPCNT/AES/BMI.... |
@martisch, SGTM. @randall77, @aclements, any other particular requests before we add a few of these? /cc @toothrot |
Sounds fine, as long as we have builder capacity for them. |
Our builders for the most part only run on Haswell CPUs on Google Compute Engine.
A number of Go packages in the standard library and runtime use assembly to choose alternate paths depending on the capabilities of the processor.
I feel like we're not getting good test coverage, only testing the Haswell paths.
We do have a GOARCH=386 builder, though, which is at one extreme, but there are a number of steps in the middle untested.
Can we put an abstraction over CPUID etc somewhere (unexported) such that the builders can fake it before assembly code can?
/cc @ianlancetaylor @minux @adg
The text was updated successfully, but these errors were encountered: