Skip to content

Commit

Permalink
Merge pull request #120 from intel/l3persocket
Browse files Browse the repository at this point in the history
* report l3 size per socket

* match instance and instances

* match l3 cache when num instances not in lscpu output
  • Loading branch information
harp-intel authored Dec 11, 2024
2 parents bc31cc8 + bcc0059 commit 9baa8f7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
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

0 comments on commit 9baa8f7

Please sign in to comment.