From e31358df2713369c9d4f6253fb71fbb578f80c3f Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Tue, 10 Dec 2024 14:37:28 -0800 Subject: [PATCH] report l3 size per socket --- .gitignore | 3 ++- internal/report/table_defs.go | 2 ++ internal/report/table_helpers.go | 28 ++++++++++++++-------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 9e98870..47f23e0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ /tools/bin /dist /internal/script/resources/x86_64 -/test \ No newline at end of file +/test +/__debug_bin*.log \ No newline at end of file diff --git a/internal/report/table_defs.go b/internal/report/table_defs.go index 3b5202b..a3d26a5 100644 --- a/internal/report/table_defs.go +++ b/internal/report/table_defs.go @@ -420,6 +420,7 @@ var tableDefinitions = map[string]TableDefinition{ script.LscpuScriptName, script.LspciBitsScriptName, script.LspciDevicesScriptName, + script.L3WaySizeName, script.CpuidScriptName, script.BaseFrequencyScriptName, script.SpecTurboCoresScriptName, @@ -1525,6 +1526,7 @@ func systemSummaryTableValues(outputs map[string]script.ScriptOutput) []Field { {Name: "CPU Model", Values: []string{valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^[Mm]odel name:\s*(.+)$`)}}, {Name: "Architecture", Values: []string{valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^Architecture:\s*(.+)$`)}}, {Name: "Microarchitecture", Values: []string{uarchFromOutput(outputs)}}, + {Name: "L3 Cache", Values: []string{l3FromOutput(outputs)}}, {Name: "Cores per Socket", Values: []string{valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^Core\(s\) per socket:\s*(.+)$`)}}, {Name: "Sockets", Values: []string{valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^Socket\(s\):\s*(.+)$`)}}, {Name: "Hyperthreading", Values: []string{hyperthreadingFromOutput(outputs)}}, diff --git a/internal/report/table_helpers.go b/internal/report/table_helpers.go index 0c7306e..84e226d 100644 --- a/internal/report/table_helpers.go +++ b/internal/report/table_helpers.go @@ -431,14 +431,13 @@ func prefetchersFromOutput(outputs map[string]script.ScriptOutput) string { return "None" } -// get L3 in MB from lscpu +// get L3 per instance in MB from lscpu // known lscpu output formats for L3 cache: // -// 1.5 MBi < Ubuntu -// 1536KB < CentOS +// L3 cache: 576 MiB (2 instances) func getL3LscpuMB(outputs map[string]script.ScriptOutput) (val float64, err error) { l3Lscpu := valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^L3 cache.*:\s*(.+?)$`) - re := regexp.MustCompile(`(\d+\.?\d*)\s*(\w+).*`) // match known formats + re := regexp.MustCompile(`(\d+\.?\d*)\s*(\w+)\s+\((\d+) instances\)`) // match known formats match := re.FindStringSubmatch(l3Lscpu) if len(match) == 0 { err = fmt.Errorf("unknown L3 format in lscpu: %s", l3Lscpu) @@ -449,12 +448,18 @@ func getL3LscpuMB(outputs map[string]script.ScriptOutput) (val float64, err erro err = fmt.Errorf("failed to parse L3 size from lscpu: %s, %v", l3Lscpu, err) return } - if strings.ToLower(match[2][:1]) == "m" { - val = l3SizeNoUnit + instances, err := strconv.Atoi(match[3]) + if err != nil { + err = fmt.Errorf("failed to parse L3 instances from lscpu: %s, %v", l3Lscpu, err) + return + } + units := match[2] + if strings.ToLower(units[:1]) == "m" { + val = l3SizeNoUnit / float64(instances) return } - if strings.ToLower(match[2][:1]) == "k" { - val = l3SizeNoUnit / 1024 + if strings.ToLower(units[:1]) == "k" { + val = l3SizeNoUnit / 1024 / float64(instances) return } err = fmt.Errorf("unknown L3 units in lscpu: %s", l3Lscpu) @@ -548,12 +553,7 @@ func l3PerCoreFromOutput(outputs map[string]script.ScriptOutput) string { slog.Error("failed to parse cores per socket", slog.String("error", err.Error())) return "" } - sockets, err := strconv.Atoi(valFromRegexSubmatch(outputs[script.LscpuScriptName].Stdout, `^Socket\(.*:\s*(.+?)$`)) - if err != nil || sockets == 0 { - slog.Error("failed to parse sockets", slog.String("error", err.Error())) - return "" - } - cacheMB := l3 / float64(coresPerSocket*sockets) + cacheMB := l3 / float64(coresPerSocket) val := strconv.FormatFloat(cacheMB, 'f', 3, 64) val = strings.TrimRight(val, "0") // trim trailing zeros val = strings.TrimRight(val, ".") // trim decimal point if trailing