19 Commits

Author SHA1 Message Date
Cherry Mui
4f4f1c6fea Revert "cpu: add HPDS, LOR, PAN detection for arm64"
This reverts CL 704075.

Reason for revert: Based on golang/go#76386, it doesn't seem to work correctly.

Fixes golang/go#76386.

Change-Id: I51ccbc8715c25c0d061d56dfbf0e8158f1207018
Reviewed-on: https://go-review.googlesource.com/c/sys/+/724160
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>
2025-11-24 15:42:25 -08:00
Chongyi Zheng
6239615695 cpu: add HPDS, LOR, PAN detection for arm64
This CL gets ID_AA64MMFR1_EL1, Memory Model Feature Register 1, and
grabs HPDS, LOR, PAN features from its bits.

Fixes golang/go#75472.

Change-Id: Ic04b109d79aceba9b3b1d3a1ea514fcf132007c5
GitHub-Last-Rev: f938ff468b
GitHub-Pull-Request: golang/sys#263
Reviewed-on: https://go-review.googlesource.com/c/sys/+/704075
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
2025-10-28 09:43:50 -07:00
Hernan Martinez
7bb0bf703b cpu: add Int8 matrix multiplication instructions CPU feature flag for ARM64
References:
5bbd9b2498/arch/arm64/include/uapi/asm/hwcap.h (L75C9-L75C31)

https://developer.arm.com/documentation/ddi0601/2024-03/AArch64-Registers/ID-AA64ISAR1-EL1--AArch64-Instruction-Set-Attribute-Register-1

Change-Id: Ic4e1cf2c23097c7e8695453b6d0b335756d474bc
Reviewed-on: https://go-review.googlesource.com/c/sys/+/595678
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-07-17 17:57:00 +00:00
Roland Shoemaker
0c18c88c71 cpu: add DIT option and hwcap DIT support
Follow-up to https://go.dev/cl/597377, add a option for DIT so it can be
set via GODEBUG, and add hwcap support for Linux.

Change-Id: Ib094b520edea9c099d37f121b09d02b31644a433
Reviewed-on: https://go-review.googlesource.com/c/sys/+/598719
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-07-17 01:04:09 +00:00
Roland Shoemaker
47fe916942 cpu: add support for DIT detection
Change-Id: I9f0991da9684ebd297e40a754e34130c418c34d0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/597377
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-11 16:45:38 +00:00
Michal Hruby
7758090324 cpu: add support for sve2 detection
Fixes golang/go#66952

Change-Id: Idaf2ce3b09baf33cf29079677a83a51ea9c4b255
GitHub-Last-Rev: eac00886d1
GitHub-Pull-Request: golang/sys#193
Reviewed-on: https://go-review.googlesource.com/c/sys/+/580655
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2024-05-03 16:45:19 +00:00
Pure White
20c2bfdbfe cpu: fix cpu cacheLineSize for arm64 darwin(a.k.a. M1)
The existing value for M1 is 64, which is the same as other arm64 cpus.
But the correct cacheLineSize for M1 should be 128, which can be
verified using the following command:

$ sysctl -a hw | grep cachelinesize
hw.cachelinesize: 128

Fixes golang/go#53075

Change-Id: I555716ed412cdc02941c8b1d9767952f7ad6678c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/408614
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-08-23 22:43:34 +00:00
Joel Sing
3d627bb497 cpu: implement CPU feature detection for openbsd/arm64
OpenBSD 7.1 onwards expose the aarch64 ISAR0 and ISAR1 registers via sysctl:

  $ sysctl machdep
  machdep.compatible=apple,j274
  machdep.id_aa64isar0=153421459058925856
  machdep.id_aa64isar1=1172796674562

Implement CPU feature detection for openbsd/arm64 based on this information.

Updates golang/go#31746

Change-Id: I6dc473d93ccff720582c05b75456de51269bc3e5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/421799
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-08-08 15:39:00 +00:00
Tobias Klauser
ef9fd89ba2 cpu: read ARM64 registers using sysctl(3) on netbsd/arm64
Use sysctl("machdep.cpu0.cpu_id") to retrieve the ARM64 cpu_id
information on netbsd/arm64. This includes the ISAR0, ISAR1 and PFR0
registers which can be parsed using existing functionality.

In order to use sysctl(3) without depending on x/sys/unix, some
functionality needed to be copied and slightly adjusted.

Change-Id: Ic9a133917ae5da516e6794f375bd7602d9bd3aa6
Reviewed-on: https://go-review.googlesource.com/c/sys/+/264378
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
2020-10-24 13:24:49 +00:00
Tobias Klauser
fb209a7c41 cpu: refactor parsing of ARM64 registers into separate function
This will allow to re-use the implementation when adding support for
netbsd/arm64 which will retreive these register values using sysctl(3).

