Skip to content

Commit

Permalink
UPSTREAM: <carry>: require configuration file enablement
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Nov 19, 2024
1 parent 0f089fa commit e84ead2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/kubelet/cm/cpumanager/policy_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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", "llcAlignment", llcalign.IsEnabled())

policy := &staticPolicy{
topology: topology,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
46 changes: 46 additions & 0 deletions pkg/kubelet/llcalign/llcalign.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e84ead2

Please sign in to comment.