diff --git a/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned.go b/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned.go index ce56d0230..7d7f8ef4c 100644 --- a/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned.go +++ b/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned.go @@ -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) } diff --git a/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned_test.go b/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned_test.go index 47227d8d7..2b875dece 100644 --- a/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned_test.go +++ b/pkg/performanceprofile/controller/performanceprofile/components/tuned/tuned_test.go @@ -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)