Change-Id: I2414cc4c6d1a91fff946466e4bf6d95d07f30137
Reviewed-on: https://go-review.googlesource.com/c/sys/+/264377
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2020-10-22 20:17:47 +00:00
Tobias Klauser
98379d014c cpu: avoid illegal instruction on openbsd/arm64
On OpenBSD, this package tries to read a privileged register, which
results in a SIGILL. Use the same workaround as Android, iOS and NetBSD.

Update golang/go#31746

Change-Id: I981249310169bc30b018c1a157529a4e46597d81
Reviewed-on: https://go-review.googlesource.com/c/sys/+/263337
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
2020-10-18 12:10:11 +00:00
Cherry Zhang
d9f96fdee2 all: add GOOS=ios
Following CL 254740, this CL does it on x/sys.

Updates golang/go#38485.

Change-Id: I5eab09a9a87c87fc883b5701434415648fb28eb0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/255557
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-09-23 18:26:05 +00:00
Polina Osadcha
0cf7623e9d cpu: add GODEBUG options to disable use of instruction set extensions
The GODEBUG environment variable can be used to disable usage of
specific processor features of Go programs that use the sys/cpu package.
This is useful for testing and benchmarking different code paths that
are guarded by sys/cpu variable checks.

Use of processor features can not be enabled through GODEBUG.

To disable usage of AVX and SSE41 cpu features on GOARCH amd64 use:
GODEBUG=cpu.avx=off,cpu.sse41=off

The special "all" option can be used to disable all options:
GODEBUG=all=off

This aligns the support of GODEBUG for sys/cpu with existing support
for GODEBUG in the Go standard library package internal/cpu.

Fixes golang/go#33963

Change-Id: I618b71af397bf06c57a49b2a300d032a16d05664
Reviewed-on: https://go-review.googlesource.com/c/sys/+/245237
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-08-05 06:55:43 +00:00
Benny Siegert
0598657881 cpu: avoid illegal instruction on netbsd/arm64
On NetBSD, this package tries to read a privileged register,
which results in a SIGILL. Use the same workaround as Android and
iOS. In the future, we could use sysctl(3) instead.

Update golang/go#30824

Change-Id: Ifd9aa2a2cf4dac43341d013602d1ccb4b8d6eb6d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/235097
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-05-23 22:24:54 +00:00
Tobias Klauser
59e60aa80a cpu: don't read ARM64 registers on Android
It seems like on Android we're not allowed in all cases to read the
registers ISAR0, ISAR1 and PFR0 to detect CPU features.

Fixes golang/go#36622

Change-Id: I577bd928a5a4dcd6e908cf059faa15fc0c80e3e5
Reviewed-on: https://go-review.googlesource.com/c/sys/+/215237
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-01-17 14:54:32 +00:00
Tobias Klauser
85b82a3add cpu: support reading arm64 CPU feature registers
This allows to detect ARM64 CPU features on non-Linux systems. On Linux,
this is used in case /proc/self/auxv cannot be read.

Change-Id: I67d55e989f2beda0c05a97ca5e55781840a8e01c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/209478
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-12-04 07:21:56 +00:00
Tobias Klauser
e77772198c cpu: fix build for GOARCH=arm64 on GOOS!=linux
The current implementation for arm64 only supports linux (through HWCaps
read from /proc/self/auxv) and fails to build e.g. on darwin/arm64.

Fixes golang/go#30237

Change-Id: I9f32a285760795441a829b0a81b2d5aff04e2dc4
Reviewed-on: https://go-review.googlesource.com/c/162797
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-14 21:44:11 +00:00
Meng Zhuo
70b957f3b6 cpu: add linux/arm64
Port from Go internal/cpu

Updates golang/go#25185

Change-Id: I8390980e38b61f6c428fafa0665a03952e7b00bb
Reviewed-on: https://go-review.googlesource.com/c/150718
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-12-06 07:42:57 +00:00
Andreas Auernhammer
4adea008a5 cpu: new package
This CL introduces a new cpu package for CPU/platform feature detection.
The cpu package is basically a copy of `internal/cpu` of the standard library.
Revision: bf86aec25972f3a100c3aa58a6abcbcc35bdea49

This CL does not export ARM64 and PPC64 feature detection since at the moment
ARM64/PPC64 requires standard library support.

Updates golang/go#24843

Change-Id: I11bc1ca60b116e902c941b5887c00870dbb1f899
Reviewed-on: https://go-review.googlesource.com/107015
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-30 17:35:09 +00:00