Skip to content

Commit

Permalink
OCPBUGS-45264: Normalize cpu sets when rendering to Tuned profiles
Browse files Browse the repository at this point in the history
Previously the isolated cpu list was passed verbatim as the user
entered it. This could have resulted in very long kernel command
line.

Example: 10,9,8,7,6,5,4,3,2,1 (imagine 500+ cpus)

This change consolidates the parsing logic in the Tuned templating
and generates simply the following in such case.

Example: 1-10
  • Loading branch information
MarSik committed Dec 2, 2024
1 parent c786628 commit b25aa76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,32 +64,28 @@ func NewNodePerformance(profile *performancev2.PerformanceProfile) (*tunedv1.Tun
templateArgs[templatePerformanceProfileName] = profile.Name

if profile.Spec.CPU.Isolated != nil {
templateArgs[templateIsolatedCpus] = string(*profile.Spec.CPU.Isolated)
if profile.Spec.CPU.BalanceIsolated != nil && !*profile.Spec.CPU.BalanceIsolated {
templateArgs[templateStaticIsolation] = strconv.FormatBool(true)
minifiedCpuSet, err := cpuset.Parse(string(*profile.Spec.CPU.Isolated))
if err != nil {
return nil, fmt.Errorf("cannot parse isolated cpuset: %v", err)
}
templateArgs[templateIsolatedCpus] = minifiedCpuSet.String()
templateArgs[templateIsolatedCpuList] = minifiedCpuSet.List()
}

if profile.Spec.HardwareTuning != nil {
isolatedCpuSet, err := cpuset.Parse(string(*profile.Spec.CPU.Isolated))
if profile.Spec.CPU.Reserved != nil {
minifiedCpuSet, err := cpuset.Parse(string(*profile.Spec.CPU.Reserved))
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot parse reserved cpuset: %v", err)
}
isolatedCpuString := components.ListToString(isolatedCpuSet.List())
// converts a string to a string slice
isolatedCpuList := strings.SplitN(isolatedCpuString, ",", len(isolatedCpuString))
templateArgs[templateReservedCpuList] = minifiedCpuSet.List()
}

reservedSet, err := cpuset.Parse(string(*profile.Spec.CPU.Reserved))
if err != nil {
return nil, err
}
reservedCpuString := components.ListToString(reservedSet.List())
// converts a string to a string slice
reservedCpuList := strings.SplitN(reservedCpuString, ",", len(reservedCpuString))
if profile.Spec.CPU.BalanceIsolated != nil && !*profile.Spec.CPU.BalanceIsolated {
templateArgs[templateStaticIsolation] = strconv.FormatBool(true)
}

if profile.Spec.HardwareTuning != nil {
templateArgs[templateHardwareTuning] = strconv.FormatBool(true)
templateArgs[templateIsolatedCpuList] = isolatedCpuList
templateArgs[templateReservedCpuList] = reservedCpuList
templateArgs[templateIsolatedCpuMaxFreq] = int(*profile.Spec.HardwareTuning.IsolatedCpuFreq)
templateArgs[templateReservedCpuMaxFreq] = int(*profile.Spec.HardwareTuning.ReservedCpuFreq)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ var _ = Describe("Tuned", func() {
Expect(bootLoaderSection.Key("cmdline_realtime_common").String()).To(Equal(cmdlineRealtimeCommon))
})

It("should normalize cpusets", func() {
test_profile := testutils.NewPerformanceProfile("test")
isolated_cpus := performancev2.CPUSet("10,9,8,7,6,5,4,3,2,1,21,22,23,24,25,26,27,28")
reserved_cpus := performancev2.CPUSet("11-15,19,18,17,16")

test_profile.Spec.CPU.Isolated = &isolated_cpus
test_profile.Spec.CPU.Reserved = &reserved_cpus

tunedData := getTunedStructuredData(test_profile, components.ProfileNamePerformance)
isolated, err := tunedData.GetSection("variables")
Expect(err).ToNot(HaveOccurred())

Expect(isolated.Key("isolated_cores").String()).To(Equal("1-10,21-28"))
})

Context("default profile default tuned", func() {
It("should [cpu] section in tuned", func() {
tunedData := getTunedStructuredData(profile, components.ProfileNamePerformance)
Expand Down

0 comments on commit b25aa76

Please sign in to comment.