]> Cypherpunks repositories - gostls13.git/commitdiff
internal/cpu,runtime: call cpu.initialize before alginit
authorMeng Zhuo <mengzhuo1203@gmail.com>
Tue, 10 Apr 2018 14:33:03 +0000 (22:33 +0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 10 Apr 2018 16:13:52 +0000 (16:13 +0000)
runtime.alginit needs runtime/support_{aes,ssse3,sse41} feature flag
to init aeshash function but internal/cpu.init not be called yet.
This CL will call internal/cpu.initialize before runtime.alginit, so
that we can move all cpu features related code to internal/cpu.

Change-Id: I00b8e403ace3553f8c707563d95f27dade0bc853
Reviewed-on: https://go-review.googlesource.com/104636
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/racewalk.go
src/internal/cpu/cpu.go
src/internal/cpu/cpu_arm64.go
src/internal/cpu/cpu_no_init.go [new file with mode: 0644]
src/internal/cpu/cpu_x86.go
src/runtime/proc.go

index 3b8e1bdc58fae6be59f07de3feec6e236ff94935..8ae080ab40861f343e13467a12ea28a0fcb8ecf7 100644 (file)
@@ -27,7 +27,7 @@ import (
 
 // Do not instrument the following packages at all,
 // at best instrumentation would cause infinite recursion.
-var omit_pkgs = []string{"runtime/internal/atomic", "runtime/internal/sys", "runtime", "runtime/race", "runtime/msan"}
+var omit_pkgs = []string{"runtime/internal/atomic", "runtime/internal/sys", "runtime", "runtime/race", "runtime/msan", "internal/cpu"}
 
 // Only insert racefuncenterfp/racefuncexit into the following packages.
 // Memory accesses in the packages are either uninteresting or will cause false positives.
index eebbf1a5d786ae70488d11df73f1139a64b3bb4c..4000530059837e804b90e3e35114e4ae52768fa2 100644 (file)
@@ -98,3 +98,10 @@ type s390x struct {
        HasVX bool // vector facility. Note: the runtime sets this when it processes auxv records.
        _     [CacheLineSize]byte
 }
+
+// initialize examines the processor and sets the relevant variables above.
+// This is called by the runtime package early in program initialization,
+// before normal init functions are run.
+func initialize() {
+       doinit()
+}
index 3809a1d854ea5bbdcfc53fc74aa5a3f934ca6364..b1c2ace0e660b9982a77bd85988d3a5a81a3159e 100644 (file)
@@ -42,7 +42,7 @@ const (
        hwcap_ASIMDFHM = (1 << 23)
 )
 
-func init() {
+func doinit() {
        // HWCAP feature bits
        ARM64.HasFP = isSet(arm64_hwcap, hwcap_FP)
        ARM64.HasASIMD = isSet(arm64_hwcap, hwcap_ASIMD)
diff --git a/src/internal/cpu/cpu_no_init.go b/src/internal/cpu/cpu_no_init.go
new file mode 100644 (file)
index 0000000..50f6232
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build !386
+// +build !amd64
+// +build !amd64p32
+// +build !arm64
+
+package cpu
+
+func doinit() {
+}
index 34c632f2f993d98e4c66e3e1e3f53bd5b89577b1..239e7289008548aac2c00029c09f7ac519a6c9ee 100644 (file)
@@ -14,7 +14,7 @@ func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)
 // xgetbv with ecx = 0 is implemented in cpu_x86.s.
 func xgetbv() (eax, edx uint32)
 
-func init() {
+func doinit() {
        maxID, _, _, _ := cpuid(0, 0)
 
        if maxID < 1 {
index 8f32320e0c5a0b41357616448ae365b57d351a87..98d78f0c82b733d5bdc82c9fafd6d6606c83beb3 100644 (file)
@@ -466,6 +466,9 @@ const (
        _GoidCacheBatch = 16
 )
 
+//go:linkname internal_cpu_initialize internal/cpu.initialize
+func internal_cpu_initialize()
+
 // The bootstrap sequence is:
 //
 //     call osinit
@@ -489,10 +492,11 @@ func schedinit() {
        stackinit()
        mallocinit()
        mcommoninit(_g_.m)
-       alginit()       // maps must not be used before this call
-       modulesinit()   // provides activeModules
-       typelinksinit() // uses maps, activeModules
-       itabsinit()     // uses activeModules
+       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
 
        msigsave(_g_.m)
        initSigmask = _g_.m.sigmask