From 51859ec2292d9c1d82a7054ec672ff551a0d7497 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Thu, 5 May 2022 10:27:24 -0500 Subject: [PATCH] internal/cpu: report CPU if known on PPC64 The PPC64 maintainers are testing on P10 hardware, so it is helpful to report the correct cpu, even if this information is not used elsewhere yet. Note, AIX will report the current CPU of the host system, so a POWER10 will not set the IsPOWER9 flag. This is existing behavior, and should be fixed in a separate patch. Change-Id: Iebe23dd96ebe03c8a1c70d1ed2dc1506bad3c330 Reviewed-on: https://go-review.googlesource.com/c/go/+/404394 TryBot-Result: Gopher Robot Run-TryBot: Paul Murphy Reviewed-by: Lynn Boger Reviewed-by: Michael Knyszek Reviewed-by: David Chase Reviewed-by: Heschi Kreinick --- src/internal/cpu/cpu.go | 13 +++++++------ src/internal/cpu/cpu_no_name.go | 2 +- src/internal/cpu/cpu_ppc64x.go | 12 ++++++++++++ src/internal/cpu/cpu_ppc64x_aix.go | 8 ++++++-- src/internal/cpu/cpu_ppc64x_linux.go | 2 ++ 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 30745344e1c..ae23b59617a 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -81,12 +81,13 @@ var MIPS64X struct { // those as well. The minimum processor requirement is POWER8 (ISA 2.07). // The struct is padded to avoid false sharing. var PPC64 struct { - _ CacheLinePad - HasDARN bool // Hardware random number generator (requires kernel enablement) - HasSCV bool // Syscall vectored (requires kernel enablement) - IsPOWER8 bool // ISA v2.07 (POWER8) - IsPOWER9 bool // ISA v3.00 (POWER9) - _ CacheLinePad + _ CacheLinePad + HasDARN bool // Hardware random number generator (requires kernel enablement) + HasSCV bool // Syscall vectored (requires kernel enablement) + IsPOWER8 bool // ISA v2.07 (POWER8) + IsPOWER9 bool // ISA v3.00 (POWER9) + IsPOWER10 bool // ISA v3.1 (POWER10) + _ CacheLinePad } var S390X struct { diff --git a/src/internal/cpu/cpu_no_name.go b/src/internal/cpu/cpu_no_name.go index 37de951ba6d..2adfa1b7099 100644 --- a/src/internal/cpu/cpu_no_name.go +++ b/src/internal/cpu/cpu_no_name.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !386 && !amd64 +//go:build !386 && !amd64 && !ppc64 && !ppc64le package cpu diff --git a/src/internal/cpu/cpu_ppc64x.go b/src/internal/cpu/cpu_ppc64x.go index 83687d6ed34..c4a08fe1bd9 100644 --- a/src/internal/cpu/cpu_ppc64x.go +++ b/src/internal/cpu/cpu_ppc64x.go @@ -21,3 +21,15 @@ func doinit() { func isSet(hwc uint, value uint) bool { return hwc&value != 0 } + +func Name() string { + switch { + case PPC64.IsPOWER10: + return "POWER10" + case PPC64.IsPOWER9: + return "POWER9" + case PPC64.IsPOWER8: + return "POWER8" + } + return "" +} diff --git a/src/internal/cpu/cpu_ppc64x_aix.go b/src/internal/cpu/cpu_ppc64x_aix.go index d518edcf490..f05ed6fad8a 100644 --- a/src/internal/cpu/cpu_ppc64x_aix.go +++ b/src/internal/cpu/cpu_ppc64x_aix.go @@ -8,13 +8,17 @@ package cpu const ( // getsystemcfg constants - _SC_IMPL = 2 - _IMPL_POWER9 = 0x20000 + _SC_IMPL = 2 + _IMPL_POWER8 = 0x10000 + _IMPL_POWER9 = 0x20000 + _IMPL_POWER10 = 0x40000 ) func osinit() { impl := getsystemcfg(_SC_IMPL) + PPC64.IsPOWER8 = isSet(impl, _IMPL_POWER8) PPC64.IsPOWER9 = isSet(impl, _IMPL_POWER9) + PPC64.IsPOWER10 = isSet(impl, _IMPL_POWER10) } // getsystemcfg is defined in runtime/os2_aix.go diff --git a/src/internal/cpu/cpu_ppc64x_linux.go b/src/internal/cpu/cpu_ppc64x_linux.go index 0fe86678433..9df82ca8a50 100644 --- a/src/internal/cpu/cpu_ppc64x_linux.go +++ b/src/internal/cpu/cpu_ppc64x_linux.go @@ -17,6 +17,7 @@ const ( // ISA Level hwcap2_ARCH_2_07 = 0x80000000 hwcap2_ARCH_3_00 = 0x00800000 + hwcap2_ARCH_3_1 = 0x00040000 // CPU features hwcap2_DARN = 0x00200000 @@ -26,6 +27,7 @@ const ( func osinit() { PPC64.IsPOWER8 = isSet(HWCap2, hwcap2_ARCH_2_07) PPC64.IsPOWER9 = isSet(HWCap2, hwcap2_ARCH_3_00) + PPC64.IsPOWER10 = isSet(HWCap2, hwcap2_ARCH_3_1) PPC64.HasDARN = isSet(HWCap2, hwcap2_DARN) PPC64.HasSCV = isSet(HWCap2, hwcap2_SCV) }