Skip to content

Commit e84ead2

Browse files
committed
UPSTREAM: <carry>: 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. Signed-off-by: Francesco Romani <[email protected]>
1 parent 0f089fa commit e84ead2

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

pkg/kubelet/cm/cpumanager/policy_static.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/topology"
3030
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager"
3131
"k8s.io/kubernetes/pkg/kubelet/cm/topologymanager/bitmask"
32+
"k8s.io/kubernetes/pkg/kubelet/llcalign"
3233
"k8s.io/kubernetes/pkg/kubelet/managed"
3334
"k8s.io/kubernetes/pkg/kubelet/metrics"
3435
"k8s.io/kubernetes/pkg/kubelet/types"
@@ -138,6 +139,7 @@ func NewStaticPolicy(topology *topology.CPUTopology, numReservedCPUs int, reserv
138139
}
139140

140141
klog.InfoS("Static policy created with configuration", "options", opts)
142+
klog.InfoS("Static policy created with configuration", "llcAlignment", llcalign.IsEnabled())
141143

142144
policy := &staticPolicy{
143145
topology: topology,
@@ -511,7 +513,9 @@ func (p *staticPolicy) takeByTopology(availableCPUs cpuset.CPUSet, numCPUs int)
511513
return takeByTopologyNUMADistributed(p.topology, availableCPUs, numCPUs, cpuGroupSize, cpuSortingStrategy)
512514
}
513515

514-
return takeByTopologyNUMAPacked(p.topology, availableCPUs, numCPUs, cpuSortingStrategy, p.options.PreferAlignByUncoreCacheOption)
516+
preferAlignByUncoreCacheOption := isAlignByUncoreCacheEnabled(p.options)
517+
klog.V(4).InfoS("Taking CPUs", "requested", numCPUs, "llcAlignment", preferAlignByUncoreCacheOption)
518+
return takeByTopologyNUMAPacked(p.topology, availableCPUs, numCPUs, cpuSortingStrategy, preferAlignByUncoreCacheOption)
515519
}
516520

517521
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
723727

724728
return alignedCPUs
725729
}
730+
731+
func isAlignByUncoreCacheEnabled(options StaticPolicyOptions) bool {
732+
if !options.PreferAlignByUncoreCacheOption {
733+
return false
734+
}
735+
if !llcalign.IsEnabled() {
736+
klog.V(4).InfoS("isAlignByUncoreCacheEnabled disabled because missing config file")
737+
return false
738+
}
739+
return true
740+
}

pkg/kubelet/llcalign/llcalign.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package llcalign
18+
19+
import (
20+
"os"
21+
)
22+
23+
var (
24+
llcAlignmentEnabled bool
25+
llcAlignmentFilename = "/etc/kubernetes/openshift-llc-alignment"
26+
)
27+
28+
func init() {
29+
readEnablementFile()
30+
}
31+
32+
func readEnablementFile() {
33+
if _, err := os.Stat(llcAlignmentFilename); err == nil {
34+
llcAlignmentEnabled = true
35+
}
36+
}
37+
38+
// TestOnlySetEnabled allows changing the state of management partition enablement
39+
// This method MUST NOT be used outside of test code
40+
func TestOnlySetEnabled(enabled bool) {
41+
llcAlignmentEnabled = enabled
42+
}
43+
44+
func IsEnabled() bool {
45+
return llcAlignmentEnabled
46+
}

0 commit comments

Comments
 (0)