Join GitHub today
runtime: document (and support) cpu options in GODEBUG #27218
Remove the experimental status of the debugcpu experiment feature in go1.12 and document the use of the environment variable
Example invocation of go test with GODEBUGCPU:
Go's CPU feature detection migration to use only the std lib package internal/cpu will be finished with go1.12. internal/cpu exports structs with bool variables that are used to guard the use of CPU instructions that are not guaranteed to be supported or are minimum requirements for the
Currently all CPU features that are supported on the current CPU executing the Go binary may be used.
Compiling go1.11 with
An environment variable is chosen to easily mask CPU features for all go programs executed with a common environment, not interfere with any program arguments and because environment variable values are available early in the GO runtime's startup. Other low level runtime options such as
For each architecture a set of CPU feature options with names matching CPU architecture documentation or the Linux kernel naming of that CPU feature is exposed. The same option name might be used by multiple CPU architectures. Only those CPU features can be changed that are not in the minimum requirements needed for the architecture to run Go programs. For example
To provide compatibility between different Go versions supporting different CPU features options a CPU feature option name that is not known is ignored. e.g. currently
The general syntax to mask a CPU feature and to change the corresponding internal/cpu feature variables is
An internal/cpu feature variables will never be set to
The special option name
Changing a list of option names including the option
An example of setting
Only enabling sse3 if it is supported and required CPU features can be done with:
Alternative Option Values
Optional Debug mode
Optionally the debugcpu feature may be released together with support for
Sounds good to me. A few nits:
I'm not sure what you mean by this. It would make sense to me if
What if the user tries to turn off a feature that is a minimum requirement? I worry it would surprise users if their request was silently ignored. But there also aren't any error cases in the current proposal, and you do specify that requests to turn on unavailable features are silently ignored.
I'm definitely not saying "=off" should be implicit. :) I'm saying the opposite: that the "=value" part should be required, even for the "all" key.
My objection was to saying "all" without an "=value" part. I just wasn't clear on whether the proposal was proposing that. I think the "=value" should be required in all cases.
My intention with "The general syntax to mask a CPU feature and to change the corresponding internal/cpu feature variables is option=value" was to require =value. I will modify the proposal text to make this explicit.
As for silently ignoring errors: Would it be ok for the runtime to log a message to stderr for each option request (on or off) that can not be fullfilled due to missing cpu support or minimum go requirements?
That's a good question. I'm inclined to say that yes, it should log to stderr. While the runtime generally doesn't log anything except when it's crashing, there are several other GODEBUG variables that do enable logging to stderr. So it seems okay to me for GODEBUGCPU to do so as well.
Enabling GODEBUGCPU without the need to set GOEXPERIMENT=debugcpu enables trybots and builders to run tests for GODEBUGCPU features in upcoming CLs that will implement the new syntax and features for non-experimental GODEBUGCPU support from proposal golang.org/issue/27218. Updates #27218 Change-Id: Icc69e51e736711a86b02b46bd441ffc28423beba Reviewed-on: https://go-review.googlesource.com/c/141817 Run-TryBot: Martin Möhrmann <email@example.com> TryBot-Result: Gobot Gobot <firstname.lastname@example.org> Reviewed-by: Brad Fitzpatrick <email@example.com>
…eatures This CL adds the ability to enable the cpu feature FEATURE by specifying FEATURE=on in GODEBUGCPU. Syntax support to enable cpu features is useful in combination with a preceeding all=off to disable all but some specific cpu features. Example: GODEBUGCPU=all=off,sse3=on This CL implements printing of warnings for invalid GODEBUGCPU settings: - requests enabling features that are not supported with the current CPU - specifying values different than 'on' or 'off' for a feature - settings for unkown cpu feature names Updates #27218 Change-Id: Ic13e5c4c35426a390c50eaa4bd2a408ef2ee21be Reviewed-on: https://go-review.googlesource.com/c/141800 Run-TryBot: Martin Möhrmann <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Keith Randall <firstname.lastname@example.org>
Adds AIX, DragonFly BSD, FreeBSD, NetBSD, OpenBSD and Solaris to the list of operating systems where the GODEBUGCPU environment variable will be parsed and interal/cpu features can be enabled and disabled. Updates #27218 Change-Id: I9cd99142e2a5147cb00ca57b581f049ea6ce8508 Reviewed-on: https://go-review.googlesource.com/c/145281 Reviewed-by: Brad Fitzpatrick <email@example.com> Run-TryBot: Martin Möhrmann <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com>