// ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
// These are initialized by archauxv in runtime/os_linux_ppc64x.go.
// These 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
+ PPC_FEATURE2_ARCH_2_07 = 0x80000000
+ PPC_FEATURE2_ARCH_3_00 = 0x00800000
// CPU features
- _PPC_FEATURE2_DARN = 0x00200000
- _PPC_FEATURE2_SCV = 0x00100000
+ PPC_FEATURE2_DARN = 0x00200000
+ PPC_FEATURE2_SCV = 0x00100000
)
func doinit() {
}
// 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)
+ 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)
}
func isSet(hwc uint, value uint) bool {
//go:cgo_import_dynamic libc_close close "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_exit exit "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_getpid getpid "libc.a/shr_64.o"
+//go:cgo_import_dynamic libc_getsystemcfg getsystemcfg "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_kill kill "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_madvise madvise "libc.a/shr_64.o"
//go:cgo_import_dynamic libc_malloc malloc "libc.a/shr_64.o"
//go:linkname libc_close libc_close
//go:linkname libc_exit libc_exit
//go:linkname libc_getpid libc_getpid
+//go:linkname libc_getsystemcfg libc_getsystemcfg
//go:linkname libc_kill libc_kill
//go:linkname libc_madvise libc_madvise
//go:linkname libc_malloc libc_malloc
libc_close,
libc_exit,
libc_getpid,
+ libc_getsystemcfg,
libc_kill,
libc_madvise,
libc_malloc,
}
}
+//go:nosplit
+func getsystemcfg(label uint) uintptr {
+ r, _ := syscall1(&libc_getsystemcfg, uintptr(label))
+ return r
+}
+
//go:nosplit
func usleep(us uint32) {
r, err := syscall1(&libc_usleep, uintptr(us))
package runtime
import (
+ "internal/cpu"
"unsafe"
)
func osinit() {
ncpu = int32(sysconf(__SC_NPROCESSORS_ONLN))
physPageSize = sysconf(__SC_PAGE_SIZE)
+ setupSystemConf()
}
// Ms related functions
}
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
+ }
+}