Skip to content

Commit ae046a4

Browse files
authored
prepare target for configuration changes to avoid conflict and/or race condition (#398)
Signed-off-by: Harper, Jason M <jason.m.harper@intel.com>
1 parent 0937138 commit ae046a4

2 files changed

Lines changed: 63 additions & 35 deletions

File tree

cmd/config/config.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,32 @@ func runCmd(cmd *cobra.Command, args []string) error {
149149
return nil
150150
}
151151

152+
// prepareTarget prepares the target for configuration changes
153+
// almost all set scripts require the msr kernel module to be loaded and
154+
// use wrmsr and rdmsr, so we do that here so that the goroutines for the
155+
// set scripts can run in parallel without conflicts
156+
func prepareTarget(myTarget target.Target, localTempDir string) (err error) {
157+
prepareScript := script.ScriptDefinition{
158+
Name: "prepare-target",
159+
ScriptTemplate: "exit 0",
160+
Superuser: true,
161+
Vendors: []string{"GenuineIntel"},
162+
Depends: []string{"wrmsr", "rdmsr"},
163+
Lkms: []string{"msr"},
164+
}
165+
_, err = runScript(myTarget, prepareScript, localTempDir)
166+
return err
167+
}
168+
152169
func setOnTarget(cmd *cobra.Command, myTarget target.Target, flagGroups []flagGroup, localTempDir string, channelError chan error, statusUpdate progress.MultiSpinnerUpdateFunc) {
170+
// prepare the target for configuration changes
171+
_ = statusUpdate(myTarget.GetName(), "preparing target for configuration changes")
172+
if err := prepareTarget(myTarget, localTempDir); err != nil {
173+
_ = statusUpdate(myTarget.GetName(), fmt.Sprintf("error preparing target: %v", err))
174+
slog.Error(fmt.Sprintf("error preparing target %s: %v", myTarget.GetName(), err))
175+
channelError <- nil
176+
return
177+
}
153178
channelSetComplete := make(chan setOutput)
154179
var successMessages []string
155180
var errorMessages []string

cmd/config/set.go

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func setLlcSize(desiredLlcSize float64, myTarget target.Target, localTempDir str
172172
ScriptTemplate: fmt.Sprintf("wrmsr -a 0xC90 %d", msrVal),
173173
Superuser: true,
174174
Vendors: []string{"GenuineIntel"},
175-
Depends: []string{"wrmsr"},
176-
Lkms: []string{"msr"},
175+
// Depends: []string{"wrmsr"},
176+
// Lkms: []string{"msr"},
177177
}
178178
_, err = runScript(myTarget, setScript, localTempDir)
179179
if err != nil {
@@ -227,7 +227,8 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
227227
ScriptTemplate: fmt.Sprintf("wrmsr 0x774 %d", value),
228228
Superuser: true,
229229
Vendors: []string{"GenuineIntel"},
230-
Depends: []string{"wrmsr"},
230+
// Depends: []string{"wrmsr"},
231+
// Lkms: []string{"msr"},
231232
}
232233
} else {
233234
value := freqInt << uint(2*8)
@@ -236,7 +237,8 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
236237
ScriptTemplate: fmt.Sprintf("wrmsr 0x199 %d", value),
237238
Superuser: true,
238239
Vendors: []string{"GenuineIntel"},
239-
Depends: []string{"wrmsr"},
240+
// Depends: []string{"wrmsr"},
241+
// Lkms: []string{"msr"},
240242
}
241243
}
242244
} else {
@@ -250,7 +252,8 @@ func setCoreFrequency(coreFrequency float64, myTarget target.Target, localTempDi
250252
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x1AD %d", value),
251253
Superuser: true,
252254
Vendors: []string{"GenuineIntel"},
253-
Depends: []string{"wrmsr"},
255+
// Depends: []string{"wrmsr"},
256+
// Lkms: []string{"msr"},
254257
}
255258
}
256259
_, err = runScript(myTarget, setScript, localTempDir)
@@ -333,9 +336,9 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
333336
Name: "get uncore frequency MSR",
334337
ScriptTemplate: "rdmsr 0x620",
335338
Vendors: []string{"GenuineIntel"},
336-
Depends: []string{"rdmsr"},
337-
Lkms: []string{"msr"},
338339
Superuser: true,
340+
// Depends: []string{"rdmsr"},
341+
// Lkms: []string{"msr"},
339342
})
340343
outputs, err := script.RunScripts(myTarget, scripts, true, localTempDir)
341344
if err != nil {
@@ -379,8 +382,8 @@ func setUncoreFrequency(maxFreq bool, uncoreFrequency float64, myTarget target.T
379382
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x620 %d", newVal),
380383
Superuser: true,
381384
Vendors: []string{"GenuineIntel"},
382-
Lkms: []string{"msr"},
383-
Depends: []string{"wrmsr"},
385+
// Depends: []string{"wrmsr"},
386+
// Lkms: []string{"msr"},
384387
}
385388
_, err = runScript(myTarget, setScript, localTempDir)
386389
if err != nil {
@@ -395,8 +398,8 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
395398
ScriptTemplate: "rdmsr 0x610",
396399
Superuser: true,
397400
Vendors: []string{"GenuineIntel"},
398-
Lkms: []string{"msr"},
399-
Depends: []string{"rdmsr"},
401+
// Lkms: []string{"msr"},
402+
// Depends: []string{"rdmsr"},
400403
}
401404
readOutput, err := script.RunScript(myTarget, readScript, localTempDir)
402405
if err != nil {
@@ -418,8 +421,8 @@ func setTDP(power int, myTarget target.Target, localTempDir string, completeChan
418421
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x610 %d", newVal),
419422
Superuser: true,
420423
Vendors: []string{"GenuineIntel"},
421-
Lkms: []string{"msr"},
422-
Depends: []string{"wrmsr"},
424+
// Depends: []string{"wrmsr"},
425+
// Lkms: []string{"msr"},
423426
}
424427
_, err := runScript(myTarget, setScript, localTempDir)
425428
if err != nil {
@@ -457,9 +460,9 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
457460
Name: "read " + msr,
458461
ScriptTemplate: "rdmsr " + msr,
459462
Vendors: []string{"GenuineIntel"},
460-
Lkms: []string{"msr"},
461-
Depends: []string{"rdmsr"},
462463
Superuser: true,
464+
// Lkms: []string{"msr"},
465+
// Depends: []string{"rdmsr"},
463466
}
464467
readOutput, err := runScript(myTarget, readScript, localTempDir)
465468
if err != nil {
@@ -481,8 +484,8 @@ func setEPB(epb int, myTarget target.Target, localTempDir string, completeChanne
481484
ScriptTemplate: fmt.Sprintf("wrmsr -a %s %d", msr, msrValue),
482485
Superuser: true,
483486
Vendors: []string{"GenuineIntel"},
484-
Lkms: []string{"msr"},
485-
Depends: []string{"wrmsr"},
487+
// Depends: []string{"wrmsr"},
488+
// Lkms: []string{"msr"},
486489
}
487490
_, err = runScript(myTarget, setScript, localTempDir)
488491
if err != nil {
@@ -500,9 +503,9 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
500503
Name: "get epp msr",
501504
ScriptTemplate: "rdmsr 0x774", // IA32_HWP_REQUEST
502505
Vendors: []string{"GenuineIntel"},
503-
Lkms: []string{"msr"},
504-
Depends: []string{"rdmsr"},
505506
Superuser: true,
507+
// Lkms: []string{"msr"},
508+
// Depends: []string{"rdmsr"},
506509
}
507510
stdout, err := runScript(myTarget, getScript, localTempDir)
508511
if err != nil {
@@ -524,8 +527,8 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
524527
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x774 %d", eppValue),
525528
Superuser: true,
526529
Vendors: []string{"GenuineIntel"},
527-
Lkms: []string{"msr"},
528-
Depends: []string{"wrmsr"},
530+
// Depends: []string{"wrmsr"},
531+
// Lkms: []string{"msr"},
529532
}
530533
_, err = runScript(myTarget, setScript, localTempDir)
531534
if err != nil {
@@ -537,9 +540,9 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
537540
Name: "get epp pkg msr",
538541
ScriptTemplate: "rdmsr 0x772", // IA32_HWP_REQUEST_PKG
539542
Vendors: []string{"GenuineIntel"},
540-
Lkms: []string{"msr"},
541-
Depends: []string{"rdmsr"},
542543
Superuser: true,
544+
// Lkms: []string{"msr"},
545+
// Depends: []string{"rdmsr"},
543546
}
544547
stdout, err = runScript(myTarget, getScript, localTempDir)
545548
if err != nil {
@@ -561,8 +564,8 @@ func setEPP(epp int, myTarget target.Target, localTempDir string, completeChanne
561564
ScriptTemplate: fmt.Sprintf("wrmsr -a 0x772 %d", eppValue),
562565
Superuser: true,
563566
Vendors: []string{"GenuineIntel"},
564-
Lkms: []string{"msr"},
565-
Depends: []string{"wrmsr"},
567+
// Depends: []string{"wrmsr"},
568+
// Lkms: []string{"msr"},
566569
}
567570
_, err = runScript(myTarget, setScript, localTempDir)
568571
if err != nil {
@@ -601,7 +604,7 @@ func setELC(elc string, myTarget target.Target, localTempDir string, completeCha
601604
Superuser: true,
602605
Vendors: []string{"GenuineIntel"},
603606
Models: []string{"173", "174", "175", "221"}, // GNR, GNR-D, SRF, CWF
604-
Depends: []string{"bhs-power-mode.sh"},
607+
Depends: []string{"bhs-power-mode.sh", "pcm-tpmi"},
605608
}
606609
_, err := runScript(myTarget, setScript, localTempDir)
607610
if err != nil {
@@ -642,9 +645,9 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
642645
Name: "get prefetcher msr",
643646
ScriptTemplate: fmt.Sprintf("rdmsr %d", pf.Msr),
644647
Vendors: []string{"GenuineIntel"},
645-
Lkms: []string{"msr"},
646-
Depends: []string{"rdmsr"},
647648
Superuser: true,
649+
// Lkms: []string{"msr"},
650+
// Depends: []string{"rdmsr"},
648651
}
649652
stdout, err := runScript(myTarget, getScript, localTempDir)
650653
if err != nil {
@@ -675,10 +678,10 @@ func setPrefetcher(enableDisable string, myTarget target.Target, localTempDir st
675678
setScript := script.ScriptDefinition{
676679
Name: "set prefetcher" + prefetcherType,
677680
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", pf.Msr, newVal),
678-
Vendors: []string{"GenuineIntel"},
679-
Lkms: []string{"msr"},
680-
Depends: []string{"wrmsr"},
681681
Superuser: true,
682+
Vendors: []string{"GenuineIntel"},
683+
// Depends: []string{"wrmsr"},
684+
// Lkms: []string{"msr"},
682685
}
683686
_, err = runScript(myTarget, setScript, localTempDir)
684687
if err != nil {
@@ -747,9 +750,9 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
747750
Name: "get C1 demotion",
748751
ScriptTemplate: "rdmsr 0xe2",
749752
Vendors: []string{"GenuineIntel"},
750-
Lkms: []string{"msr"},
751-
Depends: []string{"rdmsr"},
752753
Superuser: true,
754+
// Lkms: []string{"msr"},
755+
// Depends: []string{"rdmsr"},
753756
}
754757
stdout, err := runScript(myTarget, getScript, localTempDir)
755758
if err != nil {
@@ -782,9 +785,9 @@ func setC1Demotion(enableDisable string, myTarget target.Target, localTempDir st
782785
Name: "set C1 demotion",
783786
ScriptTemplate: fmt.Sprintf("wrmsr -a %d %d", 0xe2, newVal),
784787
Vendors: []string{"GenuineIntel"},
785-
Lkms: []string{"msr"},
786-
Depends: []string{"wrmsr"},
787788
Superuser: true,
789+
// Depends: []string{"wrmsr"},
790+
// Lkms: []string{"msr"},
788791
}
789792
_, err = runScript(myTarget, setScript, localTempDir)
790793
if err != nil {

0 commit comments

Comments
 (0)