Skip to content
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 cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log/slog"
"os"
"perfspect/internal/common"
"perfspect/internal/cpus"
"perfspect/internal/progress"
"perfspect/internal/report"
"perfspect/internal/script"
Expand Down Expand Up @@ -158,7 +159,7 @@ func prepareTarget(myTarget target.Target, localTempDir string) (err error) {
Name: "prepare-target",
ScriptTemplate: "exit 0",
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Depends: []string{"wrmsr", "rdmsr"},
Lkms: []string{"msr"},
}
Expand Down
57 changes: 29 additions & 28 deletions cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log/slog"
"math"
"perfspect/internal/cpus"
"perfspect/internal/report"
"perfspect/internal/script"
"perfspect/internal/target"
Expand Down Expand Up @@ -132,7 +133,7 @@ func setLlcSize(desiredLlcSize float64, myTarget target.Target, localTempDir str
}

uarch := report.UarchFromOutput(outputs)
cpu, err := report.GetCPUByMicroArchitecture(uarch)
cpu, err := cpus.GetCPUByMicroArchitecture(uarch)
if err != nil {
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("failed to get CPU by microarchitecture: %w", err)}
return
Expand Down Expand Up @@ -176,7 +177,7 @@ func setLlcSize(desiredLlcSize float64, myTarget target.Target, localTempDir str
Name: "set LLC size",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0xC90 %d", msrVal),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -203,7 +204,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("failed to get target vendor: %w", err)}
return
}
if targetVendor != "GenuineIntel" {
if targetVendor != cpus.IntelVendor {
completeChannel <- setOutput{goRoutineID: goRoutineId, err: fmt.Errorf("core frequency setting not supported on %s due to vendor mismatch", myTarget.GetName())}
return
}
Expand All @@ -214,7 +215,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
getScript := script.ScriptDefinition{
Name: "get pstate driver",
ScriptTemplate: "cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver",
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
}
output, err := runScript(myTarget, getScript, localTempDir)
if err != nil {
Expand All @@ -231,7 +232,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
Name: "set frequency bins",
ScriptTemplate: fmt.Sprintf("wrmsr 0x774 %d", value),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -241,7 +242,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
Name: "set frequency bins",
ScriptTemplate: fmt.Sprintf("wrmsr 0x199 %d", value),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -256,7 +257,7 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
Name: "set frequency bins",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x1AD %d", value),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand Down Expand Up @@ -326,7 +327,7 @@ func setUncoreDieFrequency(maxFreq bool, computeDie bool, uncoreFrequency float6
setScript := script.ScriptDefinition{
Name: "write max and min uncore frequency TPMI",
ScriptTemplate: fmt.Sprintf("pcm-tpmi 2 0x18 -d -b %s -w %d -i %s -e %s", bits, value, die.instance, die.entry),
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Depends: []string{"pcm-tpmi"},
Superuser: true,
}
Expand All @@ -348,7 +349,7 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
scripts = append(scripts, script.ScriptDefinition{
Name: "get uncore frequency MSR",
ScriptTemplate: "rdmsr 0x620",
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Depends: []string{"rdmsr"},
// Lkms: []string{"msr"},
Expand Down Expand Up @@ -394,7 +395,7 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
Name: "set uncore frequency MSR",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x620 %d", newVal),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -410,7 +411,7 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
Name: "get power MSR",
ScriptTemplate: "rdmsr 0x610",
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
}
Expand All @@ -433,7 +434,7 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
Name: "set tdp",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x610 %d", newVal),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand Down Expand Up @@ -472,7 +473,7 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
readScript := script.ScriptDefinition{
Name: "read " + msr,
ScriptTemplate: "rdmsr " + msr,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
Expand All @@ -496,7 +497,7 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
Name: "set epb",
ScriptTemplate: fmt.Sprintf("wrmsr -a %s %d", msr, msrValue),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -515,7 +516,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
getScript := script.ScriptDefinition{
Name: "get epp msr",
ScriptTemplate: "rdmsr 0x774", // IA32_HWP_REQUEST
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
Expand All @@ -539,7 +540,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
Name: "set epp",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand All @@ -552,7 +553,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
getScript = script.ScriptDefinition{
Name: "get epp pkg msr",
ScriptTemplate: "rdmsr 0x772", // IA32_HWP_REQUEST_PKG
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
Expand All @@ -576,7 +577,7 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
Name: "set epp",
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x772 %d", eppValue),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand Down Expand Up @@ -612,12 +613,12 @@ func setELC(elc string, myTarget target.Target, localTempDir string, completeCha
return
}
setScript := script.ScriptDefinition{
Name: "set elc",
ScriptTemplate: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Models: []string{"173", "174", "175", "221"}, // GNR, GNR-D, SRF, CWF
Depends: []string{"bhs-power-mode.sh", "pcm-tpmi"},
Name: "set elc",
ScriptTemplate: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
Superuser: true,
Vendors: []string{cpus.IntelVendor},
MicroArchitectures: []string{"GNR", "GNR-D", "SRF", "CWF"},
Depends: []string{"bhs-power-mode.sh", "pcm-tpmi"},
}
_, err := runScript(myTarget, setScript, localTempDir)
if err != nil {
Expand Down Expand Up @@ -657,7 +658,7 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
getScript := script.ScriptDefinition{
Name: "get prefetcher msr",
ScriptTemplate: fmt.Sprintf("rdmsr %d", pf.Msr),
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
Expand Down Expand Up @@ -692,7 +693,7 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
Name: "set prefetcher" + prefetcherType,
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", pf.Msr, newVal),
Superuser: true,
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
}
Expand Down Expand Up @@ -762,7 +763,7 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
getScript := script.ScriptDefinition{
Name: "get C1 demotion",
ScriptTemplate: "rdmsr 0xe2",
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Lkms: []string{"msr"},
// Depends: []string{"rdmsr"},
Expand Down Expand Up @@ -797,7 +798,7 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
setScript := script.ScriptDefinition{
Name: "set C1 demotion",
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", 0xe2, newVal),
Vendors: []string{"GenuineIntel"},
Vendors: []string{cpus.IntelVendor},
Superuser: true,
// Depends: []string{"wrmsr"},
// Lkms: []string{"msr"},
Expand Down
25 changes: 13 additions & 12 deletions cmd/metrics/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"
"time"

"perfspect/internal/cpus"
"perfspect/internal/report"
"perfspect/internal/script"
"perfspect/internal/target"
Expand Down Expand Up @@ -93,9 +94,9 @@ type MetadataCollector interface {

func NewMetadataCollector(architecture string) (MetadataCollector, error) {
switch architecture {
case "x86_64":
case cpus.X86Architecture:
return &X86MetadataCollector{}, nil
case "aarch64":
case cpus.ARMArchitecture:
return &ARMMetadataCollector{}, nil
default:
return nil, fmt.Errorf("unsupported architecture: %s", architecture)
Expand Down Expand Up @@ -145,7 +146,7 @@ func (c *X86MetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
// Vendor (from cpuInfo)
metadata.Vendor = cpuInfo[0]["vendor_id"]
// CPU microarchitecture (from cpuInfo)
cpu, err := report.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"])
cpu, err := cpus.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"])
if err != nil {
return Metadata{}, err
}
Expand Down Expand Up @@ -261,7 +262,7 @@ func (c *X86MetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
metadata.TSC = metadata.SocketCount * metadata.CoresPerSocket * metadata.ThreadsPerCore * metadata.TSCFrequencyHz
}
// uncore device IDs and uncore support
isAMDArchitecture := metadata.Vendor == "AuthenticAMD"
isAMDArchitecture := metadata.Vendor == cpus.AMDVendor
if metadata.UncoreDeviceIDs, err = getUncoreDeviceIDs(isAMDArchitecture, scriptOutputs); err != nil {
return Metadata{}, fmt.Errorf("failed to retrieve uncore device IDs: %v", err)
} else {
Expand Down Expand Up @@ -330,7 +331,7 @@ func (c *ARMMetadataCollector) CollectMetadata(myTarget target.Target, noRoot bo
if err != nil {
return Metadata{}, fmt.Errorf("failed to parse stepping: %v", err)
}
cpu, err := report.GetCPU(family, model, stepping)
cpu, err := cpus.GetCPU(family, model, stepping)
if err != nil {
return Metadata{}, err
}
Expand Down Expand Up @@ -412,7 +413,7 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
Name: "list uncore devices",
ScriptTemplate: "find /sys/bus/event_source/devices/ \\( -name uncore_* -o -name amd_* \\)",
Superuser: !noRoot,
Architectures: []string{"x86_64"},
Architectures: []string{cpus.X86Architecture},
},
{
Name: "perf stat instructions",
Expand All @@ -428,19 +429,19 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
Name: "perf stat pebs",
ScriptTemplate: perfPath + " stat -a -e INT_MISC.UNKNOWN_BRANCH_CYCLES sleep 1",
Superuser: !noRoot,
Architectures: []string{"x86_64"},
Architectures: []string{cpus.X86Architecture},
},
{
Name: "perf stat ocr",
ScriptTemplate: perfPath + " stat -a -e OCR.READS_TO_CORE.LOCAL_DRAM sleep 1",
Superuser: !noRoot,
Architectures: []string{"x86_64"},
Architectures: []string{cpus.X86Architecture},
},
{
Name: "perf stat tma",
ScriptTemplate: perfPath + " stat -a -e '{topdown.slots, topdown-bad-spec}' sleep 1",
Superuser: !noRoot,
Architectures: []string{"x86_64"},
Architectures: []string{cpus.X86Architecture},
},
{
Name: "perf stat fixed instructions",
Expand All @@ -467,7 +468,7 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
ScriptTemplate: "tsc && echo",
Depends: []string{"tsc"},
Superuser: !noRoot,
Architectures: []string{"x86_64"},
Architectures: []string{cpus.X86Architecture},
},
{
Name: "kernel version",
Expand All @@ -478,13 +479,13 @@ func getMetadataScripts(noRoot bool, perfPath string, noSystemSummary bool, numG
Name: "arm slots",
ScriptTemplate: "cat /sys/bus/event_source/devices/armv8_pmuv3_0/caps/slots",
Superuser: !noRoot,
Architectures: []string{"aarch64"},
Architectures: []string{cpus.ARMArchitecture},
},
{
Name: "arm cpuid",
ScriptTemplate: "cat /sys/devices/system/cpu/cpu0/regs/identification/midr_el1",
Superuser: !noRoot,
Architectures: []string{"aarch64"},
Architectures: []string{cpus.ARMArchitecture},
},
}
// replace script template vars
Expand Down
5 changes: 3 additions & 2 deletions cmd/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"perfspect/internal/common"
"perfspect/internal/cpus"
"perfspect/internal/progress"
"perfspect/internal/script"
"perfspect/internal/target"
Expand Down Expand Up @@ -1146,7 +1147,7 @@ func prepareTarget(targetContext *targetContext, localTempDir string, localPerfP
var err error
_ = statusUpdate(myTarget.GetName(), "configuring target")
// are PMUs being used on target?
if family, err := myTarget.GetFamily(); err == nil && family == "6" {
if family, err := myTarget.GetFamily(); err == nil && cpus.IsIntelCPUFamilyStr(family) {
output, err := script.RunScript(myTarget, script.GetScriptByName(script.PMUBusyScriptName), localTempDir)
if err != nil {
err = fmt.Errorf("failed to check if PMUs are in use: %w", err)
Expand Down Expand Up @@ -1197,7 +1198,7 @@ func prepareTarget(targetContext *targetContext, localTempDir string, localPerfP
if useDefaultMuxInterval {
// set the default mux interval to 16ms for AMD architecture
vendor, err := myTarget.GetVendor()
if err == nil && vendor == "AuthenticAMD" {
if err == nil && vendor == cpus.AMDVendor {
perfMuxInterval = 16
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/metrics/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"math"
"os"
"path/filepath"
"perfspect/internal/cpus"
"regexp"
"slices"
"strconv"
Expand Down Expand Up @@ -384,7 +385,7 @@ func (mg *MetricGroup) loadHTMLTemplateValues(metadata Metadata, metricDefinitio
//0 -> Intel, 1 -> AMD, 2 -> ARM
archIndex := 0
switch metadata.Vendor {
case "AuthenticAMD":
case cpus.AMDVendor:
archIndex = 1
case "ARM":
archIndex = 2
Expand Down
Loading