aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/proc.go
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2018-01-26 12:14:27 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2018-05-22 18:49:31 +0000
commitf045ddc624dea292257249a618e4ad1bd2bd5c6e (patch)
tree24569109aedd91e0c6540b8f2af723c0fe9c0a03 /src/runtime/proc.go
parent3d15f768814e8b06ae159b4da8f34a0c702a4cf1 (diff)
downloadgo-f045ddc624dea292257249a618e4ad1bd2bd5c6e.tar.xz
internal/cpu: add experiment to disable CPU features with GODEBUGCPU
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>
Diffstat (limited to 'src/runtime/proc.go')
-rw-r--r--src/runtime/proc.go46
1 files changed, 40 insertions, 6 deletions
diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index e22432f8ed..ba76f7c3e7 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -473,7 +473,41 @@ const (
)
//go:linkname internal_cpu_initialize internal/cpu.initialize
-func internal_cpu_initialize()
+func internal_cpu_initialize(env string)
+
+//go:linkname internal_cpu_debugOptions internal/cpu.debugOptions
+var internal_cpu_debugOptions bool
+
+// cpuinit extracts the environment variable GODEBUGCPU from the enviroment on
+// Linux and Darwin if the GOEXPERIMENT debugcpu was set and calls internal/cpu.initialize.
+func cpuinit() {
+ const prefix = "GODEBUGCPU="
+ var env string
+
+ if haveexperiment("debugcpu") && (GOOS == "linux" || GOOS == "darwin") {
+ internal_cpu_debugOptions = true
+
+ // Similar to goenv_unix but extracts the environment value for
+ // GODEBUGCPU directly.
+ // TODO(moehrmann): remove when general goenvs() can be called before cpuinit()
+ n := int32(0)
+ for argv_index(argv, argc+1+n) != nil {
+ n++
+ }
+
+ for i := int32(0); i < n; i++ {
+ p := argv_index(argv, argc+1+i)
+ s := *(*string)(unsafe.Pointer(&stringStruct{unsafe.Pointer(p), findnull(p)}))
+
+ if hasprefix(s, prefix) {
+ env = gostring(p)[len(prefix):]
+ break
+ }
+ }
+ }
+
+ internal_cpu_initialize(env)
+}
// The bootstrap sequence is:
//
@@ -498,11 +532,11 @@ func schedinit() {
stackinit()
mallocinit()
mcommoninit(_g_.m)
- internal_cpu_initialize() // must run before alginit
- alginit() // maps must not be used before this call
- modulesinit() // provides activeModules
- typelinksinit() // uses maps, activeModules
- itabsinit() // uses activeModules
+ cpuinit() // must run before alginit
+ alginit() // maps must not be used before this call
+ modulesinit() // provides activeModules
+ typelinksinit() // uses maps, activeModules
+ itabsinit() // uses activeModules
msigsave(_g_.m)
initSigmask = _g_.m.sigmask