From 055cc1842fa3ea048b9429a2e517da21c3f2204d Mon Sep 17 00:00:00 2001 From: Feruzjon Muyassarov Date: Thu, 10 Oct 2024 11:44:46 +0300 Subject: [PATCH] balloons: set frequency scaling governor only when requested Avoid enforcing the frequency scaling governor if the user hasn't explicitly requested it. Previously, we attempted to set it regardless, leading to unnecessary error logs. Furthermore, fix formatting issue when logging error case. Signed-off-by: Feruzjon Muyassarov --- pkg/resmgr/control/cpu/api.go | 6 ++++-- pkg/resmgr/control/cpu/cpu.go | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pkg/resmgr/control/cpu/api.go b/pkg/resmgr/control/cpu/api.go index 22305698c..4d14ede17 100644 --- a/pkg/resmgr/control/cpu/api.go +++ b/pkg/resmgr/control/cpu/api.go @@ -61,8 +61,10 @@ func Assign(c cache.Cache, class string, cpus ...int) error { if err := ctl.enforceCpufreq(class, cpus...); err != nil { log.Error("cpufreq enforcement failed: %v", err) } - if err := ctl.enforceCpufreqGovernor(class, cpus...); err != nil { - log.Error("cpufreq governor enforcement failed: %v", err) + if _, ok := ctl.classes[class]; ok { + if err := ctl.enforceCpufreqGovernor(class, cpus...); err != nil { + log.Error("cpufreq governor enforcement failed: %v", err) + } } if err := ctl.enforceUncore(assignments, cpus...); err != nil { log.Error("uncore frequency enforcement failed: %v", err) diff --git a/pkg/resmgr/control/cpu/cpu.go b/pkg/resmgr/control/cpu/cpu.go index db4df2a3a..7e05ca7da 100644 --- a/pkg/resmgr/control/cpu/cpu.go +++ b/pkg/resmgr/control/cpu/cpu.go @@ -128,13 +128,15 @@ func (ctl *cpuctl) enforceCpufreqGovernor(class string, cpusIds ...int) error { if _, ok := ctl.classes[class]; !ok { return fmt.Errorf("non-existent cpu class %q", class) } - governor := ctl.classes[class].FreqGovernor - for cpu := range cpusIds { - log.Info(strconv.Itoa(cpu), governor) - } - log.Debug("enforcing cpu frequency governor %q on %v", governor, cpusIds) - if err := utils.SetScalingGovernorForCPUs(cpusIds, governor); err != nil { - return fmt.Errorf("Cannot set cpufreq governor %d: %w", governor, err) + if ctl.classes[class].FreqGovernor != "" { + governor := ctl.classes[class].FreqGovernor + for cpu := range cpusIds { + log.Info(strconv.Itoa(cpu), governor) + } + log.Debug("enforcing cpu frequency governor %q on %v", governor, cpusIds) + if err := utils.SetScalingGovernorForCPUs(cpusIds, governor); err != nil { + return fmt.Errorf("cannot set cpufreq governor %q: %w", governor, err) + } } return nil }