klauspost / cpuid Goto Github PK
View Code? Open in Web Editor NEWCPU feature identification for Go
License: MIT License
CPU feature identification for Go
License: MIT License
I listened to your suggestion.
now use github.com/klauspost/cpuid as import path, but it shows
github.com/go-sql-driver/mysql
../../go-sql-driver/mysql/driver.go:88:33: undefined: driver.Connector
../../go-sql-driver/mysql/driver.go:99:49: undefined: driver.Connector
../../go-sql-driver/mysql/nulltime.go:36:15: undefined: sql.NullTime
github.com/klauspost/cpuid
../../klauspost/cpuid/cpuid.go:394:30: syntax error: unexpected _000_000 at end of statement
../../klauspost/cpuid/cpuid.go:398:37: syntax error: unexpected _000_000 at end of statement
$ cpuid --version
cpuid version 20230505
$ cpuid -1 |grep synth
(family synth) = 0x6 (6)
(model synth) = 0x8f (143)
(simple synth) = Intel Xeon (unknown type) (Sapphire Rapids E5/B3) {Golden Cove}, Intel 7
(size synth) = 49152 (48 KB)
(size synth) = 32768 (32 KB)
(size synth) = 2097152 (2 MB)
(size synth) = 110100480 (105 MB)
(QoS monitoring counter size synth) = 32
(vuln to branch type confusion synth) = true
(multi-processing synth) = multi-core (c=56), hyper-threaded (t=2)
(APIC widths synth): CORE_width=6 SMT_width=1
(APIC synth): PKG_ID=1 CORE_ID=53 SMT_ID=1
(uarch synth) = Intel Sapphire Rapids {Golden Cove}, Intel 7
(synth) = Intel Scalable (4th Gen) Bronze/Silver/Gold/Platinum (Sapphire Rapids E5/B3) {Golden Cove}, Intel 7
$ cpuid -1 |grep uarch
(uarch synth) = Intel Sapphire Rapids {Golden Cove}, Intel 7
I was go get
ing your reedsolomon module, which happened to install this one as well. I'm given this error:
XXXXXXXXX:XXXXX$ go get -u -v github.com/klauspost/cpuid
github.com/klauspost/cpuid (download)
github.com/klauspost/cpuid
# github.com/klauspost/cpuid
../go/src/github.com/klauspost/cpuid/cpuid.go:443:31: invalid operation: 1 << (feat & flagMask) (shift count type FeatureID, must be unsigned integer)
../go/src/github.com/klauspost/cpuid/cpuid.go:447:29: invalid operation: 1 << (feat & flagMask) (shift count type FeatureID, must be unsigned integer)
../go/src/github.com/klauspost/cpuid/cpuid.go:454:33: invalid operation: 1 << (offset & flagMask) (shift count type FeatureID, must be unsigned integer)
../go/src/github.com/klauspost/cpuid/cpuid.go:460:17: invalid operation: 1 << (offset & flagMask) (shift count type FeatureID, must be unsigned integer)
Is this an error with my system? I'm using Debian 10 x64, if that helps. Thank you.
The lack of a reverse map for https://github.com/klauspost/cpuid/blob/v1.2.4/cpuid.go#L24-L37 is annoying. The fact that https://github.com/klauspost/cpuid/blob/v1.2.4/cpuid.go#L815-L831 is private makes it essentially impossible to construct such a map without hardcoding names on the implementor side.
Thank you for the otherwise amazing module!
Hello I am using kcp-go v5.4.20, this library uses reedsolomon which links to cpuid v 1.3.0
I am getting the following error when trying to listen for a kcp connection when fecDecoder-> reedsolomon which calls the cpuid.initCPU function
--------- beginning of crash
2021-03-28 19:22:56.131 887-924/com.example.mobinet A/libc: Fatal signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0x7e852c59f0 in tid 924 (example.mobinet), pid 887 (example.mobinet)
2021-03-28 19:22:56.166 933-933/? E/crash_dump64: unknown process state: t
2021-03-28 19:22:56.185 933-933/? I/crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone
2021-03-28 19:22:56.186 4738-4738/? I//system/bin/tombstoned: received crash request for pid 924
2021-03-28 19:22:56.187 933-933/? I/crash_dump64: performing dump of process 887 (target tid = 924)
2021-03-28 19:22:56.197 933-933/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-03-28 19:22:56.197 933-933/? A/DEBUG: Build fingerprint: 'samsung/starlteser/starlte:10/QP1A.190711.020/G960FXXU8DTC5:user/release-keys'
2021-03-28 19:22:56.197 933-933/? A/DEBUG: Revision: '26'
2021-03-28 19:22:56.197 933-933/? A/DEBUG: ABI: 'arm64'
2021-03-28 19:22:56.201 933-933/? A/DEBUG: Timestamp: 2021-03-28 19:22:56+0600
2021-03-28 19:22:56.201 933-933/? A/DEBUG: pid: 887, tid: 924, name: example.mobinet >>> com.example.mobinet <<<
2021-03-28 19:22:56.201 933-933/? A/DEBUG: uid: 10350
2021-03-28 19:22:56.201 933-933/? A/DEBUG: signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0x7e852c59f0 (*pc=0xd5380400)
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x0 0000007e8587f300 x1 000000400010a3a0 x2 000000400010b5a0 x3 0000000000000000
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x4 0000000000000000 x5 0000000000000004 x6 0000007e8581bbe0 x7 0000000000000001
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x8 0000000000000002 x9 0000000000000004 x10 0000000000000000 x11 000000000000000d
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x12 0000000000000001 x13 0000007e851227e8 x14 0000000000000000 x15 000802aaaa00aaaa
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x16 0000000000000000 x17 0000000000000034 x18 0000007e840a8000 x19 0000000000000068
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x20 00000000000000d0 x21 0000004000146118 x22 fffffffffffffff7 x23 0000000000000008
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x24 ffffffffffffffa2 x25 0000007e85536a20 x26 0000007e8581bbe8 x27 fffffffffffffffb
2021-03-28 19:22:56.201 933-933/? A/DEBUG: x28 0000004000000180 x29 0000000000000000
2021-03-28 19:22:56.201 933-933/? A/DEBUG: sp 000000400010b570 lr 0000007e852c4a28 pc 0000007e852c59f0
2021-03-28 19:22:56.207 933-933/? A/DEBUG: backtrace:
2021-03-28 19:22:56.207 933-933/? A/DEBUG: #00 pc 000000000043f9f0 /data/app/com.example.mobinet-RRxiKLjoy_9misXpo2RfEw==/lib/arm64/libgojni.so (github.com/klauspost/cpuid.initCPU+192)
how can I avoid this error without changing the code of the libraries ?
$ go test
SIGILL: illegal instruction
PC=0x497234 m=0
goroutine 67 [running]:
github.com/klauspost/cpuid.asmXgetbv(0x6874754100000000, 0x4080000600f01, 0x178bfbff1e98220b, 0xd0047edfa, 0x4080000000001, 0x408001e98220b, 0x2000078017f1, 0x47dd77, 0x15, 0x0, ...)
/home/anoobis/PRO/go/src/github.com/klauspost/cpuid/cpuid_amd64.s:29 +0x4 fp=0xc82009db50 sp=0xc82009db48
github.com/klauspost/cpuid.support(0x15)
/home/anoobis/PRO/go/src/github.com/klauspost/cpuid/cpuid.go:793 +0x21a fp=0xc82009db90 sp=0xc82009db50
github.com/klauspost/cpuid.Detect()
/home/anoobis/PRO/go/src/github.com/klauspost/cpuid/cpuid.go:191 +0x97 fp=0xc82009dbb8 sp=0xc82009db90
github.com/klauspost/cpuid.TestMocks(0xc8200a2360)
/home/anoobis/PRO/go/src/github.com/klauspost/cpuid/mockcpu_test.go:147 +0x70e fp=0xc82009df58 sp=0xc82009dbb8
testing.tRunner(0xc8200a2360, 0x6b9e30)
/opt/go/src/testing/testing.go:456 +0x98 fp=0xc82009df90 sp=0xc82009df58
runtime.goexit()
/opt/go/src/runtime/asm_amd64.s:1696 +0x1 fp=0xc82009df98 sp=0xc82009df90
created by testing.RunTests
/opt/go/src/testing/testing.go:561 +0x86d
goroutine 1 [chan receive]:
testing.RunTests(0x61c410, 0x6b9860, 0x3f, 0x3f, 0x1)
/opt/go/src/testing/testing.go:562 +0x8ad
testing.(*M).Run(0xc820047f08, 0xc82000a7d0)
/opt/go/src/testing/testing.go:494 +0x70
main.main()
github.com/klauspost/cpuid/_test/_testmain.go:178 +0x116
rax 0x2000038017f1
rbx 0x497230
rcx 0x0
rdx 0x61c3e8
rdi 0x40800
rsi 0x40800
rbp 0x600f01
rsp 0xc82009db48
r8 0xc82009d8e0
r9 0x2c
r10 0x0
r11 0x0
r12 0x2
r13 0x619d4d
r14 0x2
r15 0x8
rip 0x497234
rflags 0x10246
cs 0x33
fs 0x0
gs 0x0
exit status 2
FAIL github.com/klauspost/cpuid 0.076s
OS: Linux 3.13.0-52-generic x86_64
CPU: AMD64 Athlon X2
go version go1.5 linux/amd64
cpuid_test.go:21: Name: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
cpuid_test.go:22: PhysicalCores: 1
cpuid_test.go:23: ThreadsPerCore: 1
cpuid_test.go:24: LogicalCores: 1
Found this as it affects minio, which uses cpuid, but it is easily reproducible just using the example program. Running that example program on my machine hangs for about an hour, then the program continues normally. Seems to be due to this for-loop which loops about 4 billion times on my machine.
Here is my CPU spec (from /proc/cpuinfo
) if it helps:
processor : 0
vendor_id : AuthenticAMD
cpu family : 25
model : 80
model name : AMD Ryzen 7 5700G with Radeon Graphics
stepping : 0
microcode : 0xa50000c
cpu MHz : 3792.874
cache size : 512 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch bpext ssbd ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr arat umip pku ospke vaes vpclmulqdq rdpid
bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips : 7585.74
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : AuthenticAMD
cpu family : 25
model : 80
model name : AMD Ryzen 7 5700G with Radeon Graphics
stepping : 0
microcode : 0xa50000c
cpu MHz : 3792.874
cache size : 512 KB
physical id : 0
siblings : 4
core id : 2
cpu cores : 4
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch bpext ssbd ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr arat umip pku ospke vaes vpclmulqdq rdpid
bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips : 7608.95
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : AuthenticAMD
cpu family : 25
model : 80
model name : AMD Ryzen 7 5700G with Radeon Graphics
stepping : 0
microcode : 0xa50000c
cpu MHz : 3792.874
cache size : 512 KB
physical id : 0
siblings : 4
core id : 4
cpu cores : 4
apicid : 4
initial apicid : 4
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch bpext ssbd ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr arat umip pku ospke vaes vpclmulqdq rdpid
bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips : 7618.22
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : AuthenticAMD
cpu family : 25
model : 80
model name : AMD Ryzen 7 5700G with Radeon Graphics
stepping : 0
microcode : 0xa50000c
cpu MHz : 3792.874
cache size : 512 KB
physical id : 0
siblings : 4
core id : 6
cpu cores : 4
apicid : 6
initial apicid : 6
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm rep_good nopl cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cr8_legacy abm sse4a misalignsse 3dnowprefetch bpext ssbd ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr arat umip pku ospke vaes vpclmulqdq rdpid
bugs : sysret_ss_attrs null_seg spectre_v1 spectre_v2 spec_store_bypass
bogomips : 7608.25
TLB size : 2560 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management:
cpu id considered as a 0xabcdaaaa something like.
Processor Information (dmidecode):
cpuid:
ADX,AESNI,AVX,AVX2,AVXVNNI,BHI_CTRL,BMI1,BMI2,CETIBT,CETSS,CLMUL,CMOV,CMPXCHG8,CX16,ERMS,F16C,FLUSH_L1D,FMA3,FSRM,FXSR,FXSROPT,GFNI,HRESET,HTT,HYBRID_CPU,IA32_ARCH_CAP,IA32_CORE_CAP,IBPB,IDPRED_CTRL,KEYLOCKER,LAHF,LZCNT,MD_CLEAR,MMX,MOVBE,MOVDIR64B,MOVDIRI,NX,OSXSAVE,POPCNT,PSFD,RDRAND,RDSEED,RDTSCP,RRSBA_CTRL,SERIALIZE,SHA,SPEC_CTRL_SSBD,SSE,SSE2,SSE3,SSE4,SSE42,SSSE3,STIBP,STOSB_SHORT,SYSCALL,SYSEE,VAES,VMX,VPCLMULQDQ,WAITPKG,X87,XGETBV1,XSAVE,XSAVEC,XSAVEOPT,XSAVES
A few months ago, @fosslinux reported that this code package looped forever under Xen. This has since been fixed, but it turns out that this code does not check if TOPOEXT is exposed before using it. Feel free to close if this has since been fixed.
It would be good to have support for AMD SME and SEV and Intel TME cpuids.
Hello,
Can you please tag and version this project?
I am the Debian Maintainer for cpuid and versioning would help Debian keep up with development.
Assuming it's trivial, can you please add virtualbox support?
Thanks.
For desktop, I have Windows 10 Pro as OS on my machine . but cpuid.CPU.VM() this call returning true for my Desktop machine. as it is desktop machine it should return true. attached sample screen shot for reference.
Attaching code sample as well.
main.go.txt
anyone help me on this.
main.go:7:2: cannot find package "github.com/klauspost/cpuid/v2" in any of:
/usr/lib/golang/src/github.com/klauspost/cpuid/v2 (from $GOROOT)
/tmp/src/github.com/klauspost/cpuid/v2 (from $GOPATH)
Hi @klauspost
What would you say should be the method to detect if the cpu architecture is one of amd64 or arm64?
Hi all,
@klauspost
@abourget
@ebfe
I'm from ARM. Currently I want to enable this project on arm64 platform.
Before the contribution, our legal team want to check inbound & outbound license.
I have found the outbound license, but didn't found the inbound license.
In general, the inbound license should be 'Developer Certificate of Origin, version 1.1'.
The legal information of inbound license should be in the file of 'CONTRIBUTING.md'.
And the legal information of outbound license should be in the file 'LICENSE'
Please see the project of 'runc' as reference:
https://github.com/opencontainers/runc/blob/master/CONTRIBUTING.md
https://github.com/opencontainers/runc/blob/master/LICENSE
Thanks.
Library incorrectly detects ThreadsPerCore count, so PhysicalCore value is also wrong:
Name: Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
PhysicalCores: 1
ThreadsPerCore: 16
LogicalCores: 16
Family 6 Model: 45
This is pretty horrible. Make a v2.
At first it seemed simple to just do the PR myself, but there were parts of the code I didn't understand, so I'm requesting the change instead...
Intel's Transactional Synchronization Extensions (TSX) support is somewhat unpredictable, given that there was a bug that led it to be disabled in Haswell and many Broadwell CPUs, and that it's not included in every Skylake and Kaby Lake model. So having it in CPUID would be especially helpful.
Currently only supports arm64, can support arm?
A number of processors support AVX but implement it by passing the vector though a 128 bit SSE ALU twice instead of using a 256 bit ALU. On these processors, AVX is thus not much faster than SSE. It would be great to have a feature flag that reports whether the current processor is afflicted by this problem. As far as I'm concerned, this affects the following processors, but I'm not super sure:
cpuid
output from Ubuntu VM running under VMware ESXi (note the number of Physical/Logical cores):
$ cpuid
Name: Intel(R) Xeon(R) CPU X5690 @ 3.47GHz
Vendor String: GenuineIntel
Vendor ID: Intel
PhysicalCores: 0
Threads Per Core: 1
Logical Cores: 0
CPU Family 6 Model: 44 Stepping: 2
Features: CMOV,CMPXCHG8,CX16,FXSR,FXSROPT,HYPERVISOR,LAHF,MMX,NX,OSXSAVE,POPCNT,RDTSCP,SSE,SSE2,SSE3,SSE4,SSE42,SSSE3,SYSCALL,SYSEE,X87,XSAVE
Microarchitecture level: 2
Cacheline bytes: 64
L1 Instruction Cache: 32768 bytes
L1 Data Cache: 32768 bytes
L2 Cache: 262144 bytes
L3 Cache: 12582912 bytes
Frequency: 3470000000 Hz
lscpu
reports the correct number of cores:
$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 40 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 44
Model name: Intel(R) Xeon(R) CPU X5690 @ 3.47GHz
Stepping: 2
CPU MHz: 3466.789
BogoMIPS: 6933.57
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 64 KiB
L1i cache: 64 KiB
L2 cache: 512 KiB
L3 cache: 24 MiB
NUMA node0 CPU(s): 0-3
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: KVM: Vulnerable
Vulnerability L1tf: Mitigation; PTE Inversion
Vulnerability Mds: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
Vulnerability Meltdown: Mitigation; PTI
Vulnerability Mmio stale data: Unknown: No mitigations
Vulnerability Retbleed: Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Retpolines, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl tsc_reli
able nonstop_tsc cpuid pni ssse3 cx16 sse4_1 sse4_2 popcnt hypervisor lahf_lm pti arat
Reference code:
https://github.com/klauspost/cpuid/blob/master/cpuid.go#L996
According to the System V Application Binary Interface - AMD64 Architecture Processor Supplement, section 3.1.1:
Any program can expect that an AMD64 processor implements the baseline features mentioned in table 3.1. Most feature names correspond to CPUID bits, as described in the
processor manual. Exceptions are OSFXSR and SCE, which are controlled by bits in the
%cr4 register and the IA32_EFER MSR.
I understand that the presence of SCE must be checked using the MSR register
(You can generate the PDF mentioned above from https://gitlab.com/x86-psABIs/x86-64-ABI)
../github.com/klauspost/cpuid/cpuid.go:441:31: invalid operation: 1 << (feat & flagMask) (shift count type FeatureID, must be unsigned integer)
../github.com/klauspost/cpuid/cpuid.go:445:29: invalid operation: 1 << (feat & flagMask) (shift count type FeatureID, must be unsigned integer)
../github.com/klauspost/cpuid/cpuid.go:452:33: invalid operation: 1 << (offset & flagMask) (shift count type FeatureID, must be unsigned integer)
../github.com/klauspost/cpuid/cpuid.go:458:17: invalid operation: 1 << (offset & flagMask) (shift count type FeatureID, must be unsigned integer)
Build the example program on:
lsb_release:
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
uname -a:
Linux pi64 5.4.0-1023-raspi #26-Ubuntu SMP PREEMPT Thu Nov 12 14:58:33 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux
From /proc/cpuinfo:
...
Hardware : BCM2835
Revision : c03111
Serial : 1000000033c9f617
Model : Raspberry Pi 4 Model B Rev 1.1
Output:
ms@pi64:~/Sync/cpuid$ ./cpuid
Name:
PhysicalCores: 0
ThreadsPerCore: 1
LogicalCores: 0
Family 0 Model: 0 Vendor ID: VendorUnknown
Features: ARMCPUID,ASIMD,CRC32,EVTSTRM,FP
Cacheline bytes: 64
L1 Data Cache: -1 bytes
L1 Instruction Cache: -1 bytes
L2 Cache: -1 bytes
L3 Cache: -1 bytes
Frequency 0 hz
Hi NFD Team,
I have ADL CPU, but i not have AVX_VNNI in label list.
I have v0.11.0 image and this issue is observed.
This ticket is imported from NFD project.
kubernetes-sigs/node-feature-discovery#844
{
"beta.kubernetes.io/arch": "amd64",
"beta.kubernetes.io/os": "linux",
"feature.node.kubernetes.io/cpu-cpuid.ADX": "true",
"feature.node.kubernetes.io/cpu-cpuid.AESNI": "true",
"feature.node.kubernetes.io/cpu-cpuid.AVX": "true",
"feature.node.kubernetes.io/cpu-cpuid.AVX2": "true",
"feature.node.kubernetes.io/cpu-cpuid.CETIBT": "true",
"feature.node.kubernetes.io/cpu-cpuid.CETSS": "true",
"feature.node.kubernetes.io/cpu-cpuid.CMPXCHG8": "true",
"feature.node.kubernetes.io/cpu-cpuid.FMA3": "true",
"feature.node.kubernetes.io/cpu-cpuid.FXSR": "true",
"feature.node.kubernetes.io/cpu-cpuid.FXSROPT": "true",
"feature.node.kubernetes.io/cpu-cpuid.IBPB": "true",
"feature.node.kubernetes.io/cpu-cpuid.LAHF": "true",
"feature.node.kubernetes.io/cpu-cpuid.MOVBE": "true",
"feature.node.kubernetes.io/cpu-cpuid.MOVDIR64B": "true",
"feature.node.kubernetes.io/cpu-cpuid.MOVDIRI": "true",
"feature.node.kubernetes.io/cpu-cpuid.OSXSAVE": "true",
"feature.node.kubernetes.io/cpu-cpuid.SCE": "true",
"feature.node.kubernetes.io/cpu-cpuid.SERIALIZE": "true",
"feature.node.kubernetes.io/cpu-cpuid.SHA": "true",
"feature.node.kubernetes.io/cpu-cpuid.STIBP": "true",
"feature.node.kubernetes.io/cpu-cpuid.VMX": "true",
"feature.node.kubernetes.io/cpu-cpuid.WAITPKG": "true",
"feature.node.kubernetes.io/cpu-cpuid.X87": "true",
"feature.node.kubernetes.io/cpu-cpuid.XSAVE": "true",
"feature.node.kubernetes.io/cpu-hardware_multithreading": "true",
"feature.node.kubernetes.io/cpu-model.family": "6",
"feature.node.kubernetes.io/cpu-model.id": "154",
"feature.node.kubernetes.io/cpu-model.vendor_id": "Intel",
"feature.node.kubernetes.io/cpu-pstate.scaling_governor": "powersave",
"feature.node.kubernetes.io/cpu-pstate.status": "active",
"feature.node.kubernetes.io/cpu-pstate.turbo": "true",
"feature.node.kubernetes.io/cpu-rdt.RDTL2CA": "true",
"feature.node.kubernetes.io/kernel-config.NO_HZ": "true",
"feature.node.kubernetes.io/kernel-config.NO_HZ_IDLE": "true",
"feature.node.kubernetes.io/kernel-version.full": "5.15.0-40-generic",
"feature.node.kubernetes.io/kernel-version.major": "5",
"feature.node.kubernetes.io/kernel-version.minor": "15",
"feature.node.kubernetes.io/kernel-version.revision": "0",
"feature.node.kubernetes.io/pci-0300_8086.present": "true",
"feature.node.kubernetes.io/pci-0300_8086.sriov.capable": "true",
"feature.node.kubernetes.io/storage-nonrotationaldisk": "true",
"feature.node.kubernetes.io/system-os_release.ID": "ubuntu",
"feature.node.kubernetes.io/system-os_release.VERSION_ID": "22.04",
"feature.node.kubernetes.io/system-os_release.VERSION_ID.major": "22",
"feature.node.kubernetes.io/system-os_release.VERSION_ID.minor": "04",
"gpu.intel.com/cards": "card0",
"kubernetes.io/arch": "amd64",
"kubernetes.io/hostname": "10.10.10.10",
"kubernetes.io/os": "linux",
"node-role.kubernetes.io/worker": "true"
}
cpuid -1 | grep AVX-VNNI
AVX-VNNI: AVX VNNI neural network instrs = true
This CPU feature is not implemented in NFD?
BR,
Ionut Nechita
ionutnechita
Lines 85 to 86 in e32428e
It's not clear if this was intentional, but it seems possible to get the dcache value on macOS. Currently both L1I
and L1D
are filled from the same sysctl.
Hi @klauspost,
I'd like to add AMX CPU features AMXBF16, AMXTILE, AMXINT8. However, we've hit the limit of 64 features in Flags
(of type uint64
).
So I'm wondering if you'd have a preference over following options, or a better idea:
CPUInfo.Features
from uint64
to an alternative of arbitrary size (like map[int]bool
, math.big.Int
, bitarray
) - and totally break the API.CPUInfo.Features2
.CPUInfo.AMX
that would hold subflags for this particular feature.CPUInfo.Features
as is for backwards compatibility.@klauspost, I'm creating this issue here as I really would like to hear your opinion on what could be done, and mainly if something should be done on cpuid
in order to properly detect those.
We've had access to Azure Intel TDX preview, and we noticed that the TDX guest cpuid leaf was not exposed there. This is a huge situation, as it seems Azure is not willing to expose all the necessary bits, and there's already discussions that happened on the kernel land about this, like: https://lore.kernel.org/linux-hyperv/20231020202158.GHZTLhZpmes+uiHOE2@fat_crate.local/T/#t
Meanwhile, I've gotten to do some tests on the created TDX VM, and a "simple patch" like the one shown below could do the trick:
intel-coco@tdvm:~/fidencio/cpuid/cmd/cpuid$ git diff
diff --git a/cpuid.go b/cpuid.go
index b5fdc6e..0021df1 100644
--- a/cpuid.go
+++ b/cpuid.go
@@ -1418,6 +1418,11 @@ func support() flagSet {
fs.setIf((a>>24)&1 == 1, VMSA_REGPROT)
}
+ if mfi >= 0x20 {
+ _, ebx, _, _ := cpuid(0x4000000C)
+ fs.setIf(ebx == 0xbe3, TDX_GUEST)
+ }
+
if mfi >= 0x21 {
// Intel Trusted Domain Extensions Guests have their own cpuid leaf (0x21).
_, ebx, ecx, edx := cpuid(0x21)
While this of TDX_GUEST, supporting things like SNP / SEV guest would basically be the matter of checking the ebx
's value, as show here https://github.com/torvalds/linux/blob/master/arch/x86/kernel/cpu/mshyperv.c#L429-L445
At this point I'm rather unsure on whether this is an acceptable approach, but I'm confident we'd need something, at least something coming from cpuid
side, so NFD could properly do the detection.
With everything written above, @klauspost, I'm super interested in your take on whether to accept a patch like the one above, or any other suggestsion on how to address this.
Let me cc some folks from Intel, Azure, and NVIDIA side here as well, just so they can add something that I may have missed and / or follow up in your suggestions.
Could you update output of example code in file README?
Now, I don't see L1 result.
cpuid
claims that AVX-512F is not supported on my Macbook, but I can execute the instructions just fine. Is this a bug in cpuid
, or does the i5-1030NG7 report incorrect feature flags?? Here's the full CPU
struct:
{
BrandName: "Intel(R) Core(TM) i5-1030NG7 CPU @ 1.10GHz",
VendorID: 1,
VendorString: "GenuineIntel",
Features: "CMOV,NX,MMX,MMXEXT,SSE,SSE2,SSE3,SSSE3,SSE4.1,SSE4.2,AVX,AVX2,FMA3,F16C,BMI1,BMI2,LZCNT,POPCNT,AESNI,CLMUL,HTT,RDRAND,RDSEED,ADX,SHA,ERMS,RDTSCP,CX16,SGX,SGXLC,IBPB,STIBP,VMX",
Arm: 0x0,
PhysicalCores: 4,
ThreadsPerCore: 2,
LogicalCores: 8,
Family: 6,
Model: 126,
CacheLine: 64,
Hz: 1113600000,
Cache: {
L1I: 32768,
L1D: 49152,
L2: 524288,
L3: 6291456,
},
SGX: {
Available: true,
LaunchControl: true,
SGX1Supported: false,
SGX2Supported: false,
MaxEnclaveSizeNot64: 1,
MaxEnclaveSize64: 1,
EPCSections: []cpuid.SGXEPCSection{},
},
maxFunc: 0x1b,
maxExFunc: 0x80000008,
}
Build command:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o main.go
ERR MSG:
#github.com/klauspost/compress/flate
~/go/src/github.com/klauspost/compress/flate/crc32_amd64.go:41:22: cpuid.CPU.SSE42 undefined (type cpuid.CPUInfo has no field or method SSE42)
$go env
GO111MODULE="auto"
GOARCH="arm64"
GOBIN="/go/bin"/Library/Caches/go-build"
GOCACHE="
GOENV="/Library/Application Support/go/env"/go/pkg/mod"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="~/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/opt/homebrew/Cellar/go/1.17.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.17.6/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8j/hl0nvryx4bx3_2cpqm2ljr3w0000gn/T/go-build944530538=/tmp/go-build -gno-record-gcc-switches -fno-common"
@ipuustin Running tests locally I get this failure:
=== RUN TestSGX
--- FAIL: TestSGX (0.00s)
cpuid_test.go:284: SGX Support: true
cpuid_test.go:293: SGX enabled without any available EPC memory
Hi NFD Team,
I try today to verify my features with cpuid go implementation.
But I noticed differences in features between cpuid your binary and lscpu.
Several features are missing.
Example: SVM for virtualization support
CPUID go implementation version: cpuid-Linux_x86_64_2.0.14
OS: openSUSE Tumbleweed 20220706
AMD CPU: AMD Ryzen 9 5900HS with Radeon Graphics
cpuid go: cpuid-go.txt
lscpu: lscpu.txt
cpuinfo: cpuinfo.txt
cpuid e0x: cpuid-e0x.txt
First file for diff: a.txt
Second file for diff: b.txt
Diff:
...
SVM | VTE
SVM_LOCK <
SYSCALL <
TCE <
TOPOEXT <
TSC <
TSC_SCALE <
UMIP <
VAES <
VGIF <
VMCB_CLEAN <
VME <
VMMCALL <
VPCLMULQDQ <
V_SPEC_CTRL <
V_VMSAVE_VMLOAD <
...
BR,
Ionut Nechita
ionutnechita
Latest 1.3.0 release fails on arm64, while previous 1.2.5 release built well:
Build log of arm64:
dh_auto_test -O--buildsystem=golang
cd obj-aarch64-linux-gnu && go test -vet=off -v -p 8 github.com/klauspost/cpuid
SIGILL: illegal instruction
PC=0x118520 m=0 sigcode=1
goroutine 1 [running, locked to thread]:
github.com/klauspost/cpuid.getProcFeatures(0x140760, 0x400018c210, 0x16d743, 0xc, 0x4000068ed8, 0x10cef4, 0x28a860, 0x10cef0, 0x4000068ee8, 0x4f78c, ...)
/build/1st/golang-github-klauspost-cpuid-1.3.0+ds/obj-aarch64-linux-gnu/src/github.com/klauspost/cpuid/cpuid_arm64.s:15 fp=0x4000068e90 sp=0x4000068e90 pc=0x118520
github.com/klauspost/cpuid.addInfo(0x28a860)
/build/1st/golang-github-klauspost-cpuid-1.3.0+ds/obj-aarch64-linux-gnu/src/github.com/klauspost/cpuid/detect_arm64.go:42 +0x20 fp=0x4000068ec0 sp=0x4000068e90 pc=0x10d620
github.com/klauspost/cpuid.Detect()
/build/1st/golang-github-klauspost-cpuid-1.3.0+ds/obj-aarch64-linux-gnu/src/github.com/klauspost/cpuid/cpuid.go:289 +0x70 fp=0x4000068ee0 sp=0x4000068ec0 pc=0x10cf80
github.com/klauspost/cpuid.init.0()
/build/1st/golang-github-klauspost-cpuid-1.3.0+ds/obj-aarch64-linux-gnu/src/github.com/klauspost/cpuid/cpuid.go:272 +0x24 fp=0x4000068ef0 sp=0x4000068ee0 pc=0x10cef4
runtime.doInit(0x2731c0)
/usr/lib/go-1.14/src/runtime/proc.go:5420 +0x9c fp=0x4000068f30 sp=0x4000068ef0 pc=0x4f78c
runtime.doInit(0x272320)
/usr/lib/go-1.14/src/runtime/proc.go:5415 +0x58 fp=0x4000068f70 sp=0x4000068f30 pc=0x4f748
runtime.main()
/usr/lib/go-1.14/src/runtime/proc.go:190 +0x1b8 fp=0x4000068fd0 sp=0x4000068f70 pc=0x42838
runtime.goexit()
/usr/lib/go-1.14/src/runtime/asm_arm64.s:1148 +0x4 fp=0x4000068fd0 sp=0x4000068fd0 pc=0x6f8b4
r0 0x28a860
r1 0x4000068380
r2 0x4000068ec0
r3 0x5
r4 0x140760
r5 0x0
r6 0x16d743
r7 0xa
r8 0xf
r9 0x4
r10 0x0
r11 0xd
r12 0x1
r13 0x802aaaa00aaaa
r14 0xf8
r15 0x0
r16 0x34
r17 0x68
r18 0x0
r19 0xd0
r20 0x4000068da8
r21 0xffffc1ed5840
r22 0x4000002000
r23 0x0
r24 0x0
r25 0x0
r26 0x273210
r27 0x28a8e8
r28 0x4000000180
r29 0x4000068e88
lr 0x10d620
sp 0x4000068e90
pc 0x118520
fault 0x0
FAIL github.com/klauspost/cpuid 0.005s
$ go test
panic: runtime error: integer divide by zero
[signal 0x8 code=0x1 addr=0x47cf4a pc=0x47cf4a]
goroutine 1 [running]:
github.com/klauspost/cpuid.physicalCores(0x0)
/go/src/github.com/klauspost/cpuid/cpuid.go:595 +0x4a
github.com/klauspost/cpuid.Detect()
/go/src/github.com/klauspost/cpuid/cpuid.go:181 +0xc7
github.com/klauspost/cpuid.init.1()
/go/src/github.com/klauspost/cpuid/cpuid.go:162 +0x14
github.com/klauspost/cpuid.init()
/go/src/github.com/klauspost/cpuid/cpuid_test.go:648 +0x1b0
main.init()
github.com/klauspost/cpuid/_test/_testmain.go:176 +0x4a
exit status 2
FAIL github.com/klauspost/cpuid 0.004s
The cpu in question is: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
threadsPerCore() returns 0. Patching that to always return 1 gives the following info:
cpuid_test.go:14: Max Function:0xd
cpuid_test.go:16: Max Extended Function:0x80000008
cpuid_test.go:19: CPUID.(EAX=07H):EBX: 0x0
cpuid_test.go:21: Name: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
cpuid_test.go:22: PhysicalCores: 0
cpuid_test.go:23: ThreadsPerCore: 1
cpuid_test.go:24: LogicalCores: 0
cpuid_test.go:25: Family 6 Model: 23
cpuid_test.go:26: Features: CMOV,NX,MMX,MMXEXT,SSE,SSE2,SSE3,SSSE3,SSE4.1,CX16
cpuid_test.go:27: Cacheline bytes: 64
cpuid_test.go:29: Yay - we have SSE 2
Let me know if you need more information.
Looks like the only safe option is to use an OS call to get these features.
Maybe the Go runtime can provide some help?
https://github.com/golang/go/tree/master/src/internal/cpu
And some in the runtime:
... though I haven't found where archauxv is actually called from.
gccgo toolchain does not support Plan 9 assembly syntax; instead it expects GNU as
syntax. When trying to build a program that references cpuid
package, I get the following errors:
$ go build -compiler gccgo
# github.com/klauspost/cpuid
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s: Assembler messages:
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:4: Error: no such instruction: `text ·asmCpuid(SB),7,$0'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:5: Error: junk `(FP)' after expression
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:5: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:7: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:8: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:9: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:10: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:16: Error: no such instruction: `text ·asmCpuidex(SB),7,$0'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:17: Error: junk `(FP)' after expression
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:17: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:18: Error: junk `(FP)' after expression
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:18: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:20: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:21: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:22: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:23: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:27: Error: no such instruction: `text ·asmXgetbv(SB),7,$0'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:28: Error: junk `(FP)' after expression
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:28: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:29: Error: no such instruction: `byte $0x0f'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:29: Error: no such instruction: `byte $0x01'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:29: Error: no such instruction: `byte $0xd0//XGETBV'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:30: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:31: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:35: Error: no such instruction: `text ·asmRdtscpAsm(SB),7,$0'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:36: Error: no such instruction: `byte $0x0F'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:36: Error: no such instruction: `byte $0x01'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:36: Error: no such instruction: `byte $0xF9//RDTSCP'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:37: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:38: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:39: Error: too many memory references for `mov'
../go/src/github.com/klauspost/cpuid/cpuid_amd64.s:40: Error: too many memory references for `mov'
Here is a cpuinfo data
processor : 11
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xf0
cpu MHz : 1259.110
cache size : 12288 KB
physical id : 0
siblings : 12
core id : 5
cpu cores : 6
apicid : 11
initial apicid : 11
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
It looks like cpuid
does not provide a way to get the "stepping" information. Would it be possible to add API access to such CPU information?
Thanks.
AFAICT there's no way to know how many physical processors exist, as cpuid only reports information for the cpu the current goroutine is running on. It would be very useful (for NUMA aware programs) to have the equivelent of
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
from /proc/cpuinfo for all physical cpus.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.