Skip to content

Commit

Permalink
Added program to check for Intel TSX support
Browse files Browse the repository at this point in the history
  • Loading branch information
linux4life798 committed Oct 3, 2018
1 parent e599240 commit 93db53c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions doihavetsx/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This simple program prints the name of the cpu and if it supports
// Intel RTM and HLE.
// It exits with status code 0 only is RTM and HLE are both supported.
package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/intel-go/cpuid"
)

func main() {
hasRTM := cpuid.HasExtendedFeature(cpuid.RTM)
hasHLE := cpuid.HasExtendedFeature(cpuid.HLE)

w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
printyesno := func(v bool) {
if v {
fmt.Fprintln(w, "Yes")
} else {
fmt.Fprintln(w, "No")
}
}

fmt.Fprintf(w, "CPU Brand:\t%s\n", cpuid.ProcessorBrandString)
fmt.Fprint(w, "RTM:\t")
printyesno(hasRTM)
fmt.Fprint(w, "HLE:\t")
printyesno(hasHLE)
w.Flush()

if hasRTM && hasHLE {
os.Exit(0)
} else {
os.Exit(1)
}
}

0 comments on commit 93db53c

Please sign in to comment.