From 94410bd9f526b53ffed152ce5c2209ccb55f0b17 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 --- .../balloons/policy/balloons-policy.go | 27 +++++++++++++++++++ .../bases/config.nri_balloonspolicies.yaml | 6 +++++ .../crds/config.nri_balloonspolicies.yaml | 6 +++++ .../v1alpha1/resmgr/policy/balloons/config.go | 4 +++ 4 files changed, 43 insertions(+) diff --git a/cmd/plugins/balloons/policy/balloons-policy.go b/cmd/plugins/balloons/policy/balloons-policy.go index 490d43fe3..2544926fa 100644 --- a/cmd/plugins/balloons/policy/balloons-policy.go +++ b/cmd/plugins/balloons/policy/balloons-policy.go @@ -35,6 +35,9 @@ import ( ) const ( + highPrio = cpuallocator.PriorityHigh + lowPrio = cpuallocator.PriorityLow + // PolicyName is the name of this policy. PolicyName = "balloons" // PolicyDescription is a short description of this policy. @@ -56,6 +59,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 + // efficient E-cores. + virtDevECores = "efficient cores" + // virtDevPCores is the name of a virtual device close to + // performance P-cores. + virtDevPCores = "performance cores" ) // balloons contains configuration and runtime attributes of the balloons policy @@ -562,8 +571,14 @@ 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()[lowPrio]}, + virtDevPCores: {p.cpuAllocator.GetCPUPriorities()[highPrio]}, }, } + log.Info("###########################################") + log.Info(p.cpuAllocator.GetCPUPriorities()[lowPrio].String()) + log.Info(p.cpuAllocator.GetCPUPriorities()[highPrio].String()) + log.Info("###########################################") if blnDef.AllocatorTopologyBalancing != nil { allocatorOptions.topologyBalancing = *blnDef.AllocatorTopologyBalancing } @@ -1202,6 +1217,12 @@ func (p *balloons) fillCloseToDevices(blnDefs []*BalloonDef) { if blnDef.PreferIsolCpus { blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevIsolatedCpus) } + if blnDef.CoreType == "performance" { + blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevPCores) + } + if blnDef.CoreType == "efficient" { + blnDef.PreferCloseToDevices = append(blnDef.PreferCloseToDevices, virtDevECores) + } } } @@ -1221,6 +1242,12 @@ func (p *balloons) fillFarFromDevices(blnDefs []*BalloonDef) { avoidDevs = append(avoidDevs, virtDevIsolatedCpus) } for _, blnDef := range blnDefs { + if blnDef.CoreType == "efficient" { + avoidDevs = append(avoidDevs, virtDevECores) + } + if blnDef.CoreType == "performance" { + avoidDevs = append(avoidDevs, virtDevPCores) + } for _, closeDev := range blnDef.PreferCloseToDevices { if _, ok := devDefClose[closeDev]; !ok { avoidDevs = append(avoidDevs, closeDev) diff --git a/config/crd/bases/config.nri_balloonspolicies.yaml b/config/crd/bases/config.nri_balloonspolicies.yaml index 6babf6d1c..cb9abc945 100644 --- a/config/crd/bases/config.nri_balloonspolicies.yaml +++ b/config/crd/bases/config.nri_balloonspolicies.yaml @@ -78,6 +78,12 @@ spec: AllocatorTopologyBalancing is the balloon type specific parameter of the policy level parameter with the same name. type: boolean + coreType: + description: 'coreType: Accepts either performance or efficienct' + enum: + - efficient + - performance + type: string cpuClass: description: |- CpuClass controls how CPUs of a balloon are (re)configured diff --git a/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml b/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml index 6babf6d1c..cb9abc945 100644 --- a/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml +++ b/deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml @@ -78,6 +78,12 @@ spec: AllocatorTopologyBalancing is the balloon type specific parameter of the policy level parameter with the same name. type: boolean + coreType: + description: 'coreType: Accepts either performance or efficienct' + enum: + - efficient + - performance + type: string cpuClass: description: |- CpuClass controls how CPUs of a balloon are (re)configured diff --git a/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go b/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go index f5b73c17e..d4c9140ad 100644 --- a/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go +++ b/pkg/apis/config/v1alpha1/resmgr/policy/balloons/config.go @@ -219,6 +219,10 @@ type BalloonDef struct { // preferIsolCpus: prefer kernel isolated cpus // +kubebuilder:default:=false PreferIsolCpus bool `json:"preferIsolCpus,omitempty"` + // coreType: Accepts either performance or efficienct + // +optional + // +kubebuilder:validation:Enum:=efficient;performance + CoreType string `json:"coreType,omitempty"` } // String stringifies a BalloonDef