Skip to content

Commit c1fcd0f

Browse files
committed
WIP
Signed-off-by: Francesco Romani <[email protected]>
1 parent 4c5b2d2 commit c1fcd0f

File tree

4 files changed

+81
-25
lines changed

4 files changed

+81
-25
lines changed

pkg/performanceprofile/controller/performanceprofile/components/components.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ type Options struct {
4343
type MachineConfigOptions struct {
4444
PinningMode *apiconfigv1.CPUPartitioningMode
4545
MixedCPUsEnabled bool
46+
LLCFileEnabled bool
47+
}
48+
49+
func (mco *MachineConfigOptions) Clone() *MachineConfigOptions {
50+
ret := MachineConfigOptions{
51+
MixedCPUsEnabled: mco.MixedCPUsEnabled,
52+
LLCFileEnabled: mco.LLCFileEnabled,
53+
}
54+
if mco.PinningMode != nil {
55+
ret.PinningMode = new(apiconfigv1.CPUPartitioningMode)
56+
*ret.PinningMode = *mco.PinningMode
57+
}
58+
return &ret
4659
}
4760

4861
type KubeletConfigOptions struct {

pkg/performanceprofile/controller/performanceprofile/components/kubeletconfig/kubeletconfig.go

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package kubeletconfig
22

33
import (
44
"encoding/json"
5+
"strconv"
56
"time"
67

78
corev1 "k8s.io/api/core/v1"
@@ -27,35 +28,29 @@ const (
2728
// 4. Reserved CPUs
2829
// 5. Memory manager policy
2930
// Please avoid specifying them and use the relevant API to configure these parameters.
30-
experimentalKubeletSnippetAnnotation = "kubeletconfig.experimental"
31-
cpuManagerPolicyStatic = "static"
32-
cpuManagerPolicyOptionFullPCPUsOnly = "full-pcpus-only"
33-
memoryManagerPolicyStatic = "Static"
34-
defaultKubeReservedMemory = "500Mi"
35-
defaultSystemReservedMemory = "500Mi"
36-
defaultHardEvictionThresholdMemory = "100Mi"
37-
defaultHardEvictionThresholdNodefs = "10%"
38-
defaultHardEvictionThresholdImagefs = "15%"
39-
defaultHardEvictionThresholdNodefsInodesFree = "5%"
40-
evictionHardMemoryAvailable = "memory.available"
41-
evictionHardNodefsAvaialble = "nodefs.available"
42-
evictionHardImagefsAvailable = "imagefs.available"
43-
evictionHardNodefsInodesFree = "nodefs.inodesFree"
31+
experimentalKubeletSnippetAnnotation = "kubeletconfig.experimental"
32+
cpuManagerPolicyStatic = "static"
33+
cpuManagerPolicyOptionFullPCPUsOnly = "full-pcpus-only"
34+
cpuManagerPolicyOptionPreferAlignCPUsByUncoreCache = "prefer-align-cpus-by-uncorecache"
35+
memoryManagerPolicyStatic = "Static"
36+
defaultKubeReservedMemory = "500Mi"
37+
defaultSystemReservedMemory = "500Mi"
38+
defaultHardEvictionThresholdMemory = "100Mi"
39+
defaultHardEvictionThresholdNodefs = "10%"
40+
defaultHardEvictionThresholdImagefs = "15%"
41+
defaultHardEvictionThresholdNodefsInodesFree = "5%"
42+
evictionHardMemoryAvailable = "memory.available"
43+
evictionHardNodefsAvaialble = "nodefs.available"
44+
evictionHardImagefsAvailable = "imagefs.available"
45+
evictionHardNodefsInodesFree = "nodefs.inodesFree"
4446
)
4547

4648
// New returns new KubeletConfig object for performance sensetive workflows
4749
func New(profile *performancev2.PerformanceProfile, opts *components.KubeletConfigOptions) (*machineconfigv1.KubeletConfig, error) {
4850
name := components.GetComponentName(profile.Name, components.ComponentNamePrefix)
49-
kubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{}
50-
if v, ok := profile.Annotations[experimentalKubeletSnippetAnnotation]; ok {
51-
if err := json.Unmarshal([]byte(v), kubeletConfig); err != nil {
52-
return nil, err
53-
}
54-
}
55-
56-
kubeletConfig.TypeMeta = metav1.TypeMeta{
57-
APIVersion: kubeletconfigv1beta1.SchemeGroupVersion.String(),
58-
Kind: "KubeletConfiguration",
51+
kubeletConfig, err := NewKubeletConfigFromExperimentalAnnotation(profile)
52+
if err != nil {
53+
return nil, err
5954
}
6055

6156
kubeletConfig.CPUManagerPolicy = cpuManagerPolicyStatic
@@ -193,3 +188,37 @@ func addStringToQuantity(q *resource.Quantity, value string) error {
193188

194189
return nil
195190
}
191+
192+
func NewKubeletConfigFromExperimentalAnnotation(profile *performancev2.PerformanceProfile) (*kubeletconfigv1beta1.KubeletConfiguration, error) {
193+
kubeletConfig := &kubeletconfigv1beta1.KubeletConfiguration{}
194+
kubeletConfig.TypeMeta = metav1.TypeMeta{
195+
APIVersion: kubeletconfigv1beta1.SchemeGroupVersion.String(),
196+
Kind: "KubeletConfiguration",
197+
}
198+
199+
if v, ok := profile.Annotations[experimentalKubeletSnippetAnnotation]; ok {
200+
if err := json.Unmarshal([]byte(v), kubeletConfig); err != nil {
201+
return nil, err
202+
}
203+
}
204+
return kubeletConfig, nil
205+
}
206+
207+
func HasExperimentalOptionLLCEnabled(profile *performancev2.PerformanceProfile) bool {
208+
if profile == nil {
209+
return false
210+
}
211+
kubeletConfig, err := NewKubeletConfigFromExperimentalAnnotation(profile)
212+
if err != nil {
213+
return false
214+
}
215+
val, ok := kubeletConfig.CPUManagerPolicyOptions[cpuManagerPolicyOptionPreferAlignCPUsByUncoreCache]
216+
if !ok {
217+
return false
218+
}
219+
v, err := strconv.ParseBool(val)
220+
if err != nil {
221+
return false
222+
}
223+
return v
224+
}

pkg/performanceprofile/controller/performanceprofile/components/machineconfig/machineconfig.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ const (
7474
ovsDynamicPinningTriggerHostFile = "/var/lib/ovn-ic/etc/enable_dynamic_cpu_affinity"
7575

7676
cpusetConfigure = "cpuset-configure"
77+
78+
// required until the LLC support code (KEP-4800) goes at least Beta
79+
llcEnablementFile = "openshift-llc-alignment"
7780
)
7881

7982
const (
@@ -392,6 +395,15 @@ func getIgnitionConfig(profile *performancev2.PerformanceProfile, opts *componen
392395
}
393396
addContent(ignitionConfig, content, filepath.Join(kubernetesConfDir, mixedCPUsConfig), ptr.To[int](0644))
394397
}
398+
399+
// required until the LLC support code (KEP-4800) goes at least Beta
400+
if opts.LLCFileEnabled {
401+
// Note: the content of LLC (enablement) file does not matter. What matters is only the file presence.
402+
// If the file is present, the feature is available and can be enabled via the PerformanceProfile object.\
403+
// If the file is missing, the feature is forced off regardless of any PerformanceProfile object content.
404+
addContent(ignitionConfig, []byte{}, filepath.Join(kubernetesConfDir, llcEnablementFile), ptr.To[int](0644))
405+
}
406+
395407
return ignitionConfig, nil
396408
}
397409

pkg/performanceprofile/controller/performanceprofile/components/manifestset/manifestset.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ func (ms *ManifestResultSet) ToManifestTable() ManifestTable {
5353
func GetNewComponents(profile *performancev2.PerformanceProfile, opts *components.Options) (*ManifestResultSet, error) {
5454
machineConfigPoolSelector := profilecomponent.GetMachineConfigPoolSelector(profile, opts.ProfileMCP)
5555

56-
mc, err := machineconfig.New(profile, &opts.MachineConfig)
56+
mcOpts := opts.MachineConfig.Clone()
57+
mcOpts.LLCFileEnabled = kubeletconfig.HasExperimentalOptionLLCEnabled(profile)
58+
mc, err := machineconfig.New(profile, mcOpts)
5759
if err != nil {
5860
return nil, err
5961
}

0 commit comments

Comments
 (0)