From f295f334cdfb67ddca64d9a0c0ba74d50c956397 Mon Sep 17 00:00:00 2001 From: Feruzjon Muyassarov Date: Mon, 12 Aug 2024 13:41:19 +0300 Subject: [PATCH] balloons: add support for picking efficient/performance cores This commit introduces a new field in the balloons configuration CR, enabling users to specify their efficient/performance core preferences for their workloads. When a user explicitly requests efficient or performance cores, the policy will attempt to allocate according to the user preferences. If the request cannot be satisfied, the policy will fall back to other available cores on the host. If a user adds `preferIsolCpus` in addition to specifying coreTypes, the policy will prioritize allocating isolated CPUs cores over the preferred efficient/performance cores, in case these sets are different. Signed-off-by: Feruzjon Muyassarov --- cmd/plugins/balloons/policy/balloons-policy.go | 15 ++++++++++++++- config/crd/bases/config.nri_balloonspolicies.yaml | 8 ++++++++ .../crds/config.nri_balloonspolicies.yaml | 8 ++++++++ .../v1alpha1/resmgr/policy/balloons/config.go | 5 +++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/cmd/plugins/balloons/policy/balloons-policy.go b/cmd/plugins/balloons/policy/balloons-policy.go index 490d43fe3..a5e4415f3 100644 --- a/cmd/plugins/balloons/policy/balloons-policy.go +++ b/cmd/plugins/balloons/policy/balloons-policy.go @@ -39,7 +39,6 @@ const ( PolicyName = "balloons" // PolicyDescription is a short description of this policy. PolicyDescription = "Flexible pools with per-pool CPU parameters" - // balloonKey is a pod annotation key, the value is a pod balloon name. balloonKey = "balloon." + PolicyName + "." + kubernetes.ResmgrKeyNamespace // hideHyperthreadsKey is a pod annotation key for pod/container-specific hyperthread allowance. @@ -56,6 +55,12 @@ const ( // virtDevIsolatedCpus is the name of a virtual device close to // host isolated CPUs. virtDevIsolatedCpus = "isolated CPUs" + // virtDevECores is the name of a virtual device close to + // power efficient cores. + virtDevECores = "efficient cores" + // virtDevPCores is the name of a virtual device close to + // high performance cores. + virtDevPCores = "performance cores" ) // balloons contains configuration and runtime attributes of the balloons policy @@ -562,6 +567,8 @@ func (p *balloons) newBalloon(blnDef *BalloonDef, confCpus bool) (*Balloon, erro virtDevCpusets: map[string][]cpuset.CPUSet{ virtDevReservedCpus: {p.reserved}, virtDevIsolatedCpus: {p.options.System.Isolated()}, + virtDevECores: {p.cpuAllocator.GetCPUPriorities()[cpuallocator.PriorityLow]}, + virtDevPCores: {p.cpuAllocator.GetCPUPriorities()[cpuallocator.PriorityHigh]}, }, } if blnDef.AllocatorTopologyBalancing != nil { @@ -1202,6 +1209,12 @@ func (p *balloons) fillCloseToDevices(blnDefs []*BalloonDef) { if blnDef.PreferIsolCpus { blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevIsolatedCpus) } + if blnDef.PreferCoreType == "performance" { + blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevPCores) + } + if blnDef.PreferCoreType == "efficient" { + blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevECores) + } } } diff --git a/config/crd/bases/config.nri_balloonspolicies.yaml b/config/crd/bases/config.nri_balloonspolicies.yaml index 6babf6d1c..16f1d3872 100644 --- a/config/crd/bases/config.nri_balloonspolicies.yaml +++ b/config/crd/bases/config.nri_balloonspolicies.yaml @@ -195,6 +195,14 @@ spec: items: type: string type: array + preferCoreType: + description: |- + preferCoreType: prefer performance or efficient (P/E) CPU cores on + hybrid architectures. + enum: + - efficient + - performance + type: string preferIsolCpus: default: false description: 'preferIsolCpus: prefer kernel isolated cpus' diff --git a/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml b/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml index 6babf6d1c..16f1d3872 100644 --- a/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml +++ b/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml @@ -195,6 +195,14 @@ spec: items: type: string type: array + preferCoreType: + description: |- + preferCoreType: prefer performance or efficient (P/E) CPU cores on + hybrid architectures. + enum: + - efficient + - performance + type: string preferIsolCpus: default: false description: 'preferIsolCpus: prefer kernel isolated cpus' diff --git a/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go b/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go index f5b73c17e..04b582e63 100644 --- a/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go +++ b/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go @@ -219,6 +219,11 @@ type BalloonDef struct { // preferIsolCpus: prefer kernel isolated cpus // +kubebuilder:default:=false PreferIsolCpus bool `json:"preferIsolCpus,omitempty"` + // preferCoreType: prefer performance or efficient (P/E) CPU cores on + // hybrid architectures. + // +optional + // +kubebuilder:validation:Enum:=efficient;performance + PreferCoreType string `json:"preferCoreType,omitempty"` } // String stringifies a BalloonDef