Commit Graph

38 Commits

Author SHA1 Message Date
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
Anton Kuklin
006507a758 cpu: add support for detecting AVX-512
The existing implementation hasn't AVX-512 detection support.
This patch extends cpu package with such a functionality.

Fixes golang/go#41288

Change-Id: Iaddd57c5ff6d73360b77886458b9210b6c446859
Reviewed-on: https://go-review.googlesource.com/c/sys/+/257937
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-09-28 20:51:50 +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
Joel Sing
d785dc2583 cpu: add missing build tag for linux
The code in this file is specific to linux and does not build on other
mips64x platforms.

Change-Id: Ic27eedf06f39a7d2c51f5b261d957eed04e5df0b
Reviewed-on: https://go-review.googlesource.com/c/sys/+/249318
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-19 17:11:15 +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
Tobias Klauser
f1bc736245 cpu: adjust godoc comment for hostByteOrder
This was changed in CL 194646 to no longer depend on the encoding/binary
package. Adjust the godoc comment as well.

Change-Id: I1f23dc83a4c1256ebce8a283623f79e1bd00da51
Reviewed-on: https://go-review.googlesource.com/c/sys/+/238037
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-15 20:00:32 +00:00
Tobias Klauser
2780627062 cpu: add all GOARCHes supported by gccgo
Extend hostByteOrder to return the correct byte order for all GOARCHes
currently supported by gccgo.

Change-Id: I019de33aa598c58fe75cd7ad55479e6fce82dd8e
Reviewed-on: https://go-review.googlesource.com/c/sys/+/237897
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-15 19:00:26 +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
Clément Chigot
1151b9dac4 cpu: add support for gccgo on aix
Change-Id: Icb963d94baf7a1876ce89d0c5fe8cee04bb50629
Reviewed-on: https://go-review.googlesource.com/c/sys/+/233717
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2020-05-15 09:58:57 +00:00
Tobias Klauser
062a44052d cpu: add mips64x feature detection
Follow CL 200579

Change-Id: Ibedd6569bda3d7836ccb77a7746ed0e5df13c633
Reviewed-on: https://go-review.googlesource.com/c/sys/+/221698
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-02 08:32:56 +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
344fec8e55 cpu: don't redeclare doinit on ppc64le
Follow-up fix for CL 206859. Also order the +build line alphabetically.

Change-Id: I568c8b3ee03161d4341c151e4ec7150cade51077
Reviewed-on: https://go-review.googlesource.com/c/sys/+/206864
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-13 16:50:28 +00:00
Tobias Klauser
2f3576d2c5 cpu: add basic support for GOARCH=riscv64
Updates golang/go#27532

Change-Id: I7250f272ff46f2765d498a97644fb570ae745a6c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/206860
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-13 15:47:02 +00:00
Tobias Klauser
e43da5d1f2 cpu: move empty doinit to own file
Avoids each GOARCH having to define an empty doinit for GOOS=linux

Change-Id: Ic7cea1be4a35c31593c4f867478194b82dd53613
Reviewed-on: https://go-review.googlesource.com/c/sys/+/206859
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-11-13 15:46:56 +00:00
John Papandriopoulos
c990c680b6 cpu: support ARM feature detection on Linux
Updates golang/go#33508

Change-Id: I9ea01090f5b4ac95c1a14881c305461bd4a7b5dd
Reviewed-on: https://go-review.googlesource.com/c/sys/+/190525
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2019-09-27 07:32:44 +00:00
Brad Fitzpatrick
7ad0cfa0b7 cpu: remove encoding/binary dependency
It's unnecessarily heavy, bringing in reflect, etc.

I'd like for this package to become a leaf package with no
dependencies so we can use it from the Go runtime directly and remove
internal/cpu.

Change-Id: I1794854add9ad87cc13b685bae4a039e1449c22d
Reviewed-on: https://go-review.googlesource.com/c/sys/+/194646
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
2019-09-11 20:15:28 +00:00
Tobias Klauser
749cb33bea cpu: add a space before build tag comment
Add a space before build tag comments so it corresponds to the format
documented at https://golang.org/pkg/go/build/.

Change-Id: Ia7c724daf70d419dec52a652188799441053a867
Reviewed-on: https://go-review.googlesource.com/c/sys/+/193198
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-09-04 15:47:56 +00:00
Tobias Klauser
5219a1e1c5 cpu: add missing linkname for libc_getsystemcfg on aix/ppc64
This fixes the aix/ppc64 build after CL 179178

Change-Id: Ie8d762b533c05d6ca262030b34ae137140896d44
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179317
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2019-05-29 13:00:38 +00:00
Brad Fitzpatrick
3626398d77 cpu: don't depend on the golang.org/x/sys/unix package for AIX
gccgo support can happen in a future CL.

Updates golang/go#32102

Change-Id: Ic9e8d7b3e413079d277bdba565551845a2b78121
Reviewed-on: https://go-review.googlesource.com/c/sys/+/179178
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2019-05-28 18:36:47 +00:00
Tobias Klauser
fead790013 cpu: use unix.Getsystemcfg to detect POWER8/POWER9 on aix/ppc64
Tested on an aix-ppc64 gomote builder.

Fixes golang/go#30732

