Skip to content
Merged
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
20 changes: 20 additions & 0 deletions api/v1/cpuscalingconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ type ConfigItem struct {
//+kubebuilder:validation:Format=duration
SamplePeriod metav1.Duration `json:"samplePeriod"`

// Time to elapse after setting a new frequency target before next CPU sampling
//+kubebuilder:validation:Format=duration
CooldownPeriod metav1.Duration `json:"cooldownPeriod"`

// Target CPU busyness, in percents
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
TargetBusyness int `json:"targetBusyness"`

// Maximum difference between target and actual CPU busyness on which
// frequency re-evaluation will not happen, in percent points
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=50
AllowedBusynessDifference int `json:"allowedBusynessDifference"`

// Maximum difference between target and actual CPU frequency on which
// frequency re-evaluation will not happen, in MHz
// +kubebuilder:validation:Minimum=0
AllowedFrequencyDifference int `json:"allowedFrequencyDifference,omitempty"`

// UID of the Pod that this ConfigItem is associated with
PodUID types.UID `json:"podUID"`
}
Expand Down
27 changes: 22 additions & 5 deletions api/v1/cpuscalingprofile_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,36 @@ import (

// CPUScalingProfileSpec defines the desired state of CPUScalingProfile
type CPUScalingProfileSpec struct {
// Name of the CPUScalingProfile
Name string `json:"name"`

// Minimum time to elapse between two CPU sample periods
//+kubebuilder:validation:Format=duration
SamplePeriod *metav1.Duration `json:"samplePeriod,omitempty"`

// Max frequency cores can run at
// Time to elapse after setting a new frequency target before next CPU sampling
// +kubebuilder:validation:Format=duration
CooldownPeriod *metav1.Duration `json:"cooldownPeriod,omitempty"`

// Target CPU busyness, in percents
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
TargetBusyness *int `json:"targetBusyness,omitempty"`

// Maximum difference between target and actual CPU busyness on which
// frequency re-evaluation will not happen, in percent points
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=50
AllowedBusynessDifference *int `json:"allowedBusynessDifference,omitempty"`

// Maximum difference between target and actual CPU frequency on which
// frequency re-evaluation will not happen, in MHz
// +kubebuilder:validation:Minimum=0
AllowedFrequencyDifference *int `json:"allowedFrequencyDifference,omitempty"`

// Maximum frequency CPUs can run at
//+kubebuilder:validation:XIntOrString
//+kubebuilder:validation:Pattern="^([1-9]?[0-9]|100)%$"
Max *intstr.IntOrString `json:"max,omitempty"`

// Min frequency cores can run at
// Minimum frequency CPUs can run at
//+kubebuilder:validation:XIntOrString
//+kubebuilder:validation:Pattern="^([1-9]?[0-9]|100)%$"
Min *intstr.IntOrString `json:"min,omitempty"`
Expand Down
21 changes: 21 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions config/crd/bases/power.intel.com_cpuscalingconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ spec:
description: List of configurations that should be applied on a node.
items:
properties:
allowedBusynessDifference:
description: |-
Maximum difference between target and actual CPU busyness on which
frequency re-evaluation will not happen, in percent points
maximum: 50
minimum: 0
type: integer
allowedFrequencyDifference:
description: |-
Maximum difference between target and actual CPU frequency on which
frequency re-evaluation will not happen, in MHz
minimum: 0
type: integer
cooldownPeriod:
description: Time to elapse after setting a new frequency target
before next CPU sampling
format: duration
type: string
cpuIDs:
description: List of CPU IDs which should adhere to the configuration
in this item
Expand All @@ -70,12 +88,20 @@ spec:
description: Minimum time to elapse between two CPU sample periods
format: duration
type: string
targetBusyness:
description: Target CPU busyness, in percents
maximum: 100
minimum: 0
type: integer
required:
- allowedBusynessDifference
- cooldownPeriod
- cpuIDs
- fallbackFreqPercent
- podUID
- powerProfile
- samplePeriod
- targetBusyness
type: object
type: array
type: object
Expand Down
32 changes: 25 additions & 7 deletions config/crd/bases/power.intel.com_cpuscalingprofiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ spec:
spec:
description: CPUScalingProfileSpec defines the desired state of CPUScalingProfile
properties:
allowedBusynessDifference:
description: |-
Maximum difference between target and actual CPU busyness on which
frequency re-evaluation will not happen, in percent points
maximum: 50
minimum: 0
type: integer
allowedFrequencyDifference:
description: |-
Maximum difference between target and actual CPU frequency on which
frequency re-evaluation will not happen, in MHz
minimum: 0
type: integer
cooldownPeriod:
description: Time to elapse after setting a new frequency target before
next CPU sampling
format: duration
type: string
epp:
description: The priority value associated with this CPUScalingProfile
enum:
Expand All @@ -51,25 +69,25 @@ spec:
anyOf:
- type: integer
- type: string
description: Max frequency cores can run at
description: Maximum frequency CPUs can run at
pattern: ^([1-9]?[0-9]|100)%$
x-kubernetes-int-or-string: true
min:
anyOf:
- type: integer
- type: string
description: Min frequency cores can run at
description: Minimum frequency CPUs can run at
pattern: ^([1-9]?[0-9]|100)%$
x-kubernetes-int-or-string: true
name:
description: Name of the CPUScalingProfile
type: string
samplePeriod:
description: Minimum time to elapse between two CPU sample periods
format: duration
type: string
required:
- name
targetBusyness:
description: Target CPU busyness, in percents
maximum: 100
minimum: 0
type: integer
type: object
status:
description: CPUScalingProfileStatus defines the observed state of CPUScalingProfile
Expand Down
40 changes: 28 additions & 12 deletions internal/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,55 @@ type eppValues struct {
var eppDefaults map[powerv1.EPP]eppValues = map[powerv1.EPP]eppValues{
powerv1.EPPPerformance: {
cpuScalingProfileSpec: powerv1.CPUScalingProfileSpec{
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
CooldownPeriod: &metav1.Duration{Duration: 3 * 10 * time.Millisecond},
TargetBusyness: ptr.To(80),
AllowedBusynessDifference: ptr.To(5),
AllowedFrequencyDifference: ptr.To(25),
},
configItem: powerv1.ConfigItem{
FallbackFreqPercent: 100,
},
},
powerv1.EPPBalancePerformance: {
cpuScalingProfileSpec: powerv1.CPUScalingProfileSpec{
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
CooldownPeriod: &metav1.Duration{Duration: 3 * 10 * time.Millisecond},
TargetBusyness: ptr.To(80),
AllowedBusynessDifference: ptr.To(5),
AllowedFrequencyDifference: ptr.To(25),
},
configItem: powerv1.ConfigItem{
FallbackFreqPercent: 50,
},
},
powerv1.EPPBalancePower: {
cpuScalingProfileSpec: powerv1.CPUScalingProfileSpec{
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
CooldownPeriod: &metav1.Duration{Duration: 3 * 10 * time.Millisecond},
TargetBusyness: ptr.To(80),
AllowedBusynessDifference: ptr.To(5),
AllowedFrequencyDifference: ptr.To(25),
},
configItem: powerv1.ConfigItem{
FallbackFreqPercent: 25,
},
},
powerv1.EPPPower: {
cpuScalingProfileSpec: powerv1.CPUScalingProfileSpec{
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
Min: ptr.To(intstr.FromString("0%")),
Max: ptr.To(intstr.FromString("100%")),
SamplePeriod: &metav1.Duration{Duration: 10 * time.Millisecond},
CooldownPeriod: &metav1.Duration{Duration: 3 * 10 * time.Millisecond},
TargetBusyness: ptr.To(80),
AllowedBusynessDifference: ptr.To(5),
AllowedFrequencyDifference: ptr.To(25),
},
configItem: powerv1.ConfigItem{
FallbackFreqPercent: 0,
Expand Down
27 changes: 24 additions & 3 deletions internal/controller/cpuscalingconfiguration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (r *CPUScalingConfigurationReconciler) Reconcile(ctx context.Context, req c
logger.Error(err, "error validating sample periods")
return ctrl.Result{}, nil
}
err = r.validateCooldownPeriods(config.Spec.Items)
if err != nil {
logger.Error(err, "error validating cooldown periods")
return ctrl.Result{}, nil
}

r.CPUScalingManager.UpdateConfig(
r.parseConfig(config.Spec.Items),
Expand Down Expand Up @@ -145,6 +150,18 @@ func (r *CPUScalingConfigurationReconciler) validateSamplePeriods(configItems []
return nil
}

func (r *CPUScalingConfigurationReconciler) validateCooldownPeriods(configItems []powerv1.ConfigItem) error {
for _, item := range configItems {
cooldownPeriod := item.CooldownPeriod.Duration
samplePeriod := item.SamplePeriod.Duration
if cooldownPeriod < samplePeriod {
return fmt.Errorf("cooldown period %s must be larger than sample period %s", cooldownPeriod, samplePeriod)
}
}

return nil
}

func (r *CPUScalingConfigurationReconciler) parseConfig(configItems []powerv1.ConfigItem) []scaling.CPUScalingOpts {
optsList := make([]scaling.CPUScalingOpts, 0)

Expand All @@ -156,9 +173,13 @@ func (r *CPUScalingConfigurationReconciler) parseConfig(configItems []powerv1.Co
}
for _, cpuID := range item.CpuIDs {
opts := scaling.CPUScalingOpts{
CPUID: cpuID,
SamplePeriod: item.SamplePeriod.Duration,
FallbackFreq: fallbackFreq,
CPUID: cpuID,
SamplePeriod: item.SamplePeriod.Duration,
CooldownPeriod: item.CooldownPeriod.Duration,
TargetBusyness: item.TargetBusyness,
AllowedBusynessDifference: item.AllowedBusynessDifference,
AllowedFrequencyDifference: item.AllowedFrequencyDifference,
FallbackFreq: fallbackFreq,
}
optsList = append(optsList, opts)
}
Expand Down
Loading
Loading