Involved Source Files Package cpuid provides information about the CPU running the current program.
CPU features are detected on startup, and kept for fast access through the life of the application.
Currently x86 / x64 (AMD64) as well as arm64 is supported.
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
Package home: https://github.com/klauspost/cpuiddetect_x86.gofeatureid_string.gocpuid_amd64.s
CPUInfo contains information about the detected system CPU.AMDMemEncryptionAMDMemEncryptionSupportAVX10Leveluint8 // Max clock speed, if known, 0 otherwise // Brand name reported by the CPUCachestruct{L1I int; L1D int; L2 int; L3 int} // Cache line size in bytes. Will be 0 if undetectable. // CPU family number // Hypervisor vendor // Raw hypervisor vendor string // Clock speed, if known, 0 otherwise. Will attempt to contain base clock speed. // Number of physical cores times threads that can run on each core through the use of hyperthreading. Will be 0 if undetectable. // CPU model number // holds information about the PMU // Number of physical processor cores in your CPU. Will be 0 if undetectable.SGXSGXSupport // CPU stepping info // Number of threads per physical core. Will be 1 if undetectable. // Comparable CPU vendor ID // Raw vendor string. AnyOf returns whether the CPU supports one or more of the requested features. Disable will disable one or several features. Enable will disable one or several features even if they were undetected.
This is of course not recommended for obvious reasons. FeatureSet returns all available features as strings. Has allows for checking a single feature.
Should be inlined by the compiler.(*CPUInfo) HasAll(f Features) bool Ia32TscAux returns the IA32_TSC_AUX part of the RDTSCP.
This variable is OS dependent, but on Linux contains information
about the current cpu/core the code is running on.
If the RDTSCP instruction isn't supported on the CPU, the value 0 is returned. IsVendor returns true if vendor is recognized as Intel LogicalCPU will return the Logical CPU the code is currently executing on.
This is likely to change when the OS re-schedules the running thread
to another CPU.
If the current core cannot be detected, -1 will be returned. RTCounter returns the 64-bit time-stamp counter
Uses the RDTSCP instruction. The value 0 is returned
if the CPU does not support the instruction. Supports returns whether the CPU supports all of the requested features. SveLengths returns arm SVE vector and predicate lengths in bits.
Will return 0, 0 if SVE is not enabled or otherwise unable to detect. VM Will return true if the cpu id indicates we are in
a virtual machine. X64Level returns the microarchitecture level detected on the CPU.
If features are lacking or non x64 mode, 0 is returned.
See https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
var CPU
Features contains several features combined for a fast check using
CpuInfo.HasAll
func CombineFeatures(ids ...FeatureID) Features
func (*CPUInfo).HasAll(f Features) bool
PerformanceMonitoringInfo holds information about CPU performance monitoring capabilities.
This is primarily populated from CPUID leaf 0xAh on x86 FixedPMCWidth: Bit width of Fixed-Function Performance Counters.
Valid on x86 if VersionID > 1. On ARM, the cycle counter (PMCCNTR_EL0) is 64-bit. GPPMCWidth: Bit width of General-Purpose Performance Monitoring Counters.
On ARM, typically 64 for PMU event counters. NumFixedPMC: Number of Fixed-Function Performance Counters.
Valid on x86 if VersionID > 1. On ARM, this typically includes at least the cycle counter (PMCCNTR_EL0). NumGPPMC: Number of General-Purpose Performance Monitoring Counters per logical processor.
On ARM, this is derived from PMCR_EL0.N (number of event counters).RawEAXuint32 Raw register output from CPUID leaf 0xAh.RawEDXuint32 VersionID (x86 only): Version ID of architectural performance monitoring.
A value of 0 means architectural performance monitoring is not supported or information is unavailable.
CombineFeatures allows to combine several features for a close to constant time lookup.
Detect will re-detect current CPU info.
This will replace the content of the exported CPU variable.
Unless you expect the CPU to change while you are running your program
you should not need to call this function.
If you call this, you must ensure that no other goroutine is accessing the
exported CPU variable.
DetectARM will detect ARM64 features.
This is NOT done automatically since it can potentially crash
if the OS does not handle the command.
If in the future this can be done safely this function may not
do anything.
Flags will enable flags.
This must be called *before* flag.Parse AND
Detect must be called after the flags have been parsed.
Note that this means that any detection used in init() functions
will not contain these flags.
ParseFeature will parse the string and return the ID of the matching feature.
Will return UNKNOWN if not found.
Package-Level Variables (only one)
CPU contains information about the CPU as detected on startup,
or when Detect last was called.
Use this as the primary entry point to you data.
const MOVUFeatureID = 116 // AMD: MOVU SSE instructions are more efficient and should be preferred to SSE MOVL/MOVH. MOVUPS is more efficient than MOVLPS/MOVHPS. MOVUPD is more efficient than MOVLPD/MOVHPD
const PPINFeatureID = 126 // AMD: Protected Processor Inventory Number support. Indicates that Protected Processor Inventory Number (PPIN) capability can be enabled
const SVMDAFeatureID = 170 // Indicates support for the SVM decode assists.
const SVMFBASIDFeatureID = 171 // SVM, Indicates that TLB flush events, including CR3 writes and CR4.PGE toggles, flush only the current ASID's TLB entries. Also indicates support for the extended VMCBTLB_Control
const SVMLFeatureID = 172 // AMD SVM lock. Indicates support for SVM-Lock.
const TLBFeatureID = 224 // Outer Shareable and TLB range maintenance instructions
const TLB_FLUSH_NESTEDFeatureID = 180 // AMD: Flushing includes all the nested translations for guest translations
const TMEFeatureID = 181 // Intel Total Memory Encryption. The following MSRs are supported: IA32_TME_CAPABILITY, IA32_TME_ACTIVATE, IA32_TME_EXCLUDE_MASK, and IA32_TME_EXCLUDE_BASE.
const TOPEXTFeatureID = 182 // TopologyExtensions: topology extensions support. Indicates support for CPUID Fn8000_001D_EAX_x[N:0]-CPUID Fn8000_001E_EDX.
const XSAVESFeatureID = 204 // Supports XSAVES/XRSTORS and IA32_XSS
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.