Skip to content

Commit b1af182

Browse files
authored
Merge pull request #142 from intel/eppfix
consider pkg control value when getting and setting EPP
2 parents 482f9dd + b6f6931 commit b1af182

File tree

4 files changed

+62
-35
lines changed

4 files changed

+62
-35
lines changed

cmd/config/config.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,7 @@ func setEpb(epb int, myTarget target.Target, localTempDir string) {
700700

701701
func setEpp(epp int, myTarget target.Target, localTempDir string) {
702702
fmt.Printf("set energy performance profile (EPP) to %d on %s\n", epp, myTarget.GetName())
703-
// Mark the per-processor EPP values as invalid, so that the
704-
// package EPP value is used. Then set the package EPP value.
703+
// Set both the per-core EPP value and the package EPP value
705704
// Reference: 15.4.4 Managing HWP in the Intel SDM
706705

707706
// get the current value of the IAEW_HWP_REQUEST MSR that includes the current EPP valid value in bit 60
@@ -724,12 +723,14 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
724723
slog.Error("failed to parse msr value", slog.String("msr", stdout), slog.String("error", err.Error()))
725724
return
726725
}
727-
// clear bit 60 in the IA32_HWP_REQUEST MSR value
728-
maskedValue := msrValue & 0xEFFFFFFFFFFFFFFF
726+
// mask out bits 24-31 IA32_HWP_REQUEST MSR value
727+
maskedValue := msrValue & 0xFFFFFFFF00FFFFFF
728+
// put the EPP value in bits 24-31
729+
eppValue := maskedValue | uint64(epp)<<24
729730
// write it back to the MSR
730731
setScript := script.ScriptDefinition{
731-
Name: "set epp valid",
732-
Script: fmt.Sprintf("wrmsr -a 0x774 %d", maskedValue),
732+
Name: "set epp",
733+
Script: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
733734
Superuser: true,
734735
Architectures: []string{"x86_64"},
735736
Families: []string{"6"}, // Intel only
@@ -738,7 +739,7 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
738739
}
739740
_, err = runScript(myTarget, setScript, localTempDir)
740741
if err != nil {
741-
fmt.Fprintf(os.Stderr, "Error: failed to set EPP valid: %v\n", err)
742+
fmt.Fprintf(os.Stderr, "Error: failed to set EPP: %v\n", err)
742743
return
743744
}
744745

@@ -754,7 +755,7 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
754755
}
755756
stdout, err = runScript(myTarget, getScript, localTempDir)
756757
if err != nil {
757-
fmt.Fprintf(os.Stderr, "Error: failed to get EPP: %v\n", err)
758+
fmt.Fprintf(os.Stderr, "Error: failed to get pkg EPP: %v\n", err)
758759
return
759760
}
760761
msrValue, err = strconv.ParseUint(strings.TrimSpace(stdout), 16, 64)
@@ -766,7 +767,7 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
766767
// mask out bits 24-31 IA32_HWP_REQUEST_PKG MSR value
767768
maskedValue = msrValue & 0xFFFFFFFF00FFFFFF
768769
// put the EPP value in bits 24-31
769-
eppValue := maskedValue | uint64(epp)<<24
770+
eppValue = maskedValue | uint64(epp)<<24
770771
// write it back to the MSR
771772
setScript = script.ScriptDefinition{
772773
Name: "set epp",
@@ -779,7 +780,7 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
779780
}
780781
_, err = runScript(myTarget, setScript, localTempDir)
781782
if err != nil {
782-
fmt.Fprintf(os.Stderr, "Error: failed to set EPP: %v\n", err)
783+
fmt.Fprintf(os.Stderr, "Error: failed to set pkg EPP: %v\n", err)
783784
}
784785
}
785786

