jason 075d766964 first | il y a 3 ans | |
---|---|---|
.. | ||
private | il y a 3 ans | |
testdata | il y a 3 ans | |
.gitignore | il y a 3 ans | |
.travis.yml | il y a 3 ans | |
CONTRIBUTING.txt | il y a 3 ans | |
LICENSE | il y a 3 ans | |
README.md | il y a 3 ans | |
cpuid.go | il y a 3 ans | |
cpuid_386.s | il y a 3 ans | |
cpuid_amd64.s | il y a 3 ans | |
cpuid_test.go | il y a 3 ans | |
detect_intel.go | il y a 3 ans | |
detect_ref.go | il y a 3 ans | |
generate.go | il y a 3 ans | |
mockcpu_test.go | il y a 3 ans | |
private-gen.go | il y a 3 ans |
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) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
Package home: https://github.com/klauspost/cpuid
# example
Go package main
import (
"fmt"
"github.com/klauspost/cpuid"
)
func main() {
// Print basic CPU information:
fmt.Println("Name:", cpuid.CPU.BrandName)
fmt.Println("PhysicalCores:", cpuid.CPU.PhysicalCores)
fmt.Println("ThreadsPerCore:", cpuid.CPU.ThreadsPerCore)
fmt.Println("LogicalCores:", cpuid.CPU.LogicalCores)
fmt.Println("Family", cpuid.CPU.Family, "Model:", cpuid.CPU.Model)
fmt.Println("Features:", cpuid.CPU.Features)
fmt.Println("Cacheline bytes:", cpuid.CPU.CacheLine)
fmt.Println("L1 Data Cache:", cpuid.CPU.Cache.L1D, "bytes")
fmt.Println("L1 Instruction Cache:", cpuid.CPU.Cache.L1D, "bytes")
fmt.Println("L2 Cache:", cpuid.CPU.Cache.L2, "bytes")
fmt.Println("L3 Cache:", cpuid.CPU.Cache.L3, "bytes")
// Test if we have a specific feature:
if cpuid.CPU.SSE() {
fmt.Println("We have Streaming SIMD Extensions")
}
}
Sample output:
go run main.go Name: Intel(R) Core(TM) i5-2540M CPU @ 2.60GHz PhysicalCores: 2 ThreadsPerCore: 2 LogicalCores: 4 Family 6 Model: 42 Features: CMOV,MMX,MMXEXT,SSE,SSE2,SSE3,SSSE3,SSE4.1,SSE4.2,AVX,AESNI,CLMUL Cacheline bytes: 64 We have Streaming SIMD Extensions ```
In the "private" folder you can find an autogenerated version of the library you can include in your own packages.
For this purpose all exports are removed, and functions and constants are lowercased.
This is not a recommended way of using the library, but provided for convenience, if it is difficult for you to use external packages.
This code is published under an MIT license. See LICENSE file for more information.