Skip to content

Commit 5b4e090

Browse files
authored
recognize DMR, refactor to handle multiple Intel families (#526)
Signed-off-by: Harper, Jason M <[email protected]>
1 parent 2a4ad53 commit 5b4e090

File tree

14 files changed

+321
-313
lines changed

14 files changed

+321
-313
lines changed

cmd/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"log/slog"
1010
"os"
1111
"perfspect/internal/common"
12+
"perfspect/internal/cpus"
1213
"perfspect/internal/progress"
1314
"perfspect/internal/report"
1415
"perfspect/internal/script"
@@ -158,7 +159,7 @@ func prepareTarget(myTarget target.Target, localTempDir string) (err error) {
158159
Name: "prepare-target",
159160
ScriptTemplate: "exit 0",
160161
Superuser: true,
161-
Vendors: []string{"GenuineIntel"},
162+
Vendors: []string{cpus.IntelVendor},
162163
Depends: []string{"wrmsr", "rdmsr"},
163164
Lkms: []string{"msr"},
164165
}

cmd/config/set.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log/slog"
66
"math"
7+
"perfspect/internal/cpus"
78
"perfspect/internal/report"
89
"perfspect/internal/script"
910
"perfspect/internal/target"
@@ -132,7 +133,7 @@ func setLlcSize(desiredLlcSize float64, myTarget target.Target, localTempDir str
132133
}
133134

134135
uarch := report.UarchFromOutput(outputs)
135-
cpu, err := report.GetCPUByMicroArchitecture(uarch)
136+
cpu, err := cpus.GetCPUByMicroArchitecture(uarch)
136137
if err != nil {
137138
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("failed to get CPU by microarchitecture: %w", err)}
138139
return
@@ -176,7 +177,7 @@ func setLlcSize(desiredLlcSize float64, myTarget target.Target, localTempDir str
176177
Name: "set LLC size",
177178
ScriptTemplate: fmt.Sprintf("wrmsr -a 0xC90 %d", msrVal),
178179
Superuser: true,
179-
Vendors: []string{"GenuineIntel"},
180+
Vendors: []string{cpus.IntelVendor},
180181
// Depends: []string{"wrmsr"},
181182
// Lkms: []string{"msr"},
182183
}
@@ -203,7 +204,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
203204
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("failed to get target vendor: %w", err)}
204205
return
205206
}
206-
if targetVendor != "GenuineIntel" {
207+
if targetVendor != cpus.IntelVendor {
207208
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("core frequency setting not supported on %s due to vendor mismatch", myTarget.GetName())}
208209
return
209210
}
@@ -214,7 +215,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
214215
getScript := script.ScriptDefinition{
215216
Name: "get pstate driver",
216217
ScriptTemplate: "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver",
217-
Vendors: []string{"GenuineIntel"},
218+
Vendors: []string{cpus.IntelVendor},
218219
}
219220
output, err := runScript(myTarget, getScript, localTempDir)
220221
if err != nil {
@@ -231,7 +232,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
231232
Name: "set frequency bins",
232233
ScriptTemplate: fmt.Sprintf("wrmsr 0x774 %d", value),
233234
Superuser: true,
234-
Vendors: []string{"GenuineIntel"},
235+
Vendors: []string{cpus.IntelVendor},
235236
// Depends: []string{"wrmsr"},
236237
// Lkms: []string{"msr"},
237238
}
@@ -241,7 +242,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
241242
Name: "set frequency bins",
242243
ScriptTemplate: fmt.Sprintf("wrmsr 0x199 %d", value),
243244
Superuser: true,
244-
Vendors: []string{"GenuineIntel"},
245+
Vendors: []string{cpus.IntelVendor},
245246
// Depends: []string{"wrmsr"},
246247
// Lkms: []string{"msr"},
247248
}
@@ -256,7 +257,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
256257
Name: "set frequency bins",
257258
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x1AD %d", value),
258259
Superuser: true,
259-
Vendors: []string{"GenuineIntel"},
260+
Vendors: []string{cpus.IntelVendor},
260261
// Depends: []string{"wrmsr"},
261262
// Lkms: []string{"msr"},
262263
}
@@ -326,7 +327,7 @@ func setUncoreDieFrequency(maxFreq bool, computeDie bool, uncoreFrequency float6
326327
setScript := script.ScriptDefinition{
327328
Name: "write max and min uncore frequency TPMI",
328329
ScriptTemplate: fmt.Sprintf("pcm-tpmi 2 0x18 -d -b %s -w %d -i %s -e %s", bits, value, die.instance, die.entry),
329-
Vendors: []string{"GenuineIntel"},
330+
Vendors: []string{cpus.IntelVendor},
330331
Depends: []string{"pcm-tpmi"},
331332
Superuser: true,
332333
}
@@ -348,7 +349,7 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
348349
scripts = append(scripts, script.ScriptDefinition{
349350
Name: "get uncore frequency MSR",
350351
ScriptTemplate: "rdmsr 0x620",
351-
Vendors: []string{"GenuineIntel"},
352+
Vendors: []string{cpus.IntelVendor},
352353
Superuser: true,
353354
// Depends: []string{"rdmsr"},
354355
// Lkms: []string{"msr"},
@@ -394,7 +395,7 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
394395
Name: "set uncore frequency MSR",
395396
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x620 %d", newVal),
396397
Superuser: true,
397-
Vendors: []string{"GenuineIntel"},
398+
Vendors: []string{cpus.IntelVendor},
398399
// Depends: []string{"wrmsr"},
399400
// Lkms: []string{"msr"},
400401
}
@@ -410,7 +411,7 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
410411
Name: "get power MSR",
411412
ScriptTemplate: "rdmsr 0x610",
412413
Superuser: true,
413-
Vendors: []string{"GenuineIntel"},
414+
Vendors: []string{cpus.IntelVendor},
414415
// Lkms: []string{"msr"},
415416
// Depends: []string{"rdmsr"},
416417
}
@@ -433,7 +434,7 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
433434
Name: "set tdp",
434435
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x610 %d", newVal),
435436
Superuser: true,
436-
Vendors: []string{"GenuineIntel"},
437+
Vendors: []string{cpus.IntelVendor},
437438
// Depends: []string{"wrmsr"},
438439
// Lkms: []string{"msr"},
439440
}
@@ -472,7 +473,7 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
472473
readScript := script.ScriptDefinition{
473474
Name: "read " + msr,
474475
ScriptTemplate: "rdmsr " + msr,
475-
Vendors: []string{"GenuineIntel"},
476+
Vendors: []string{cpus.IntelVendor},
476477
Superuser: true,
477478
// Lkms: []string{"msr"},
478479
// Depends: []string{"rdmsr"},
@@ -496,7 +497,7 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
496497
Name: "set epb",
497498
ScriptTemplate: fmt.Sprintf("wrmsr -a %s %d", msr, msrValue),
498499
Superuser: true,
499-
Vendors: []string{"GenuineIntel"},
500+
Vendors: []string{cpus.IntelVendor},
500501
// Depends: []string{"wrmsr"},
501502
// Lkms: []string{"msr"},
502503
}
@@ -515,7 +516,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
515516
getScript := script.ScriptDefinition{
516517
Name: "get epp msr",
517518
ScriptTemplate: "rdmsr 0x774", // IA32_HWP_REQUEST
518-
Vendors: []string{"GenuineIntel"},
519+
Vendors: []string{cpus.IntelVendor},
519520
Superuser: true,
520521
// Lkms: []string{"msr"},
521522
// Depends: []string{"rdmsr"},
@@ -539,7 +540,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
539540
Name: "set epp",
540541
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
541542
Superuser: true,
542-
Vendors: []string{"GenuineIntel"},
543+
Vendors: []string{cpus.IntelVendor},
543544
// Depends: []string{"wrmsr"},
544545
// Lkms: []string{"msr"},
545546
}
@@ -552,7 +553,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
552553
getScript = script.ScriptDefinition{
553554
Name: "get epp pkg msr",
554555
ScriptTemplate: "rdmsr 0x772", // IA32_HWP_REQUEST_PKG
555-
Vendors: []string{"GenuineIntel"},
556+
Vendors: []string{cpus.IntelVendor},
556557
Superuser: true,
557558
// Lkms: []string{"msr"},
558559
// Depends: []string{"rdmsr"},
@@ -576,7 +577,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
576577
Name: "set epp",
577578
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x772 %d", eppValue),
578579
Superuser: true,
579-
Vendors: []string{"GenuineIntel"},
580+
Vendors: []string{cpus.IntelVendor},
580581
// Depends: []string{"wrmsr"},
581582
// Lkms: []string{"msr"},
582583
}
@@ -612,12 +613,12 @@ func setELC(elc string, myTarget target.Target, localTempDir string, completeCha
612613
return
613614
}
614615
setScript := script.ScriptDefinition{
615-
Name: "set elc",
616-
ScriptTemplate: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
617-
Superuser: true,
618-
Vendors: []string{"GenuineIntel"},
619-
Models: []string{"173", "174", "175", "221"}, // GNR, GNR-D, SRF, CWF
620-
Depends: []string{"bhs-power-mode.sh", "pcm-tpmi"},
616+
Name: "set elc",
617+
ScriptTemplate: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
618+
Superuser: true,
619+
Vendors: []string{cpus.IntelVendor},
620+
MicroArchitectures: []string{"GNR", "GNR-D", "SRF", "CWF"},
621+
Depends: []string{"bhs-power-mode.sh", "pcm-tpmi"},
621622
}
622623
_, err := runScript(myTarget, setScript, localTempDir)
623624
if err != nil {
@@ -657,7 +658,7 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
657658
getScript := script.ScriptDefinition{
658659
Name: "get prefetcher msr",
659660
ScriptTemplate: fmt.Sprintf("rdmsr %d", pf.Msr),
660-
Vendors: []string{"GenuineIntel"},
661+
Vendors: []string{cpus.IntelVendor},
661662
Superuser: true,
662663
// Lkms: []string{"msr"},
663664
// Depends: []string{"rdmsr"},
@@ -692,7 +693,7 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
692693
Name: "set prefetcher" + prefetcherType,
693694
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", pf.Msr, newVal),
694695
Superuser: true,
695-
Vendors: []string{"GenuineIntel"},
696+
Vendors: []string{cpus.IntelVendor},
696697
// Depends: []string{"wrmsr"},
697698
// Lkms: []string{"msr"},
698699
}
@@ -762,7 +763,7 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
762763
getScript := script.ScriptDefinition{
763764
Name: "get C1 demotion",
764765
ScriptTemplate: "rdmsr 0xe2",
765-
Vendors: []string{"GenuineIntel"},
766+
Vendors: []string{cpus.IntelVendor},
766767
Superuser: true,
767768
// Lkms: []string{"msr"},
768769
// Depends: []string{"rdmsr"},
@@ -797,7 +798,7 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
797798
setScript := script.ScriptDefinition{
798799
Name: "set C1 demotion",
799800
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", 0xe2, newVal),
800-
Vendors: []string{"GenuineIntel"},
801+
Vendors: []string{cpus.IntelVendor},
801802
Superuser: true,
802803
// Depends: []string{"wrmsr"},
803804
// Lkms: []string{"msr"},

cmd/metrics/metadata.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"strings"
1919
"time"
2020

21+
"perfspect/internal/cpus"
2122
"perfspect/internal/report"
2223
"perfspect/internal/script"
2324
"perfspect/internal/target"
@@ -93,9 +94,9 @@ type MetadataCollector interface {
9394

9495
func NewMetadataCollector(architecture string) (MetadataCollector, error) {
9596
switch architecture {
96-
case "x86_64":
97+
case cpus.X86Architecture:
9798
return &X86MetadataCollector{}, nil
98-
case "aarch64":
99+
case cpus.ARMArchitecture:
99100
return &ARMMetadataCollector{}, nil
100101
default:
101102
return nil, fmt.Errorf("unsupported architecture: %s", architecture)
@@ -145,7 +146,7 @@ func (c *X86MetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
145146
// Vendor (from cpuInfo)
146147
metadata.Vendor = cpuInfo[0]["vendor_id"]
147148
// CPU microarchitecture (from cpuInfo)
148-
cpu, err := report.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"])
149+
cpu, err := cpus.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"])
149150
if err != nil {
150151
return Metadata{}, err
151152
}
@@ -261,7 +262,7 @@ func (c *X86MetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
261262
metadata.TSC = metadata.SocketCount * metadata.CoresPerSocket * metadata.ThreadsPerCore * metadata.TSCFrequencyHz
262263
}
263264
// uncore device IDs and uncore support
264-
isAMDArchitecture := metadata.Vendor == "AuthenticAMD"
265+
isAMDArchitecture := metadata.Vendor == cpus.AMDVendor
265266
if metadata.UncoreDeviceIDs, err = getUncoreDeviceIDs(isAMDArchitecture, scriptOutputs); err != nil {
266267
return Metadata{}, fmt.Errorf("failed to retrieve uncore device IDs: %v", err)
267268
} else {
@@ -330,7 +331,7 @@ func (c *ARMMetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
330331
if err != nil {
331332
return Metadata{}, fmt.Errorf("failed to parse stepping: %v", err)
332333
}
333-
cpu, err := report.GetCPU(family, model, stepping)
334+
cpu, err := cpus.GetCPU(family, model, stepping)
334335
if err != nil {
335336
return Metadata{}, err
336337
}
@@ -412,7 +413,7 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
412413
Name: "list uncore devices",
413414
ScriptTemplate: "find /sys/bus/event_source/devices/ \\( -name uncore_* -o -name amd_* \\)",
414415
Superuser: !noRoot,
415-
Architectures: []string{"x86_64"},
416+
Architectures: []string{cpus.X86Architecture},
416417
},
417418
{
418419
Name: "perf stat instructions",
@@ -428,19 +429,19 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
428429
Name: "perf stat pebs",
429430
ScriptTemplate: perfPath + " stat -a -e INT_MISC.UNKNOWN_BRANCH_CYCLES sleep 1",
430431
Superuser: !noRoot,
431-
Architectures: []string{"x86_64"},
432+
Architectures: []string{cpus.X86Architecture},
432433
},
433434
{
434435
Name: "perf stat ocr",
435436
ScriptTemplate: perfPath + " stat -a -e OCR.READS_TO_CORE.LOCAL_DRAM sleep 1",
436437
Superuser: !noRoot,
437-
Architectures: []string{"x86_64"},
438+
Architectures: []string{cpus.X86Architecture},
438439
},
439440
{
440441
Name: "perf stat tma",
441442
ScriptTemplate: perfPath + " stat -a -e '{topdown.slots, topdown-bad-spec}' sleep 1",
442443
Superuser: !noRoot,
443-
Architectures: []string{"x86_64"},
444+
Architectures: []string{cpus.X86Architecture},
444445
},
445446
{
446447
Name: "perf stat fixed instructions",
@@ -467,7 +468,7 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
467468
ScriptTemplate: "tsc && echo",
468469
Depends: []string{"tsc"},
469470
Superuser: !noRoot,
470-
Architectures: []string{"x86_64"},
471+
Architectures: []string{cpus.X86Architecture},
471472
},
472473
{
473474
Name: "kernel version",
@@ -478,13 +479,13 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
478479
Name: "arm slots",
479480
ScriptTemplate: "cat /sys/bus/event_source/devices/armv8_pmuv3_0/caps/slots",
480481
Superuser: !noRoot,
481-
Architectures: []string{"aarch64"},
482+
Architectures: []string{cpus.ARMArchitecture},
482483
},
483484
{
484485
Name: "arm cpuid",
485486
ScriptTemplate: "cat /sys/devices/system/cpu/cpu0/regs/identification/midr_el1",
486487
Superuser: !noRoot,
487-
Architectures: []string{"aarch64"},
488+
Architectures: []string{cpus.ARMArchitecture},
488489
},
489490
}
490491
// replace script template vars

cmd/metrics/metrics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"perfspect/internal/common"
27+
"perfspect/internal/cpus"
2728
"perfspect/internal/progress"
2829
"perfspect/internal/script"
2930
"perfspect/internal/target"
@@ -1146,7 +1147,7 @@ func prepareTarget(targetContext *targetContext, localTempDir string, localPerfP
11461147
var err error
11471148
_ = statusUpdate(myTarget.GetName(), "configuring target")
11481149
// are PMUs being used on target?
1149-
if family, err := myTarget.GetFamily(); err == nil && family == "6" {
1150+
if family, err := myTarget.GetFamily(); err == nil && cpus.IsIntelCPUFamilyStr(family) {
11501151
output, err := script.RunScript(myTarget, script.GetScriptByName(script.PMUBusyScriptName), localTempDir)
11511152
if err != nil {
11521153
err = fmt.Errorf("failed to check if PMUs are in use: %w", err)
@@ -1197,7 +1198,7 @@ func prepareTarget(targetContext *targetContext, localTempDir string, localPerfP
11971198
if useDefaultMuxInterval {
11981199
// set the default mux interval to 16ms for AMD architecture
11991200
vendor, err := myTarget.GetVendor()
1200-
if err == nil && vendor == "AuthenticAMD" {
1201+
if err == nil && vendor == cpus.AMDVendor {
12011202
perfMuxInterval = 16
12021203
}
12031204
}

cmd/metrics/summary.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"math"
1616
"os"
1717
"path/filepath"
18+
"perfspect/internal/cpus"
1819
"regexp"
1920
"slices"
2021
"strconv"
@@ -384,7 +385,7 @@ func (mg *MetricGroup) loadHTMLTemplateValues(metadata Metadata, metricDefinitio
384385
//0 -> Intel, 1 -> AMD, 2 -> ARM
385386
archIndex := 0
386387
switch metadata.Vendor {
387-
case "AuthenticAMD":
388+
case cpus.AMDVendor:
388389
archIndex = 1
389390
case "ARM":
390391
archIndex = 2

0 commit comments

Comments
 (0)