Skip to content

Commit 500a805

Browse files
committed
perfprof: enable exec-cpu-affinity by default
For High-performance configuration, cri-o started supporting exec-cpu-affinity feature and when configured to `first` it provides the ability for exec process to be pinned to the first CPU from the shared-CPUs IF set or to the first one from the islolated set. (see cri-o/cri-o@4dd7fb9) In performance profile, we want to enable this high-performance feature by default, and disbale it (legacy) it provides an annotation option. The annotation is there just as a backup in case of bugs getting reported by the consequences of this feature enablement, and should be removed in 2 releases. Signed-off-by: Shereen Haj <shajmakh@redhat.com>
1 parent ccb071f commit 500a805

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

assets/performanceprofile/configs/99-runtimes.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ infra_ctr_cpuset = "{{.ReservedCpus}}"
1111
# do not have high-performance binary under the $PATH that will point to it.
1212
[crio.runtime.runtimes.high-performance]
1313
inherit_default_runtime = true
14+
{{if .ExecCPUAffinity}}exec_cpu_affinity = "{{.ExecCPUAffinity}}"{{end}}
1415
allowed_annotations = ["cpu-load-balancing.crio.io", "cpu-quota.crio.io", "irq-load-balancing.crio.io", "cpu-c-states.crio.io", "cpu-freq-governor.crio.io"{{ if .CrioSharedCPUsAnnotation }}{{ printf ", %q" .CrioSharedCPUsAnnotation}}{{end}}]

pkg/apis/performanceprofile/v2/performanceprofile_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ const PerformanceProfileEnablePhysicalRpsAnnotation = "performance.openshift.io/
3434
// Valid values: "true", "enable" (to enable), "false", "disable" (to disable).
3535
const PerformanceProfileEnableRpsAnnotation = "performance.openshift.io/enable-rps"
3636

37+
// PerformanceProfileDisableExecCPUAffinityAnnotation disables the exec-cpu-affinity setting for the node.
38+
// Valid values: "true". Other values are ignored and treated as "false".
39+
// remove in 4.23
40+
const PerformanceProfileDisableExecCPUAffinityAnnotation = "performance.openshift.io/disable-exec-cpu-affinity"
41+
3742
// PerformanceProfileSpec defines the desired state of PerformanceProfile.
3843
type PerformanceProfileSpec struct {
3944
// CPU defines a set of CPU related parameters.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const (
118118
templateOvsSliceUsageFile = "01-use-ovs-slice.conf"
119119
templateWorkload = "Workload"
120120
templateCrioSharedCPUsAnnotation = "CrioSharedCPUsAnnotation"
121+
templateExecCPUAffinity = "ExecCPUAffinity"
121122
)
122123

123124
// New returns new machine configuration object for performance sensitive workloads
@@ -587,6 +588,10 @@ func renderCrioConfigSnippet(profile *performancev2.PerformanceProfile, src stri
587588
templateArgs[templateReservedCpus] = string(*profile.Spec.CPU.Reserved)
588589
}
589590

591+
if profilecomponent.IsExecCPUAffinityEnabled(profile) {
592+
templateArgs[templateExecCPUAffinity] = "first"
593+
}
594+
590595
if opts.MixedCPUsEnabled {
591596
templateArgs[templateSharedCpus] = string(*profile.Spec.CPU.Shared)
592597
templateArgs[templateCrioSharedCPUsAnnotation] = "cpu-shared.crio.io"

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"path/filepath"
89
"regexp"
910
"strings"
1011

@@ -141,6 +142,59 @@ var _ = Describe("Machine Config", func() {
141142
})
142143
})
143144

145+
Context("machine config creation with CRI-O runtime config", func() {
146+
crioRuntimeConfigPath := filepath.Join(crioConfd, crioRuntimesConfig)
147+
148+
It("should create machine config with exec-cpu-affinity set by default", func() {
149+
profile := testutils.NewPerformanceProfile("test")
150+
profile.Spec.CPU.Shared = nil
151+
152+
mc, err := New(profile, &components.MachineConfigOptions{})
153+
Expect(err).ToNot(HaveOccurred())
154+
155+
result := igntypes.Config{}
156+
Expect(json.Unmarshal(mc.Spec.Config.Raw, &result)).To(Succeed())
157+
158+
var content string
159+
for _, f := range result.Storage.Files {
160+
if f.Path == crioRuntimeConfigPath {
161+
base64Data := strings.TrimPrefix(*f.Contents.Source, "data:text/plain;charset=utf-8;base64,")
162+
decoded, err := base64.StdEncoding.DecodeString(base64Data)
163+
Expect(err).ToNot(HaveOccurred())
164+
content = string(decoded)
165+
break
166+
}
167+
}
168+
Expect(content).ToNot(BeEmpty(), "crio runtime config not found")
169+
Expect(content).To(ContainSubstring("exec_cpu_affinity = \"first\""))
170+
})
171+
172+
It("should create machine config without exec-cpu-affinity when annotation is set to true", func() {
173+
profile := testutils.NewPerformanceProfile("test")
174+
profile.Annotations = map[string]string{}
175+
profile.Annotations[performancev2.PerformanceProfileDisableExecCPUAffinityAnnotation] = "true"
176+
177+
mc, err := New(profile, &components.MachineConfigOptions{})
178+
Expect(err).ToNot(HaveOccurred())
179+
180+
result := igntypes.Config{}
181+
Expect(json.Unmarshal(mc.Spec.Config.Raw, &result)).To(Succeed())
182+
183+
var content string
184+
for _, f := range result.Storage.Files {
185+
if f.Path == crioRuntimeConfigPath {
186+
base64Data := strings.TrimPrefix(*f.Contents.Source, "data:text/plain;charset=utf-8;base64,")
187+
decoded, err := base64.StdEncoding.DecodeString(base64Data)
188+
Expect(err).ToNot(HaveOccurred())
189+
content = string(decoded)
190+
break
191+
}
192+
}
193+
Expect(content).ToNot(BeEmpty(), "crio runtime config not found")
194+
Expect(content).To(Not(ContainSubstring("exec_cpu_affinity = \"first\"")))
195+
})
196+
})
197+
144198
Context("machine config creation with enabled RPS using alternative values", func() {
145199
It("should create machine config with RPS configuration when enabled with 'enable'", func() {
146200
profile := testutils.NewPerformanceProfile("test")

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,17 @@ func IsMixedCPUsEnabled(profile *performancev2.PerformanceProfile) bool {
9494
}
9595
return *profile.Spec.WorkloadHints.MixedCpus
9696
}
97+
98+
// IsExecCPUAffinityEnabled checks if exec-cpu-affinity feature should be enabled
99+
func IsExecCPUAffinityEnabled(profile *performancev2.PerformanceProfile) bool {
100+
if profile.Annotations != nil {
101+
isExecCPUAffinityDisabled, ok := profile.Annotations[performancev2.PerformanceProfileDisableExecCPUAffinityAnnotation]
102+
if ok && isExecCPUAffinityDisabled == "true" {
103+
// run the legacy behavior and disable exec-cpu-affinity
104+
return false
105+
}
106+
}
107+
108+
// The default behavior is to enable exec-cpu-affinity whenever profile is applied
109+
return true
110+
}

0 commit comments

Comments
 (0)