Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

balloons: add support for cpu frequency governor tuning #374

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
klihub marked this conversation as resolved.
Show resolved Hide resolved
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