From 4b63ff930157cc89564034e573b75cc730a3519a Mon Sep 17 00:00:00 2001 From: Jrelvas <55360900+Noted-Jrelvas@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:34:21 +0000 Subject: [PATCH] sysinfo: check if cpu has split lock detection flag (#289) * sysinfo: check if cpu has split lock detection flag * sysinfo: Consolidate cpu fields into struct * sysinfo: (reluctantly) expanded cpu struct * Revert "sysinfo: (reluctantly) expanded cpu struct" This reverts commit de1159e2380531c556c7d2da3afd4e8896350635. wael moment * sysinfo: implement cpu struct in a sane and non-awful way * sysinfo: yet another cpu struct initialization change when will the pain end --- cmd/vinegar/vinegar.go | 3 ++- sysinfo/cpu.go | 26 +++++++++++++++++++++++--- sysinfo/sysinfo.go | 7 ++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cmd/vinegar/vinegar.go b/cmd/vinegar/vinegar.go index 7715bd3f..de4a5ae0 100644 --- a/cmd/vinegar/vinegar.go +++ b/cmd/vinegar/vinegar.go @@ -147,10 +147,11 @@ func Sysinfo(pfx *wine.Prefix) { * Distro: %s * Processor: %s * Supports AVX: %t + * Supports split lock detection: %t * Kernel: %s * Wine: %s` - fmt.Printf(info, Version, revision, sysinfo.Distro, sysinfo.CPU, sysinfo.HasAVX, sysinfo.Kernel, ver) + fmt.Printf(info, Version, revision, sysinfo.Distro, sysinfo.CPU.Name, sysinfo.CPU.AVX, sysinfo.CPU.SplitLockDetect, sysinfo.Kernel, ver) if sysinfo.InFlatpak { fmt.Println("* Flatpak: [x]") } diff --git a/sysinfo/cpu.go b/sysinfo/cpu.go index f8c5fc20..82e04ca8 100644 --- a/sysinfo/cpu.go +++ b/sysinfo/cpu.go @@ -6,9 +6,23 @@ import ( "bufio" "os" "regexp" + "strings" + + cpulib "golang.org/x/sys/cpu" ) -func cpuModel() string { +type cpu struct { + Name string + AVX bool + SplitLockDetect bool +} + +func getCPU() cpu { + c := cpu{ + Name: "unknown cpu", + AVX: cpulib.X86.HasAVX, + } + column := regexp.MustCompile("\t+: ") f, _ := os.Open("/proc/cpuinfo") @@ -24,9 +38,15 @@ func cpuModel() string { // pfft, who needs multiple cpus? just return if we got all we need if sl[0] == "model name" { - return sl[1] + c.Name = sl[1] + } + + if sl[0] == "flags" { + c.SplitLockDetect = strings.Contains(sl[1], "split_lock_detect") + break } + } - return "unknown cpu" + return c } diff --git a/sysinfo/sysinfo.go b/sysinfo/sysinfo.go index 3852a7ff..cf269d08 100644 --- a/sysinfo/sysinfo.go +++ b/sysinfo/sysinfo.go @@ -4,22 +4,19 @@ package sysinfo import ( "os" - - "golang.org/x/sys/cpu" ) var ( Kernel string - CPU string + CPU cpu Cards []Card Distro string - HasAVX = cpu.X86.HasAVX InFlatpak bool ) func init() { Kernel = getKernel() - CPU = cpuModel() + CPU = getCPU() Cards = getCards() Distro = getDistro()