internal/report/table_defs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ var tableDefinitions = map[string]TableDefinition{
217217
script.EpbScriptName,
218218
script.EppScriptName,
219219
script.EppValidScriptName,
220+
script.EppPackageControlScriptName,
220221
script.EppPackageScriptName,
221222
script.ScalingDriverScriptName,
222223
script.ScalingGovernorScriptName},
@@ -461,6 +462,7 @@ var tableDefinitions = map[string]TableDefinition{
461462
script.EpbScriptName,
462463
script.EppScriptName,
463464
script.EppValidScriptName,
465+
script.EppPackageControlScriptName,
464466
script.EppPackageScriptName,
465467
script.ScalingGovernorScriptName,
466468
script.UncoreMaxFromMSRScriptName,

internal/report/table_helpers.go

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,16 @@ func eppValToLabel(msr int) string {
871871
return fmt.Sprintf("%s (%d)", val, msr)
872872
}
873873

874+
// eppFromOutput gets EPP value from script outputs
875+
// IF 0x774[42] is '1' AND 0x774[60] is '0'
876+
// THEN
877+
//       get EPP from 0x772 (package)
878+
// ELSE
879+
//       get EPP from 0x774 (per core)
874880
func eppFromOutput(outputs map[string]script.ScriptOutput) string {
875-
eppValidConsistent := true
881+
// check if the epp valid bit is set and consistent across all cores
876882
var eppValid string
877-
for i, line := range strings.Split(outputs[script.EppValidScriptName].Stdout, "\n") {
883+
for i, line := range strings.Split(outputs[script.EppValidScriptName].Stdout, "\n") { // MSR 0x774, bit 60
878884
if line == "" {
879885
continue
880886
}
@@ -884,14 +890,36 @@ func eppFromOutput(outputs map[string]script.ScriptOutput) string {
884890
continue
885891
}
886892
if currentEpbValid != eppValid {
887-
eppValidConsistent = false
888-
break
893+
slog.Warn("EPP valid bit is inconsistent across cores")
894+
return "inconsistent"
889895
}
890896
}
891-
if eppValidConsistent && eppValid == "1" {
892-
eppConsistent := true
897+
// check if epp package control bit is set and consistent across all cores
898+
var eppPkgCtrl string
899+
for i, line := range strings.Split(outputs[script.EppPackageControlScriptName].Stdout, "\n") { // MSR 0x774, bit 42
900+
if line == "" {
901+
continue
902+
}
903+
currentEppPkgCtrl := strings.TrimSpace(strings.Split(line, ":")[1])
904+
if i == 0 {
905+
eppPkgCtrl = currentEppPkgCtrl
906+
continue
907+
}
908+
if currentEppPkgCtrl != eppPkgCtrl {
909+
slog.Warn("EPP package control bit is inconsistent across cores")
910+
return "inconsistent"
911+
}
912+
}
913+
if eppPkgCtrl == "1" && eppValid == "0" {
914+
eppPackage := strings.TrimSpace(outputs[script.EppPackageScriptName].Stdout) // MSR 0x772, bits 24-31 (package)
915+
msr, err := strconv.ParseInt(eppPackage, 16, 0)
916+
if err != nil {
917+
return "EPP pkg parse error"
918+
}
919+
return eppValToLabel(int(msr))
920+
} else {
893921
var epp string
894-
for i, line := range strings.Split(outputs[script.EppScriptName].Stdout, "\n") {
922+
for i, line := range strings.Split(outputs[script.EppScriptName].Stdout, "\n") { // MSR 0x774, bits 24-31 (per-core)
895923
if line == "" {
896924
continue
897925
}
@@ -901,30 +929,16 @@ func eppFromOutput(outputs map[string]script.ScriptOutput) string {
901929
continue
902930
}
903931
if currentEpp != epp {
904-
eppConsistent = false
905-
break
932+
slog.Warn("EPP is inconsistent across cores")
933+
return "inconsistent"
906934
}
907935
}
908-
if eppConsistent {
909-
msr, err := strconv.ParseInt(epp, 16, 0)
910-
if err != nil {
911-
return "epp parse error"
912-
}
913-
return eppValToLabel(int(msr))
914-
} else {
915-
return "Varied"
916-
}
917-
} else if eppValidConsistent && eppValid == "0" {
918-
eppPackage := strings.TrimSpace(outputs[script.EppPackageScriptName].Stdout)
919-
msr, err := strconv.ParseInt(eppPackage, 16, 0)
936+
msr, err := strconv.ParseInt(epp, 16, 0)
920937
if err != nil {
921-
return "epp pkg parse error"
938+
return "EPP parse error"
922939
}
923940
return eppValToLabel(int(msr))
924-
} else if eppValid != "" {
925-
return "Varied"
926941
}
927-
return ""
928942
}
929943

930944
func operatingSystemFromOutput(outputs map[string]script.ScriptOutput) string {

internal/script/script_defs.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const (
5959
EpbScriptName = "energy performance bias"
6060
EppScriptName = "energy performance preference"
6161
EppValidScriptName = "epp valid"
62+
EppPackageControlScriptName = "epp package control"
6263
EppPackageScriptName = "energy performance preference package"
6364
IaaDevicesScriptName = "iaa devices"
6465
DsaDevicesScriptName = "dsa devices"
@@ -337,6 +338,15 @@ fi`,
337338
Depends: []string{"rdmsr"},
338339
Superuser: true,
339340
},
341+
{
342+
Name: EppPackageControlScriptName,
343+
Script: "rdmsr -a -f 42:42 0x774", // IA32_HWP_REQUEST: Energy Performance Preference, bit 42 indicates if package control is enabled
344+
Architectures: []string{x86_64},
345+
Families: []string{"6"}, // Intel
346+
Lkms: []string{"msr"},
347+
Depends: []string{"rdmsr"},
348+
Superuser: true,
349+
},
340350
{
341351
Name: EppScriptName,
342352
Script: "rdmsr -a -f 31:24 0x774", // IA32_HWP_REQUEST: Energy Performance Preference, bits 24-31 (0 is highest perf, 255 is highest energy saving)

0 commit comments

Comments
 (0)