Skip to content

Commit 37ea66f

Browse files
authored
refactor scripts to use templating (#222)
1 parent 9111dff commit 37ea66f

File tree

10 files changed

+1034
-1013
lines changed

10 files changed

+1034
-1013
lines changed

cmd/config/config.go

Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func setCoreCount(cores int, myTarget target.Target, localTempDir string) (strin
406406
fmt.Printf("set core count per processor to %d on %s\n", cores, myTarget.GetName())
407407
setScript := script.ScriptDefinition{
408408
Name: "set core count",
409-
Script: fmt.Sprintf(`
409+
ScriptTemplate: fmt.Sprintf(`
410410
desired_core_count_per_socket=%d
411411
num_cpus=$(ls /sys/devices/system/cpu/ | grep -E "^cpu[0-9]+$" | wc -l)
412412
num_threads=$(lscpu | grep 'Thread(s) per core' | awk '{print $NF}')
@@ -544,14 +544,14 @@ func setLlcSize(llcSize float64, myTarget target.Target, localTempDir string) {
544544
}
545545
// set the LLC size
546546
setScript := script.ScriptDefinition{
547-
Name: "set LLC size",
548-
Script: fmt.Sprintf("wrmsr -a 0xC90 %d", cacheWays[waysToSet]),
549-
Superuser: true,
550-
Architectures: []string{"x86_64"},
551-
Families: []string{"6"}, // Intel only
552-
Models: []string{"63", "79", "86", "85", "106", "108", "143", "207"}, // not SRF, GNR
553-
Depends: []string{"wrmsr"},
554-
Lkms: []string{"msr"},
547+
Name: "set LLC size",
548+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0xC90 %d", cacheWays[waysToSet]),
549+
Superuser: true,
550+
Architectures: []string{"x86_64"},
551+
Families: []string{"6"}, // Intel only
552+
Models: []string{"63", "79", "86", "85", "106", "108", "143", "207"}, // not SRF, GNR
553+
Depends: []string{"wrmsr"},
554+
Lkms: []string{"msr"},
555555
}
556556
_, err = runScript(myTarget, setScript, localTempDir)
557557
if err != nil {
@@ -567,12 +567,12 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
567567
msr = msr | freqInt<<uint(i*8)
568568
}
569569
setScript := script.ScriptDefinition{
570-
Name: "set frequency bins",
571-
Script: fmt.Sprintf("wrmsr -a 0x1AD %d", msr),
572-
Superuser: true,
573-
Architectures: []string{"x86_64"},
574-
Families: []string{"6"}, // Intel only
575-
Depends: []string{"wrmsr"},
570+
Name: "set frequency bins",
571+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x1AD %d", msr),
572+
Superuser: true,
573+
Architectures: []string{"x86_64"},
574+
Families: []string{"6"}, // Intel only
575+
Depends: []string{"wrmsr"},
576576
}
577577
_, err := runScript(myTarget, setScript, localTempDir)
578578
if err != nil {
@@ -649,12 +649,12 @@ func setUncoreDieFrequency(maxFreq bool, computeDie bool, uncoreFrequency float6
649649
// run script for each die of specified type
650650
for _, die := range dies {
651651
setScript := script.ScriptDefinition{
652-
Name: "write max and min uncore frequency TPMI",
653-
Script: fmt.Sprintf("pcm-tpmi 2 0x18 -d -b %s -w %d -i %s -e %s", bits, value, die.instance, die.entry),
654-
Architectures: []string{"x86_64"},
655-
Families: []string{"6"}, // Intel only
656-
Depends: []string{"pcm-tpmi"},
657-
Superuser: true,
652+
Name: "write max and min uncore frequency TPMI",
653+
ScriptTemplate: fmt.Sprintf("pcm-tpmi 2 0x18 -d -b %s -w %d -i %s -e %s", bits, value, die.instance, die.entry),
654+
Architectures: []string{"x86_64"},
655+
Families: []string{"6"}, // Intel only
656+
Depends: []string{"pcm-tpmi"},
657+
Superuser: true,
658658
}
659659
_, err = runScript(myTarget, setScript, localTempDir)
660660
if err != nil {
@@ -674,13 +674,13 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
674674
fmt.Printf("set uncore %s frequency to %.1f GHz on %s\n", minmax, uncoreFrequency, myTarget.GetName())
675675
scripts := []script.ScriptDefinition{}
676676
scripts = append(scripts, script.ScriptDefinition{
677-
Name: "get uncore frequency MSR",
678-
Script: "rdmsr 0x620",
679-
Lkms: []string{"msr"},
680-
Architectures: []string{"x86_64"},
681-
Families: []string{"6"}, // Intel only
682-
Depends: []string{"rdmsr"},
683-
Superuser: true,
677+
Name: "get uncore frequency MSR",
678+
ScriptTemplate: "rdmsr 0x620",
679+
Lkms: []string{"msr"},
680+
Architectures: []string{"x86_64"},
681+
Families: []string{"6"}, // Intel only
682+
Depends: []string{"rdmsr"},
683+
Superuser: true,
684684
})
685685
outputs, err := script.RunScripts(myTarget, scripts, true, localTempDir)
686686
if err != nil {
@@ -727,13 +727,13 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
727727
newVal = newVal | newFreq<<8
728728
}
729729
setScript := script.ScriptDefinition{
730-
Name: "set uncore frequency MSR",
731-
Script: fmt.Sprintf("wrmsr -a 0x620 %d", newVal),
732-
Superuser: true,
733-
Architectures: []string{"x86_64"},
734-
Families: []string{"6"}, // Intel only
735-
Lkms: []string{"msr"},
736-
Depends: []string{"wrmsr"},
730+
Name: "set uncore frequency MSR",
731+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x620 %d", newVal),
732+
Superuser: true,
733+
Architectures: []string{"x86_64"},
734+
Families: []string{"6"}, // Intel only
735+
Lkms: []string{"msr"},
736+
Depends: []string{"wrmsr"},
737737
}
738738
_, err = runScript(myTarget, setScript, localTempDir)
739739
if err != nil {
@@ -744,13 +744,13 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
744744
func setPower(power int, myTarget target.Target, localTempDir string) {
745745
fmt.Printf("set power to %d Watts on %s\n", power, myTarget.GetName())
746746
readScript := script.ScriptDefinition{
747-
Name: "get power MSR",
748-
Script: "rdmsr 0x610",
749-
Superuser: true,
750-
Architectures: []string{"x86_64"},
751-
Families: []string{"6"}, // Intel only
752-
Lkms: []string{"msr"},
753-
Depends: []string{"rdmsr"},
747+
Name: "get power MSR",
748+
ScriptTemplate: "rdmsr 0x610",
749+
Superuser: true,
750+
Architectures: []string{"x86_64"},
751+
Families: []string{"6"}, // Intel only
752+
Lkms: []string{"msr"},
753+
Depends: []string{"rdmsr"},
754754
}
755755
readOutput, err := script.RunScript(myTarget, readScript, localTempDir)
756756
if err != nil {
@@ -768,13 +768,13 @@ func setPower(power int, myTarget target.Target, localTempDir string) {
768768
// add in the new power value
769769
newVal = newVal | uint64(power*8)
770770
setScript := script.ScriptDefinition{
771-
Name: "set tdp",
772-
Script: fmt.Sprintf("wrmsr -a 0x610 %d", newVal),
773-
Superuser: true,
774-
Architectures: []string{"x86_64"},
775-
Families: []string{"6"}, // Intel only
776-
Lkms: []string{"msr"},
777-
Depends: []string{"wrmsr"},
771+
Name: "set tdp",
772+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x610 %d", newVal),
773+
Superuser: true,
774+
Architectures: []string{"x86_64"},
775+
Families: []string{"6"}, // Intel only
776+
Lkms: []string{"msr"},
777+
Depends: []string{"wrmsr"},
778778
}
779779
_, err := runScript(myTarget, setScript, localTempDir)
780780
if err != nil {
@@ -787,13 +787,13 @@ func setPower(power int, myTarget target.Target, localTempDir string) {
787787
func setEpb(epb int, myTarget target.Target, localTempDir string) {
788788
fmt.Printf("set energy performance bias (EPB) to %d on %s\n", epb, myTarget.GetName())
789789
setScript := script.ScriptDefinition{
790-
Name: "set epb",
791-
Script: fmt.Sprintf("wrmsr -a 0x1B0 %d", epb),
792-
Superuser: true,
793-
Architectures: []string{"x86_64"},
794-
Families: []string{"6"}, // Intel only
795-
Lkms: []string{"msr"},
796-
Depends: []string{"wrmsr"},
790+
Name: "set epb",
791+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x1B0 %d", epb),
792+
Superuser: true,
793+
Architectures: []string{"x86_64"},
794+
Families: []string{"6"}, // Intel only
795+
Lkms: []string{"msr"},
796+
Depends: []string{"wrmsr"},
797797
}
798798
_, err := runScript(myTarget, setScript, localTempDir)
799799
if err != nil {
@@ -808,13 +808,13 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
808808

809809
// get the current value of the IAEW_HWP_REQUEST MSR that includes the current EPP valid value in bit 60
810810
getScript := script.ScriptDefinition{
811-
Name: "get epp msr",
812-
Script: "rdmsr 0x774", // IA32_HWP_REQUEST
813-
Architectures: []string{"x86_64"},
814-
Families: []string{"6"}, // Intel only
815-
Lkms: []string{"msr"},
816-
Depends: []string{"rdmsr"},
817-
Superuser: true,
811+
Name: "get epp msr",
812+
ScriptTemplate: "rdmsr 0x774", // IA32_HWP_REQUEST
813+
Architectures: []string{"x86_64"},
814+
Families: []string{"6"}, // Intel only
815+
Lkms: []string{"msr"},
816+
Depends: []string{"rdmsr"},
817+
Superuser: true,
818818
}
819819
stdout, err := runScript(myTarget, getScript, localTempDir)
820820
if err != nil {
@@ -832,13 +832,13 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
832832
eppValue := maskedValue | uint64(epp)<<24
833833
// write it back to the MSR
834834
setScript := script.ScriptDefinition{
835-
Name: "set epp",
836-
Script: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
837-
Superuser: true,
838-
Architectures: []string{"x86_64"},
839-
Families: []string{"6"}, // Intel only
840-
Lkms: []string{"msr"},
841-
Depends: []string{"wrmsr"},
835+
Name: "set epp",
836+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
837+
Superuser: true,
838+
Architectures: []string{"x86_64"},
839+
Families: []string{"6"}, // Intel only
840+
Lkms: []string{"msr"},
841+
Depends: []string{"wrmsr"},
842842
}
843843
_, err = runScript(myTarget, setScript, localTempDir)
844844
if err != nil {
@@ -848,13 +848,13 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
848848

849849
// get the current value of the IA32_HWP_REQUEST_PKG MSR that includes the current package EPP value
850850
getScript = script.ScriptDefinition{
851-
Name: "get epp pkg msr",
852-
Script: "rdmsr 0x772", // IA32_HWP_REQUEST_PKG
853-
Architectures: []string{"x86_64"},
854-
Families: []string{"6"}, // Intel only
855-
Lkms: []string{"msr"},
856-
Depends: []string{"rdmsr"},
857-
Superuser: true,
851+
Name: "get epp pkg msr",
852+
ScriptTemplate: "rdmsr 0x772", // IA32_HWP_REQUEST_PKG
853+
Architectures: []string{"x86_64"},
854+
Families: []string{"6"}, // Intel only
855+
Lkms: []string{"msr"},
856+
Depends: []string{"rdmsr"},
857+
Superuser: true,
858858
}
859859
stdout, err = runScript(myTarget, getScript, localTempDir)
860860
if err != nil {
@@ -873,13 +873,13 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
873873
eppValue = maskedValue | uint64(epp)<<24
874874
// write it back to the MSR
875875
setScript = script.ScriptDefinition{
876-
Name: "set epp",
877-
Script: fmt.Sprintf("wrmsr -a 0x772 %d", eppValue),
878-
Superuser: true,
879-
Architectures: []string{"x86_64"},
880-
Families: []string{"6"}, // Intel only
881-
Lkms: []string{"msr"},
882-
Depends: []string{"wrmsr"},
876+
Name: "set epp",
877+
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x772 %d", eppValue),
878+
Superuser: true,
879+
Architectures: []string{"x86_64"},
880+
Families: []string{"6"}, // Intel only
881+
Lkms: []string{"msr"},
882+
Depends: []string{"wrmsr"},
883883
}
884884
_, err = runScript(myTarget, setScript, localTempDir)
885885
if err != nil {
@@ -890,9 +890,9 @@ func setEpp(epp int, myTarget target.Target, localTempDir string) {
890890
func setGovernor(governor string, myTarget target.Target, localTempDir string) {
891891
fmt.Printf("set governor to %s on %s\n", governor, myTarget.GetName())
892892
setScript := script.ScriptDefinition{
893-
Name: "set governor",
894-
Script: fmt.Sprintf("echo %s | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor", governor),
895-
Superuser: true,
893+
Name: "set governor",
894+
ScriptTemplate: fmt.Sprintf("echo %s | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor", governor),
895+
Superuser: true,
896896
}
897897
_, err := runScript(myTarget, setScript, localTempDir)
898898
if err != nil {
@@ -913,13 +913,13 @@ func setElc(elc string, myTarget target.Target, localTempDir string) {
913913
return
914914
}
915915
setScript := script.ScriptDefinition{
916-
Name: "set elc",
917-
Script: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
918-
Superuser: true,
919-
Architectures: []string{"x86_64"},
920-
Families: []string{"6"}, // Intel only
921-
Models: []string{"173", "175"}, // GNR and SRF only
922-
Depends: []string{"bhs-power-mode.sh"},
916+
Name: "set elc",
917+
ScriptTemplate: fmt.Sprintf("bhs-power-mode.sh --%s", mode),
918+
Superuser: true,
919+
Architectures: []string{"x86_64"},
920+
Families: []string{"6"}, // Intel only
921+
Models: []string{"173", "175"}, // GNR and SRF only
922+
Depends: []string{"bhs-power-mode.sh"},
923923
}
924924
_, err := runScript(myTarget, setScript, localTempDir)
925925
if err != nil {

0 commit comments

Comments
 (0)