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

report l3 size per socket #120

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/tools/bin
/dist
/internal/script/resources/x86_64
/test
/test
/__debug_bin*.log
2 changes: 2 additions & 0 deletions internal/report/table_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ var tableDefinitions = map[string]TableDefinition{
script.LscpuScriptName,
script.LspciBitsScriptName,
script.LspciDevicesScriptName,
script.L3WaySizeName,
script.CpuidScriptName,
script.BaseFrequencyScriptName,
script.SpecTurboCoresScriptName,
Expand Down Expand Up @@ -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)}},
Expand Down
43 changes: 26 additions & 17 deletions internal/report/table_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,30 +431,44 @@ 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)
// L3 cache: 210 MiB
func getL3LscpuMB(outputs map[string]script.ScriptOutput) (val float64, err error) {
var instances int
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+) instance[s]*\)`) // match known formats
match := re.FindStringSubmatch(l3Lscpu)
if len(match) == 0 {
err = fmt.Errorf("unknown L3 format in lscpu: %s", l3Lscpu)
return
if match != nil {
instances, err = strconv.Atoi(match[3])
if err != nil {
err = fmt.Errorf("failed to parse L3 instances from lscpu: %s, %v", l3Lscpu, err)
return
}
} else {
// try regex without the instance count
re = regexp.MustCompile(`(\d+\.?\d*)\s*(\w+)`)
match = re.FindStringSubmatch(l3Lscpu)
if match == nil {
err = fmt.Errorf("unknown L3 format in lscpu: %s", l3Lscpu)
return
}
instances = 1
}
l3SizeNoUnit, err := strconv.ParseFloat(match[1], 64)
if err != nil {
err = fmt.Errorf("failed to parse L3 size from lscpu: %s, %v", l3Lscpu, err)
return
}
if strings.ToLower(match[2][:1]) == "m" {
val = l3SizeNoUnit
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)
Expand Down Expand Up @@ -548,12 +562,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
Expand Down
Loading