From 054924aa1473daff3393e131812cd7a0ed65e2a2 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Tue, 29 Oct 2024 17:31:26 +0100 Subject: [PATCH] UPSTREAM: : require configuration file enablement similarly to what we do for the managed CPU (aka workload partitioning) feature, introduce a master configuration file `/etc/kubernetes/openshift-llc-alignment` which needs to be present for the LLC alignment feature to be activated, in addition to the policy option being required. This can be dropped when the feature per KEP https://github.com/kubernetes/enhancements/issues/4800 goes beta. Signed-off-by: Francesco Romani --- pkg/kubelet/cm/cpumanager/policy_static.go | 17 +++++++- pkg/kubelet/llcalign/llcalign.go | 46 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 pkg/kubelet/llcalign/llcalign.go diff --git a/pkg/kubelet/cm/cpumanager/policy_static.go b/pkg/kubelet/cm/cpumanager/policy_static.go index 899c4dd7de5d8..fc4ce21af0130 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static.go +++ b/pkg/kubelet/cm/cpumanager/policy_static.go @@ -29,6 +29,7 @@ import ( "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager" "k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask" + "k8s.io/kubernetes/pkg/kubelet/llcalign" "k8s.io/kubernetes/pkg/kubelet/managed" "k8s.io/kubernetes/pkg/kubelet/metrics" "k8s.io/kubernetes/pkg/kubelet/types" @@ -138,6 +139,7 @@ func NewStaticPolicy(topology *topology.CPUTopology, numReservedCPUs int, reserv } klog.InfoS("Static policy created with configuration", "options", opts) + klog.InfoS("Static policy created with configuration", "llcAlignmentSupportEnabled", llcalign.IsEnabled()) policy := &staticPolicy{ topology: topology, @@ -511,7 +513,9 @@ func (p *staticPolicy) takeByTopology(availableCPUs cpuset.CPUSet, numCPUs int) return takeByTopologyNUMADistributed(p.topology, availableCPUs, numCPUs, cpuGroupSize, cpuSortingStrategy) } - return takeByTopologyNUMAPacked(p.topology, availableCPUs, numCPUs, cpuSortingStrategy, p.options.PreferAlignByUncoreCacheOption) + preferAlignByUncoreCacheOption := isAlignByUncoreCacheEnabled(p.options) + klog.V(4).InfoS("Taking CPUs", "requested", numCPUs, "llcAlignment", preferAlignByUncoreCacheOption) + return takeByTopologyNUMAPacked(p.topology, availableCPUs, numCPUs, cpuSortingStrategy, preferAlignByUncoreCacheOption) } func (p *staticPolicy) GetTopologyHints(s state.State, pod *v1.Pod, container *v1.Container) map[string][]topologymanager.TopologyHint { @@ -723,3 +727,14 @@ func (p *staticPolicy) getAlignedCPUs(numaAffinity bitmask.BitMask, allocatableC return alignedCPUs } + +func isAlignByUncoreCacheEnabled(options StaticPolicyOptions) bool { + if !options.PreferAlignByUncoreCacheOption { + return false + } + if !llcalign.IsEnabled() { + klog.V(4).InfoS("isAlignByUncoreCacheEnabled disabled because missing config file") + return false + } + return true +} diff --git a/pkg/kubelet/llcalign/llcalign.go b/pkg/kubelet/llcalign/llcalign.go new file mode 100644 index 0000000000000..11dcf0f18bfe6 --- /dev/null +++ b/pkg/kubelet/llcalign/llcalign.go @@ -0,0 +1,46 @@ +/* +Copyright 2024 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package llcalign + +import ( + "os" +) + +var ( + llcAlignmentEnabled bool + llcAlignmentFilename = "/etc/kubernetes/openshift-llc-alignment" +) + +func init() { + readEnablementFile() +} + +func readEnablementFile() { + if _, err := os.Stat(llcAlignmentFilename); err == nil { + llcAlignmentEnabled = true + } +} + +// TestOnlySetEnabled allows changing the state of management partition enablement +// This method MUST NOT be used outside of test code +func TestOnlySetEnabled(enabled bool) { + llcAlignmentEnabled = enabled +} + +func IsEnabled() bool { + return llcAlignmentEnabled +}