From 93db53cdd0ceb7ab926710f265588d90470c9f06 Mon Sep 17 00:00:00 2001 From: Craig Hesling Date: Tue, 2 Oct 2018 21:54:17 -0400 Subject: [PATCH] Added program to check for Intel TSX support --- doihavetsx/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 doihavetsx/main.go diff --git a/doihavetsx/main.go b/doihavetsx/main.go new file mode 100644 index 0000000..3b0ab00 --- /dev/null +++ b/doihavetsx/main.go @@ -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) + } +}