Skip to content

Commit

Permalink
Add CPU level test (#96)
Browse files Browse the repository at this point in the history
Example: `cpuid -check-level=4`
  • Loading branch information
klauspost committed Mar 18, 2022
1 parent a4e6a85 commit 65b2768
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/cpuid/main.go
Expand Up @@ -14,16 +14,30 @@ import (
"encoding/json"
"flag"
"fmt"
"log"
"os"
"strings"

"github.com/klauspost/cpuid/v2"
)

var js = flag.Bool("json", false, "Output as JSON")
var level = flag.Int("check-level", 0, "Check microarchitecture level. Exit code will be 0 if supported")

func main() {
flag.Parse()
if level != nil && *level > 0 {
if *level < 1 || *level > 4 {
log.Fatalln("Supply CPU level 1-4 to test as argument")
}
log.Println(cpuid.CPU.BrandName)
if cpuid.CPU.X64Level() < *level {
// Does os.Exit(1)
log.Fatalf("Microarchitecture level %d not supported. Max level is %d.", *level, cpuid.CPU.X64Level())
}
log.Printf("Microarchitecture level %d is supported. Max level is %d.", *level, cpuid.CPU.X64Level())
os.Exit(0)
}
if *js {
info := struct {
cpuid.CPUInfo
Expand Down

0 comments on commit 65b2768

Please sign in to comment.