Skip to content

Commit

Permalink
balloons: add support for cpu frequency governor tuning
Browse files Browse the repository at this point in the history
This commit introduces a new field in the balloons configuration CR,
enabling users to specify CPU frequency governor mode preferences.

Signed-off-by: Feruzjon Muyassarov <[email protected]>
  • Loading branch information
fmuyassarov authored and klihub committed Oct 7, 2024
1 parent 7399adb commit 8a8d920
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/crd/bases/config.nri_balloonspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/config.nri_templatepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/config.nri_topologyawarepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ spec:
description: EnergyPerformancePreference for CPUs in
this class.
type: integer
freqGovernor:
description: CPUFreq Governor for this class.
type: string
maxFreq:
description: MaxFreq is the maximum frequency for this
class.
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/config/v1alpha1/resmgr/control/cpu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ type Class struct {
UncoreMinFreq uint `json:"uncoreMinFreq,omitempty"`
// UncoreMaxFreq is the maximum uncore frequency for this class.
UncoreMaxFreq uint `json:"uncoreMaxFreq,omitempty"`
// CPUFreq Governor for this class.
FreqGovernor string `json:"freqGovernor,omitempty"`
}
3 changes: 3 additions & 0 deletions pkg/resmgr/control/cpu/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ 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 err := ctl.enforceUncore(assignments, cpus...); err != nil {
log.Error("uncore frequency enforcement failed: %v", err)
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/resmgr/control/cpu/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cpu

import (
"fmt"
"strconv"

"github.com/containers/nri-plugins/pkg/utils/cpuset"

Expand Down Expand Up @@ -122,6 +123,22 @@ func (ctl *cpuctl) PostStopHook(c cache.Container) error {
return nil
}

// enforceCpufreqGovernor enforces a class-specific cpufreq governor to a cpuset.
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)
}
return nil
}

// enforceCpufreq enforces a class-specific cpufreq configuration to a cpuset
func (ctl *cpuctl) enforceCpufreq(class string, cpus ...int) error {
if _, ok := ctl.classes[class]; !ok {
Expand Down Expand Up @@ -259,6 +276,9 @@ func (ctl *cpuctl) configure(cfg *cfgapi.Config) error {
if err := ctl.enforceCpufreq(class, cpus.SortedMembers()...); err != nil {
log.Error("cpufreq enforcement on re-configure failed: %v", err)
}
if err := ctl.enforceCpufreqGovernor(class, cpus.SortedMembers()...); err != nil {
log.Error("cpufreq enforcement on re-configure failed: %v", err)
}
} else {
// TODO: what should we really do with classes that do not exist in
// the configuration anymore? Now we remember the CPUs assigned to
Expand Down

0 comments on commit 8a8d920

Please sign in to comment.