Skip to content

Commit 97b4b4b

Browse files
authored
Merge pull request #149 from intel/archconfig
limit config flags to specific uarchs
2 parents 43fc051 + 6649e92 commit 97b4b4b

File tree

8 files changed

+69
-29
lines changed

8 files changed

+69
-29
lines changed

cmd/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func getFlagGroups() []common.FlagGroup {
156156
},
157157
{
158158
Name: flagElcName,
159-
Help: "set Efficiency Latency Control (SRF and GNR) (" + strings.Join(elcOptions, ", ") + ")",
159+
Help: "set Efficiency Latency Control (" + strings.Join(elcOptions, ", ") + ")",
160160
},
161161
}
162162
groups := []common.FlagGroup{}
@@ -507,7 +507,8 @@ func setLlcSize(llcSize float64, myTarget target.Target, localTempDir string) {
507507
Script: fmt.Sprintf("wrmsr -a 0xC90 %d", cacheWays[waysToSet]),
508508
Superuser: true,
509509
Architectures: []string{"x86_64"},
510-
Families: []string{"6"}, // Intel only
510+
Families: []string{"6"}, // Intel only
511+
Models: []string{"63", "79", "86", "85", "106", "108", "143", "207"}, // not SRF, GNR
511512
Depends: []string{"wrmsr"},
512513
Lkms: []string{"msr"},
513514
}