Change-Id: I8e74dcde8bd4ded0f425c90eefe799970ebd325c
Reviewed-on: https://go-review.googlesource.com/c/sys/+/166466
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-12 06:12:37 +00:00
Ian Lance Taylor
584f3b12f4 cpu: add build tag to cpu_wasm.go
Fixes the build for Go versions before 1.11.

Fixes golang/go#30668

Change-Id: I0dfb2eafcbcbe7e466a3b0b5d20656be3e6f4982
Reviewed-on: https://go-review.googlesource.com/c/sys/+/166137
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-08 02:30:53 +00:00
Bryan C. Mills
b354f8bf4d cpu: define cacheLineSize and doinit for WASM
This fixes a build break when compiling this package with
GOOS=js / GOARCH=wasm.

Updates golang/go#30241

Change-Id: I0b35aa50a69370ed0d83c522e12ce7613c4c3ec4
Reviewed-on: https://go-review.googlesource.com/c/sys/+/165749
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-03-06 22:02:34 +00:00
Michael Munday
6c9a33b5f7 cpu: add CPU features for s390x
Add basic support for IBM Z (s390x) CPU feature (known as
'facilities') detection.

Note that some of these features are mandatory when using the Go
compiler (for example, ldisp and eimm) but aren't mandatory when
using gccgo.

Cryptographic function detection is not yet implemented for
gccgo.

Change-Id: Ic6494d0df0bc1c1ad1713c9ff11ae23fba03d215
Reviewed-on: https://go-review.googlesource.com/c/163003
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-02-28 11:51:10 +00:00
Tobias Klauser
92a0ff1e1e cpu: don't panic on error reading /proc/self/auxv
On Android /proc/self/auxv is not readable, leading to a panic in init.
Instead of panic'ing in this case, introduce the Initialized global bool
to report whether the CPU features were initialized i.e. /proc/self/auxv
was successfullly read.

Fixes golang/go#30413

Change-Id: Ib520f202990614a76bceb0bf9d19a88eadd13e10
Reviewed-on: https://go-review.googlesource.com/c/164057
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-28 07:16:10 +00:00
Tobias Klauser
b4e8571b14 cpu: fix build for GOARCH=ppc64{,le} on GOOS!=linux
The current implementation for ppc64{,le} only supports linux (through
HWCaps read from /proc/self/auxv) and fails to build e.g. on
aix/ppc64.

Change-Id: I5e1efe75c781fd08bc7bbe797df88295726ba62b
Reviewed-on: https://go-review.googlesource.com/c/162798
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-21 07:52:27 +00:00
Michael Munday
153ac47618 cpu: unexport HWCap and HWCap2
These are an implementation detail and should not have been
exported. This only affects Linux on platforms other than 386 and
amd64.

Fixes golang/go#30255.

Change-Id: Ib23b42a7309fd6093b6b9d8b6628de222a3928be
Reviewed-on: https://go-review.googlesource.com/c/163004
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-02-19 09:28:55 +00:00
Michael Munday
d0b11bdaac cpu: fix auxval parsing on big-endian systems
The words in auxval are encoded in native byte order.

I haven't added a test. This fix will be tested when s390x support
is added to the package.

Change-Id: I276f833660e6906c319995798faf9054ffc69461
Reviewed-on: https://go-review.googlesource.com/c/162902
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-02-15 14:29:49 +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
Tobias Klauser
2970a3744d cpu: detect RDRAND and RDSEED instructions on x86
Change-Id: I2d0094d64ba12f888758aeebdb43aed353ddeeb9
Reviewed-on: https://go-review.googlesource.com/c/160577
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-02-01 07:34:06 +00:00
Carlos Eduardo Seo
20be8e55dc cpu: add linux/ppc64x
Port from Go internal/cpu.

Fixes golang/go#25185

Change-Id: Id3cac18da6ffec9d10df755c4032ce3068ab634d
Reviewed-on: https://go-review.googlesource.com/c/152938
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-07 17:34:14 +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
Ian Lance Taylor
9527bec266 cpu: fix gccgo build
Current versions of gccgo report a redefinition error for both a
declaration and definition, as of https://golang.org/cl/93083.
Fix the last change to work with this.

Change-Id: Iae6a664fcc9fe97d4e3b7845a05dab3a8ad56830
Reviewed-on: https://go-review.googlesource.com/116776
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-06 20:27:47 +00:00
Alex Vaghin
bc2ef10f1b cpu: add gccgo implementation
It uses __get_cpuid_count, provided by cpuid.h.
The xgetbv is implemented after its counterpart in cpu_x86.s.

Change-Id: I97624d7da67ab4ec3c9a53b0bfc4dfcdf7d12c87
Reviewed-on: https://go-review.googlesource.com/116155
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-06-06 16:53:29 +00:00
Tobias Klauser
538ab54ba9 cpu: introduce and export type CacheLinePad
Add a CacheLinePad struct type that has a size of cacheLineSize.
This can be used for padding structs in order to avoid false sharing.

Fixes golang/go#25203

Change-Id: I6b6daf91ea0e9c50428ffa053035429c3921b461
Reviewed-on: https://go-review.googlesource.com/111775
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-06-06 11:15:58 +00:00
Tobias Klauser
7db1c3b1a9 cpu: use t.Fatal instead of t.Fatalf
The messages contain no format string, so there is no need to use
t.Fatalf.

Change-Id: I29098c04797f919784b732af84a63fbaed671558
Reviewed-on: https://go-review.googlesource.com/111776
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-05-07 13:57:25 +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