Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPU level test #96

Merged
merged 1 commit into from Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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