cmd/metrics/metadata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func LoadMetadata(myTarget target.Target, noRoot bool, perfPath string, localTem
8989
metadata.Vendor = cpuInfo[0]["vendor_id"]
9090
// CPU microarchitecture
9191
cpuDb := cpudb.NewCPUDB()
92-
cpu, err := cpuDb.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"], "", "", "")
92+
cpu, err := cpuDb.GetCPU(cpuInfo[0]["cpu family"], cpuInfo[0]["model"], cpuInfo[0]["stepping"])
9393
if err != nil {
9494
return
9595
}

internal/cpudb/cpu_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,52 @@ import (
1111
func TestGetCPU(t *testing.T) {
1212
cpudb := NewCPUDB()
1313
// should fail
14-
_, err := cpudb.GetCPU("0", "0", "0", "", "", "")
14+
_, err := cpudb.GetCPU("0", "0", "0")
1515
if err == nil {
1616
t.Fatal(err)
1717
}
1818

19-
cpu, err := cpudb.GetCPU("6", "85", "4", "", "", "") //SKX
19+
cpu, err := cpudb.GetCPU("6", "85", "4") //SKX
2020
if err != nil {
2121
t.Fatal(err)
2222
}
2323
if cpu.MicroArchitecture != "SKX" {
2424
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
2525
}
2626

27-
cpu, err = cpudb.GetCPU("6", "85", "7", "", "", "") //CLX
27+
cpu, err = cpudb.GetCPU("6", "85", "7") //CLX
2828
if err != nil {
2929
t.Fatal(err)
3030
}
3131
if cpu.MicroArchitecture != "CLX" {
3232
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
3333
}
3434

35-
cpu, err = cpudb.GetCPU("6", "85", "6", "", "", "") //CLX
35+
cpu, err = cpudb.GetCPU("6", "85", "6") //CLX
3636
if err != nil {
3737
t.Fatal(err)
3838
}
3939
if cpu.MicroArchitecture != "CLX" {
4040
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
4141
}
4242

43-
cpu, err = cpudb.GetCPU("6", "108", "", "", "", "0") //ICX
43+
cpu, err = cpudb.GetCPU("6", "108", "0") //ICX
4444
if err != nil {
4545
t.Fatal(err)
4646
}
4747
if cpu.MicroArchitecture != "ICX" {
4848
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
4949
}
5050

51-
cpu, err = cpudb.GetCPU("6", "71", "", "", "", "0") //BDW
51+
cpu, err = cpudb.GetCPU("6", "71", "0") //BDW
5252
if err != nil {
5353
t.Fatal(err)
5454
}
5555
if cpu.MicroArchitecture != "BDW" {
5656
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
5757
}
5858

59-
cpu, err = cpudb.GetCPU("6", "173", "", "", "2", "10") // GNR_X3
59+
cpu, err = cpudb.GetCPUExtended("6", "173", "", "", "2", "10") // GNR_X3
6060
if err != nil {
6161
t.Fatal(err)
6262
}
@@ -67,7 +67,7 @@ func TestGetCPU(t *testing.T) {
6767
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
6868
}
6969

70-
cpu, err = cpudb.GetCPU("6", "173", "", "", "2", "8") // GNR_X2
70+
cpu, err = cpudb.GetCPUExtended("6", "173", "", "", "2", "8") // GNR_X2
7171
if err != nil {
7272
t.Fatal(err)
7373
}
@@ -78,7 +78,7 @@ func TestGetCPU(t *testing.T) {
7878
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
7979
}
8080

81-
cpu, err = cpudb.GetCPU("6", "173", "", "", "2", "6") // GNR_X1
81+
cpu, err = cpudb.GetCPUExtended("6", "173", "", "", "2", "6") // GNR_X1
8282
if err != nil {
8383
t.Fatal(err)
8484
}
@@ -89,15 +89,15 @@ func TestGetCPU(t *testing.T) {
8989
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
9090
}
9191

92-
cpu, err = cpudb.GetCPU("6", "173", "", "", "", "") // GNR with no differentiation
92+
cpu, err = cpudb.GetCPU("6", "173", "") // GNR with no differentiation
9393
if err != nil {
9494
t.Fatal(err)
9595
}
9696
if cpu.MicroArchitecture != "GNR" {
9797
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
9898
}
9999

100-
cpu, err = cpudb.GetCPU("6", "207", "", "c0", "", "") // EMR XCC
100+
cpu, err = cpudb.GetCPUExtended("6", "207", "", "c0", "", "") // EMR XCC
101101
if err != nil {
102102
t.Fatal(err)
103103
}
@@ -108,7 +108,7 @@ func TestGetCPU(t *testing.T) {
108108
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
109109
}
110110

111-
cpu, err = cpudb.GetCPU("6", "207", "", "40", "", "") // EMR MCC
111+
cpu, err = cpudb.GetCPUExtended("6", "207", "", "40", "", "") // EMR MCC
112112
if err != nil {
113113
t.Fatal(err)
114114
}
@@ -119,7 +119,7 @@ func TestGetCPU(t *testing.T) {
119119
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
120120
}
121121

122-
cpu, err = cpudb.GetCPU("6", "207", "", "", "", "") // EMR with no differentiation
122+
cpu, err = cpudb.GetCPU("6", "207", "") // EMR with no differentiation
123123
if err != nil {
124124
t.Fatal(err)
125125
}
@@ -130,7 +130,7 @@ func TestGetCPU(t *testing.T) {
130130
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
131131
}
132132

133-
cpu, err = cpudb.GetCPU("25", "1", "", "", "", "") // Milan
133+
cpu, err = cpudb.GetCPU("25", "1", "") // Milan
134134
if err != nil {
135135
t.Fatal(err)
136136
}
@@ -141,7 +141,7 @@ func TestGetCPU(t *testing.T) {
141141
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
142142
}
143143

144-
cpu, err = cpudb.GetCPU("25", "17", "", "", "", "") // Genoa
144+
cpu, err = cpudb.GetCPU("25", "17", "") // Genoa
145145
if err != nil {
146146
t.Fatal(err)
147147
}
@@ -152,23 +152,23 @@ func TestGetCPU(t *testing.T) {
152152
t.Fatal(fmt.Errorf("Incorrect channel count: %d", cpu.MemoryChannelCount))
153153
}
154154

155-
cpu, err = cpudb.GetCPU("6", "69", "99", "", "", "") //HSW
155+
cpu, err = cpudb.GetCPU("6", "69", "99") //HSW
156156
if err != nil {
157157
t.Fatal(err)
158158
}
159159
if cpu.MicroArchitecture != "HSW" {
160160
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
161161
}
162162

163-
cpu, err = cpudb.GetCPU("6", "70", "", "", "", "") //HSW
163+
cpu, err = cpudb.GetCPU("6", "70", "") //HSW
164164
if err != nil {
165165
t.Fatal(err)
166166
}
167167
if cpu.MicroArchitecture != "HSW" {
168168
t.Fatal(fmt.Errorf("Found the wrong CPU: %s", cpu.MicroArchitecture))
169169
}
170170

171-
cpu, err = cpudb.GetCPU("", "1", "r3p1", "", "", "") // N1
171+
cpu, err = cpudb.GetCPU("", "1", "r3p1") // N1
172172
if err != nil {
173173
t.Fatal(err)
174174
}

internal/cpudb/cpudb.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ func NewCPUDB() *CPUDB {
2121
}
2222

2323
// GetCPU retrieves the CPU structure that matches the provided args
24+
func (c *CPUDB) GetCPU(family, model, stepping string) (cpu CPU, err error) {
25+
return c.GetCPUExtended(family, model, stepping, "", "", "")
26+
}
27+
28+
// GetCPUExtended retrieves the CPU structure that matches the provided args
2429
// capid4 needed to differentiate EMR MCC from EMR XCC
2530
//
2631
// capid4: $ lspci -s $(lspci | grep 325b | awk 'NR==1{{print $1}}') -xxx | awk '$1 ~ /^90/{{print $9 $8 $7 $6; exit}}'
2732
//
2833
// sockets and devices (eventually devices per socket) needed to differentiate GNR X1/2/3
2934
//
3035
// devices: $ lspci -d 8086:3258 | wc -l
31-
func (c *CPUDB) GetCPU(family, model, stepping, capid4, sockets, devices string) (cpu CPU, err error) {
36+
func (c *CPUDB) GetCPUExtended(family, model, stepping, capid4, sockets, devices string) (cpu CPU, err error) {
3237
for _, info := range *c {
3338
// if family matches
3439
if info.Family == family {

internal/report/table_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func uarchFromOutput(outputs map[string]script.ScriptOutput) string {
146146
capid4 := valFromRegexSubmatch(outputs[script.LspciBitsScriptName].Stdout, `^([0-9a-fA-F]+)`)
147147
devices := valFromRegexSubmatch(outputs[script.LspciDevicesScriptName].Stdout, `^([0-9]+)`)
148148
CPUdb := cpudb.NewCPUDB()
149-
cpu, err := CPUdb.GetCPU(family, model, stepping, capid4, sockets, devices)
149+
cpu, err := CPUdb.GetCPUExtended(family, model, stepping, capid4, sockets, devices)
150150
if err == nil {
151151
return cpu.MicroArchitecture
152152
}
@@ -305,7 +305,7 @@ func hyperthreadingFromOutput(outputs map[string]script.ScriptOutput) string {
305305
return ""
306306
}
307307
CPUdb := cpudb.NewCPUDB()
308-
cpu, err := CPUdb.GetCPU(family, model, stepping, "", sockets, "")
308+
cpu, err := CPUdb.GetCPUExtended(family, model, stepping, "", sockets, "")
309309
if err != nil {
310310
return ""
311311
}
@@ -353,7 +353,7 @@ func channelsFromOutput(outputs map[string]script.ScriptOutput) string {
353353
capid4 := valFromRegexSubmatch(outputs[script.LspciBitsScriptName].Stdout, `^([0-9a-fA-F]+)`)
354354
devices := valFromRegexSubmatch(outputs[script.LspciDevicesScriptName].Stdout, `^([0-9]+)`)
355355
CPUdb := cpudb.NewCPUDB()
356-
cpu, err := CPUdb.GetCPU(family, model, stepping, capid4, sockets, devices)
356+
cpu, err := CPUdb.GetCPUExtended(family, model, stepping, capid4, sockets, devices)
357357
if err != nil {
358358
slog.Error("error getting CPU from CPUdb", slog.String("error", err.Error()))
359359
return ""

internal/script/script.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func RunScript(myTarget target.Target, script ScriptDefinition, localTempDir str
4848
if len(script.Architectures) > 0 && !util.StringInList(targetArchitecture, script.Architectures) ||
4949
len(script.Families) > 0 && !util.StringInList(targetFamily, script.Families) ||
5050
len(script.Models) > 0 && !util.StringInList(targetModel, script.Models) {
51-
err = fmt.Errorf("\"%s\" script is not intended for the target processor", script.Name)
51+
err = fmt.Errorf("the \"%s\" script is not intended for the target processor (arch: %s, family: %s, model: %s)", script.Name, targetArchitecture, targetFamily, targetModel)
5252
return
5353
}
5454
scriptOutputs, err := RunScripts(myTarget, []ScriptDefinition{script}, false, localTempDir)

internal/script/script_defs.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,17 @@ func getCollectionScripts(duration, interval int, frequency int) (scripts []Scri
152152
{
153153
Name: LspciBitsScriptName,
154154
Script: "lspci -s $(lspci | grep 325b | awk 'NR==1{{print $1}}') -xxx | awk '$1 ~ /^90/{{print $9 $8 $7 $6; exit}}'",
155+
Families: []string{"6"}, // Intel
156+
Models: []string{"143", "207", "173"}, // SPR, EMR, GNR
155157
Superuser: true,
156158
Depends: []string{"lspci"},
157159
},
158160
{
159-
Name: LspciDevicesScriptName,
160-
Script: "lspci -d 8086:3258 | wc -l",
161-
Depends: []string{"lspci"},
161+
Name: LspciDevicesScriptName,
162+
Script: "lspci -d 8086:3258 | wc -l",
163+
Families: []string{"6"}, // Intel
164+
Models: []string{"143", "207", "173"}, // SPR, EMR, GNR
165+
Depends: []string{"lspci"},
162166
},
163167
{
164168
Name: LspciVmmScriptName,

internal/target/target.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type Target interface {
5151
// It returns a string representing the model and any error that occurred.
5252
GetModel() (model string, err error)
5353

54+
// GetStepping returns the stepping of the target system's CPU.
55+
// It returns a string representing the stepping and any error that occurred.
56+
GetStepping() (stepping string, err error)
57+
5458
// GetName returns the name of the target system.
5559
// It returns a string representing the host.
5660
GetName() (name string)
@@ -119,6 +123,7 @@ type LocalTarget struct {
119123
arch string
120124
family string
121125
model string
126+
stepping string
122127
userPath string
123128
canElevate int // zero indicates unknown, 1 indicates yes, -1 indicates no
124129
}
@@ -135,6 +140,7 @@ type RemoteTarget struct {
135140
arch string
136141
family string
137142
model string
143+
stepping string
138144
userPath string
139145
canElevate int
140146
}
@@ -260,6 +266,20 @@ func (t *RemoteTarget) GetModel() (family string, err error) {
260266
return t.model, err
261267
}
262268

269+
func (t *LocalTarget) GetStepping() (stepping string, err error) {
270+
if t.stepping == "" {
271+
t.stepping, err = getStepping(t)
272+
}
273+
return t.stepping, err
274+
}
275+
276+
func (t *RemoteTarget) GetStepping() (stepping string, err error) {
277+
if t.stepping == "" {
278+
t.stepping, err = getStepping(t)
279+
}
280+
return t.stepping, err
281+
}
282+
263283
// CreateTempDirectory creates a temporary directory under the specified root directory.
264284
// It returns the path of the created temporary directory and any error encountered.
265285
func (t *LocalTarget) CreateTempDirectory(rootDir string) (tempDir string, err error) {
@@ -781,6 +801,16 @@ func getModel(t Target) (model string, err error) {
781801
return
782802
}
783803

804+
func getStepping(t Target) (stepping string, err error) {
805+
cmd := exec.Command("bash", "-c", "lscpu | grep -i stepping: | awk '{print $NF}'")
806+
stepping, _, _, err = t.RunCommand(cmd, 0, true)
807+
if err != nil {
808+
return
809+
}
810+
stepping = strings.TrimSpace(stepping)
811+
return
812+
}
813+
784814
func installLkms(t Target, lkms []string) (installedLkms []string, err error) {
785815
if !t.CanElevatePrivileges() {
786816
err = fmt.Errorf("can't elevate privileges; elevated privileges required to install lkms")

0 commit comments

Comments
 (0)