]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move ppc64/aix cpu feature detection to internal/cpu
authorMartin Möhrmann <moehrmann@google.com>
Wed, 28 Oct 2020 21:43:59 +0000 (22:43 +0100)
committerMartin Möhrmann <moehrmann@google.com>
Thu, 29 Oct 2020 13:49:26 +0000 (13:49 +0000)
Additionally removed unused PPC64.IsPOWER8 CPU feature detection.

Change-Id: I1411b03d396a72e08d6d51f8a1d1bad49eaa720e
Reviewed-on: https://go-review.googlesource.com/c/go/+/266077
Trust: Martin Möhrmann <moehrmann@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/internal/cpu/cpu.s [new file with mode: 0644]
src/internal/cpu/cpu_ppc64x.go
src/internal/cpu/cpu_ppc64x_aix.go [new file with mode: 0644]
src/internal/cpu/cpu_ppc64x_linux.go [new file with mode: 0644]
src/runtime/os2_aix.go
src/runtime/os_aix.go

diff --git a/src/internal/cpu/cpu.s b/src/internal/cpu/cpu.s
new file mode 100644 (file)
index 0000000..3c770c1
--- /dev/null
@@ -0,0 +1,6 @@
+// Copyright 2020 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.
+
+// This assembly file exists to allow internal/cpu to call
+// non-exported runtime functions that use "go:linkname".
\ No newline at end of file
index 2487879c4696f389ad282a9b80054a660c6495c1..beb1765427ee2c7ab2185a47666e47eb20a20a91 100644 (file)
@@ -8,39 +8,14 @@ package cpu
 
 const CacheLinePadSize = 128
 
-// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
-// These are initialized by archauxv and should not be changed after they are
-// initialized.
-// On aix/ppc64, these values are initialized early in the runtime in runtime/os_aix.go.
-var HWCap uint
-var HWCap2 uint
-
-// HWCAP/HWCAP2 bits. These are exposed by the kernel.
-const (
-       // ISA Level
-       PPC_FEATURE2_ARCH_2_07 = 0x80000000
-       PPC_FEATURE2_ARCH_3_00 = 0x00800000
-
-       // CPU features
-       PPC_FEATURE2_DARN = 0x00200000
-       PPC_FEATURE2_SCV  = 0x00100000
-)
-
 func doinit() {
        options = []option{
                {Name: "darn", Feature: &PPC64.HasDARN},
                {Name: "scv", Feature: &PPC64.HasSCV},
                {Name: "power9", Feature: &PPC64.IsPOWER9},
-
-               // These capabilities should always be enabled on ppc64 and ppc64le:
-               {Name: "power8", Feature: &PPC64.IsPOWER8, Required: true},
        }
 
-       // HWCAP2 feature bits
-       PPC64.IsPOWER8 = isSet(HWCap2, PPC_FEATURE2_ARCH_2_07)
-       PPC64.IsPOWER9 = isSet(HWCap2, PPC_FEATURE2_ARCH_3_00)
-       PPC64.HasDARN = isSet(HWCap2, PPC_FEATURE2_DARN)
-       PPC64.HasSCV = isSet(HWCap2, PPC_FEATURE2_SCV)
+       osinit()
 }
 
 func isSet(hwc uint, value uint) bool {
diff --git a/src/internal/cpu/cpu_ppc64x_aix.go b/src/internal/cpu/cpu_ppc64x_aix.go
new file mode 100644 (file)
index 0000000..b840b82
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2020 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 ppc64 ppc64le
+
+package cpu
+
+const (
+       // getsystemcfg constants
+       _SC_IMPL     = 2
+       _IMPL_POWER9 = 0x20000
+)
+
+func osinit() {
+       impl := getsystemcfg(_SC_IMPL)
+       PPC64.IsPOWER9 = isSet(impl, _IMPL_POWER9)
+}
+
+// getsystemcfg is defined in runtime/os2_aix.go
+func getsystemcfg(label uint) uint
diff --git a/src/internal/cpu/cpu_ppc64x_linux.go b/src/internal/cpu/cpu_ppc64x_linux.go
new file mode 100644 (file)
index 0000000..73b1914
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2020 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 ppc64 ppc64le
+
+package cpu
+
+// ppc64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
+// These are initialized by archauxv and should not be changed after they are
+// initialized.
+var HWCap uint
+var HWCap2 uint
+
+// HWCAP bits. These are exposed by Linux.
+const (
+       // ISA Level
+       hwcap2_ARCH_3_00 = 0x00800000
+
+       // CPU features
+       hwcap2_DARN = 0x00200000
+       hwcap2_SCV  = 0x00100000
+)
+
+func osinit() {
+       PPC64.IsPOWER9 = isSet(HWCap2, hwcap2_ARCH_3_00)
+       PPC64.HasDARN = isSet(HWCap2, hwcap2_DARN)
+       PPC64.HasSCV = isSet(HWCap2, hwcap2_SCV)
+}
index 31ac6ddf79a597ede9ecb4dd4abe4b87c48e4833..428ff7f225c3701019e6df7130c37680043d403b 100644 (file)
@@ -518,9 +518,10 @@ func sigaltstack(new, old *stackt) {
 }
 
 //go:nosplit
-func getsystemcfg(label uint) uintptr {
+//go:linkname internal_cpu_getsystemcfg internal/cpu.getsystemcfg
+func internal_cpu_getsystemcfg(label uint) uint {
        r, _ := syscall1(&libc_getsystemcfg, uintptr(label))
-       return r
+       return uint(r)
 }
 
 func usleep1(us uint32)
index 9a6b8aec7c167e835bbc55a147d27f52d16eb255..0c501be96a94c8366781c2f075cb9f117812d824 100644 (file)
@@ -7,7 +7,6 @@
 package runtime
 
 import (
-       "internal/cpu"
        "unsafe"
 )
 
@@ -94,7 +93,6 @@ func semawakeup(mp *m) {
 func osinit() {
        ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN))
        physPageSize = sysconf(__SC_PAGE_SIZE)
-       setupSystemConf()
 }
 
 // newosproc0 is a version of newosproc that can be called before the runtime
@@ -340,25 +338,6 @@ func walltime1() (sec int64, nsec int32) {
        return ts.tv_sec, int32(ts.tv_nsec)
 }
 
-const (
-       // getsystemcfg constants
-       _SC_IMPL     = 2
-       _IMPL_POWER8 = 0x10000
-       _IMPL_POWER9 = 0x20000
-)
-
-// setupSystemConf retrieves information about the CPU and updates
-// cpu.HWCap variables.
-func setupSystemConf() {
-       impl := getsystemcfg(_SC_IMPL)
-       if impl&_IMPL_POWER8 != 0 {
-               cpu.HWCap2 |= cpu.PPC_FEATURE2_ARCH_2_07
-       }
-       if impl&_IMPL_POWER9 != 0 {
-               cpu.HWCap2 |= cpu.PPC_FEATURE2_ARCH_3_00
-       }
-}
-
 //go:nosplit
 func fcntl(fd, cmd, arg int32) int32 {
        r, _ := syscall3(&libc_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg))